Re: [V3 PATCH 07/16] powerpc/vas: Define QoS credit flag to allocate window

2021-05-09 Thread Nicholas Piggin
Excerpts from Haren Myneni's message of April 18, 2021 7:06 am:
> 
> pHyp introduces two different type of credits: Default and Quality
> of service (QoS).
> 
> The total number of default credits available on each LPAR depends
> on CPU resources configured. But these credits can be shared or
> over-committed across LPARs in shared mode which can result in
> paste command failure (RMA_busy). To avoid NX HW contention, phyp
> introduces QoS credit type which makes sure guaranteed access to NX
> resources. The system admins can assign QoS credits for each LPAR
> via HMC.
> 
> Default credit type is used to allocate a VAS window by default as
> on powerVM implementation. But the process can pass VAS_WIN_QOS_CREDITS


There's some interchanging of pHyp and PowerVM in the series.

PowerVM is probably the better term to use, with uppercase P.
Unless you mean PAPR or pseries etc.

I think you can say the PAPR VAS spec has two different types of 
credits, rather than say a specific hypervisor is introducing them.

> flag with VAS_TX_WIN_OPEN ioctl to open QoS type window.
> 
> Signed-off-by: Haren Myneni 
> ---
>  arch/powerpc/include/uapi/asm/vas-api.h | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/include/uapi/asm/vas-api.h 
> b/arch/powerpc/include/uapi/asm/vas-api.h
> index ebd4b2424785..eb7c8694174f 100644
> --- a/arch/powerpc/include/uapi/asm/vas-api.h
> +++ b/arch/powerpc/include/uapi/asm/vas-api.h
> @@ -13,11 +13,15 @@
>  #define VAS_MAGIC'v'
>  #define VAS_TX_WIN_OPEN  _IOW(VAS_MAGIC, 0x20, struct 
> vas_tx_win_open_attr)
>  
> +/* Flags to VAS TX open window ioctl */
> +/* To allocate a window with QoS credit, otherwise default credit is used */
> +#define  VAS_WIN_QOS_CREDITS 0x0001
> +
>  struct vas_tx_win_open_attr {

Some consistency of naming might help, VAS_TX_WIN_FLAG_QOS_CREDIT.

>   __u32   version;
>   __s16   vas_id; /* specific instance of vas or -1 for default */
>   __u16   reserved1;
> - __u64   flags;  /* Future use */
> + __u64   flags;
>   __u64   reserved2[6];
>  };
>  
> -- 
> 2.18.2
> 
> 
> 


Re: [V3 PATCH 06/16] powerpc/pseries/vas: Define VAS/NXGZIP HCALLs and structs

2021-05-09 Thread Nicholas Piggin
Excerpts from Haren Myneni's message of April 18, 2021 7:05 am:
> 
> This patch adds HCALLs and other definitions. Also define structs
> that are used in VAS implementation on powerVM.
> 
> Signed-off-by: Haren Myneni 
> ---
>  arch/powerpc/include/asm/hvcall.h|  7 ++
>  arch/powerpc/include/asm/vas.h   | 28 
>  arch/powerpc/platforms/pseries/vas.h | 96 
>  3 files changed, 131 insertions(+)
>  create mode 100644 arch/powerpc/platforms/pseries/vas.h
> 
> diff --git a/arch/powerpc/include/asm/hvcall.h 
> b/arch/powerpc/include/asm/hvcall.h
> index ed6086d57b22..accbb7f6f272 100644
> --- a/arch/powerpc/include/asm/hvcall.h
> +++ b/arch/powerpc/include/asm/hvcall.h
> @@ -294,6 +294,13 @@
>  #define H_RESIZE_HPT_COMMIT  0x370
>  #define H_REGISTER_PROC_TBL  0x37C
>  #define H_SIGNAL_SYS_RESET   0x380
> +#define  H_ALLOCATE_VAS_WINDOW   0x388
> +#define  H_MODIFY_VAS_WINDOW 0x38C
> +#define  H_DEALLOCATE_VAS_WINDOW 0x390
> +#define  H_QUERY_VAS_WINDOW  0x394
> +#define  H_QUERY_VAS_CAPABILITIES0x398
> +#define  H_QUERY_NX_CAPABILITIES 0x39C
> +#define  H_GET_NX_FAULT  0x3A0

These should be spaces.

>  #define H_INT_GET_SOURCE_INFO   0x3A8
>  #define H_INT_SET_SOURCE_CONFIG 0x3AC
>  #define H_INT_GET_SOURCE_CONFIG 0x3B0
> diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h
> index f928bf4c7e98..d15784506a54 100644
> --- a/arch/powerpc/include/asm/vas.h
> +++ b/arch/powerpc/include/asm/vas.h
> @@ -179,6 +179,7 @@ struct vas_tx_win_attr {
>   bool rx_win_ord_mode;
>  };
>  
> +#ifdef CONFIG_PPC_POWERNV
>  /*
>   * Helper to map a chip id to VAS id.
>   * For POWER9, this is a 1:1 mapping. In the future this maybe a 1:N
> @@ -243,6 +244,33 @@ int vas_paste_crb(struct vas_window *win, int offset, 
> bool re);
>  int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type,
>const char *name);
>  void vas_unregister_api_powernv(void);
> +#endif
> +
> +#ifdef CONFIG_PPC_PSERIES
> +
> +/* VAS Capabilities */
> +#define VAS_GZIP_QOS_FEAT0x1
> +#define VAS_GZIP_DEF_FEAT0x2
> +#define VAS_GZIP_QOS_FEAT_BIT(1UL << (63 - VAS_GZIP_QOS_FEAT)) /* 
> Bit 1 */
> +#define VAS_GZIP_DEF_FEAT_BIT(1UL << (63 - VAS_GZIP_DEF_FEAT)) /* 
> Bit 2 */

Use PPC_BIT for these.

> +
> +/* NX Capabilities */
> +#define  VAS_NX_GZIP_FEAT0x1
> +#define  VAS_NX_GZIP_FEAT_BIT(1UL << (63 - VAS_NX_GZIP_FEAT)) /* Bit 
> 1 */
> +#define  VAS_DESCR_LEN   8
> +
> +struct vas_all_capabs_be {
> + __be64  descriptor;
> + __be64  feat_type;
> +} __packed __aligned(0x1000);
> +
> +struct vas_all_capabs {
> + charname[VAS_DESCR_LEN + 1];
> + u64 descriptor;
> + u64 feat_type;
> +};

You're using _be for the struct that is passed to the hcall, and a 
non-postfixed one for something the driver uses internally? It seems
like buf or buffer, or hv_ prefix is typically used rather than be (host 
kernel could be BE).

struct hv_query_vas_capabilities_buffer for example.

Does the hcall really require 0x1000 alignment?

> +
> +#endif
>  
>  /*
>   * Register / unregister coprocessor type to VAS API which will be exported
> diff --git a/arch/powerpc/platforms/pseries/vas.h 
> b/arch/powerpc/platforms/pseries/vas.h
> new file mode 100644
> index ..208682fffa57
> --- /dev/null
> +++ b/arch/powerpc/platforms/pseries/vas.h
> @@ -0,0 +1,96 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright 2020-21 IBM Corp.
> + */
> +
> +#ifndef _VAS_H
> +#define _VAS_H
> +#include 
> +#include 
> +#include 
> +
> +/*
> + * VAS window modify flags
> + */
> +#define  VAS_MOD_WIN_CLOSE   (1UL << 63)
> +#define  VAS_MOD_WIN_JOBS_KILL   (1UL << (63 - 1))
> +#define  VAS_MOD_WIN_DR  (1UL << (63 - 3))
> +#define  VAS_MOD_WIN_PR  (1UL << (63 - 4))
> +#define  VAS_MOD_WIN_SF  (1UL << (63 - 5))
> +#define  VAS_MOD_WIN_TA  (1UL << (63 - 6))
> +#define  VAS_MOD_WIN_FLAGS   (VAS_MOD_WIN_JOBS_KILL | VAS_MOD_WIN_DR 
> | \
> + VAS_MOD_WIN_PR | VAS_MOD_WIN_SF)
> +
> +#define  VAS_WIN_ACTIVE  0x0
> +#define  VAS_WIN_CLOSED  0x1
> +#define  VAS_WIN_INACTIVE0x2 /* Inactive due to HW failure */
> +/* Process of being modified, deallocated, or quiesced */
> +#define  VAS_WIN_MOD_IN_PROCESS  0x3
> +
> +#define  VAS_COPY_PASTE_USER_MODE0x0001
> +#define  VAS_COP_OP_USER_MODE0x0010
> +
> +/*
> + * Co-processor feature - GZIP QoS windows or GZIP default windows
> + */
> +enum vas_cop_feat_type {
> + VAS_GZIP_QOS_FEAT_TYPE,
> + VAS_GZIP_DEF_FEAT_TYPE,
> + VAS_MAX_FEAT_TYPE,
> +};
> +
> +struct vas_ct_capabs_be {
> + __be64  descriptor;
> + u8  win_type;   /* Default or QoS type */
> + u8  

Re: [V3 PATCH 05/16] powerpc/vas: Define and use common vas_window struct

2021-05-09 Thread Nicholas Piggin
Excerpts from Haren Myneni's message of April 18, 2021 7:04 am:
> 
> 

Empty email?

Thanks,
Nick


Re: [V3 PATCH 04/16] powerpc/vas: Move update_csb/dump_crb to common book3s platform

2021-05-09 Thread Nicholas Piggin
Excerpts from Haren Myneni's message of April 18, 2021 7:03 am:
> 
> NX issues an interrupt when sees fault on user space buffer.

If a coprocessor encounters an error translating an address, the VAS 
will cause an interrupt in the host.


> The
> kernel processes the fault by updating CSB. This functionality is
> same for both powerNV and pseries. So this patch moves these
> functions to common vas-api.c and the actual functionality is not
> changed.
> 
> Signed-off-by: Haren Myneni 
> ---
>  arch/powerpc/include/asm/vas.h |   3 +
>  arch/powerpc/platforms/book3s/vas-api.c| 146 ++-
>  arch/powerpc/platforms/powernv/vas-fault.c | 155 ++---
>  3 files changed, 157 insertions(+), 147 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h
> index 2daaa1a2a9a9..66bf8fb1a1be 100644
> --- a/arch/powerpc/include/asm/vas.h
> +++ b/arch/powerpc/include/asm/vas.h
> @@ -210,4 +210,7 @@ int vas_register_coproc_api(struct module *mod, enum 
> vas_cop_type cop_type,
>  void vas_unregister_coproc_api(void);
>  
>  int vas_reference_task(struct vas_win_task *vtask);
> +void vas_update_csb(struct coprocessor_request_block *crb,
> + struct vas_win_task *vtask);
> +void vas_dump_crb(struct coprocessor_request_block *crb);
>  #endif /* __ASM_POWERPC_VAS_H */
> diff --git a/arch/powerpc/platforms/book3s/vas-api.c 
> b/arch/powerpc/platforms/book3s/vas-api.c
> index d98caa734154..dc131b2e4acd 100644
> --- a/arch/powerpc/platforms/book3s/vas-api.c
> +++ b/arch/powerpc/platforms/book3s/vas-api.c
> @@ -111,6 +111,150 @@ int vas_reference_task(struct vas_win_task *vtask)
>   return 0;
>  }
>  
> +/*
> + * Update the CSB to indicate a translation error.
> + *
> + * User space will be polling on CSB after the request is issued.
> + * If NX can handle the request without any issues, it updates CSB.
> + * Whereas if NX encounters page fault, the kernel will handle the
> + * fault and update CSB with translation error.
> + *
> + * If we are unable to update the CSB means copy_to_user failed due to
> + * invalid csb_addr, send a signal to the process.
> + */
> +void vas_update_csb(struct coprocessor_request_block *crb,
> + struct vas_win_task *vtask)
> +{
> + struct coprocessor_status_block csb;
> + struct kernel_siginfo info;
> + struct task_struct *tsk;
> + void __user *csb_addr;
> + struct pid *pid;
> + int rc;
> +
> + /*
> +  * NX user space windows can not be opened for task->mm=NULL
> +  * and faults will not be generated for kernel requests.
> +  */
> + if (WARN_ON_ONCE(!vtask->mm))
> + return;
> +
> + csb_addr = (void __user *)be64_to_cpu(crb->csb_addr);
> +
> + memset(, 0, sizeof(csb));
> + csb.cc = CSB_CC_FAULT_ADDRESS;
> + csb.ce = CSB_CE_TERMINATION;
> + csb.cs = 0;
> + csb.count = 0;
> +
> + /*
> +  * NX operates and returns in BE format as defined CRB struct.
> +  * So saves fault_storage_addr in BE as NX pastes in FIFO and
> +  * expects user space to convert to CPU format.
> +  */
> + csb.address = crb->stamp.nx.fault_storage_addr;
> + csb.flags = 0;
> +
> + pid = vtask->pid;
> + tsk = get_pid_task(pid, PIDTYPE_PID);
> + /*
> +  * Process closes send window after all pending NX requests are
> +  * completed. In multi-thread applications, a child thread can
> +  * open a window and can exit without closing it. May be some
> +  * requests are pending or this window can be used by other
> +  * threads later. We should handle faults if NX encounters
> +  * pages faults on these requests. Update CSB with translation
> +  * error and fault address. If csb_addr passed by user space is
> +  * invalid, send SEGV signal to pid saved in window. If the
> +  * child thread is not running, send the signal to tgid.
> +  * Parent thread (tgid) will close this window upon its exit.
> +  *
> +  * pid and mm references are taken when window is opened by
> +  * process (pid). So tgid is used only when child thread opens
> +  * a window and exits without closing it.
> +  */
> + if (!tsk) {
> + pid = vtask->tgid;
> + tsk = get_pid_task(pid, PIDTYPE_PID);
> + /*
> +  * Parent thread (tgid) will be closing window when it
> +  * exits. So should not get here.
> +  */
> + if (WARN_ON_ONCE(!tsk))
> + return;
> + }
> +
> + /* Return if the task is exiting. */
> + if (tsk->flags & PF_EXITING) {
> + put_task_struct(tsk);
> + return;
> + }
> +
> + kthread_use_mm(vtask->mm);
> + rc = copy_to_user(csb_addr, , sizeof(csb));
> + /*
> +  * User space polls on csb.flags (first byte). So add barrier
> +  * then copy first byte with csb flags update.
> +  */
> + if (!rc) {
> + 

Re: [V3 PATCH 03/16] powerpc/vas: Create take/drop task reference functions

2021-05-09 Thread Nicholas Piggin
Excerpts from Haren Myneni's message of April 18, 2021 7:03 am:
> 
> Take task reference when each window opens and drops during close.
> This functionality is needed for powerNV and pseries. So this patch
> defines the existing code as functions in common book3s platform
> vas-api.c
> 
> Signed-off-by: Haren Myneni 
> ---
>  arch/powerpc/include/asm/vas.h  | 20 
>  arch/powerpc/platforms/book3s/vas-api.c | 51 ++
>  arch/powerpc/platforms/powernv/vas-fault.c  | 10 ++--
>  arch/powerpc/platforms/powernv/vas-window.c | 57 ++---
>  arch/powerpc/platforms/powernv/vas.h|  6 +--
>  5 files changed, 83 insertions(+), 61 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h
> index 6bbade60d8f4..2daaa1a2a9a9 100644
> --- a/arch/powerpc/include/asm/vas.h
> +++ b/arch/powerpc/include/asm/vas.h
> @@ -5,6 +5,9 @@
>  
>  #ifndef _ASM_POWERPC_VAS_H
>  #define _ASM_POWERPC_VAS_H
> +#include 
> +#include 
> +#include 
>  #include 
>  
>  
> @@ -60,6 +63,22 @@ struct vas_user_win_ops {
>   int (*close_win)(void *);
>  };
>  
> +struct vas_win_task {
> + struct pid *pid;/* Thread group ID of owner */
> + struct pid *tgid;   /* Linux process mm_struct */
> + struct mm_struct *mm;   /* Linux process mm_struct */
> +};

Looks okay, happy with struct vas_win_task? (and vas_user_win_ops)?

I'd be happier to have everything related to vas windows prefixed with 
vas_window_ consistently, and have _user be present always for userspace
windows, but you have to read and type it.

> +
> +static inline void vas_drop_reference_task(struct vas_win_task *task)

This is not dropping a reference task, but a task reference. And it's 
not really a task reference as far as Linux understands, but a
reference on pid (not task) and mm related to an open vas window. And
specifically a user window (with corresponding vas_user_win_ops).

Could it be called a 'struct vas_window_user_ref' instead?

Thanks,
Nick

> +{
> + /* Drop references to pid and mm */
> + put_pid(task->pid);
> + if (task->mm) {
> + mm_context_remove_vas_window(task->mm);
> + mmdrop(task->mm);
> + }


Re: [PATCH V3 02/16] powerpc/vas: Move VAS API to common book3s platform

2021-05-09 Thread Nicholas Piggin
Excerpts from Haren Myneni's message of April 18, 2021 7:02 am:
> 
> Using the same /dev/crypto/nx-gzip interface for both powerNV and
> pseries.

The pseries NX driver will use the powernv VAS API ?

> So this patch creates platforms/book3s/ and moves VAS API
> to that directory. The actual functionality is not changed.
> 
> Common interface functions such as open, window open ioctl, mmap
> and close are moved to arch/powerpc/platforms/book3s/vas-api.c
> Added hooks to call platform specific code, but the underline
> powerNV code in these functions is not changed.

Even so, could you do one patch that just moves, and another that
adds the ops struct?

> 
> Signed-off-by: Haren Myneni 
> ---
>  arch/powerpc/include/asm/vas.h| 22 ++-
>  arch/powerpc/platforms/Kconfig|  1 +
>  arch/powerpc/platforms/Makefile   |  1 +
>  arch/powerpc/platforms/book3s/Kconfig | 15 +
>  arch/powerpc/platforms/book3s/Makefile|  2 +

The usual place for these would be arch/powerpc/sysdev/vas. E.g., see
arch/powerpc/sysdev/xive.

>  .../platforms/{powernv => book3s}/vas-api.c   | 64 ++
>  arch/powerpc/platforms/powernv/Kconfig| 14 
>  arch/powerpc/platforms/powernv/Makefile   |  2 +-
>  arch/powerpc/platforms/powernv/vas-window.c   | 66 +++
>  9 files changed, 143 insertions(+), 44 deletions(-)
>  create mode 100644 arch/powerpc/platforms/book3s/Kconfig
>  create mode 100644 arch/powerpc/platforms/book3s/Makefile
>  rename arch/powerpc/platforms/{powernv => book3s}/vas-api.c (83%)
> 
> diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h
> index 41f73fae7ab8..6bbade60d8f4 100644
> --- a/arch/powerpc/include/asm/vas.h
> +++ b/arch/powerpc/include/asm/vas.h
> @@ -5,6 +5,8 @@
>  
>  #ifndef _ASM_POWERPC_VAS_H
>  #define _ASM_POWERPC_VAS_H
> +#include 
> +
>  
>  struct vas_window;
>  
> @@ -48,6 +50,16 @@ enum vas_cop_type {
>   VAS_COP_TYPE_MAX,
>  };
>  
> +/*
> + * User space window operations used for powernv and powerVM
> + */
> +struct vas_user_win_ops {
> + struct vas_window * (*open_win)(struct vas_tx_win_open_attr *,
> + enum vas_cop_type);
> + u64 (*paste_addr)(void *);
> + int (*close_win)(void *);
> +};
> +
>  /*
>   * Receive window attributes specified by the (in-kernel) owner of window.
>   */
> @@ -161,6 +173,9 @@ int vas_copy_crb(void *crb, int offset);
>   * assumed to be true for NX windows.
>   */
>  int vas_paste_crb(struct vas_window *win, int offset, bool re);
> +int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type,
> +  const char *name);
> +void vas_unregister_api_powernv(void);
>  
>  /*
>   * Register / unregister coprocessor type to VAS API which will be exported
> @@ -170,8 +185,9 @@ int vas_paste_crb(struct vas_window *win, int offset, 
> bool re);
>   * Only NX GZIP coprocessor type is supported now, but this API can be
>   * used for others in future.
>   */
> -int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type,
> -  const char *name);
> -void vas_unregister_api_powernv(void);
> +int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type,
> + const char *name,
> + struct vas_user_win_ops *vops);
> +void vas_unregister_coproc_api(void);
>  
>  #endif /* __ASM_POWERPC_VAS_H */
> diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
> index 7a5e8f4541e3..594544a65b02 100644
> --- a/arch/powerpc/platforms/Kconfig
> +++ b/arch/powerpc/platforms/Kconfig
> @@ -20,6 +20,7 @@ source "arch/powerpc/platforms/embedded6xx/Kconfig"
>  source "arch/powerpc/platforms/44x/Kconfig"
>  source "arch/powerpc/platforms/40x/Kconfig"
>  source "arch/powerpc/platforms/amigaone/Kconfig"
> +source "arch/powerpc/platforms/book3s/Kconfig"
>  
>  config KVM_GUEST
>   bool "KVM Guest support"
> diff --git a/arch/powerpc/platforms/Makefile b/arch/powerpc/platforms/Makefile
> index 143d4417f6cc..0e75d7df387b 100644
> --- a/arch/powerpc/platforms/Makefile
> +++ b/arch/powerpc/platforms/Makefile
> @@ -22,3 +22,4 @@ obj-$(CONFIG_PPC_CELL)  += cell/
>  obj-$(CONFIG_PPC_PS3)+= ps3/
>  obj-$(CONFIG_EMBEDDED6xx)+= embedded6xx/
>  obj-$(CONFIG_AMIGAONE)   += amigaone/
> +obj-$(CONFIG_PPC_BOOK3S) += book3s/
> diff --git a/arch/powerpc/platforms/book3s/Kconfig 
> b/arch/powerpc/platforms/book3s/Kconfig
> new file mode 100644
> index ..51e14db83a79
> --- /dev/null
> +++ b/arch/powerpc/platforms/book3s/Kconfig
> @@ -0,0 +1,15 @@
> +# SPDX-License-Identifier: GPL-2.0
> +config PPC_VAS
> + bool "IBM Virtual Accelerator Switchboard (VAS)"
> + depends on PPC_POWERNV && PPC_64K_PAGES
> + default y
> + help
> +   This enables support for IBM Virtual Accelerator Switchboard (VAS).
> +
> +   VAS allows 

Re: [V3 PATCH 01/16] powerpc/powernv/vas: Rename register/unregister functions

2021-05-09 Thread Nicholas Piggin
Excerpts from Haren Myneni's message of April 18, 2021 7:00 am:
> 
> powerNV and pseries drivers register / unregister to the corresponding
> VAS code separately. So rename powerNV VAS API register/unregister
> functions.

The pseries VAS driver will have different calls for registering a
coprocessor driver, you mean?

It certainly looks the same 

(from patch 13)
ret = vas_register_api_pseries(THIS_MODULE, VAS_COP_TYPE_GZIP,
   "nx-gzip");

So I guess it's just a matter of the driver being different enough that 
there is no benefit to making this call common (and branching to pseries
or powernv dynamically).

Reviewed-by: Nicholas Piggin 

> 
> Signed-off-by: Haren Myneni 
> ---
>  arch/powerpc/include/asm/vas.h   |  6 +++---
>  arch/powerpc/platforms/powernv/vas-api.c | 10 +-
>  drivers/crypto/nx/nx-common-powernv.c|  6 +++---
>  3 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/vas.h b/arch/powerpc/include/asm/vas.h
> index e33f80b0ea81..41f73fae7ab8 100644
> --- a/arch/powerpc/include/asm/vas.h
> +++ b/arch/powerpc/include/asm/vas.h
> @@ -170,8 +170,8 @@ int vas_paste_crb(struct vas_window *win, int offset, 
> bool re);
>   * Only NX GZIP coprocessor type is supported now, but this API can be
>   * used for others in future.
>   */
> -int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type,
> - const char *name);
> -void vas_unregister_coproc_api(void);
> +int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type,
> +  const char *name);
> +void vas_unregister_api_powernv(void);
>  
>  #endif /* __ASM_POWERPC_VAS_H */
> diff --git a/arch/powerpc/platforms/powernv/vas-api.c 
> b/arch/powerpc/platforms/powernv/vas-api.c
> index 98ed5d8c5441..72d8ce39e56c 100644
> --- a/arch/powerpc/platforms/powernv/vas-api.c
> +++ b/arch/powerpc/platforms/powernv/vas-api.c
> @@ -207,8 +207,8 @@ static struct file_operations coproc_fops = {
>   * Supporting only nx-gzip coprocessor type now, but this API code
>   * extended to other coprocessor types later.
>   */
> -int vas_register_coproc_api(struct module *mod, enum vas_cop_type cop_type,
> - const char *name)
> +int vas_register_api_powernv(struct module *mod, enum vas_cop_type cop_type,
> +  const char *name)
>  {
>   int rc = -EINVAL;
>   dev_t devno;
> @@ -262,9 +262,9 @@ int vas_register_coproc_api(struct module *mod, enum 
> vas_cop_type cop_type,
>   unregister_chrdev_region(coproc_device.devt, 1);
>   return rc;
>  }
> -EXPORT_SYMBOL_GPL(vas_register_coproc_api);
> +EXPORT_SYMBOL_GPL(vas_register_api_powernv);
>  
> -void vas_unregister_coproc_api(void)
> +void vas_unregister_api_powernv(void)
>  {
>   dev_t devno;
>  
> @@ -275,4 +275,4 @@ void vas_unregister_coproc_api(void)
>   class_destroy(coproc_device.class);
>   unregister_chrdev_region(coproc_device.devt, 1);
>  }
> -EXPORT_SYMBOL_GPL(vas_unregister_coproc_api);
> +EXPORT_SYMBOL_GPL(vas_unregister_api_powernv);
> diff --git a/drivers/crypto/nx/nx-common-powernv.c 
> b/drivers/crypto/nx/nx-common-powernv.c
> index 13c65deda8e9..88d728415bb2 100644
> --- a/drivers/crypto/nx/nx-common-powernv.c
> +++ b/drivers/crypto/nx/nx-common-powernv.c
> @@ -1090,8 +1090,8 @@ static __init int nx_compress_powernv_init(void)
>* normal FIFO priority is assigned for userspace.
>* 842 compression is supported only in kernel.
>*/
> - ret = vas_register_coproc_api(THIS_MODULE, VAS_COP_TYPE_GZIP,
> - "nx-gzip");
> + ret = vas_register_api_powernv(THIS_MODULE, VAS_COP_TYPE_GZIP,
> +"nx-gzip");
>  
>   /*
>* GZIP is not supported in kernel right now.
> @@ -1127,7 +1127,7 @@ static void __exit nx_compress_powernv_exit(void)
>* use. So delete this API use for GZIP engine.
>*/
>   if (!nx842_ct)
> - vas_unregister_coproc_api();
> + vas_unregister_api_powernv();
>  
>   crypto_unregister_alg(_powernv_alg);
>  
> -- 
> 2.18.2
> 
> 
> 


[PATCH 11/11] PCI: shpchp: Use sysfs_emit() and sysfs_emit_at() in "show" functions

2021-05-09 Thread Krzysztof Wilczyński
The sysfs_emit() and sysfs_emit_at() functions were introduced to make
it less ambiguous which function is preferred when writing to the output
buffer in a device attribute's "show" callback [1].

Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
latter is aware of the PAGE_SIZE buffer and correctly returns the number
of bytes written into the buffer.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Related to:
  commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in 
"show" functions")

Signed-off-by: Krzysztof Wilczyński 
---
 drivers/pci/hotplug/shpchp_sysfs.c | 38 +-
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/drivers/pci/hotplug/shpchp_sysfs.c 
b/drivers/pci/hotplug/shpchp_sysfs.c
index 45658bb5c554..64beed7a26be 100644
--- a/drivers/pci/hotplug/shpchp_sysfs.c
+++ b/drivers/pci/hotplug/shpchp_sysfs.c
@@ -24,50 +24,54 @@
 static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, 
char *buf)
 {
struct pci_dev *pdev;
-   char *out = buf;
int index, busnr;
struct resource *res;
struct pci_bus *bus;
+   size_t len = 0;
 
pdev = to_pci_dev(dev);
bus = pdev->subordinate;
 
-   out += sprintf(buf, "Free resources: memory\n");
+   len += sysfs_emit_at(buf, len, "Free resources: memory\n");
pci_bus_for_each_resource(bus, res, index) {
if (res && (res->flags & IORESOURCE_MEM) &&
!(res->flags & IORESOURCE_PREFETCH)) {
-   out += sprintf(out, "start = %8.8llx, length = 
%8.8llx\n",
-  (unsigned long long)res->start,
-  (unsigned long long)resource_size(res));
+   len += sysfs_emit_at(buf, len,
+"start = %8.8llx, length = 
%8.8llx\n",
+(unsigned long long)res->start,
+(unsigned long 
long)resource_size(res));
}
}
-   out += sprintf(out, "Free resources: prefetchable memory\n");
+   len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n");
pci_bus_for_each_resource(bus, res, index) {
if (res && (res->flags & IORESOURCE_MEM) &&
   (res->flags & IORESOURCE_PREFETCH)) {
-   out += sprintf(out, "start = %8.8llx, length = 
%8.8llx\n",
-  (unsigned long long)res->start,
-  (unsigned long long)resource_size(res));
+   len += sysfs_emit_at(buf, len,
+"start = %8.8llx, length = 
%8.8llx\n",
+(unsigned long long)res->start,
+(unsigned long 
long)resource_size(res));
}
}
-   out += sprintf(out, "Free resources: IO\n");
+   len += sysfs_emit_at(buf, len, "Free resources: IO\n");
pci_bus_for_each_resource(bus, res, index) {
if (res && (res->flags & IORESOURCE_IO)) {
-   out += sprintf(out, "start = %8.8llx, length = 
%8.8llx\n",
-  (unsigned long long)res->start,
-  (unsigned long long)resource_size(res));
+   len += sysfs_emit_at(buf, len,
+"start = %8.8llx, length = 
%8.8llx\n",
+(unsigned long long)res->start,
+(unsigned long 
long)resource_size(res));
}
}
-   out += sprintf(out, "Free resources: bus numbers\n");
+   len += sysfs_emit_at(buf, len, "Free resources: bus numbers\n");
for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) {
if (!pci_find_bus(pci_domain_nr(bus), busnr))
break;
}
if (busnr < bus->busn_res.end)
-   out += sprintf(out, "start = %8.8x, length = %8.8x\n",
-   busnr, (int)(bus->busn_res.end - busnr));
+   len += sysfs_emit_at(buf, len,
+"start = %8.8x, length = %8.8x\n",
+busnr, (int)(bus->busn_res.end - busnr));
 
-   return out - buf;
+   return len;
 }
 static DEVICE_ATTR(ctrl, S_IRUGO, show_ctrl, NULL);
 
-- 
2.31.1



[PATCH 10/11] PCI: hotplug: Use sysfs_emit() and sysfs_emit_at() in "show" functions

2021-05-09 Thread Krzysztof Wilczyński
The sysfs_emit() and sysfs_emit_at() functions were introduced to make
it less ambiguous which function is preferred when writing to the output
buffer in a device attribute's "show" callback [1].

Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
latter is aware of the PAGE_SIZE buffer and correctly returns the number
of bytes written into the buffer.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Related to:
  commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in 
"show" functions")

Signed-off-by: Krzysztof Wilczyński 
---
 drivers/pci/hotplug/pci_hotplug_core.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/hotplug/pci_hotplug_core.c 
b/drivers/pci/hotplug/pci_hotplug_core.c
index 5ac31f683b85..058d5937d8a9 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -73,7 +73,7 @@ static ssize_t power_read_file(struct pci_slot *pci_slot, 
char *buf)
if (retval)
return retval;
 
-   return sprintf(buf, "%d\n", value);
+   return sysfs_emit(buf, "%d\n", value);
 }
 
 static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf,
@@ -130,7 +130,7 @@ static ssize_t attention_read_file(struct pci_slot 
*pci_slot, char *buf)
if (retval)
return retval;
 
-   return sprintf(buf, "%d\n", value);
+   return sysfs_emit(buf, "%d\n", value);
 }
 
 static ssize_t attention_write_file(struct pci_slot *pci_slot, const char *buf,
@@ -175,7 +175,7 @@ static ssize_t latch_read_file(struct pci_slot *pci_slot, 
char *buf)
if (retval)
return retval;
 
-   return sprintf(buf, "%d\n", value);
+   return sysfs_emit(buf, "%d\n", value);
 }
 
 static struct pci_slot_attribute hotplug_slot_attr_latch = {
@@ -192,7 +192,7 @@ static ssize_t presence_read_file(struct pci_slot 
*pci_slot, char *buf)
if (retval)
return retval;
 
-   return sprintf(buf, "%d\n", value);
+   return sysfs_emit(buf, "%d\n", value);
 }
 
 static struct pci_slot_attribute hotplug_slot_attr_presence = {
-- 
2.31.1



[PATCH 09/11] PCI: rpadlpar: Use sysfs_emit() and sysfs_emit_at() in "show" functions

2021-05-09 Thread Krzysztof Wilczyński
The sysfs_emit() and sysfs_emit_at() functions were introduced to make
it less ambiguous which function is preferred when writing to the output
buffer in a device attribute's "show" callback [1].

Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
latter is aware of the PAGE_SIZE buffer and correctly returns the number
of bytes written into the buffer.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Related to:
  commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in 
"show" functions")

Signed-off-by: Krzysztof Wilczyński 
---
 drivers/pci/hotplug/rpadlpar_sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c 
b/drivers/pci/hotplug/rpadlpar_sysfs.c
index dbfa0b55d31a..068b7810a574 100644
--- a/drivers/pci/hotplug/rpadlpar_sysfs.c
+++ b/drivers/pci/hotplug/rpadlpar_sysfs.c
@@ -50,7 +50,7 @@ static ssize_t add_slot_store(struct kobject *kobj, struct 
kobj_attribute *attr,
 static ssize_t add_slot_show(struct kobject *kobj,
 struct kobj_attribute *attr, char *buf)
 {
-   return sprintf(buf, "0\n");
+   return sysfs_emit(buf, "0\n");
 }
 
 static ssize_t remove_slot_store(struct kobject *kobj,
@@ -80,7 +80,7 @@ static ssize_t remove_slot_store(struct kobject *kobj,
 static ssize_t remove_slot_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
 {
-   return sprintf(buf, "0\n");
+   return sysfs_emit(buf, "0\n");
 }
 
 static struct kobj_attribute add_slot_attr =
-- 
2.31.1



[PATCH 08/11] PCI: switchtec: Use sysfs_emit() and sysfs_emit_at() in "show" functions

2021-05-09 Thread Krzysztof Wilczyński
The sysfs_emit() and sysfs_emit_at() functions were introduced to make
it less ambiguous which function is preferred when writing to the output
buffer in a device attribute's "show" callback [1].

Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
latter is aware of the PAGE_SIZE buffer and correctly returns the number
of bytes written into the buffer.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Related to:
  commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in 
"show" functions")

Signed-off-by: Krzysztof Wilczyński 
---
 drivers/pci/switch/switchtec.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/switch/switchtec.c b/drivers/pci/switch/switchtec.c
index ba52459928f7..0b301f8be9ed 100644
--- a/drivers/pci/switch/switchtec.c
+++ b/drivers/pci/switch/switchtec.c
@@ -280,7 +280,7 @@ static ssize_t device_version_show(struct device *dev,
 
ver = ioread32(>mmio_sys_info->device_version);
 
-   return sprintf(buf, "%x\n", ver);
+   return sysfs_emit(buf, "%x\n", ver);
 }
 static DEVICE_ATTR_RO(device_version);
 
@@ -292,7 +292,7 @@ static ssize_t fw_version_show(struct device *dev,
 
ver = ioread32(>mmio_sys_info->firmware_version);
 
-   return sprintf(buf, "%08x\n", ver);
+   return sysfs_emit(buf, "%08x\n", ver);
 }
 static DEVICE_ATTR_RO(fw_version);
 
@@ -344,7 +344,7 @@ static ssize_t component_vendor_show(struct device *dev,
 
/* component_vendor field not supported after gen3 */
if (stdev->gen != SWITCHTEC_GEN3)
-   return sprintf(buf, "none\n");
+   return sysfs_emit(buf, "none\n");
 
return io_string_show(buf, >gen3.component_vendor,
  sizeof(si->gen3.component_vendor));
@@ -359,9 +359,9 @@ static ssize_t component_id_show(struct device *dev,
 
/* component_id field not supported after gen3 */
if (stdev->gen != SWITCHTEC_GEN3)
-   return sprintf(buf, "none\n");
+   return sysfs_emit(buf, "none\n");
 
-   return sprintf(buf, "PM%04X\n", id);
+   return sysfs_emit(buf, "PM%04X\n", id);
 }
 static DEVICE_ATTR_RO(component_id);
 
@@ -373,9 +373,9 @@ static ssize_t component_revision_show(struct device *dev,
 
/* component_revision field not supported after gen3 */
if (stdev->gen != SWITCHTEC_GEN3)
-   return sprintf(buf, "255\n");
+   return sysfs_emit(buf, "255\n");
 
-   return sprintf(buf, "%d\n", rev);
+   return sysfs_emit(buf, "%d\n", rev);
 }
 static DEVICE_ATTR_RO(component_revision);
 
@@ -384,7 +384,7 @@ static ssize_t partition_show(struct device *dev,
 {
struct switchtec_dev *stdev = to_stdev(dev);
 
-   return sprintf(buf, "%d\n", stdev->partition);
+   return sysfs_emit(buf, "%d\n", stdev->partition);
 }
 static DEVICE_ATTR_RO(partition);
 
@@ -393,7 +393,7 @@ static ssize_t partition_count_show(struct device *dev,
 {
struct switchtec_dev *stdev = to_stdev(dev);
 
-   return sprintf(buf, "%d\n", stdev->partition_count);
+   return sysfs_emit(buf, "%d\n", stdev->partition_count);
 }
 static DEVICE_ATTR_RO(partition_count);
 
-- 
2.31.1



[PATCH 07/11] PCI/ASPM: Use sysfs_emit() and sysfs_emit_at() in "show" functions

2021-05-09 Thread Krzysztof Wilczyński
The sysfs_emit() and sysfs_emit_at() functions were introduced to make
it less ambiguous which function is preferred when writing to the output
buffer in a device attribute's "show" callback [1].

Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
latter is aware of the PAGE_SIZE buffer and correctly returns the number
of bytes written into the buffer.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Related to:
  commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in 
"show" functions")

Signed-off-by: Krzysztof Wilczyński 
---
 drivers/pci/pcie/aspm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index ac0557a305af..013a47f587ce 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -1208,7 +1208,7 @@ static ssize_t aspm_attr_show_common(struct device *dev,
struct pci_dev *pdev = to_pci_dev(dev);
struct pcie_link_state *link = pcie_aspm_get_link(pdev);
 
-   return sprintf(buf, "%d\n", (link->aspm_enabled & state) ? 1 : 0);
+   return sysfs_emit(buf, "%d\n", (link->aspm_enabled & state) ? 1 : 0);
 }
 
 static ssize_t aspm_attr_store_common(struct device *dev,
@@ -1265,7 +1265,7 @@ static ssize_t clkpm_show(struct device *dev,
struct pci_dev *pdev = to_pci_dev(dev);
struct pcie_link_state *link = pcie_aspm_get_link(pdev);
 
-   return sprintf(buf, "%d\n", link->clkpm_enabled);
+   return sysfs_emit(buf, "%d\n", link->clkpm_enabled);
 }
 
 static ssize_t clkpm_store(struct device *dev,
-- 
2.31.1



[PATCH 06/11] PCI/P2PDMA: Use sysfs_emit() and sysfs_emit_at() in "show" functions

2021-05-09 Thread Krzysztof Wilczyński
The sysfs_emit() and sysfs_emit_at() functions were introduced to make
it less ambiguous which function is preferred when writing to the output
buffer in a device attribute's "show" callback [1].

Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
latter is aware of the PAGE_SIZE buffer and correctly returns the number
of bytes written into the buffer.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Related to:
  commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in 
"show" functions")

Signed-off-by: Krzysztof Wilczyński 
---
 drivers/pci/p2pdma.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
index 196382630363..a1351b3e2c4c 100644
--- a/drivers/pci/p2pdma.c
+++ b/drivers/pci/p2pdma.c
@@ -53,7 +53,7 @@ static ssize_t size_show(struct device *dev, struct 
device_attribute *attr,
if (pdev->p2pdma->pool)
size = gen_pool_size(pdev->p2pdma->pool);
 
-   return scnprintf(buf, PAGE_SIZE, "%zd\n", size);
+   return sysfs_emit(buf, "%zd\n", size);
 }
 static DEVICE_ATTR_RO(size);
 
@@ -66,7 +66,7 @@ static ssize_t available_show(struct device *dev, struct 
device_attribute *attr,
if (pdev->p2pdma->pool)
avail = gen_pool_avail(pdev->p2pdma->pool);
 
-   return scnprintf(buf, PAGE_SIZE, "%zd\n", avail);
+   return sysfs_emit(buf, "%zd\n", avail);
 }
 static DEVICE_ATTR_RO(available);
 
@@ -75,8 +75,7 @@ static ssize_t published_show(struct device *dev, struct 
device_attribute *attr,
 {
struct pci_dev *pdev = to_pci_dev(dev);
 
-   return scnprintf(buf, PAGE_SIZE, "%d\n",
-pdev->p2pdma->p2pmem_published);
+   return sysfs_emit(buf, "%d\n", pdev->p2pdma->p2pmem_published);
 }
 static DEVICE_ATTR_RO(published);
 
-- 
2.31.1



[PATCH 05/11] PCI/IOV: Use sysfs_emit() and sysfs_emit_at() in "show" functions

2021-05-09 Thread Krzysztof Wilczyński
The sysfs_emit() and sysfs_emit_at() functions were introduced to make
it less ambiguous which function is preferred when writing to the output
buffer in a device attribute's "show" callback [1].

Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
latter is aware of the PAGE_SIZE buffer and correctly returns the number
of bytes written into the buffer.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Related to:
  commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in 
"show" functions")

Signed-off-by: Krzysztof Wilczyński 
---
 drivers/pci/iov.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index afc06e6ce115..a71258347323 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -346,7 +346,7 @@ static ssize_t sriov_totalvfs_show(struct device *dev,
 {
struct pci_dev *pdev = to_pci_dev(dev);
 
-   return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev));
+   return sysfs_emit(buf, "%u\n", pci_sriov_get_totalvfs(pdev));
 }
 
 static ssize_t sriov_numvfs_show(struct device *dev,
@@ -361,7 +361,7 @@ static ssize_t sriov_numvfs_show(struct device *dev,
num_vfs = pdev->sriov->num_VFs;
device_unlock(>dev);
 
-   return sprintf(buf, "%u\n", num_vfs);
+   return sysfs_emit(buf, "%u\n", num_vfs);
 }
 
 /*
@@ -435,7 +435,7 @@ static ssize_t sriov_offset_show(struct device *dev,
 {
struct pci_dev *pdev = to_pci_dev(dev);
 
-   return sprintf(buf, "%u\n", pdev->sriov->offset);
+   return sysfs_emit(buf, "%u\n", pdev->sriov->offset);
 }
 
 static ssize_t sriov_stride_show(struct device *dev,
@@ -444,7 +444,7 @@ static ssize_t sriov_stride_show(struct device *dev,
 {
struct pci_dev *pdev = to_pci_dev(dev);
 
-   return sprintf(buf, "%u\n", pdev->sriov->stride);
+   return sysfs_emit(buf, "%u\n", pdev->sriov->stride);
 }
 
 static ssize_t sriov_vf_device_show(struct device *dev,
@@ -453,7 +453,7 @@ static ssize_t sriov_vf_device_show(struct device *dev,
 {
struct pci_dev *pdev = to_pci_dev(dev);
 
-   return sprintf(buf, "%x\n", pdev->sriov->vf_device);
+   return sysfs_emit(buf, "%x\n", pdev->sriov->vf_device);
 }
 
 static ssize_t sriov_drivers_autoprobe_show(struct device *dev,
@@ -462,7 +462,7 @@ static ssize_t sriov_drivers_autoprobe_show(struct device 
*dev,
 {
struct pci_dev *pdev = to_pci_dev(dev);
 
-   return sprintf(buf, "%u\n", pdev->sriov->drivers_autoprobe);
+   return sysfs_emit(buf, "%u\n", pdev->sriov->drivers_autoprobe);
 }
 
 static ssize_t sriov_drivers_autoprobe_store(struct device *dev,
-- 
2.31.1



[PATCH 04/11] PCI/MSI: Use sysfs_emit() and sysfs_emit_at() in "show" functions

2021-05-09 Thread Krzysztof Wilczyński
The sysfs_emit() and sysfs_emit_at() functions were introduced to make
it less ambiguous which function is preferred when writing to the output
buffer in a device attribute's "show" callback [1].

Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
latter is aware of the PAGE_SIZE buffer and correctly returns the number
of bytes written into the buffer.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Related to:
  commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in 
"show" functions")

Signed-off-by: Krzysztof Wilczyński 
---
 drivers/pci/msi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 217dc9f0231f..dbfec59dfe41 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -465,8 +465,8 @@ static ssize_t msi_mode_show(struct device *dev, struct 
device_attribute *attr,
 
entry = irq_get_msi_desc(irq);
if (entry)
-   return sprintf(buf, "%s\n",
-   entry->msi_attrib.is_msix ? "msix" : "msi");
+   return sysfs_emit(buf, "%s\n",
+ entry->msi_attrib.is_msix ? "msix" : "msi");
 
return -ENODEV;
 }
-- 
2.31.1



[PATCH 02/11] PCI/AER: Use sysfs_emit() and sysfs_emit_at() in "show" functions

2021-05-09 Thread Krzysztof Wilczyński
The sysfs_emit() and sysfs_emit_at() functions were introduced to make
it less ambiguous which function is preferred when writing to the output
buffer in a device attribute's "show" callback [1].

Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
latter is aware of the PAGE_SIZE buffer and correctly returns the number
of bytes written into the buffer.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Related to:
  commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in 
"show" functions")

Signed-off-by: Krzysztof Wilczyński 
---
 drivers/pci/pcie/aer.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
index ec943cee5ecc..40ef7bed7a77 100644
--- a/drivers/pci/pcie/aer.c
+++ b/drivers/pci/pcie/aer.c
@@ -529,21 +529,23 @@ static const char *aer_agent_string[] = {
 char *buf) \
 {  \
unsigned int i; \
-   char *str = buf;\
struct pci_dev *pdev = to_pci_dev(dev); \
u64 *stats = pdev->aer_stats->stats_array;  \
+   size_t len = 0; \
\
for (i = 0; i < ARRAY_SIZE(strings_array); i++) {   \
if (strings_array[i])   \
-   str += sprintf(str, "%s %llu\n",\
-  strings_array[i], stats[i]); \
+   len += sysfs_emit_at(buf, len, "%s %llu\n", \
+strings_array[i],  \
+stats[i]); \
else if (stats[i])  \
-   str += sprintf(str, #stats_array "_bit[%d] %llu\n",\
-  i, stats[i]);\
+   len += sysfs_emit_at(buf, len,  \
+#stats_array "_bit[%d] %llu\n",\
+i, stats[i]);  \
}   \
-   str += sprintf(str, "TOTAL_%s %llu\n", total_string,\
-  pdev->aer_stats->total_field);   \
-   return str-buf; \
+   len += sysfs_emit_at(buf, len, "TOTAL_%s %llu\n", total_string, \
+pdev->aer_stats->total_field); \
+   return len; \
 }  \
 static DEVICE_ATTR_RO(name)
 
@@ -563,7 +565,7 @@ aer_stats_dev_attr(aer_dev_nonfatal, dev_nonfatal_errs,
 char *buf) \
 {  \
struct pci_dev *pdev = to_pci_dev(dev); \
-   return sprintf(buf, "%llu\n", pdev->aer_stats->field);  \
+   return sysfs_emit(buf, "%llu\n", pdev->aer_stats->field);   \
 }  \
 static DEVICE_ATTR_RO(name)
 
-- 
2.31.1



[PATCH 01/11] PCI: Use sysfs_emit() and sysfs_emit_at() in "show" functions

2021-05-09 Thread Krzysztof Wilczyński
The sysfs_emit() and sysfs_emit_at() functions were introduced to make
it less ambiguous which function is preferred when writing to the output
buffer in a device attribute's "show" callback [1].

Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
latter is aware of the PAGE_SIZE buffer and correctly returns the number
of bytes written into the buffer.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Related to:
  commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in 
"show" functions")

Signed-off-by: Krzysztof Wilczyński 
---
 drivers/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b717680377a9..5ed316ea5831 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -6439,7 +6439,7 @@ static ssize_t resource_alignment_show(struct bus_type 
*bus, char *buf)
 
spin_lock(_alignment_lock);
if (resource_alignment_param)
-   count = scnprintf(buf, PAGE_SIZE, "%s", 
resource_alignment_param);
+   count = sysfs_emit(buf, "%s", resource_alignment_param);
spin_unlock(_alignment_lock);
 
/*
-- 
2.31.1



[PATCH 03/11] PCI: Use sysfs_emit() and sysfs_emit_at() in "show" functions

2021-05-09 Thread Krzysztof Wilczyński
The sysfs_emit() and sysfs_emit_at() functions were introduced to make
it less ambiguous which function is preferred when writing to the output
buffer in a device attribute's "show" callback [1].

Convert the PCI sysfs object "show" functions from sprintf(), snprintf()
and scnprintf() to sysfs_emit() and sysfs_emit_at() accordingly, as the
latter is aware of the PAGE_SIZE buffer and correctly returns the number
of bytes written into the buffer.

Modify the function dsm_label_utf16s_to_utf8s() to directly return the
number of bytes written into the buffer so that the strlen() used later
to calculate the length of the buffer can be removed as it would no
longer be needed.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Related to:
  commit ad025f8e46f3 ("PCI/sysfs: Use sysfs_emit() and sysfs_emit_at() in 
"show" functions")

Signed-off-by: Krzysztof Wilczyński 
---
 drivers/pci/pci-label.c | 18 ++
 drivers/pci/slot.c  | 16 
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/drivers/pci/pci-label.c b/drivers/pci/pci-label.c
index c32f3b7540e8..000e169c7197 100644
--- a/drivers/pci/pci-label.c
+++ b/drivers/pci/pci-label.c
@@ -139,14 +139,17 @@ enum acpi_attr_enum {
ACPI_ATTR_INDEX_SHOW,
 };
 
-static void dsm_label_utf16s_to_utf8s(union acpi_object *obj, char *buf)
+static int dsm_label_utf16s_to_utf8s(union acpi_object *obj, char *buf)
 {
int len;
+
len = utf16s_to_utf8s((const wchar_t *)obj->buffer.pointer,
  obj->buffer.length,
  UTF16_LITTLE_ENDIAN,
  buf, PAGE_SIZE);
buf[len] = '\n';
+
+   return len;
 }
 
 static int dsm_get_label(struct device *dev, char *buf,
@@ -154,7 +157,7 @@ static int dsm_get_label(struct device *dev, char *buf,
 {
acpi_handle handle = ACPI_HANDLE(dev);
union acpi_object *obj, *tmp;
-   int len = -1;
+   int len = 0;
 
if (!handle)
return -1;
@@ -175,20 +178,19 @@ static int dsm_get_label(struct device *dev, char *buf,
 * this entry must return a null string.
 */
if (attr == ACPI_ATTR_INDEX_SHOW) {
-   scnprintf(buf, PAGE_SIZE, "%llu\n", tmp->integer.value);
+   len = sysfs_emit(buf, "%llu\n", tmp->integer.value);
} else if (attr == ACPI_ATTR_LABEL_SHOW) {
if (tmp[1].type == ACPI_TYPE_STRING)
-   scnprintf(buf, PAGE_SIZE, "%s\n",
- tmp[1].string.pointer);
+   len = sysfs_emit(buf, "%s\n",
+tmp[1].string.pointer);
else if (tmp[1].type == ACPI_TYPE_BUFFER)
-   dsm_label_utf16s_to_utf8s(tmp + 1, buf);
+   len = dsm_label_utf16s_to_utf8s(tmp + 1, buf);
}
-   len = strlen(buf) > 0 ? strlen(buf) : -1;
}
 
ACPI_FREE(obj);
 
-   return len;
+   return len > 0 ? len : -1;
 }
 
 static ssize_t label_show(struct device *dev, struct device_attribute *attr,
diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
index d627dd9179b4..7487e8f8f13f 100644
--- a/drivers/pci/slot.c
+++ b/drivers/pci/slot.c
@@ -39,19 +39,19 @@ static const struct sysfs_ops pci_slot_sysfs_ops = {
 static ssize_t address_read_file(struct pci_slot *slot, char *buf)
 {
if (slot->number == 0xff)
-   return sprintf(buf, "%04x:%02x\n",
-   pci_domain_nr(slot->bus),
-   slot->bus->number);
+   return sysfs_emit(buf, "%04x:%02x\n",
+ pci_domain_nr(slot->bus),
+ slot->bus->number);
else
-   return sprintf(buf, "%04x:%02x:%02x\n",
-   pci_domain_nr(slot->bus),
-   slot->bus->number,
-   slot->number);
+   return sysfs_emit(buf, "%04x:%02x:%02x\n",
+ pci_domain_nr(slot->bus),
+ slot->bus->number,
+ slot->number);
 }
 
 static ssize_t bus_speed_read(enum pci_bus_speed speed, char *buf)
 {
-   return sprintf(buf, "%s\n", pci_speed_string(speed));
+   return sysfs_emit(buf, "%s\n", pci_speed_string(speed));
 }
 
 static ssize_t max_speed_read_file(struct pci_slot *slot, char *buf)
-- 
2.31.1



[PATCH v13 8/8] powerpc/32: use set_memory_attr()

2021-05-09 Thread Jordan Niethe
From: Christophe Leroy 

Use set_memory_attr() instead of the PPC32 specific change_page_attr()

change_page_attr() was checking that the address was not mapped by
blocks and was handling highmem, but that's unneeded because the
affected pages can't be in highmem and block mapping verification
is already done by the callers.

Signed-off-by: Christophe Leroy 
[ruscur: rebase on powerpc/merge with Christophe's new patches]
Signed-off-by: Russell Currey 
Signed-off-by: Jordan Niethe 
---
 arch/powerpc/mm/pgtable_32.c | 60 ++--
 1 file changed, 10 insertions(+), 50 deletions(-)

diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index e0ec67a16887..dcf5ecca19d9 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -132,64 +133,20 @@ void __init mapin_ram(void)
}
 }
 
-static int __change_page_attr_noflush(struct page *page, pgprot_t prot)
-{
-   pte_t *kpte;
-   unsigned long address;
-
-   BUG_ON(PageHighMem(page));
-   address = (unsigned long)page_address(page);
-
-   if (v_block_mapped(address))
-   return 0;
-   kpte = virt_to_kpte(address);
-   if (!kpte)
-   return -EINVAL;
-   __set_pte_at(_mm, address, kpte, mk_pte(page, prot), 0);
-
-   return 0;
-}
-
-/*
- * Change the page attributes of an page in the linear mapping.
- *
- * THIS DOES NOTHING WITH BAT MAPPINGS, DEBUG USE ONLY
- */
-static int change_page_attr(struct page *page, int numpages, pgprot_t prot)
-{
-   int i, err = 0;
-   unsigned long flags;
-   struct page *start = page;
-
-   local_irq_save(flags);
-   for (i = 0; i < numpages; i++, page++) {
-   err = __change_page_attr_noflush(page, prot);
-   if (err)
-   break;
-   }
-   wmb();
-   local_irq_restore(flags);
-   flush_tlb_kernel_range((unsigned long)page_address(start),
-  (unsigned long)page_address(page));
-   return err;
-}
-
 void mark_initmem_nx(void)
 {
-   struct page *page = virt_to_page(_sinittext);
unsigned long numpages = PFN_UP((unsigned long)_einittext) -
 PFN_DOWN((unsigned long)_sinittext);
 
if (v_block_mapped((unsigned long)_sinittext))
mmu_mark_initmem_nx();
else
-   change_page_attr(page, numpages, PAGE_KERNEL);
+   set_memory_attr((unsigned long)_sinittext, numpages, 
PAGE_KERNEL);
 }
 
 #ifdef CONFIG_STRICT_KERNEL_RWX
 void mark_rodata_ro(void)
 {
-   struct page *page;
unsigned long numpages;
 
if (v_block_mapped((unsigned long)_stext + 1)) {
@@ -198,20 +155,18 @@ void mark_rodata_ro(void)
return;
}
 
-   page = virt_to_page(_stext);
numpages = PFN_UP((unsigned long)_etext) -
   PFN_DOWN((unsigned long)_stext);
 
-   change_page_attr(page, numpages, PAGE_KERNEL_ROX);
+   set_memory_attr((unsigned long)_stext, numpages, PAGE_KERNEL_ROX);
/*
 * mark .rodata as read only. Use __init_begin rather than __end_rodata
 * to cover NOTES and EXCEPTION_TABLE.
 */
-   page = virt_to_page(__start_rodata);
numpages = PFN_UP((unsigned long)__init_begin) -
   PFN_DOWN((unsigned long)__start_rodata);
 
-   change_page_attr(page, numpages, PAGE_KERNEL_RO);
+   set_memory_attr((unsigned long)__start_rodata, numpages, 
PAGE_KERNEL_RO);
 
// mark_initmem_nx() should have already run by now
ptdump_check_wx();
@@ -221,9 +176,14 @@ void mark_rodata_ro(void)
 #ifdef CONFIG_DEBUG_PAGEALLOC
 void __kernel_map_pages(struct page *page, int numpages, int enable)
 {
+   unsigned long addr = (unsigned long)page_address(page);
+
if (PageHighMem(page))
return;
 
-   change_page_attr(page, numpages, enable ? PAGE_KERNEL : __pgprot(0));
+   if (enable)
+   set_memory_attr(addr, numpages, PAGE_KERNEL);
+   else
+   set_memory_attr(addr, numpages, __pgprot(0));
 }
 #endif /* CONFIG_DEBUG_PAGEALLOC */
-- 
2.25.1



[PATCH v13 7/8] powerpc/mm: implement set_memory_attr()

2021-05-09 Thread Jordan Niethe
From: Christophe Leroy 

In addition to the set_memory_xx() functions which allows to change
the memory attributes of not (yet) used memory regions, implement a
set_memory_attr() function to:
- set the final memory protection after init on currently used
kernel regions.
- enable/disable kernel memory regions in the scope of DEBUG_PAGEALLOC.

Unlike the set_memory_xx() which can act in three step as the regions
are unused, this function must modify 'on the fly' as the kernel is
executing from them. At the moment only PPC32 will use it and changing
page attributes on the fly is not an issue.

Signed-off-by: Christophe Leroy 
Reported-by: kbuild test robot 
[ruscur: cast "data" to unsigned long instead of int]
Signed-off-by: Russell Currey 
Signed-off-by: Jordan Niethe 
---
 arch/powerpc/include/asm/set_memory.h |  2 ++
 arch/powerpc/mm/pageattr.c| 33 +++
 2 files changed, 35 insertions(+)

diff --git a/arch/powerpc/include/asm/set_memory.h 
b/arch/powerpc/include/asm/set_memory.h
index 64011ea444b4..b040094f7920 100644
--- a/arch/powerpc/include/asm/set_memory.h
+++ b/arch/powerpc/include/asm/set_memory.h
@@ -29,4 +29,6 @@ static inline int set_memory_x(unsigned long addr, int 
numpages)
return change_memory_attr(addr, numpages, SET_MEMORY_X);
 }
 
+int set_memory_attr(unsigned long addr, int numpages, pgprot_t prot);
+
 #endif
diff --git a/arch/powerpc/mm/pageattr.c b/arch/powerpc/mm/pageattr.c
index acfdde78e0fb..7dee30cd6b48 100644
--- a/arch/powerpc/mm/pageattr.c
+++ b/arch/powerpc/mm/pageattr.c
@@ -98,3 +98,36 @@ int change_memory_attr(unsigned long addr, int numpages, 
long action)
return apply_to_existing_page_range(_mm, start, size,
change_page_attr, (void *)action);
 }
+
+/*
+ * Set the attributes of a page:
+ *
+ * This function is used by PPC32 at the end of init to set final kernel memory
+ * protection. It includes changing the maping of the page it is executing from
+ * and data pages it is using.
+ */
+static int set_page_attr(pte_t *ptep, unsigned long addr, void *data)
+{
+   pgprot_t prot = __pgprot((unsigned long)data);
+
+   spin_lock(_mm.page_table_lock);
+
+   set_pte_at(_mm, addr, ptep, pte_modify(*ptep, prot));
+   flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
+
+   spin_unlock(_mm.page_table_lock);
+
+   return 0;
+}
+
+int set_memory_attr(unsigned long addr, int numpages, pgprot_t prot)
+{
+   unsigned long start = ALIGN_DOWN(addr, PAGE_SIZE);
+   unsigned long sz = numpages * PAGE_SIZE;
+
+   if (numpages <= 0)
+   return 0;
+
+   return apply_to_existing_page_range(_mm, start, sz, set_page_attr,
+   (void *)pgprot_val(prot));
+}
-- 
2.25.1



[PATCH v13 6/8] powerpc: Set ARCH_HAS_STRICT_MODULE_RWX

2021-05-09 Thread Jordan Niethe
From: Russell Currey 

To enable strict module RWX on powerpc, set:

CONFIG_STRICT_MODULE_RWX=y

You should also have CONFIG_STRICT_KERNEL_RWX=y set to have any real
security benefit.

ARCH_HAS_STRICT_MODULE_RWX is set to require ARCH_HAS_STRICT_KERNEL_RWX.
This is due to a quirk in arch/Kconfig and arch/powerpc/Kconfig that
makes STRICT_MODULE_RWX *on by default* in configurations where
STRICT_KERNEL_RWX is *unavailable*.

Since this doesn't make much sense, and module RWX without kernel RWX
doesn't make much sense, having the same dependencies as kernel RWX
works around this problem.

With STRICT_MODULE_RWX, now make module_alloc() allocate pages with
KERNEL_PAGE protection rather than KERNEL_PAGE_EXEC.

Book32s/32 processors with a hash mmu (i.e. 604 core) can not set memory
protection on a page by page basis so do not enable.

Signed-off-by: Russell Currey 
[jpn: - predicate on !PPC_BOOK3S_604
  - make module_alloc() use PAGE_KERNEL protection]
Signed-off-by: Jordan Niethe 
---
v10: - Predicate on !PPC_BOOK3S_604
 - Make module_alloc() use PAGE_KERNEL protection
v11: - Neaten up
v13: Use strict_kernel_rwx_enabled()
---
 arch/powerpc/Kconfig | 1 +
 arch/powerpc/kernel/module.c | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index cce0a137b046..cb5d9d862c35 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -140,6 +140,7 @@ config PPC
select ARCH_HAS_SCALED_CPUTIME  if VIRT_CPU_ACCOUNTING_NATIVE 
&& PPC_BOOK3S_64
select ARCH_HAS_SET_MEMORY
select ARCH_HAS_STRICT_KERNEL_RWX   if ((PPC_BOOK3S_64 || PPC32) && 
!HIBERNATION)
+   select ARCH_HAS_STRICT_MODULE_RWX   if ARCH_HAS_STRICT_KERNEL_RWX 
&& !PPC_BOOK3S_604
select ARCH_HAS_TICK_BROADCAST  if GENERIC_CLOCKEVENTS_BROADCAST
select ARCH_HAS_UACCESS_FLUSHCACHE
select ARCH_HAS_COPY_MC if PPC64
diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c
index 3f35c8d20be7..f24004635ed5 100644
--- a/arch/powerpc/kernel/module.c
+++ b/arch/powerpc/kernel/module.c
@@ -92,12 +92,14 @@ int module_finalize(const Elf_Ehdr *hdr,
 static __always_inline void *
 __module_alloc(unsigned long size, unsigned long start, unsigned long end)
 {
+   pgprot_t prot = strict_kernel_rwx_enabled() ? PAGE_KERNEL : 
PAGE_KERNEL_EXEC;
+
/*
 * Don't do huge page allocations for modules yet until more testing
 * is done. STRICT_MODULE_RWX may require extra work to support this
 * too.
 */
-   return __vmalloc_node_range(size, 1, start, end, GFP_KERNEL, 
PAGE_KERNEL_EXEC,
+   return __vmalloc_node_range(size, 1, start, end, GFP_KERNEL, prot,
VM_FLUSH_RESET_PERMS | VM_NO_HUGE_VMAP,
NUMA_NO_NODE, __builtin_return_address(0));
 }
-- 
2.25.1



[PATCH v13 5/8] powerpc/bpf: Write protect JIT code

2021-05-09 Thread Jordan Niethe
Add the necessary call to bpf_jit_binary_lock_ro() to remove write and
add exec permissions to the JIT image after it has finished being
written.

Without CONFIG_STRICT_MODULE_RWX the image will be writable and
executable until the call to bpf_jit_binary_lock_ro().

Reviewed-by: Christophe Leroy 
Signed-off-by: Jordan Niethe 
---
v10: New to series
v11: Remove CONFIG_STRICT_MODULE_RWX conditional
---
 arch/powerpc/net/bpf_jit_comp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index 6c8c268e4fe8..53aefee3fe70 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -237,6 +237,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
fp->jited_len = alloclen;
 
bpf_flush_icache(bpf_hdr, (u8 *)bpf_hdr + (bpf_hdr->pages * PAGE_SIZE));
+   bpf_jit_binary_lock_ro(bpf_hdr);
if (!fp->is_func || extra_pass) {
bpf_prog_fill_jited_linfo(fp, addrs);
 out_addrs:
-- 
2.25.1



[PATCH v13 4/8] powerpc/bpf: Remove bpf_jit_free()

2021-05-09 Thread Jordan Niethe
Commit 74451e66d516 ("bpf: make jited programs visible in traces") added
a default bpf_jit_free() implementation. Powerpc did not use the default
bpf_jit_free() as powerpc did not set the images read-only. The default
bpf_jit_free() called bpf_jit_binary_unlock_ro() is why it could not be
used for powerpc.

Commit d53d2f78cead ("bpf: Use vmalloc special flag") moved keeping
track of read-only memory to vmalloc. This included removing
bpf_jit_binary_unlock_ro(). Therefore there is no reason powerpc needs
its own bpf_jit_free(). Remove it.

Reviewed-by: Christophe Leroy 
Signed-off-by: Jordan Niethe 
---
v11: New to series
---
 arch/powerpc/net/bpf_jit_comp.c | 12 
 1 file changed, 12 deletions(-)

diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index 798ac4350a82..6c8c268e4fe8 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -257,15 +257,3 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
 
return fp;
 }
-
-/* Overriding bpf_jit_free() as we don't set images read-only. */
-void bpf_jit_free(struct bpf_prog *fp)
-{
-   unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
-   struct bpf_binary_header *bpf_hdr = (void *)addr;
-
-   if (fp->jited)
-   bpf_jit_binary_free(bpf_hdr);
-
-   bpf_prog_unlock_free(fp);
-}
-- 
2.25.1



[PATCH v13 3/8] powerpc/kprobes: Mark newly allocated probes as ROX

2021-05-09 Thread Jordan Niethe
From: Russell Currey 

Add the arch specific insn page allocator for powerpc. This allocates
ROX pages if STRICT_KERNEL_RWX is enabled. These pages are only written
to with patch_instruction() which is able to write RO pages.

Reviewed-by: Daniel Axtens 
Signed-off-by: Russell Currey 
Signed-off-by: Christophe Leroy 
[jpn: Reword commit message, switch to __vmalloc_node_range()]
Signed-off-by: Jordan Niethe 
---
v9: - vmalloc_exec() no longer exists
- Set the page to RW before freeing it
v10: - use __vmalloc_node_range()
v11: - Neaten up
v12: - Switch from __vmalloc_node_range() to module_alloc()
v13: Use strict_kernel_rwx_enabled()
---
 arch/powerpc/kernel/kprobes.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index 01ab2163659e..b517f3e6e7c5 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -19,11 +19,13 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
@@ -103,6 +105,21 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name, 
unsigned int offset)
return addr;
 }
 
+void *alloc_insn_page(void)
+{
+   void *page;
+
+   page = module_alloc(PAGE_SIZE);
+   if (!page)
+   return NULL;
+
+   if (strict_kernel_rwx_enabled()) {
+   set_memory_ro((unsigned long)page, 1);
+   set_memory_x((unsigned long)page, 1);
+   }
+   return page;
+}
+
 int arch_prepare_kprobe(struct kprobe *p)
 {
int ret = 0;
-- 
2.25.1



[PATCH v13 2/8] powerpc/lib/code-patching: Set up Strict RWX patching earlier

2021-05-09 Thread Jordan Niethe
setup_text_poke_area() is a late init call so it runs before
mark_rodata_ro() and after the init calls. This lets all the init code
patching simply write to their locations. In the future, kprobes is
going to allocate its instruction pages RO which means they will need
setup_text__poke_area() to have been already called for their code
patching. However, init_kprobes() (which allocates and patches some
instruction pages) is an early init call so it happens before
setup_text__poke_area().

start_kernel() calls poking_init() before any of the init calls. On
powerpc, poking_init() is currently a nop. setup_text_poke_area() relies
on kernel virtual memory, cpu hotplug and per_cpu_areas being setup.
setup_per_cpu_areas(), boot_cpu_hotplug_init() and mm_init() are called
before poking_init().

Turn setup_text_poke_area() into poking_init().

Reviewed-by: Christophe Leroy 
Reviewed-by: Russell Currey 
Signed-off-by: Jordan Niethe 
---
v9: New to series
---
 arch/powerpc/lib/code-patching.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 870b30d9be2f..15296207e1ba 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -70,14 +70,11 @@ static int text_area_cpu_down(unsigned int cpu)
 }
 
 /*
- * Run as a late init call. This allows all the boot time patching to be done
- * simply by patching the code, and then we're called here prior to
- * mark_rodata_ro(), which happens after all init calls are run. Although
- * BUG_ON() is rude, in this case it should only happen if ENOMEM, and we judge
- * it as being preferable to a kernel that will crash later when someone tries
- * to use patch_instruction().
+ * Although BUG_ON() is rude, in this case it should only happen if ENOMEM, and
+ * we judge it as being preferable to a kernel that will crash later when
+ * someone tries to use patch_instruction().
  */
-static int __init setup_text_poke_area(void)
+int __init poking_init(void)
 {
BUG_ON(!cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
"powerpc/text_poke:online", text_area_cpu_up,
@@ -85,7 +82,6 @@ static int __init setup_text_poke_area(void)
 
return 0;
 }
-late_initcall(setup_text_poke_area);
 
 /*
  * This can be called for kernel text or a module.
-- 
2.25.1



[PATCH v13 1/8] powerpc/mm: Implement set_memory() routines

2021-05-09 Thread Jordan Niethe
From: Russell Currey 

The set_memory_{ro/rw/nx/x}() functions are required for
STRICT_MODULE_RWX, and are generally useful primitives to have.  This
implementation is designed to be generic across powerpc's many MMUs.
It's possible that this could be optimised to be faster for specific
MMUs.

This implementation does not handle cases where the caller is attempting
to change the mapping of the page it is executing from, or if another
CPU is concurrently using the page being altered.  These cases likely
shouldn't happen, but a more complex implementation with MMU-specific code
could safely handle them.

On hash, the linear mapping is not kept in the linux pagetable, so this
will not change the protection if used on that range. Currently these
functions are not used on the linear map so just WARN for now.

apply_to_existing_page_range() does not work on huge pages so for now
disallow changing the protection of huge pages.

Reviewed-by: Daniel Axtens 
Signed-off-by: Russell Currey 
Signed-off-by: Christophe Leroy 
[jpn: - Allow set memory functions to be used without Strict RWX
  - Hash: Disallow certain regions
  - Have change_page_attr() take function pointers to manipulate ptes
  - Radix: Add ptesync after set_pte_at()]
Signed-off-by: Jordan Niethe 
---
v10: WARN if trying to change the hash linear map
v11: - Update copywrite dates
 - Allow set memory functions to be used without Strict RWX
 - Hash: Disallow certain regions and add comment explaining why
 - Have change_page_attr() take function pointers to manipulate ptes
 - Clarify change_page_attr()'s comment
 - Radix: Add ptesync after set_pte_at()
v12: - change_page_attr() back to taking an action value
 - disallow operating on huge pages
---
 arch/powerpc/Kconfig  |   1 +
 arch/powerpc/include/asm/set_memory.h |  32 +
 arch/powerpc/mm/Makefile  |   2 +-
 arch/powerpc/mm/pageattr.c| 100 ++
 4 files changed, 134 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/include/asm/set_memory.h
 create mode 100644 arch/powerpc/mm/pageattr.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 3f863dd21374..cce0a137b046 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -138,6 +138,7 @@ config PPC
select ARCH_HAS_MEMBARRIER_CALLBACKS
select ARCH_HAS_MEMBARRIER_SYNC_CORE
select ARCH_HAS_SCALED_CPUTIME  if VIRT_CPU_ACCOUNTING_NATIVE 
&& PPC_BOOK3S_64
+   select ARCH_HAS_SET_MEMORY
select ARCH_HAS_STRICT_KERNEL_RWX   if ((PPC_BOOK3S_64 || PPC32) && 
!HIBERNATION)
select ARCH_HAS_TICK_BROADCAST  if GENERIC_CLOCKEVENTS_BROADCAST
select ARCH_HAS_UACCESS_FLUSHCACHE
diff --git a/arch/powerpc/include/asm/set_memory.h 
b/arch/powerpc/include/asm/set_memory.h
new file mode 100644
index ..64011ea444b4
--- /dev/null
+++ b/arch/powerpc/include/asm/set_memory.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_POWERPC_SET_MEMORY_H
+#define _ASM_POWERPC_SET_MEMORY_H
+
+#define SET_MEMORY_RO  0
+#define SET_MEMORY_RW  1
+#define SET_MEMORY_NX  2
+#define SET_MEMORY_X   3
+
+int change_memory_attr(unsigned long addr, int numpages, long action);
+
+static inline int set_memory_ro(unsigned long addr, int numpages)
+{
+   return change_memory_attr(addr, numpages, SET_MEMORY_RO);
+}
+
+static inline int set_memory_rw(unsigned long addr, int numpages)
+{
+   return change_memory_attr(addr, numpages, SET_MEMORY_RW);
+}
+
+static inline int set_memory_nx(unsigned long addr, int numpages)
+{
+   return change_memory_attr(addr, numpages, SET_MEMORY_NX);
+}
+
+static inline int set_memory_x(unsigned long addr, int numpages)
+{
+   return change_memory_attr(addr, numpages, SET_MEMORY_X);
+}
+
+#endif
diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index c3df3a8501d4..9142cf1fb0d5 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -5,7 +5,7 @@
 
 ccflags-$(CONFIG_PPC64):= $(NO_MINIMAL_TOC)
 
-obj-y  := fault.o mem.o pgtable.o mmap.o maccess.o \
+obj-y  := fault.o mem.o pgtable.o mmap.o maccess.o 
pageattr.o \
   init_$(BITS).o pgtable_$(BITS).o \
   pgtable-frag.o ioremap.o ioremap_$(BITS).o \
   init-common.o mmu_context.o drmem.o \
diff --git a/arch/powerpc/mm/pageattr.c b/arch/powerpc/mm/pageattr.c
new file mode 100644
index ..acfdde78e0fb
--- /dev/null
+++ b/arch/powerpc/mm/pageattr.c
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * MMU-generic set_memory implementation for powerpc
+ *
+ * Copyright 2019-2021, IBM Corporation.
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+
+/*
+ * Updates the attributes of a page in three steps:
+ *
+ * 1. invalidate the page table entry
+ * 2. 

[PATCH v13 0/8] powerpc: Further Strict RWX support

2021-05-09 Thread Jordan Niethe
Adding more Strict RWX support on powerpc, in particular Strict Module RWX.
Thanks for all of the feedback everyone.
It is now rebased on linux-next + powerpc/64s/radix: Enable huge vmalloc 
mappings
(https://lore.kernel.org/linuxppc-dev/20210503091755.613393-1-npig...@gmail.com/)

For reference the previous revision is available here: 
https://lore.kernel.org/linuxppc-dev/20210506023449.3568630-1-jniet...@gmail.com/

The changes in v13 for each patch:

Christophe Leroy (2):
  powerpc/mm: implement set_memory_attr()
  powerpc/32: use set_memory_attr()

Jordan Niethe (3):
  powerpc/lib/code-patching: Set up Strict RWX patching earlier
  powerpc/bpf: Remove bpf_jit_free()
  powerpc/bpf: Write protect JIT code

Russell Currey (3):
  powerpc/mm: Implement set_memory() routines
  powerpc/kprobes: Mark newly allocated probes as ROX
- v13: Use strict_kernel_rwx_enabled()
  powerpc: Set ARCH_HAS_STRICT_MODULE_RWX
- v13: Use strict_kernel_rwx_enabled()

 arch/powerpc/Kconfig  |   2 +
 arch/powerpc/include/asm/set_memory.h |  34 +++
 arch/powerpc/kernel/kprobes.c |  17 
 arch/powerpc/kernel/module.c  |   4 +-
 arch/powerpc/lib/code-patching.c  |  12 +--
 arch/powerpc/mm/Makefile  |   2 +-
 arch/powerpc/mm/pageattr.c| 133 ++
 arch/powerpc/mm/pgtable_32.c  |  60 ++--
 arch/powerpc/net/bpf_jit_comp.c   |  13 +--
 9 files changed, 205 insertions(+), 72 deletions(-)
 create mode 100644 arch/powerpc/include/asm/set_memory.h
 create mode 100644 arch/powerpc/mm/pageattr.c

-- 
2.25.1



Re: [PATCH v12 6/8] powerpc: Set ARCH_HAS_STRICT_MODULE_RWX

2021-05-09 Thread Jordan Niethe
On Fri, May 7, 2021 at 3:35 PM Christophe Leroy
 wrote:
>
>
>
> Le 06/05/2021 à 04:34, Jordan Niethe a écrit :
> > From: Russell Currey 
> >
> > To enable strict module RWX on powerpc, set:
> >
> >  CONFIG_STRICT_MODULE_RWX=y
> >
> > You should also have CONFIG_STRICT_KERNEL_RWX=y set to have any real
> > security benefit.
> >
> > ARCH_HAS_STRICT_MODULE_RWX is set to require ARCH_HAS_STRICT_KERNEL_RWX.
> > This is due to a quirk in arch/Kconfig and arch/powerpc/Kconfig that
> > makes STRICT_MODULE_RWX *on by default* in configurations where
> > STRICT_KERNEL_RWX is *unavailable*.
> >
> > Since this doesn't make much sense, and module RWX without kernel RWX
> > doesn't make much sense, having the same dependencies as kernel RWX
> > works around this problem.
> >
> > With STRICT_MODULE_RWX, now make module_alloc() allocate pages with
> > KERNEL_PAGE protection rather than KERNEL_PAGE_EXEC.
> >
> > Book32s/32 processors with a hash mmu (i.e. 604 core) can not set memory
> > protection on a page by page basis so do not enable.
> >
> > Signed-off-by: Russell Currey 
> > [jpn: - predicate on !PPC_BOOK3S_604
> >- make module_alloc() use PAGE_KERNEL protection]
> > Signed-off-by: Jordan Niethe 
> > ---
> > v10: - Predicate on !PPC_BOOK3S_604
> >   - Make module_alloc() use PAGE_KERNEL protection
> > v11: - Neaten up
> > ---
> >   arch/powerpc/Kconfig | 1 +
> >   arch/powerpc/kernel/module.c | 4 +++-
> >   2 files changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> > index cce0a137b046..cb5d9d862c35 100644
> > --- a/arch/powerpc/Kconfig
> > +++ b/arch/powerpc/Kconfig
> > @@ -140,6 +140,7 @@ config PPC
> >   select ARCH_HAS_SCALED_CPUTIME  if VIRT_CPU_ACCOUNTING_NATIVE 
> > && PPC_BOOK3S_64
> >   select ARCH_HAS_SET_MEMORY
> >   select ARCH_HAS_STRICT_KERNEL_RWX   if ((PPC_BOOK3S_64 || PPC32) 
> > && !HIBERNATION)
> > + select ARCH_HAS_STRICT_MODULE_RWX   if ARCH_HAS_STRICT_KERNEL_RWX 
> > && !PPC_BOOK3S_604
> >   select ARCH_HAS_TICK_BROADCAST  if 
> > GENERIC_CLOCKEVENTS_BROADCAST
> >   select ARCH_HAS_UACCESS_FLUSHCACHE
> >   select ARCH_HAS_COPY_MC if PPC64
> > diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c
> > index 3f35c8d20be7..33e4011228b0 100644
> > --- a/arch/powerpc/kernel/module.c
> > +++ b/arch/powerpc/kernel/module.c
> > @@ -92,12 +92,14 @@ int module_finalize(const Elf_Ehdr *hdr,
> >   static __always_inline void *
> >   __module_alloc(unsigned long size, unsigned long start, unsigned long end)
> >   {
> > + pgprot_t prot = IS_ENABLED(CONFIG_STRICT_MODULE_RWX) ? PAGE_KERNEL :
> > +
> > PAGE_KERNEL_EXEC;
>
> I'm not sure this test is OK, because strict kernel/module rwx can be 
> disabled at boottime.
> There is a global variable 'rodata_enabled' to reflect that.
>
> We have a helper in powerpc asm/mmu.h called strict_kernel_rwx_enabled() to 
> check it.
Thanks, I will change to that.
>
>
> >   /*
> >* Don't do huge page allocations for modules yet until more testing
> >* is done. STRICT_MODULE_RWX may require extra work to support this
> >* too.
> >*/
> > - return __vmalloc_node_range(size, 1, start, end, GFP_KERNEL, 
> > PAGE_KERNEL_EXEC,
> > + return __vmalloc_node_range(size, 1, start, end, GFP_KERNEL, prot,
> >   VM_FLUSH_RESET_PERMS | VM_NO_HUGE_VMAP,
> >   NUMA_NO_NODE, 
> > __builtin_return_address(0));
> >   }
> >


Re: Radeon NI: GIT kernel with the nislands_smc commit doesn't boot on a Freescale P5040 board and P.A.Semi Nemo board

2021-05-09 Thread Gustavo A. R. Silva
Hi Christian,

On 5/8/21 06:33, Christian Zigotzky wrote:
> Hi Gustavo,
> 
> Your patch works! Thanks a lot! I tested it with my Freescale P5040 board and 
> P.A.Semi Nemo board with a connected AMD Radeon HD6970 NI graphics cards 
> (Cayman
> XT) today.

Awesome! :)

Thank you!
--
Gustavo

> 
> Have a nice day,
> Christian
> 
> 
> On 07 May 2021 at 08:43am, Christian Zigotzky wrote:
>> Hi Gustavo,
>>
>> Great! I will test it. Many thanks for your help.
>>
>> Cheers,
>> Christian
>>
>>
>>> On 7. May 2021, at 01:55, Gustavo A. R. Silva  
>>> wrote:
>>>
>>> Hi Christian,
>>>
 On 4/30/21 06:59, Christian Zigotzky wrote:
 Hello,

 The Nemo board (A-EON AmigaOne X1000) [1] and the FSL P5040 Cyrus+ board 
 (A-EON AmigaOne X5000) [2] with installed AMD Radeon HD6970 NI graphics 
 cards (Cayman
 XT) [3] don't boot with the latest git kernel anymore after the commit 
 "drm/radeon/nislands_smc.h: Replace one-element array with flexible-array 
 member in
 struct NISLANDS_SMC_SWSTATE branch" [4].  This git kernel boots in a 
 virtual e5500 QEMU machine with a VirtIO-GPU [5].

 I bisected today [6].

 Result: drm/radeon/nislands_smc.h: Replace one-element array with 
 flexible-array member in struct NISLANDS_SMC_SWSTATE branch
 (434fb1e7444a2efc3a4ebd950c7f771ebfcffa31) [4] is the first bad commit.
>>> I have a fix ready for this bug:
>>> https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?h=testing/drm-nislands
>>>
>>> I wonder if you could help me to test it with your environment, please.
>>> It should be applied on top of mainline.
>>>
>>> Thank you!
>>> -- 
>>> Gustavo
>>>
 I was able to revert this commit [7] and after a new compiling, the kernel 
 boots without any problems on my AmigaOnes.

 After that I created a patch for reverting this commit for new git test 
 kernels. [3]

 The kernel compiles and boots with this patch on my AmigaOnes. Please find 
 attached the kernel config files.

 Please check the first bad commit.

 Thanks,
 Christian

 [1] https://en.wikipedia.org/wiki/AmigaOne_X1000
 [2] http://wiki.amiga.org/index.php?title=X5000
 [3] https://forum.hyperion-entertainment.com/viewtopic.php?f=35=4377
 [4] 
 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=434fb1e7444a2efc3a4ebd950c7f771ebfcffa31
 [5] qemu-system-ppc64 -M ppce500 -cpu e5500 -m 1024 -kernel uImage -drive 
 format=raw,file=MintPPC32-X5000.img,index=0,if=virtio -netdev 
 user,id=mynet0 -device
 virtio-net-pci,netdev=mynet0 -append "rw root=/dev/vda" -device virtio-vga 
 -usb -device usb-ehci,id=ehci -device usb-tablet -device 
 virtio-keyboard-pci -smp 4
 -vnc :1
 [6] https://forum.hyperion-entertainment.com/viewtopic.php?p=53074#p53074
 [7] git revert 434fb1e7444a2efc3a4ebd950c7f771ebfcffa3
> 


[PATCH] arch: powerpc: kvm: remove unnecessary casting

2021-05-09 Thread Nour-eddine Taleb
remove unnecessary castings, from "void *" to "struct kvmppc_xics *"

Signed-off-by: Nour-eddine Taleb <1337.nouredd...@gmail.com>
---
 arch/powerpc/kvm/book3s_xics.c| 2 +-
 arch/powerpc/kvm/book3s_xive.c| 2 +-
 arch/powerpc/kvm/book3s_xive_native.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index 303e3cb096db..9ae74fa551a6 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -1440,7 +1440,7 @@ static int kvmppc_xics_create(struct kvm_device
*dev, u32 type)

 static void kvmppc_xics_init(struct kvm_device *dev)
 {
-struct kvmppc_xics *xics = (struct kvmppc_xics *)dev->private;
+struct kvmppc_xics *xics = dev->private;

 xics_debugfs_init(xics);
 }
diff --git a/arch/powerpc/kvm/book3s_xive.c b/arch/powerpc/kvm/book3s_xive.c
index e7219b6f5f9a..05bcaf81a90a 100644
--- a/arch/powerpc/kvm/book3s_xive.c
+++ b/arch/powerpc/kvm/book3s_xive.c
@@ -2242,7 +2242,7 @@ static void xive_debugfs_init(struct kvmppc_xive *xive)

 static void kvmppc_xive_init(struct kvm_device *dev)
 {
-struct kvmppc_xive *xive = (struct kvmppc_xive *)dev->private;
+struct kvmppc_xive *xive = dev->private;

 /* Register some debug interfaces */
 xive_debugfs_init(xive);
diff --git a/arch/powerpc/kvm/book3s_xive_native.c
b/arch/powerpc/kvm/book3s_xive_native.c
index 76800c84f2a3..2703432cea78 100644
--- a/arch/powerpc/kvm/book3s_xive_native.c
+++ b/arch/powerpc/kvm/book3s_xive_native.c
@@ -1265,7 +1265,7 @@ static void xive_native_debugfs_init(struct
kvmppc_xive *xive)

 static void kvmppc_xive_native_init(struct kvm_device *dev)
 {
-struct kvmppc_xive *xive = (struct kvmppc_xive *)dev->private;
+struct kvmppc_xive *xive = dev->private;

 /* Register some debug interfaces */
 xive_native_debugfs_init(xive);
-- 
2.30.2


Re: [FSL P50x0] Xorg always restarts again and again after the the PowerPC updates 5.13-1

2021-05-09 Thread Christian Zigotzky

On 09 May 2021 at 07:43 pm, Christophe Leroy wrote:


On my side, book3e (corenet64_smp_defconfig) built with GCC 10.1 works 
well with QEMU 2.11.2


A kernel built with the configuration you provided doesn't boot on 
QEMU, no output at all, even with kernel v5.12.


What versions of GCC and QEMU are you using ?

Thanks
Christophe

Hi Christophe,

I use the following QEMU versions (qemu-system-ppc64):

- QEMU 5.0.0 (Debian 1:5.0-5) ELF 32-bit PowerPC with or without KVM on 
Debian Sid 32-bit userland with some 64-bit kernels [1] [3] [11] [12] 
[13] [14] [15] [16] [17]

- QEMU 5.2.0 ELF 64-bit x86_64 on Ubuntu 18.04 64-bit [2]
- QEMU 5.2.0 Mach-O 64-bit on macOS Catalina 10.15.7
- QEMU 5.2.0 on Windows Server 2016 [4] [5] [6] [7] [8] [9] [10]

The kernels work really well with my kernel configuration in QEMU (see 
screenshots [1] - [17]). You can also see the kernel 5.12 in virtual 
QEMU machines in the screenshots.
I work very often with my kernels in e5500 QEMU machines on Linux, 
macOS, and Windows.


I build my kernels with the GCC 7.5.0. We are testing very intensive all 
kernel builds in our test threads [18] [19] [20] and the kernel 5.12 
works very well on our AmigaOnes and in virtual

e5500 QEMU machines.

Cheers,
Christian

[1] 
https://i.pinimg.com/originals/94/a1/56/94a156481ab469dd6cd0eba97bd88855.png
[2] 
https://i.pinimg.com/originals/93/5a/97/935a9792ca4b76b569eeb40857b2162f.png
[3] 
https://i.pinimg.com/originals/c5/0d/85/c50d85d7e8f20b4caa1a439faf751964.png
[4] 
https://i.pinimg.com/originals/cb/1d/12/cb1d12610c197a5e24f4a549c4dc56fe.png
[5] 
https://i.pinimg.com/originals/46/e0/1a/46e01a5ef174cc65420d760b074e2f23.png
[6] 
https://i.pinimg.com/originals/15/3c/9c/153c9cba276542528721d313812f232a.png
[7] 
https://i.pinimg.com/originals/b7/dc/c0/b7dcc0d04d8a7d8e771c888403aa9f6f.png
[8] 
https://i.pinimg.com/originals/1f/37/0e/1f370e80ec9805c93d3bd30c0c3a6926.png
[9] 
https://i.pinimg.com/originals/7c/4b/1a/7c4b1a602a0760865a1722ef1608cedf.png
[10] 
https://i.pinimg.com/originals/c3/89/19/c3891928d359500ab5e7484357b4ab01.png
[11] 
https://i.pinimg.com/originals/e4/53/00/e4530020d4292b36cd1dd22a20f2ba93.png
[12] 
https://i.pinimg.com/originals/fa/92/5b/fa925bbe132caf6d7f84bdc4090690c6.png
[13] 
https://i.pinimg.com/originals/4f/b0/14/4fb01476edd7abe6be1e1203a8e7e152.png
[14] 
https://i.pinimg.com/originals/f1/23/a4/f123a448743b8039b0b5fba320daee7c.png
[15] 
https://i.pinimg.com/originals/6e/3b/59/6e3b59fe10276c5644b15622a81f43f1.png
[16] 
https://i.pinimg.com/originals/f2/a5/e3/f2a5e34e2015381b0cb87cc51232a8bc.png
[17] 
https://i.pinimg.com/originals/57/d9/83/57d98324cd055b7ae00a87ad5a45a42f.png

[18] https://forum.hyperion-entertainment.com/viewtopic.php?f=58=4612
[19] https://forum.hyperion-entertainment.com/viewtopic.php?f=35=4611
[20] https://forum.hyperion-entertainment.com/viewtopic.php?f=58=4564


Re: [PATCH v2 2/3] powerpc/fsl: set fsl, i2c-erratum-a004447 flag for P2041 i2c controllers

2021-05-09 Thread Chris Packham

On 7/05/21 8:24 pm, Joakim Tjernlund wrote:
> On Fri, 2021-05-07 at 10:04 +0200, Joakim Tjernlund wrote:
>> On Fri, 2021-05-07 at 12:40 +1200, Chris Packham wrote:
>>> The i2c controllers on the P2040/P2041 have an erratum where the
>>> documented scheme for i2c bus recovery will not work (A-004447). A
>>> different mechanism is needed which is documented in the P2040 Chip
>>> Errata Rev Q (latest available at the time of writing).
>>  From what I can tell this Erratum also applies to P1010
Will add for v3.
>>   Jocke
> Reference: https://media.digikey.com/pdf/PCNs/Freescale/P1010CE_RevL.pdf
>
> Also, I think this series should go to stable.
This series builds on changes that have been merged for v5.13. I haven't 
checked if it applies to stable, I think at least commit 65171b2df15e 
("i2c: mpc: Make use of i2c_recover_bus()") would need to come along 
with it.

Re: [PATCH v2 1/3] dt-bindings: i2c: mpc: Add fsl, i2c-erratum-a004447 flag

2021-05-09 Thread Chris Packham

On 8/05/21 9:49 am, Rob Herring wrote:
> On Fri, May 07, 2021 at 12:40:45PM +1200, Chris Packham wrote:
>> Document the fsl,i2c-erratum-a004447 flag which indicates the presence
>> of an i2c erratum on some QorIQ SoCs.
>>
>> Signed-off-by: Chris Packham 
>> ---
>>   Documentation/devicetree/bindings/i2c/i2c-mpc.yaml | 7 +++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/i2c/i2c-mpc.yaml 
>> b/Documentation/devicetree/bindings/i2c/i2c-mpc.yaml
>> index 7b553d559c83..98c6fcf7bf26 100644
>> --- a/Documentation/devicetree/bindings/i2c/i2c-mpc.yaml
>> +++ b/Documentation/devicetree/bindings/i2c/i2c-mpc.yaml
>> @@ -46,6 +46,13 @@ properties:
>>   description: |
>> I2C bus timeout in microseconds
>>   
>> +  fsl,i2c-erratum-a004447:
>> +$ref: /schemas/types.yaml#/definitions/flag
>> +description: |
>> +  Indicates the presence of QorIQ erratum A-004447, which
>> +  says that the standard i2c recovery scheme mechanism does
>> +  not work and an alternate implementation is needed.
> The problem with adding a property for an errata is you have to update
> the dtb. If you use the compatible string, then only an OS update is
> needed. That assumes you have specific enough compatible strings.

I was following the style of the existing fsl,usb-erratum-a007792 or 
fsl,erratum-a008585 properties. But that's not really a compelling reason.

The existing compatible string is "fsl-i2c" and it's used by pretty much 
every powerpc QorIQ SoC. There are some specific compatible strings in 
the driver for some of the older mpc SoCs. A more specific compatible 
string will work although determining which ones are affected might be a 
bit troublesome. That we know of the P2041 and P1010 are affected but I 
suspect there may be more. One disadvantage of using the compatible 
string is that as affected SoCs are identified we'll have to update the 
driver to know that SoC is affected and update the dtb to use it. With 
the property we'd just have to update the dtb.

I'm not too fussed either way so if that's a hard NACK on the property I 
can send a version that uses compatible strings instead.


Re: [FSL P50x0] Xorg always restarts again and again after the the PowerPC updates 5.13-1

2021-05-09 Thread Christophe Leroy




Le 09/05/2021 à 14:27, Christian Zigotzky a écrit :

On 08 May 2021 at 06:39pm, Christian Zigotzky wrote:

On 06 May 2021 at 03:58 pm, Christian Zigotzky wrote:

I have started bisecting again.

Link: https://forum.hyperion-entertainment.com/viewtopic.php?p=53106#p53106 





On 6. May 2021, at 10:09, Christophe Leroy  wrote:


- Can you check that 887f3ceb51cd with cherry-picked 525642624783 has Xorg 
working ?

git checkout 887f3ceb51cd
git cherry-pick 525642624783

Result: Xorg works.
- Can you bisect between 887f3ceb51cd[good] and 56bec2f9d4d0[bad] to identify first bad commit 
that stops after loading the dtb and uImage ?
- Once that first bad commit is identified, can you check whether the preceeding commit with 
cherry-picked 525642624783 has Xorg working or not ?


Thanks
Christophe

git bisect start
git bisect good 887f3ceb51cd
git bisect bad 56bec2f9d4d0
git bisect good -- Xorg restarts again and again but we are looking for the first bad commit that 
stops the boot after loading the dtb and uImage.

git bisect good -- Xorg restarts again and again.
git bisect good -- Xorg restarts again and again.
git bisect good -- Xorg restarts again and again.

Result:

56bec2f9d4d05675cada96772a8a93010f4d82bf is the first bad commit
commit 56bec2f9d4d05675cada96772a8a93010f4d82bf
Author: Michael Ellerman 
Date:   Wed Mar 31 11:38:40 2021 +1100

    powerpc/mm/64s: Add _PAGE_KERNEL_ROX

    In the past we had a fallback definition for _PAGE_KERNEL_ROX, but we
    removed that in commit d82fd29c5a8c ("powerpc/mm: Distribute platform
    specific PAGE and PMD flags and definitions") and added definitions
    for each MMU family.

    However we missed adding a definition for 64s, which was not really a
    bug because it's currently not used.

    But we'd like to use PAGE_KERNEL_ROX in a future patch so add a
    definition now.

    Signed-off-by: Michael Ellerman 
    Link: https://lore.kernel.org/r/20210331003845.216246-1-...@ellerman.id.au

:04 04 ff8171830c08e4f99852947a5c3b62e784220a26 85aff144e5219bce4eb6adb2ac32c6459cac22d0 
M    arch


---

git cherry-pick 525642624783

Output:

powerpc/signal32: Fix erroneous SIGSEGV on RT signal return
 Author: Christophe Leroy 
 Date: Fri Apr 23 13:52:10 2021 +
 1 file changed, 2 insertions(+), 2 deletions(-)

---

Xorg works after compiling with the cherry-pick of 525642624783.

Hi All,

I compiled and tested the latest git kernel with the new PowerPC updates 5.13-2 today. Unfortunately 
the Xorg issue still exists.

If I revert the PowerPC updates 5.13-1 and 5.13-2 then Xorg works without any 
problems.

Please check the BookE changes in the PowerPC updates 5.13-1 because my Book3S machines aren't 
affected by this issue.




On my side, book3e (corenet64_smp_defconfig) built with GCC 10.1 works well 
with QEMU 2.11.2

A kernel built with the configuration you provided doesn't boot on QEMU, no output at all, even with 
kernel v5.12.


What versions of GCC and QEMU are you using ?

Thanks
Christophe


Re: [FSL P50x0] Xorg always restarts again and again after the the PowerPC updates 5.13-1

2021-05-09 Thread Christophe Leroy

Thanks for testing

Le 08/05/2021 à 18:39, Christian Zigotzky a écrit :

On 06 May 2021 at 03:58 pm, Christian Zigotzky wrote:

I have started bisecting again.

Link: https://forum.hyperion-entertainment.com/viewtopic.php?p=53106#p53106 





On 6. May 2021, at 10:09, Christophe Leroy  wrote:


- Can you check that 887f3ceb51cd with cherry-picked 525642624783 has Xorg 
working ?

git checkout 887f3ceb51cd
git cherry-pick 525642624783


Good to know. So this confirms your problem is not related to the commit you 
bisected initially



Result: Xorg works.
- Can you bisect between 887f3ceb51cd[good] and 56bec2f9d4d0[bad] to identify first bad commit 
that stops after loading the dtb and uImage ?
- Once that first bad commit is identified, can you check whether the preceeding commit with 
cherry-picked 525642624783 has Xorg working or not ?


Thanks
Christophe

git bisect start
git bisect good 887f3ceb51cd
git bisect bad 56bec2f9d4d0
git bisect good -- Xorg restarts again and again but we are looking for the first bad commit that 
stops the boot after loading the dtb and uImage.

git bisect good -- Xorg restarts again and again.
git bisect good -- Xorg restarts again and again.
git bisect good -- Xorg restarts again and again.

Result:

56bec2f9d4d05675cada96772a8a93010f4d82bf is the first bad commit
commit 56bec2f9d4d05675cada96772a8a93010f4d82bf
Author: Michael Ellerman 
Date:   Wed Mar 31 11:38:40 2021 +1100

     powerpc/mm/64s: Add _PAGE_KERNEL_ROX



Here I'm a bit sceptique. This is a book3s related patch and it's only an additional define no I 
can't see how it can break the boot on book3e.


I see that's the top of the range I asked you to bisect on, so there is 
something wrong in the analysis.

Based on the information you gave in 
https://forum.hyperion-entertainment.com/viewtopic.php?p=53103=c8fc65914bfcba65489240cd5eb7e836#p53103 
, I rerun your bisect and established the following log:


git bisect start '--' 'arch/powerpc'
# good: [627b72bee84d6652e0af26617e71ce2b3c18fcd5] powerpc/signal32: Convert 
restore_[tm]_user_regs() to user access block

git bisect good 627b72bee84d6652e0af26617e71ce2b3c18fcd5
# bad: [c70a4be130de333ea079c59da41cc959712bb01c] Merge tag 'powerpc-5.13-1' of 
git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux

git bisect bad c70a4be130de333ea079c59da41cc959712bb01c
# bad: [49c1d07fd04f54eb588c4a1dfcedc8d22c5ffd50] powerpc/powernv: Enable HAIL (HV AIL) for ISA v3.1 
processors

git bisect bad 49c1d07fd04f54eb588c4a1dfcedc8d22c5ffd50
# skip: [01c1b9984a12a379f332c39c4b1fd96e473b93b0] powerpc/rtas-proc: remove 
unused RMO_READ_BUF_MAX
git bisect skip 01c1b9984a12a379f332c39c4b1fd96e473b93b0
# skip: [107dadb046178173dea18e0a78ff8ea3cc27c213] powerpc/perf: Make symbol 
'isa207_pmu_format_attr' static

git bisect skip 107dadb046178173dea18e0a78ff8ea3cc27c213
# skip: [56bec2f9d4d05675cada96772a8a93010f4d82bf] powerpc/mm/64s: Add 
_PAGE_KERNEL_ROX
git bisect skip 56bec2f9d4d05675cada96772a8a93010f4d82bf
# skip: [2235dea17d56238642121a8085b71d68598534bb] powerpc/pseries/pmem: Make symbol 
'drc_pmem_match' static

git bisect skip 2235dea17d56238642121a8085b71d68598534bb
# skip: [2c02e656a29d5f64193eb93da92781bcf0517146] powerpc/64s: Use htab_convert_pte_flags() in 
hash__mark_rodata_ro()

git bisect skip 2c02e656a29d5f64193eb93da92781bcf0517146
# skip: [472724111f0f72042deb6a9dcee9578e5398a1a1] powerpc/iommu: Enable remaining IOMMU Pagesizes 
present in LoPAR

git bisect skip 472724111f0f72042deb6a9dcee9578e5398a1a1
# skip: [ceff77efa4f8d9f02d8442171b325d3b7068fe5e] powerpc/64e/interrupt: Use new interrupt context 
tracking scheme

git bisect skip ceff77efa4f8d9f02d8442171b325d3b7068fe5e
# skip: [7dcc37b3eff97379b194adb17eb9a8270512dd1d] powerpc/xive: Map one IPI 
interrupt per node
git bisect skip 7dcc37b3eff97379b194adb17eb9a8270512dd1d
# skip: [097157e16cf8bf91b9cf6fbda05d234d3599c01f] powerpc/64e/interrupt: reconcile irq soft-mask 
state in C

git bisect skip 097157e16cf8bf91b9cf6fbda05d234d3599c01f


Then I looked at the list of commits in the kernel, and identified all the ones marked with ZZ or 
ZZZ as the ones which are up to now identified as not booting. And 
56bec2f9d4d05675cada96772a8a93010f4d82bf is the first commit that you skipped.


Did I do an error in my analysis ?

BAD *   c70a4be130de Merge tag 'powerpc-5.13-1' of 
git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux

|\
| * 525642624783 powerpc/signal32: Fix erroneous SIGSEGV on RT signal return
| * f9cd5f91a897 powerpc: Avoid clang uninitialized warning in 
__get_user_size_allowed
| * adb68c38d8d4 powerpc/papr_scm: Mark nvdimm as unarmed if needed during probe
| * ee1bc694fbae powerpc/kvm: Fix build error when PPC_MEM_KEYS/PPC_PSERIES=n
| * 30c400886bad powerpc/kasan: Fix shadow start address with modules
| * fc5590fd56c9 powerpc/kernel/iommu: Use largepool as a last resort when 
!largealloc
| * 3c0468d4451e 

Re: [FSL P50x0] Xorg always restarts again and again after the the PowerPC updates 5.13-1

2021-05-09 Thread Christian Zigotzky

On 08 May 2021 at 06:39pm, Christian Zigotzky wrote:

On 06 May 2021 at 03:58 pm, Christian Zigotzky wrote:

I have started bisecting again.

Link: 
https://forum.hyperion-entertainment.com/viewtopic.php?p=53106#p53106 




On 6. May 2021, at 10:09, Christophe Leroy 
 wrote:



- Can you check that 887f3ceb51cd with cherry-picked 525642624783 
has Xorg working ?

git checkout 887f3ceb51cd
git cherry-pick 525642624783

Result: Xorg works.
- Can you bisect between 887f3ceb51cd[good] and 56bec2f9d4d0[bad] to 
identify first bad commit that stops after loading the dtb and uImage ?
- Once that first bad commit is identified, can you check whether 
the preceeding commit with cherry-picked 525642624783 has Xorg 
working or not ?


Thanks
Christophe

git bisect start
git bisect good 887f3ceb51cd
git bisect bad 56bec2f9d4d0
git bisect good -- Xorg restarts again and again but we are looking 
for the first bad commit that stops the boot after loading the dtb and 
uImage.

git bisect good -- Xorg restarts again and again.
git bisect good -- Xorg restarts again and again.
git bisect good -- Xorg restarts again and again.

Result:

56bec2f9d4d05675cada96772a8a93010f4d82bf is the first bad commit
commit 56bec2f9d4d05675cada96772a8a93010f4d82bf
Author: Michael Ellerman 
Date:   Wed Mar 31 11:38:40 2021 +1100

    powerpc/mm/64s: Add _PAGE_KERNEL_ROX

    In the past we had a fallback definition for _PAGE_KERNEL_ROX, but we
    removed that in commit d82fd29c5a8c ("powerpc/mm: Distribute platform
    specific PAGE and PMD flags and definitions") and added definitions
    for each MMU family.

    However we missed adding a definition for 64s, which was not really a
    bug because it's currently not used.

    But we'd like to use PAGE_KERNEL_ROX in a future patch so add a
    definition now.

    Signed-off-by: Michael Ellerman 
    Link: 
https://lore.kernel.org/r/20210331003845.216246-1-...@ellerman.id.au


:04 04 ff8171830c08e4f99852947a5c3b62e784220a26 
85aff144e5219bce4eb6adb2ac32c6459cac22d0 M    arch


---

git cherry-pick 525642624783

Output:

powerpc/signal32: Fix erroneous SIGSEGV on RT signal return
 Author: Christophe Leroy 
 Date: Fri Apr 23 13:52:10 2021 +
 1 file changed, 2 insertions(+), 2 deletions(-)

---

Xorg works after compiling with the cherry-pick of 525642624783.

Hi All,

I compiled and tested the latest git kernel with the new PowerPC updates 
5.13-2 today. Unfortunately the Xorg issue still exists.
If I revert the PowerPC updates 5.13-1 and 5.13-2 then Xorg works 
without any problems.


Please check the BookE changes in the PowerPC updates 5.13-1 because my 
Book3S machines aren't affected by this issue.


Thanks,
Christian


Re: [PATCH 2/3] hotplug-memory.c: enhance dlpar_memory_remove* LMB checks

2021-05-09 Thread David Gibson
On Fri, May 07, 2021 at 01:36:06PM -0300, Daniel Henrique Barboza wrote:
> 
> 
> On 5/3/21 10:02 PM, David Gibson wrote:
> > On Fri, Apr 30, 2021 at 09:09:16AM -0300, Daniel Henrique Barboza wrote:
> > > dlpar_memory_remove_by_ic() validates the amount of LMBs to be removed
> > > by checking !DRCONF_MEM_RESERVED, and in the following loop before
> > > dlpar_remove_lmb() a check for DRCONF_MEM_ASSIGNED is made before
> > > removing it. This means that a LMB that is both !DRCONF_MEM_RESERVED and
> > > !DRCONF_MEM_ASSIGNED will be counted as valid, but then not being
> > > removed.  The function will end up not removing all 'lmbs_to_remove'
> > > LMBs while also not reporting any errors.
> > > 
> > > Comparing it to dlpar_memory_remove_by_count(), the validation is done
> > > via lmb_is_removable(), which checks for DRCONF_MEM_ASSIGNED and fadump
> > > constraints. No additional check is made afterwards, and
> > > DRCONF_MEM_RESERVED is never checked before dlpar_remove_lmb(). The
> > > function doesn't have the same 'check A for validation, then B for
> > > removal' issue as remove_by_ic(), but it's not checking if the LMB is
> > > reserved.
> > > 
> > > There is no reason for these functions to validate the same operation in
> > > two different manners.
> > 
> > Actually, I think there is: remove_by_ic() is handling a request to
> > remove a specific range of LMBs.  If any are reserved, they can't be
> > removed and so this needs to fail.  But if they are !ASSIGNED, that
> > essentially means they're *already* removed (or never added), so
> > "removing" them is, correctly, a no-op.
> 
> I guess that makes sense. Although I am not aware of any situation, at least
> thinking about how QEMU adds/removes LMBs, where some LMBs would be removed
> 'ad-hoc' in the middle of a LMB range that maps to a QEMU DIMM, I can't say
> that this wouldn't never happen either.

Right.  I believe a user could explicitly offline LMBs in the middle
of a DIMM. There's not much reason to do so, but it's possible.  There
might also be situations involving memory errors where individual LMBs
could get offlined.

> It is sensible to make remove_by_ic()
> resilient to this situation.
> 
> I'll re-send this patch just with the remove_by_count() change.
> 
> 
> Thanks,
> 
> 
> Daniel
> 
> > 
> > remove_by_count(), in contrast, is being asked to remove a fixed
> > number of LMBs from wherever they can be found, and for that it needs
> > to find LMBs that haven't already been removed.
> > 
> > Basically remove_by_ic() is an absolute request: "make this set of
> > LMBs be not-plugged", whereas remove_by_count() is a relative request
> > "make N less LMBs be plugged".
> > 
> > 
> > So I think remove_by_ic()s existing handling is correct.  I'm less
> > sure if remove_by_count() ignoring RESERVED is correct - I couldn't
> > quickly find under what circumstances RESERVED gets set.
> > 
> > 
> > > This patch addresses that by changing
> > > lmb_is_removable() to also check for DRCONF_MEM_RESERVED to tell if a
> > > lmb is removable, making dlpar_memory_remove_by_count() take the
> > > reservation state into account when counting the LMBs.
> > > lmb_is_removable() is then used in the validation step of
> > > dlpar_memory_remove_by_ic(), which is already checking for both states
> > > but in different stages, to avoid counting a LMB that is not assigned as
> > > eligible for removal. We can then skip the check before
> > > dlpar_remove_lmb() since we're validating all LMBs beforehand.
> > > 
> > > Signed-off-by: Daniel Henrique Barboza 
> > > ---
> > >   arch/powerpc/platforms/pseries/hotplug-memory.c | 8 +++-
> > >   1 file changed, 3 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c 
> > > b/arch/powerpc/platforms/pseries/hotplug-memory.c
> > > index bb98574a84a2..4e6d162c3f1a 100644
> > > --- a/arch/powerpc/platforms/pseries/hotplug-memory.c
> > > +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
> > > @@ -348,7 +348,8 @@ static int pseries_remove_mem_node(struct device_node 
> > > *np)
> > >   static bool lmb_is_removable(struct drmem_lmb *lmb)
> > >   {
> > > - if (!(lmb->flags & DRCONF_MEM_ASSIGNED))
> > > + if ((lmb->flags & DRCONF_MEM_RESERVED) ||
> > > + !(lmb->flags & DRCONF_MEM_ASSIGNED))
> > >   return false;
> > >   #ifdef CONFIG_FA_DUMP
> > > @@ -523,7 +524,7 @@ static int dlpar_memory_remove_by_ic(u32 
> > > lmbs_to_remove, u32 drc_index)
> > >   /* Validate that there are enough LMBs to satisfy the request */
> > >   for_each_drmem_lmb_in_range(lmb, start_lmb, end_lmb) {
> > > - if (lmb->flags & DRCONF_MEM_RESERVED)
> > > + if (!lmb_is_removable(lmb))
> > >   break;
> > >   lmbs_available++;
> > > @@ -533,9 +534,6 @@ static int dlpar_memory_remove_by_ic(u32 
> > > lmbs_to_remove, u32 drc_index)
> > >   return -EINVAL;
> > >