Re: [PATCH v3] powerpc: Add support for function error injection

2018-06-08 Thread Samuel Mendoza-Jonas
On Thu, 2018-06-07 at 15:22 +0530, Naveen N. Rao wrote:
> We implement regs_set_return_value() and override_function_with_return()
> for this purpose.
> 
> On powerpc, a return from a function (blr) just branches to the location
> contained in the link register. So, we can just update pt_regs rather
> than redirecting execution to a dummy function that returns.
> 
> Signed-off-by: Naveen N. Rao 
> ---
> The only change is to add a comment in override_function_with_return() 
> to clarify that we don't need to worry about 32-bit userspace while 
> emulating 'blr'.

Reviewed-by: Samuel Mendoza-Jonas 

> 
> - Naveen
> 
>  arch/powerpc/Kconfig   |  1 +
>  arch/powerpc/include/asm/error-injection.h | 13 +
>  arch/powerpc/include/asm/ptrace.h  |  5 +
>  arch/powerpc/lib/Makefile  |  2 ++
>  arch/powerpc/lib/error-inject.c| 16 
>  5 files changed, 37 insertions(+)
>  create mode 100644 arch/powerpc/include/asm/error-injection.h
>  create mode 100644 arch/powerpc/lib/error-inject.c
> 
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 076fe3094856..00dad3c759a0 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -187,6 +187,7 @@ config PPC
>   select HAVE_EBPF_JITif PPC64
>   select HAVE_EFFICIENT_UNALIGNED_ACCESS  if !(CPU_LITTLE_ENDIAN && 
> POWER7_CPU)
>   select HAVE_FTRACE_MCOUNT_RECORD
> + select HAVE_FUNCTION_ERROR_INJECTION
>   select HAVE_FUNCTION_GRAPH_TRACER
>   select HAVE_FUNCTION_TRACER
>   select HAVE_GCC_PLUGINS
> diff --git a/arch/powerpc/include/asm/error-injection.h 
> b/arch/powerpc/include/asm/error-injection.h
> new file mode 100644
> index ..740c3075bdf4
> --- /dev/null
> +++ b/arch/powerpc/include/asm/error-injection.h
> @@ -0,0 +1,13 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +
> +#ifndef _ASM_ERROR_INJECTION_H
> +#define _ASM_ERROR_INJECTION_H
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +void override_function_with_return(struct pt_regs *regs);
> +
> +#endif /* _ASM_ERROR_INJECTION_H */
> diff --git a/arch/powerpc/include/asm/ptrace.h 
> b/arch/powerpc/include/asm/ptrace.h
> index e4923686e43a..c0705296c2f0 100644
> --- a/arch/powerpc/include/asm/ptrace.h
> +++ b/arch/powerpc/include/asm/ptrace.h
> @@ -101,6 +101,11 @@ static inline long regs_return_value(struct pt_regs 
> *regs)
>   return -regs->gpr[3];
>  }
>  
> +static inline void regs_set_return_value(struct pt_regs *regs, unsigned long 
> rc)
> +{
> + regs->gpr[3] = rc;
> +}
> +
>  #ifdef __powerpc64__
>  #define user_mode(regs) regs)->msr) >> MSR_PR_LG) & 0x1)
>  #else
> diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
> index d0ca13ad8231..dd43c5a53396 100644
> --- a/arch/powerpc/lib/Makefile
> +++ b/arch/powerpc/lib/Makefile
> @@ -14,6 +14,8 @@ obj-y += string.o alloc.o code-patching.o feature-fixups.o
>  
>  obj-$(CONFIG_PPC32)  += div64.o copy_32.o crtsavres.o
>  
> +obj-$(CONFIG_FUNCTION_ERROR_INJECTION)   += error-inject.o
> +
>  # See corresponding test in arch/powerpc/Makefile
>  # 64-bit linker creates .sfpr on demand for final link (vmlinux),
>  # so it is only needed for modules, and only for older linkers which
> diff --git a/arch/powerpc/lib/error-inject.c b/arch/powerpc/lib/error-inject.c
> new file mode 100644
> index ..407b992fb02f
> --- /dev/null
> +++ b/arch/powerpc/lib/error-inject.c
> @@ -0,0 +1,16 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +
> +#include 
> +#include 
> +#include 
> +
> +void override_function_with_return(struct pt_regs *regs)
> +{
> + /*
> +  * Emulate 'blr'. 'regs' represents the state on entry of a predefined
> +  * function in the kernel/module, captured on a kprobe. We don't need
> +  * to worry about 32-bit userspace on a 64-bit kernel.
> +  */
> + regs->nip = regs->link;
> +}
> +NOKPROBE_SYMBOL(override_function_with_return);



Re: [PATCH] powerpc/ptrace: Use copy_{from, to}_user() rather than open-coding

2018-05-30 Thread Samuel Mendoza-Jonas
On Tue, 2018-05-29 at 22:57 +1000, Michael Ellerman wrote:
> From: Al Viro 
> 
> In PPC_PTRACE_GETHWDBGINFO and PPC_PTRACE_SETHWDEBUG we do an
> access_ok() check and then __copy_{from,to}_user().
> 
> Instead we should just use copy_{from,to}_user() which does all that
> for us and is less error prone.
> 
> Signed-off-by: Al Viro 
> Signed-off-by: Michael Ellerman 

Reviewed-by: Samuel Mendoza-Jonas 

> ---
>  arch/powerpc/kernel/ptrace.c | 20 ++--
>  1 file changed, 6 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
> index 0f63dd5972e9..9667666eb18e 100644
> --- a/arch/powerpc/kernel/ptrace.c
> +++ b/arch/powerpc/kernel/ptrace.c
> @@ -3082,27 +3082,19 @@ long arch_ptrace(struct task_struct *child, long 
> request,
>  #endif /* CONFIG_HAVE_HW_BREAKPOINT */
>  #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
>  
> - if (!access_ok(VERIFY_WRITE, datavp,
> -sizeof(struct ppc_debug_info)))
> + if (copy_to_user(datavp, ,
> +  sizeof(struct ppc_debug_info)))
>   return -EFAULT;
> - ret = __copy_to_user(datavp, ,
> -  sizeof(struct ppc_debug_info)) ?
> -   -EFAULT : 0;
> - break;
> + return 0;
>   }
>  
>   case PPC_PTRACE_SETHWDEBUG: {
>   struct ppc_hw_breakpoint bp_info;
>  
> - if (!access_ok(VERIFY_READ, datavp,
> -sizeof(struct ppc_hw_breakpoint)))
> + if (copy_from_user(_info, datavp,
> +sizeof(struct ppc_hw_breakpoint)))
>   return -EFAULT;
> - ret = __copy_from_user(_info, datavp,
> -sizeof(struct ppc_hw_breakpoint)) ?
> -   -EFAULT : 0;
> - if (!ret)
> - ret = ppc_set_hwdebug(child, _info);
> - break;
> + return ppc_set_hwdebug(child, _info);
>   }
>  
>   case PPC_PTRACE_DELHWDEBUG: {



Re: [PATCH 1/3] powerpc/io: Add __raw_writeq_be() __raw_rm_writeq_be()

2018-05-18 Thread Samuel Mendoza-Jonas
On Mon, 2018-05-14 at 22:50 +1000, Michael Ellerman wrote:
> Add byte-swapping versions of __raw_writeq() and __raw_rm_writeq().
> 
> This allows us to avoid sparse warnings caused by passing __be64 to
> __raw_writeq(), which takes unsigned long:
> 
>   arch/powerpc/platforms/powernv/pci-ioda.c:1981:38:
>   warning: incorrect type in argument 1 (different base types)
>   expected unsigned long [unsigned] v
>   got restricted __be64 [usertype] 
> 
> It's also generally preferable to use a byte-swapping accessor rather
> than doing it by hand in the code, which is more bug prone.
> 
> Signed-off-by: Michael Ellerman <m...@ellerman.id.au>

For this and the following patches:

Reviewed-by: Samuel Mendoza-Jonas <s...@mendozajonas.com>

> ---
>  arch/powerpc/include/asm/io.h | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h
> index af074923d598..e0331e754568 100644
> --- a/arch/powerpc/include/asm/io.h
> +++ b/arch/powerpc/include/asm/io.h
> @@ -367,6 +367,11 @@ static inline void __raw_writeq(unsigned long v, 
> volatile void __iomem *addr)
>   *(volatile unsigned long __force *)PCI_FIX_ADDR(addr) = v;
>  }
>  
> +static inline void __raw_writeq_be(unsigned long v, volatile void __iomem 
> *addr)
> +{
> + __raw_writeq((__force unsigned long)cpu_to_be64(v), addr);
> +}
> +
>  /*
>   * Real mode versions of the above. Those instructions are only supposed
>   * to be used in hypervisor real mode as per the architecture spec.
> @@ -395,6 +400,11 @@ static inline void __raw_rm_writeq(u64 val, volatile 
> void __iomem *paddr)
>   : : "r" (val), "r" (paddr) : "memory");
>  }
>  
> +static inline void __raw_rm_writeq_be(u64 val, volatile void __iomem *paddr)
> +{
> + __raw_rm_writeq((__force u64)cpu_to_be64(val), paddr);
> +}
> +
>  static inline u8 __raw_rm_readb(volatile void __iomem *paddr)
>  {
>   u8 ret;



Re: [PATCH v5 11/13] powerpc: Allow userspace to set device tree properties in kexec_file_load

2016-08-11 Thread Samuel Mendoza-Jonas
On Thu, 2016-08-11 at 20:08 -0300, Thiago Jung Bauermann wrote:
> Implement the arch_kexec_verify_buffer hook to verify that a device
> tree blob passed by userspace via kexec_file_load contains only nodes
> and properties from a whitelist.
> 
> In elf64_load we merge those properties into the device tree that
> will be passed to the next kernel.
> 
> Suggested-by: Michael Ellerman 
> Signed-off-by: Thiago Jung Bauermann 
> ---
>  arch/powerpc/include/asm/kexec.h   |   1 +
>  arch/powerpc/kernel/kexec_elf_64.c |   9 ++
>  arch/powerpc/kernel/machine_kexec_64.c | 242 
> +
>  3 files changed, 252 insertions(+)
> 
> diff --git a/arch/powerpc/include/asm/kexec.h 
> b/arch/powerpc/include/asm/kexec.h
> index f263cc867891..31bc64e07c8f 100644
> --- a/arch/powerpc/include/asm/kexec.h
> +++ b/arch/powerpc/include/asm/kexec.h
> @@ -99,6 +99,7 @@ int setup_purgatory(struct kimage *image, const void 
> *slave_code,
>  int setup_new_fdt(void *fdt, unsigned long initrd_load_addr,
>   unsigned long initrd_len, const char *cmdline);
>  bool find_debug_console(const void *fdt, int chosen_node);
> +int merge_partial_dtb(void *to, const void *from);
>  #endif /* CONFIG_KEXEC_FILE */
>  
>  #else /* !CONFIG_KEXEC */
> diff --git a/arch/powerpc/kernel/kexec_elf_64.c 
> b/arch/powerpc/kernel/kexec_elf_64.c
> index 49cba9509464..1b902ad66e2a 100644
> --- a/arch/powerpc/kernel/kexec_elf_64.c
> +++ b/arch/powerpc/kernel/kexec_elf_64.c
> @@ -210,6 +210,15 @@ void *elf64_load(struct kimage *image, char *kernel_buf,
> goto out;
> }
>  
> +   /* Add nodes and properties from the DTB passed by userspace. */
> +   if (image->dtb_buf) {
> +   ret = merge_partial_dtb(fdt, image->dtb_buf);
> +   if (ret) {
> +   pr_err("Error merging partial device tree.\n");
> +   goto out;
> +   }
> +   }
> +
> ret = setup_new_fdt(fdt, initrd_load_addr, initrd_len, cmdline);
> if (ret)
> goto out;
> diff --git a/arch/powerpc/kernel/machine_kexec_64.c 
> b/arch/powerpc/kernel/machine_kexec_64.c
> index 527f98efe651..a484a6346146 100644
> --- a/arch/powerpc/kernel/machine_kexec_64.c
> +++ b/arch/powerpc/kernel/machine_kexec_64.c
> @@ -35,6 +35,7 @@
>  #include 
>  
>  #define SLAVE_CODE_SIZE256
> +#define MAX_DT_PATH512
>  
>  #ifdef CONFIG_KEXEC_FILE
>  static struct kexec_file_ops *kexec_file_loaders[] = {
> @@ -908,4 +909,245 @@ bool find_debug_console(const void *fdt, int 
> chosen_node)
> return false;
>  }
>  
> +/**
> + * struct allowed_node - a node in the whitelist and its allowed properties.
> + * @name:  node name or full node path
> + * @properties:NULL-terminated array of names or name=value 
> pairs
> + *
> + * If name starts with /, then the node has to be at the specified path in
> + * the device tree (including unit addresses for all nodes in the path).
> + * If it doesn't, then the node can be anywhere in the device tree.
> + *
> + * An entry in properties can specify a string value that the property must
> + * have by using the "name=value" format. If the entry ends with =, it means
> + * that the property must be empty.
> + */
> +static struct allowed_node {
> +   const char *name;
> +   const char *properties[9];
> +} allowed_nodes[] = {
> +   {
> +   .name = "/chosen",
> +   .properties = {
> +   "stdout-path",
> +   "linux,stdout-path",
> +   NULL,
> +   }
> +   },
> +   {
> +   .name = "vga",
> +   .properties = {
> +   "device_type=display",
> +   "assigned-addresses",
> +   "width",
> +   "height",
> +   "depth",
> +   "little-endian=",
> +   "linux,opened=",
> +   "linux,boot-display=",ss
> +   NULL,
> +   }
> +   },
> +};

Hi Thiago,

As much as this solves problems for *me*, I suspect adding 'vga' here
might be the subject of some discussion. Having /chosen whitelisted makes
sense on it's own, but 'vga' and its properties are very specific without
much explanation.

If everyone's happy to have it there, cool! If not, I have the majority
of a patch that handles the original reason for these property updates
separately in the kernel rather than from userspace. If needed I'll clean
it up and we can handle it that way.

Cheers,
Sam


Re: [PATCH 1/7] ima: on soft reboot, restore the measurement list

2016-08-09 Thread Samuel Mendoza-Jonas
On Tue, 2016-08-09 at 10:19 -0300, Thiago Jung Bauermann wrote:
> Am Dienstag, 09 August 2016, 09:01:13 schrieb Mimi Zohar:
> > 
> > On Tue, 2016-08-09 at 20:59 +1000, Michael Ellerman wrote:
> > > 
> > > Mimi Zohar  writes:
> > > > 
> > > > diff --git a/security/integrity/ima/ima.h
> > > > b/security/integrity/ima/ima.h
> > > > index b5728da..84e8d36 100644
> > > > --- a/security/integrity/ima/ima.h
> > > > +++ b/security/integrity/ima/ima.h
> > > > @@ -102,6 +102,13 @@ struct ima_queue_entry {
> > > > 
> > > >  };
> > > >  extern struct list_head ima_measurements;  /* list of all 
> measurements
> > 
> > > 
> > > > 
> > > >  */
> > > > 
> > > > +/* Some details preceding the binary serialized measurement list */
> > > > +struct ima_kexec_hdr {
> > > > +   unsigned short version;
> > > > +   unsigned long buffer_size;
> > > > +   unsigned long count;
> > > > +} __packed;
> > > > +
> > > 
> > > Am I understanding it correctly that this structure is passed between
> > > kernels?
> > Yes, the header prefixes the measurement list, which is being passed on
> > the same computer to the next kernel.  Could the architecture (eg.
> > LE/BE) change between soft re-boots?
> 
> Yes. I am able to boot a BE kernel from an LE kernel with my patches. 
> Whether we want to support that or not is another question...

The answer to that question is almost certainly yes - on POWER the most
immediate example would be soft-rebooting from a BE host into an LE
Petitboot kernel, or vice versa.


[PATCH V2 2/2] tty/hvc: Use opal irqchip interface if available

2016-07-10 Thread Samuel Mendoza-Jonas
Update the hvc driver to use the OPAL irqchip if made available by the
running firmware. If it is not present, the driver falls back to the
existing OPAL event number.

Signed-off-by: Samuel Mendoza-Jonas <s...@mendozajonas.com>
Cc: <sta...@vger.kernel.org> # 4.1.x-
---
v2: Always try irq_of_parse_and_map before falling back

 drivers/tty/hvc/hvc_opal.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c
index b7cd0ae..5107993 100644
--- a/drivers/tty/hvc/hvc_opal.c
+++ b/drivers/tty/hvc/hvc_opal.c
@@ -214,7 +214,13 @@ static int hvc_opal_probe(struct platform_device *dev)
dev->dev.of_node->full_name,
boot ? " (boot console)" : "");
 
-   irq = opal_event_request(ilog2(OPAL_EVENT_CONSOLE_INPUT));
+   irq = irq_of_parse_and_map(dev->dev.of_node, 0);
+   if (!irq) {
+   pr_info("hvc%d: No interrupts property, using OPAL event\n",
+   termno);
+   irq = opal_event_request(ilog2(OPAL_EVENT_CONSOLE_INPUT));
+   }
+
if (!irq) {
pr_err("hvc_opal: Unable to map interrupt for device %s\n",
dev->dev.of_node->full_name);
-- 
2.9.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V2 1/2] tty/hvc: Use IRQF_SHARED for OPAL hvc consoles

2016-07-10 Thread Samuel Mendoza-Jonas
Commit 2def86a7200c
("hvc: Convert to using interrupts instead of opal events")
enabled the use of interrupts in the hvc_driver for OPAL platforms.
However on machines with more than one hvc console, any console after
the first will fail to register an interrupt handler in
notifier_add_irq() since all consoles share the same IRQ number but do
not set the IRQF_SHARED flag:

[   51.179907] genirq: Flags mismatch irq 31.  (hvc_console) vs.
 (hvc_console)
[   51.180010] hvc_open: request_irq failed with rc -16.

This error propagates up to hvc_open() and the console is closed, but
OPAL will still generate interrupts that are not handled, leading to
rcu_sched stall warnings.

Set IRQF_SHARED when calling request_irq, allowing additional consoles
to start properly. This is only set for consoles handled by
hvc_opal_probe(), leaving other types unaffected.

Signed-off-by: Samuel Mendoza-Jonas <s...@mendozajonas.com>
Cc: <sta...@vger.kernel.org> # 4.1.x-
---
 drivers/tty/hvc/hvc_console.h | 1 +
 drivers/tty/hvc/hvc_irq.c | 7 +--
 drivers/tty/hvc/hvc_opal.c| 3 +++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/hvc/hvc_console.h b/drivers/tty/hvc/hvc_console.h
index 9131019..798c48d 100644
--- a/drivers/tty/hvc/hvc_console.h
+++ b/drivers/tty/hvc/hvc_console.h
@@ -60,6 +60,7 @@ struct hvc_struct {
struct winsize ws;
struct work_struct tty_resize;
struct list_head next;
+   unsigned long flags;
 };
 
 /* implemented by a low level driver */
diff --git a/drivers/tty/hvc/hvc_irq.c b/drivers/tty/hvc/hvc_irq.c
index c9adb05..57d9df7 100644
--- a/drivers/tty/hvc/hvc_irq.c
+++ b/drivers/tty/hvc/hvc_irq.c
@@ -14,6 +14,9 @@ static irqreturn_t hvc_handle_interrupt(int irq, void 
*dev_instance)
/* if hvc_poll request a repoll, then kick the hvcd thread */
if (hvc_poll(dev_instance))
hvc_kick();
+   /* We're safe to always return IRQ_HANDLED as the hvcd thread will
+* iterate through each hvc_struct
+*/
return IRQ_HANDLED;
 }
 
@@ -28,8 +31,8 @@ int notifier_add_irq(struct hvc_struct *hp, int irq)
hp->irq_requested = 0;
return 0;
}
-   rc = request_irq(irq, hvc_handle_interrupt, 0,
-  "hvc_console", hp);
+   rc = request_irq(irq, hvc_handle_interrupt, hp->flags,
+   "hvc_console", hp);
if (!rc)
hp->irq_requested = 1;
return rc;
diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c
index 47b54c6..b7cd0ae 100644
--- a/drivers/tty/hvc/hvc_opal.c
+++ b/drivers/tty/hvc/hvc_opal.c
@@ -224,6 +224,9 @@ static int hvc_opal_probe(struct platform_device *dev)
hp = hvc_alloc(termno, irq, ops, MAX_VIO_PUT_CHARS);
if (IS_ERR(hp))
return PTR_ERR(hp);
+
+   /* hvc consoles on powernv may need to share a single irq */
+   hp->flags = IRQF_SHARED;
dev_set_drvdata(>dev, hp);
 
return 0;
-- 
2.9.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [2/2] tty/hvc: Use opal irqchip interface if available

2016-07-05 Thread Samuel Mendoza-Jonas
On Tue, 2016-07-05 at 15:31 +1000, Michael Ellerman wrote:
> On Tue, 2016-28-06 at 03:11:39 UTC, Sam Mendoza-Jonas wrote:
> > diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c
> > index b7cd0ae..8c53f5b 100644
> > --- a/drivers/tty/hvc/hvc_opal.c
> > +++ b/drivers/tty/hvc/hvc_opal.c
> > @@ -214,7 +216,15 @@ static int hvc_opal_probe(struct platform_device *dev)
> > dev->dev.of_node->full_name,
> > boot ? " (boot console)" : "");
> >  
> > -   irq = opal_event_request(ilog2(OPAL_EVENT_CONSOLE_INPUT));
> > +   rc = of_property_read_u32(dev->dev.of_node, "interrupts", );
> > +   if (rc) {
> > +   pr_info("hvc%d: No interrupts property, using OPAL event\n",
> > +   termno);
> > +   irq = opal_event_request(ilog2(OPAL_EVENT_CONSOLE_INPUT));
> > +   } else {
> > +   irq = irq_of_parse_and_map(dev->dev.of_node, 0);
> > +   }
> 
> That seems a bit backward.
> 
> Shouldn't we try irq_of_parse_and_map() and if that fails, then we go back to
> opal_event_request() ?
> 
> cheers

I was unsure for a minute so I double checked this;
of_property_read_u32() returns of_property_read_u32_array(), which
returns 0 on success, unlike a bunch of other of_property helpers.

So if the 'interrupts' property does exist we get 0, and try
irq_of_parse_and_map(). But are you suggesting we try
irq_of_parse_and_map() regardless and then fall back to
opal_event_request()?

Cheers,
Sam


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: device tree passing feature

2016-07-03 Thread Samuel Mendoza-Jonas
On Fri, 2016-07-01 at 13:15 -0300, Thiago Jung Bauermann wrote:
> Hi Samuel,
> 
> Thanks for your response.
> 
> Am Freitag, 01 Juli 2016, 11:46:21 schrieb Samuel Mendoza-Jonas:
> > On Thu, 2016-06-30 at 11:27 -0300, Thiago Jung Bauermann wrote:
> > > I have a question about the petitboot feature which allows the user to
> > > specify a device tree blob to pass to the target OS being loaded. What
> > > is
> > > the use case for it? Is it a debugging and development aid, or do you
> > > expect it be useful in a production environment?
> > 
> > Passing the dtb isn't really a Petitboot feature, rather part of how
> > kexec works for PowerPC and ARM. Petitboot may make modifications to, or
> > replace the dtb, but the method via with the target kernel obtains its
> > device-tree is kexec. So I suspect you would have to say it is mandatory
> > for production.
> 
> Right. I already have a working kexec_file_load implementation [1], and what 
> I'm doing in my patch set is taking the device tree that was used to boot 
> the current kernel and modifying it as necessary to pass it to the next 
> kernel.

Ah ok - I skimmed over the series but didn't notice that, great!

> 
> My question is: is there any need in a production environment for userspace 
> to provide a different device tree for the next kernel, or can the currently 
> running kernel always use the device tree that it received when it was 
> booted?
>
> So one new piece of information for me is that Petitboot makes modifications 
> to the dtb. Does it do that only if the system administrator provided a 
> custom dtb (either via the boot options screen or a configuration file), or 
> can it change/replace the dtb even if the system administrator didn't 
> provide a custom dtb? Which modifications does Petitboot make?
> 

For the next kernel it's sufficient just to have the device-tree, but
Petitboot does make modifications to it to help the next kernel in
certain ways, for example:
- Sorting the device-tree properly if
firmware hasn't done so
- Setting framebuffer information on
OpenPOWER machines
- Setting the primary stdout for the next
kernel

These aren't required for *booting*, but a number of people might start 
shouting if they go away.

> > > I ask this because I'm implementing the kexec_file_load system call for
> > > powerpc, and given its prototype:
> > > 
> > > long kexec_file_load(int kernel_fd, int initrd_fd, unsigned long
> > > cmdline_len, const char *cmdline_ptr, unsigned long flags)
> > > 
> > > It wouldn't be very straightforward to allow the caller to specify a
> > > device tree blob, so I have to ask how necessary such a feature is.
> > 
> > Yep, I think the problem is kexec_file_load was first implemented with a
> > focus on x86 where this isn't an issue, and now we need to consider what
> > to do :)
> 
> Yes, that's true. I was able to make it work on powerpc even with that x86 
> bias, but now I'm wondering if that's enough or not.
> 
> > We are definitely going to need a way to pass the device-tree to the
> > target kernel - whether we do that by changing the prototype for
> > kexec_file_load() PowerPC and ARM, or by dealing with it some other way
> > I'm not sure.
> 
> Do you say definitely because the kexec'd kernel needs to be passed a device 
> tree, or is it because userspace needs to have some control over the device 
> tree that the kexec'd kernel receives?

As above the 'definitely' comes from the kexec'd kernel needing to be
passed a device-tree, as well as some updates made by userspace.

> 
> > Sounds like the start of a interesting conversation on the
> > linuxppc-dev list :)
> 
> Indeed. :-) I'm copying linuxppc-dev here just in case.
> 
> A conversation about this just started in the kexec mailing list (I'm 
> copying the linuxppc-dev mailing list in my response as well):
> 
> https://lists.infradead.org/pipermail/kexec/2016-July/016279.html
> 
> []'s
> Thiago Jung Bauermann
> IBM Linux Technology Center
> 
> 
> [1] https://lists.ozlabs.org/pipermail/linuxppc-dev/2016-June/144658.html
> 

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 1/2] tty/hvc: Use IRQF_SHARED for OPAL hvc consoles

2016-06-27 Thread Samuel Mendoza-Jonas
Commit 2def86a7200c
("hvc: Convert to using interrupts instead of opal events")
enabled the use of interrupts in the hvc_driver for OPAL platforms.
However on machines with more than one hvc console, any console after
the first will fail to register an interrupt handler in
notifier_add_irq() since all consoles share the same IRQ number but do
not set the IRQF_SHARED flag:

[   51.179907] genirq: Flags mismatch irq 31.  (hvc_console) vs.
 (hvc_console)
[   51.180010] hvc_open: request_irq failed with rc -16.

This error propagates up to hvc_open() and the console is closed, but
OPAL will still generate interrupts that are not handled, leading to
rcu_sched stall warnings.

Set IRQF_SHARED when calling request_irq, allowing additional consoles
to start properly. This is only set for consoles handled by
hvc_opal_probe(), leaving other types unaffected.

Signed-off-by: Samuel Mendoza-Jonas <s...@mendozajonas.com>
Cc: <sta...@vger.kernel.org> # 4.1.x-
---
 drivers/tty/hvc/hvc_console.h | 1 +
 drivers/tty/hvc/hvc_irq.c | 7 +--
 drivers/tty/hvc/hvc_opal.c| 3 +++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/hvc/hvc_console.h b/drivers/tty/hvc/hvc_console.h
index 9131019..798c48d 100644
--- a/drivers/tty/hvc/hvc_console.h
+++ b/drivers/tty/hvc/hvc_console.h
@@ -60,6 +60,7 @@ struct hvc_struct {
struct winsize ws;
struct work_struct tty_resize;
struct list_head next;
+   unsigned long flags;
 };
 
 /* implemented by a low level driver */
diff --git a/drivers/tty/hvc/hvc_irq.c b/drivers/tty/hvc/hvc_irq.c
index c9adb05..57d9df7 100644
--- a/drivers/tty/hvc/hvc_irq.c
+++ b/drivers/tty/hvc/hvc_irq.c
@@ -14,6 +14,9 @@ static irqreturn_t hvc_handle_interrupt(int irq, void 
*dev_instance)
/* if hvc_poll request a repoll, then kick the hvcd thread */
if (hvc_poll(dev_instance))
hvc_kick();
+   /* We're safe to always return IRQ_HANDLED as the hvcd thread will
+* iterate through each hvc_struct
+*/
return IRQ_HANDLED;
 }
 
@@ -28,8 +31,8 @@ int notifier_add_irq(struct hvc_struct *hp, int irq)
hp->irq_requested = 0;
return 0;
}
-   rc = request_irq(irq, hvc_handle_interrupt, 0,
-  "hvc_console", hp);
+   rc = request_irq(irq, hvc_handle_interrupt, hp->flags,
+   "hvc_console", hp);
if (!rc)
hp->irq_requested = 1;
return rc;
diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c
index 47b54c6..b7cd0ae 100644
--- a/drivers/tty/hvc/hvc_opal.c
+++ b/drivers/tty/hvc/hvc_opal.c
@@ -224,6 +224,9 @@ static int hvc_opal_probe(struct platform_device *dev)
hp = hvc_alloc(termno, irq, ops, MAX_VIO_PUT_CHARS);
if (IS_ERR(hp))
return PTR_ERR(hp);
+
+   /* hvc consoles on powernv may need to share a single irq */
+   hp->flags = IRQF_SHARED;
dev_set_drvdata(>dev, hp);
 
return 0;
-- 
2.9.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 2/2] tty/hvc: Use opal irqchip interface if available

2016-06-27 Thread Samuel Mendoza-Jonas
Update the hvc driver to use the OPAL irqchip if made available by the
running firmware. If it is not present, the driver falls back to the
existing OPAL event number.

Signed-off-by: Samuel Mendoza-Jonas <s...@mendozajonas.com>
Cc: <sta...@vger.kernel.org> # 4.1.x-
---
 drivers/tty/hvc/hvc_opal.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c
index b7cd0ae..8c53f5b 100644
--- a/drivers/tty/hvc/hvc_opal.c
+++ b/drivers/tty/hvc/hvc_opal.c
@@ -170,6 +170,8 @@ static int hvc_opal_probe(struct platform_device *dev)
hv_protocol_t proto;
unsigned int termno, irq, boot = 0;
const __be32 *reg;
+   u32 prop;
+   int rc;
 
if (of_device_is_compatible(dev->dev.of_node, "ibm,opal-console-raw")) {
proto = HV_PROTOCOL_RAW;
@@ -214,7 +216,15 @@ static int hvc_opal_probe(struct platform_device *dev)
dev->dev.of_node->full_name,
boot ? " (boot console)" : "");
 
-   irq = opal_event_request(ilog2(OPAL_EVENT_CONSOLE_INPUT));
+   rc = of_property_read_u32(dev->dev.of_node, "interrupts", );
+   if (rc) {
+   pr_info("hvc%d: No interrupts property, using OPAL event\n",
+   termno);
+   irq = opal_event_request(ilog2(OPAL_EVENT_CONSOLE_INPUT));
+   } else {
+   irq = irq_of_parse_and_map(dev->dev.of_node, 0);
+   }
+
if (!irq) {
pr_err("hvc_opal: Unable to map interrupt for device %s\n",
dev->dev.of_node->full_name);
-- 
2.9.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] tty/hvc: Use IRQF_SHARED for hvc consoles

2016-03-19 Thread Samuel Mendoza-Jonas
Commit 2def86a7200c
("hvc: Convert to using interrupts instead of opal events")
enabled the use of interrupts in the hvc_driver for OPAL platforms.
However on machines with more than one hvc console, any console after
the first will fail to register an interrupt handler in
notifier_add_irq() since all consoles share the same IRQ number but do
not set the IRQF_SHARED flag:

[   51.179907] genirq: Flags mismatch irq 31.  (hvc_console) vs.
 (hvc_console)
[   51.180010] hvc_open: request_irq failed with rc -16.

This error propagates up to hvc_open() and the console is closed, but
OPAL will still generate interrupts that are not handled, leading to
rcu_sched stall warnings.

Set IRQF_SHARED when calling request_irq, allowing additional consoles
to start properly.

Signed-off-by: Samuel Mendoza-Jonas <s...@mendozajonas.com>
Cc: <sta...@vger.kernel.org> # 4.1.x-
---
 drivers/tty/hvc/hvc_irq.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/hvc/hvc_irq.c b/drivers/tty/hvc/hvc_irq.c
index c9adb05..621263a 100644
--- a/drivers/tty/hvc/hvc_irq.c
+++ b/drivers/tty/hvc/hvc_irq.c
@@ -14,6 +14,9 @@ static irqreturn_t hvc_handle_interrupt(int irq, void 
*dev_instance)
/* if hvc_poll request a repoll, then kick the hvcd thread */
if (hvc_poll(dev_instance))
hvc_kick();
+   /* We're safe to always return IRQ_HANDLED as the hvcd thread will
+* iterate through each hvc_struct
+*/
return IRQ_HANDLED;
 }
 
@@ -28,7 +31,7 @@ int notifier_add_irq(struct hvc_struct *hp, int irq)
hp->irq_requested = 0;
return 0;
}
-   rc = request_irq(irq, hvc_handle_interrupt, 0,
+   rc = request_irq(irq, hvc_handle_interrupt, IRQF_SHARED,
   "hvc_console", hp);
if (!rc)
hp->irq_requested = 1;
-- 
2.7.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [RFC PATCH] powerpc/kexec: Wait 1s for secondaries to enter OPAL

2015-07-28 Thread Samuel Mendoza-Jonas
On 27/07/15 15:56, Stewart Smith wrote:
 Samuel Mendoza-Jonas sam...@au1.ibm.com writes:
 Always include a timeout when waiting for secondary cpus to enter OPAL
 in the kexec path, rather than only when crashing.
 
 This *sounds* reasonable... but I wonder what actual worse case could
 be and why we'd get stuck too long waiting for things?
 
 What was the original bug/problem that inspired this patch?
 
 and is 1s enough?

It sounds reasonable was more or less the inspiration :)
While I was going over some of the code relating to the previous kexec
fix with Ben he pointed this out and suggested there wasn't
much of a reason to differentiate between a crashing/non-crashing
cpu as far as the timeout goes - if we're not 'crashing' we still
don't want to spin forever.

I'll let Ben comment on whether 1s per cpu is enough.

 
 ___
 Linuxppc-dev mailing list
 Linuxppc-dev@lists.ozlabs.org
 https://lists.ozlabs.org/listinfo/linuxppc-dev
 


-- 
---
LTC Ozlabs
IBM

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[RFC PATCH] powerpc/kexec: Wait 1s for secondaries to enter OPAL

2015-07-21 Thread Samuel Mendoza-Jonas
Always include a timeout when waiting for secondary cpus to enter OPAL
in the kexec path, rather than only when crashing.

Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
---
 arch/powerpc/platforms/powernv/setup.c | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/setup.c 
b/arch/powerpc/platforms/powernv/setup.c
index 59076db..f916601 100644
--- a/arch/powerpc/platforms/powernv/setup.c
+++ b/arch/powerpc/platforms/powernv/setup.c
@@ -195,7 +195,7 @@ static void pnv_kexec_wait_secondaries_down(void)
 
for_each_online_cpu(i) {
uint8_t status;
-   int64_t rc;
+   int64_t rc, timeout = 1000;
 
if (i == my_cpu)
continue;
@@ -212,6 +212,18 @@ static void pnv_kexec_wait_secondaries_down(void)
   i, paca[i].hw_cpu_id);
notified = i;
}
+
+   /*
+* On crash secondaries might be unreachable or hung,
+* so timeout if we've waited too long
+* */
+   mdelay(1);
+   if (timeout-- == 0) {
+   printk(KERN_ERR kexec: timed out waiting for 
+  cpu %d (physical %d) to enter OPAL\n,
+  i, paca[i].hw_cpu_id);
+   break;
+   }
}
}
 }
@@ -233,13 +245,6 @@ static void pnv_kexec_cpu_down(int crash_shutdown, int 
secondary)
 
/* Return the CPU to OPAL */
opal_return_cpu();
-   } else if (crash_shutdown) {
-   /*
-* On crash, we don't wait for secondaries to go
-* down as they might be unreachable or hung, so
-* instead we just wait a bit and move on.
-*/
-   mdelay(1);
} else {
/* Primary waits for the secondaries to have reached OPAL */
pnv_kexec_wait_secondaries_down();
-- 
2.4.6

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V4 2/2] powerpc/kexec: Reset HILE before kexec_sequence

2015-07-21 Thread Samuel Mendoza-Jonas
On powernv secondary cpus are returned to OPAL, and will then enter
the target kernel in big-endian. However if it is set the HILE bit
will persist, causing the first exception in the target kernel to be
delivered in litte-endian regardless of the current endianess.

If running on top of OPAL make sure the HILE bit is reset once we've
finished waiting for all of the secondaries to be returned to OPAL.

Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
---
 arch/powerpc/platforms/powernv/setup.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/setup.c 
b/arch/powerpc/platforms/powernv/setup.c
index 53737e0..59076db 100644
--- a/arch/powerpc/platforms/powernv/setup.c
+++ b/arch/powerpc/platforms/powernv/setup.c
@@ -243,6 +243,13 @@ static void pnv_kexec_cpu_down(int crash_shutdown, int 
secondary)
} else {
/* Primary waits for the secondaries to have reached OPAL */
pnv_kexec_wait_secondaries_down();
+
+   /*
+* We might be running as little-endian - now that interrupts
+* are disabled, reset the HILE bit to big-endian so we don't
+* take interrupts in the wrong endian later
+*/
+   opal_reinit_cpus(OPAL_REINIT_CPUS_HILE_BE);
}
 }
 #endif /* CONFIG_KEXEC */
-- 
2.4.6

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V4 1/2] powerpc/kexec: Reset secondary cpu endianess before kexec

2015-07-21 Thread Samuel Mendoza-Jonas
If the target kernel does not inlcude the FIXUP_ENDIAN check, coming
from a different-endian kernel will cause the target kernel to panic.
All ppc64 kernels can handle starting in big-endian mode, so return to
big-endian before branching into the target kernel.

This mainly affects pseries as secondaries on powernv are returned to
OPAL.

Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
---
 arch/powerpc/kernel/misc_64.S | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/misc_64.S b/arch/powerpc/kernel/misc_64.S
index 4e314b9..6e4168c 100644
--- a/arch/powerpc/kernel/misc_64.S
+++ b/arch/powerpc/kernel/misc_64.S
@@ -475,9 +475,18 @@ _GLOBAL(kexec_wait)
 #ifdef CONFIG_KEXEC/* use no memory without kexec */
lwz r4,0(r5)
cmpwi   0,r4,0
-   bnea0x60
+   beq 99b
+#ifdef CONFIG_PPC_BOOK3S_64
+   li  r10,0x60
+   mfmsr   r11
+   clrrdi  r11,r11,1   /* Clear MSR_LE */
+   mtsrr0  r10
+   mtsrr1  r11
+   rfid
+#else
+   ba  0x60
+#endif
 #endif
-   b   99b
 
 /* this can be in text because we won't change it until we are
  * running in real anyways
-- 
2.4.6

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V4 0/2] powerpc/kexec: Reset endianess before kexec

2015-07-21 Thread Samuel Mendoza-Jonas
Older ppc64 kernels, namely those missing FIXUP_ENDIAN or opal_reinit_cpus,
will fail to boot if started via kexec from a little-endian kernel.
The following two patches make sure that the current endianess is reset to
big-endian just before entering the target kernel, and are accompanied by
a separate patch to kexec-lite that resets the endianess of the boot cpu.

Changes in v4:
As pointed out by Ben since interrupts are already disabled before checking
that all secondaries are in OPAL, we can make the call to opal_reinit_cpus
in C, in pnv_kexec_cpu_down().

Changes in v3: 
Move the call to opal_reinit_cpus into kexec_sequence so we can call it in
real mode with interrupts disabled. Update the kexec_sequence prototype so
that we can check if OPAL is present.
Fix the !CONFIG_PPC_BOOK3S_64 case in kexec_wait to correctly branch to 0x60

Changes in v2:
Add an #ifdef for subarch-specific code
Neaten the endian check (and extra call to mfmsr!) by modifying the msr and
branching to the target kernel in the same call to rfid.


Samuel Mendoza-Jonas (2):
  powerpc/kexec: Reset secondary cpu endianess before kexec
  powerpc/kexec: Reset HILE before kexec_sequence

 arch/powerpc/kernel/misc_64.S  | 13 +++--
 arch/powerpc/platforms/powernv/setup.c |  7 +++
 2 files changed, 18 insertions(+), 2 deletions(-)

-- 
2.4.6

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V3 1/2] powerpc/kexec: Reset secondary cpu endianess before kexec

2015-07-09 Thread Samuel Mendoza-Jonas
If the target kernel does not inlcude the FIXUP_ENDIAN check, coming
from a different-endian kernel will cause the target kernel to panic.
All ppc64 kernels can handle starting in big-endian mode, so return to
big-endian before branching into the target kernel.

This mainly affects pseries as secondaries on powernv are returned to
OPAL.

Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
---
 arch/powerpc/kernel/misc_64.S | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/misc_64.S b/arch/powerpc/kernel/misc_64.S
index 4e314b9..6e4168c 100644
--- a/arch/powerpc/kernel/misc_64.S
+++ b/arch/powerpc/kernel/misc_64.S
@@ -475,9 +475,18 @@ _GLOBAL(kexec_wait)
 #ifdef CONFIG_KEXEC/* use no memory without kexec */
lwz r4,0(r5)
cmpwi   0,r4,0
-   bnea0x60
+   beq 99b
+#ifdef CONFIG_PPC_BOOK3S_64
+   li  r10,0x60
+   mfmsr   r11
+   clrrdi  r11,r11,1   /* Clear MSR_LE */
+   mtsrr0  r10
+   mtsrr1  r11
+   rfid
+#else
+   ba  0x60
+#endif
 #endif
-   b   99b
 
 /* this can be in text because we won't change it until we are
  * running in real anyways
-- 
2.4.5

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V3 2/2] powerpc/kexec: Reset HILE before entering target kernel

2015-07-09 Thread Samuel Mendoza-Jonas
On powernv secondary cpus are returned to OPAL, and will then enter the
target kernel in big-endian. However if it is set the HILE bit will persist,
causing the first exception in the target kernel to be delivered in
litte-endian regardless of the current endianess.

If running on top of OPAL make sure the HILE bit is reset before any
thread branches into the target kernel.

Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
---
 arch/powerpc/kernel/machine_kexec_64.c |  6 --
 arch/powerpc/kernel/misc_64.S  | 19 +--
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/machine_kexec_64.c 
b/arch/powerpc/kernel/machine_kexec_64.c
index 1a74446..60bb626 100644
--- a/arch/powerpc/kernel/machine_kexec_64.c
+++ b/arch/powerpc/kernel/machine_kexec_64.c
@@ -29,6 +29,7 @@
 #include asm/prom.h
 #include asm/smp.h
 #include asm/hw_breakpoint.h
+#include asm/firmware.h
 
 int default_machine_kexec_prepare(struct kimage *image)
 {
@@ -313,7 +314,8 @@ struct paca_struct kexec_paca;
 /* Our assembly helper, in misc_64.S */
 extern void kexec_sequence(void *newstack, unsigned long start,
   void *image, void *control,
-  void (*clear_all)(void)) __noreturn;
+  void (*clear_all)(void),
+  unsigned long features) __noreturn;
 
 /* too late to fail here */
 void default_machine_kexec(struct kimage *image)
@@ -361,7 +363,7 @@ void default_machine_kexec(struct kimage *image)
 */
kexec_sequence(kexec_stack, image-start, image,
page_address(image-control_code_page),
-   ppc_md.hpte_clear_all);
+   ppc_md.hpte_clear_all, powerpc_firmware_features);
/* NOTREACHED */
 }
 
diff --git a/arch/powerpc/kernel/misc_64.S b/arch/powerpc/kernel/misc_64.S
index 6e4168c..abde07d 100644
--- a/arch/powerpc/kernel/misc_64.S
+++ b/arch/powerpc/kernel/misc_64.S
@@ -19,6 +19,7 @@
 #include asm/errno.h
 #include asm/processor.h
 #include asm/page.h
+#include asm/opal.h
 #include asm/cache.h
 #include asm/ppc_asm.h
 #include asm/asm-offsets.h
@@ -539,7 +540,7 @@ real_mode:  /* assume normal blr return */
 
 
 /*
- * kexec_sequence(newstack, start, image, control, clear_all())
+ * kexec_sequence(newstack, start, image, control, clear_all(), features)
  *
  * does the grungy work with stack switching and real mode switches
  * also does simple calls to other code
@@ -575,7 +576,7 @@ _GLOBAL(kexec_sequence)
mr  r29,r5  /* image (virt) */
mr  r28,r6  /* control, unused */
mr  r27,r7  /* clear_all() fn desc */
-   mr  r26,r8  /* spare */
+   mr  r26,r8  /* powerpc_firmware_features */
lhz r25,PACAHWCPUID(r13)/* get our phys cpu from paca */
 
/* disable interrupts, we are overwriting kernel data next */
@@ -590,6 +591,20 @@ _GLOBAL(kexec_sequence)
/* turn off mmu */
bl  real_mode
 
+#if defined(CONFIG_PPC_BOOK3S_64)  defined(CONFIG_PPC_POWERNV)
+   li  r3,(FW_FEATURE_OPAL  16)
+   rldicr  r3,r3,16,63
+   and.r3,r3,r26
+   cmpwi   r3,0
+   beq 99f
+
+   /* Reset HILE bit now that interrupts are disabled */
+   li  r3,1
+   li  r0,OPAL_REINIT_CPUS
+   bl  opal_call_realmode
+99:
+#endif
+
/* copy  0x100 bytes starting at start to 0 */
li  r3,0
mr  r4,r30  /* start, aka phys mem offset */
-- 
2.4.5

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V3 0/2] powerpc/kexec: Reset endianess before kexec

2015-07-09 Thread Samuel Mendoza-Jonas
Older ppc64 kernels, namely those missing FIXUP_ENDIAN or opal_reinit_cpus,
will fail to boot if started via kexec from a little-endian kernel.
The following two patches make sure that the current endianess is reset to
big-endian just before entering the target kernel, and are accompanied by
a separate patch to kexec-lite that resets the endianess of the boot cpu.

Changes in v3: 
Move the call to opal_reinit_cpus into kexec_sequence so we can call it in
real mode with interrupts disabled. Update the kexec_sequence prototype so
that we can check if OPAL is present.
Fix the !CONFIG_PPC_BOOK3S_64 case in kexec_wait to correctly branch to 0x60

Changes in v2:
Add an #ifdef for subarch-specific code
Neaten the endian check (and extra call to mfmsr!) by modifying the msr and
branching to the target kernel in the same call to rfid.

Samuel Mendoza-Jonas (2):
  powerpc/kexec: Reset secondary cpu endianess before kexec
  powerpc/kexec: Reset HILE before entering target kernel

 arch/powerpc/kernel/machine_kexec_64.c |  6 --
 arch/powerpc/kernel/misc_64.S  | 32 
 2 files changed, 32 insertions(+), 6 deletions(-)

-- 
2.4.5

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH V2 2/2] powerpc/kexec: Reset HILE before kexec_sequence

2015-07-08 Thread Samuel Mendoza-Jonas
On 08/07/15 16:51, Stewart Smith wrote:
 Michael Ellerman m...@ellerman.id.au writes:
 On Wed, 2015-07-08 at 14:37 +1000, Samuel Mendoza-Jonas wrote:
 On powernv secondary cpus are returned to OPAL, and will then enter the
 target kernel in big-endian. However if it is set the HILE bit will persist,
 causing the first exception in the target kernel to be delivered in
 litte-endian regardless of the kernel endianess.
 Make sure that the HILE bit is switched off before entering
 kexec_sequence.

 Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
 ---
  arch/powerpc/kernel/machine_kexec_64.c | 6 ++
  1 file changed, 6 insertions(+)

 diff --git a/arch/powerpc/kernel/machine_kexec_64.c 
 b/arch/powerpc/kernel/machine_kexec_64.c
 index 1a74446..2266135c 100644
 --- a/arch/powerpc/kernel/machine_kexec_64.c
 +++ b/arch/powerpc/kernel/machine_kexec_64.c
 @@ -22,8 +22,10 @@
  #include asm/page.h
  #include asm/current.h
  #include asm/machdep.h
 +#include asm/opal.h
  #include asm/cacheflush.h
  #include asm/paca.h
 +#include asm/firmware.h
  #include asm/mmu.h
  #include asm/sections.h  /* _end */
  #include asm/prom.h
 @@ -356,6 +358,10 @@ void default_machine_kexec(struct kimage *image)
  * switched to a static version!
  */
  
 +   /* Reset HILE in case we kexec into an older BE kernel */
 +   if (firmware_has_feature(FW_FEATURE_OPALv3))
 +   opal_reinit_cpus(OPAL_REINIT_CPUS_HILE_BE);

 It's not safe to do this here.

 We are still in virtual mode and have external interrupts enabled, so you 
 could
 easily take an exception of some kind and then you'd blow up. Mashing the
 keyboard during kexec might even be enough.
 
 Hrm... interrupts are disabled in kexec_sequence, should we be doing
 this there instead I wonder? At this point we're pretty much at the
 point of no return, so maybe we just need to disable interrupts first?
 
 I think a better API would be that opal_return_cpu() deals with this under 
 the
 covers. I think we talked about that, so maybe there was some reason that
 wasn't possible.
 
 opal_return_cpu() acts on current CPU which if we started flipping HILE
 there we'd hit PowerISA 2.07 Section 2.11:
 The contents of the HILE bit must be the same for all
 threads under the control of a given instance of the
 hypervisor; otherwise all results are undefined.
 
 so we'd have to do something kind of funny in opal_return_cpu() to work
 out what's going on. Keeping in mind that opal_return_cpu() is also used
 in the fsp code update path (which I haven't gone and really looked at
 in this context though).
 
 I'm not convinced that opal_return_cpu() doing the HILE switch is
 safe when we'd be relying on the kernel to pretty much do this all at
 the same time (when we really have opal_reinit_cpus to do that)

Having discovered opal_call_realmode, it looks like we can probably do this
safely in real mode just before moving the kernel around and releasing
the secondaries into the next kernel. I'll test this and send a V2 if it
looks good.

 
 Although PowerISA also says:
 The HILE bit is set, by an implementa-
 tion-dependent method, during system initialization,
 and cannot be modified after system initialization.
 
 Which... umm... we are clearly doing and have been since we started
 supporting LE powernv, so there's something somewhere in some document
 describing it all... I just have to find it (or poke Ben to find out
 where he worked it out from).
 


-- 
---
LTC Ozlabs
IBM

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 1/2] powerpc/kexec: Reset secondary cpu endianess before kexec

2015-07-07 Thread Samuel Mendoza-Jonas
If the target kernel does not inlcude the FIXUP_ENDIAN check, coming
from a different-endian kernel will cause the target kernel to panic.
All ppc64 kernels can handle starting in big-endian mode, so return to
big-endian before branching into the target kernel.

This mainly affects pseries as secondaries on powernv are returned to
OPAL.

Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
---
 arch/powerpc/kernel/misc_64.S | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/misc_64.S b/arch/powerpc/kernel/misc_64.S
index 4e314b9..c73e587 100644
--- a/arch/powerpc/kernel/misc_64.S
+++ b/arch/powerpc/kernel/misc_64.S
@@ -475,9 +475,20 @@ _GLOBAL(kexec_wait)
 #ifdef CONFIG_KEXEC/* use no memory without kexec */
lwz r4,0(r5)
cmpwi   0,r4,0
-   bnea0x60
+   beq 99b
+   mfmsr   r9  /* Check endianess */
+   clrldi. r10,r9,63
+   beqa0x60/* Already big-endian */
+   bcl 20,31,$+4
+   mflrr10
+   addir10,r10,28
+   mfmsr   r11
+   xorir11,r11,1
+   mtsrr0  r10
+   mtsrr1  r11
+   rfid
+   .long   0x6248  /* ba 0x60 */
 #endif
-   b   99b
 
 /* this can be in text because we won't change it until we are
  * running in real anyways
-- 
2.4.5

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 2/2] powerpc/kexec: Reset HILE before kexec_sequence

2015-07-07 Thread Samuel Mendoza-Jonas
On powernv secondary cpus are returned to OPAL, and will then enter the
target kernel in big-endian. However if it is set the HILE bit will persist,
causing the first exception in the target kernel to be delivered in
litte-endian regardless of the kernel endianess.
Make sure that the HILE bit is switched off before entering
kexec_sequence.

Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
---
 arch/powerpc/kernel/machine_kexec_64.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/powerpc/kernel/machine_kexec_64.c 
b/arch/powerpc/kernel/machine_kexec_64.c
index 1a74446..2266135c 100644
--- a/arch/powerpc/kernel/machine_kexec_64.c
+++ b/arch/powerpc/kernel/machine_kexec_64.c
@@ -22,8 +22,10 @@
 #include asm/page.h
 #include asm/current.h
 #include asm/machdep.h
+#include asm/opal.h
 #include asm/cacheflush.h
 #include asm/paca.h
+#include asm/firmware.h
 #include asm/mmu.h
 #include asm/sections.h  /* _end */
 #include asm/prom.h
@@ -356,6 +358,10 @@ void default_machine_kexec(struct kimage *image)
 * switched to a static version!
 */
 
+   /* Reset HILE in case we kexec into an older BE kernel */
+   if (firmware_has_feature(FW_FEATURE_OPALv3))
+   opal_reinit_cpus(OPAL_REINIT_CPUS_HILE_BE);
+
/* Some things are best done in assembly.  Finding globals with
 * a toc is easier in C, so pass in what we can.
 */
-- 
2.4.5

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [kexec-lite PATCH] trampoline: Reset primary cpu endian to big-endian

2015-07-07 Thread Samuel Mendoza-Jonas
On 08/07/15 11:56, Anton Blanchard wrote:
 Hi Sam,
 
 Older big-endian ppc64 kernels don't include the FIXUP_ENDIAN check,
 meaning if we kexec from a little-endian kernel the target kernel will
 fail to boot.
 Returning to big-endian before we enter the target kernel ensures that
 the target kernel can boot whether or not it includes FIXUP_ENDIAN.
 
 Thanks!
 
 I wonder if we can do something simpler, and always enter via rfid.
 Avoids the need for the endian trampoline. Something like:
 
   mtsrr0  r4
 
   mfmsr   r5
   clrrdi  r5,r5,1 /* Clear MSR_LE */
   mtsrr1  r5
 
   li  r5,0
 
   rfid
 
 Anton
 

Ah that's a neat idea, I'll test and send a V2.

Cheers,
Sam

-- 
---
LTC Ozlabs
IBM

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[kexec-lite PATCH] trampoline: Reset primary cpu endian to big-endian

2015-07-07 Thread Samuel Mendoza-Jonas
Older big-endian ppc64 kernels don't include the FIXUP_ENDIAN check,
meaning if we kexec from a little-endian kernel the target kernel will
fail to boot.
Returning to big-endian before we enter the target kernel ensures that
the target kernel can boot whether or not it includes FIXUP_ENDIAN.

Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
---
 kexec_trampoline.S |  9 -
 kexec_trampoline.h | 17 +++--
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/kexec_trampoline.S b/kexec_trampoline.S
index a3eb314..29537ab 100644
--- a/kexec_trampoline.S
+++ b/kexec_trampoline.S
@@ -41,6 +41,8 @@
 #definer7  7
 #definer8  8
 #definer9  9
+#definer10 10
+#definer11 11
 
 #ifdef __powerpc64__
 #define LOAD   ld
@@ -50,8 +52,10 @@
 
 #if defined(__LITTLE_ENDIAN__)
 #define STWX_BEstwbrx
+#define BCTR .long 0x2004804e
 #elif defined(__BIG_ENDIAN__)
 #define STWX_BEstwx
+#define BCTR bctr
 #else
 #error no endianness defined!
 #endif
@@ -89,7 +93,10 @@ start:
li  r5,0
 
mtctr   r4
-   bctr
+
+   RESET_ENDIAN
+
+   BCTR
 
 . = KERNEL_ADDR_OFFSET
 kernel_addr:
diff --git a/kexec_trampoline.h b/kexec_trampoline.h
index 6485c88..909953b 100644
--- a/kexec_trampoline.h
+++ b/kexec_trampoline.h
@@ -27,7 +27,20 @@
 /* Fixed offset in device tree for storing the physical ID of the boot CPU */
 #define DT_CPU_OFFSET  28
 
-#ifndef __ASSEMBLY__
+#ifdef __ASSEMBLY__
+#define RESET_ENDIAN  \
+   mfmsr   r9;\
+   clrldi. r10,r9,63; \
+   beq $+36;   /* Already big-endian */   \
+   bcl 20,31,$+4; \
+   mflrr10;   \
+   addir10,r10,28;\
+   mfmsr   r11;   \
+   xorir11,r11,1; \
+   mtsrr0  r10;   \
+   mtsrr1  r11;   \
+   rfid;
+#else
 
 extern char __trampoline_start[];
 extern char __trampoline_end[];
@@ -48,6 +61,6 @@ static inline void trampoline_set_device_tree(void *p, 
unsigned long addr)
*v = addr;
 }
 
-#endif
+#endif /* !__ASSEMBLY__ */
 
 #endif
-- 
2.4.5

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [kexec-lite PATCH V2] trampoline: Reset primary cpu endian to big-endian

2015-07-07 Thread Samuel Mendoza-Jonas
On 08/07/15 13:37, Scott Wood wrote:
 On Wed, 2015-07-08 at 13:29 +1000, Samuel Mendoza-Jonas wrote:
 Older big-endian ppc64 kernels don't include the FIXUP_ENDIAN check,
 meaning if we kexec from a little-endian kernel the target kernel will
 fail to boot.
 Returning to big-endian before we enter the target kernel ensures that
 the target kernel can boot whether or not it includes FIXUP_ENDIAN.

 Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
 ---
 V2: As suggested by Anton take advantage of the rfid call and switch off
 MSR_LE and branch to the target kernel in the same step.

  kexec_trampoline.S | 11 +--
  1 file changed, 9 insertions(+), 2 deletions(-)

 diff --git a/kexec_trampoline.S b/kexec_trampoline.S
 index a3eb314..3751112 100644
 --- a/kexec_trampoline.S
 +++ b/kexec_trampoline.S
 @@ -88,8 +88,15 @@ start:
  
   li  r5,0
  
 - mtctr   r4
 - bctr
 + mtsrr0  r4
 +
 + mfmsr   r5
 + clrrdi  r5,r5,1 /* Clear MSR_LE */
 + mtsrr1  r5
 +
 + li  r5,0
 +
 + rfid
 
 Is kexec-lite meant to be specific to book3s-64?  The README just says A 
 simple kexec for flattened device tree platforms and I see a __powerpc64__ 
 ifdef in kexec_trampoline.S (but not in the above patch)...
 
 -Scott
 

I believe that particular ifdef is to check if we're little-endian when reading
the device tree, but that's still a good point - I'll check with Anton.

-- 
---
LTC Ozlabs
IBM

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[kexec-lite PATCH V2] trampoline: Reset primary cpu endian to big-endian

2015-07-07 Thread Samuel Mendoza-Jonas
Older big-endian ppc64 kernels don't include the FIXUP_ENDIAN check,
meaning if we kexec from a little-endian kernel the target kernel will
fail to boot.
Returning to big-endian before we enter the target kernel ensures that
the target kernel can boot whether or not it includes FIXUP_ENDIAN.

Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
---
V2: As suggested by Anton take advantage of the rfid call and switch off
MSR_LE and branch to the target kernel in the same step.

 kexec_trampoline.S | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/kexec_trampoline.S b/kexec_trampoline.S
index a3eb314..3751112 100644
--- a/kexec_trampoline.S
+++ b/kexec_trampoline.S
@@ -88,8 +88,15 @@ start:
 
li  r5,0
 
-   mtctr   r4
-   bctr
+   mtsrr0  r4
+
+   mfmsr   r5
+   clrrdi  r5,r5,1 /* Clear MSR_LE */
+   mtsrr1  r5
+
+   li  r5,0
+
+   rfid
 
 . = KERNEL_ADDR_OFFSET
 kernel_addr:
-- 
2.4.5

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V2 2/2] powerpc/kexec: Reset HILE before kexec_sequence

2015-07-07 Thread Samuel Mendoza-Jonas
On powernv secondary cpus are returned to OPAL, and will then enter the
target kernel in big-endian. However if it is set the HILE bit will persist,
causing the first exception in the target kernel to be delivered in
litte-endian regardless of the kernel endianess.
Make sure that the HILE bit is switched off before entering
kexec_sequence.

Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
---
 arch/powerpc/kernel/machine_kexec_64.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/powerpc/kernel/machine_kexec_64.c 
b/arch/powerpc/kernel/machine_kexec_64.c
index 1a74446..2266135c 100644
--- a/arch/powerpc/kernel/machine_kexec_64.c
+++ b/arch/powerpc/kernel/machine_kexec_64.c
@@ -22,8 +22,10 @@
 #include asm/page.h
 #include asm/current.h
 #include asm/machdep.h
+#include asm/opal.h
 #include asm/cacheflush.h
 #include asm/paca.h
+#include asm/firmware.h
 #include asm/mmu.h
 #include asm/sections.h  /* _end */
 #include asm/prom.h
@@ -356,6 +358,10 @@ void default_machine_kexec(struct kimage *image)
 * switched to a static version!
 */
 
+   /* Reset HILE in case we kexec into an older BE kernel */
+   if (firmware_has_feature(FW_FEATURE_OPALv3))
+   opal_reinit_cpus(OPAL_REINIT_CPUS_HILE_BE);
+
/* Some things are best done in assembly.  Finding globals with
 * a toc is easier in C, so pass in what we can.
 */
-- 
2.4.5

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V2 1/2] powerpc/kexec: Reset secondary cpu endianess before kexec

2015-07-07 Thread Samuel Mendoza-Jonas
If the target kernel does not inlcude the FIXUP_ENDIAN check, coming
from a different-endian kernel will cause the target kernel to panic.
All ppc64 kernels can handle starting in big-endian mode, so return to
big-endian before branching into the target kernel.

This mainly affects pseries as secondaries on powernv are returned to
OPAL.

Signed-off-by: Samuel Mendoza-Jonas sam...@au1.ibm.com
---
v2: Add an #ifdef for subarch-specific code
Neaten the endian check (and extra call to mfmsr!) by modifying the msr and
branching to the target kernel in the same call to rfid.
 arch/powerpc/kernel/misc_64.S | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/misc_64.S b/arch/powerpc/kernel/misc_64.S
index 4e314b9..89f0600 100644
--- a/arch/powerpc/kernel/misc_64.S
+++ b/arch/powerpc/kernel/misc_64.S
@@ -475,9 +475,18 @@ _GLOBAL(kexec_wait)
 #ifdef CONFIG_KEXEC/* use no memory without kexec */
lwz r4,0(r5)
cmpwi   0,r4,0
-   bnea0x60
+   beq 99b
+#ifdef CONFIG_PPC_BOOK3S_64
+   li  r10,0x60
+   mfmsr   r11
+   clrrdi  r11,r11,1   /* Clear MSR_LE */
+   mtsrr0  r10
+   mtsrr1  r11
+   rfid
+#else
+   b   0x60
+#endif
 #endif
-   b   99b
 
 /* this can be in text because we won't change it until we are
  * running in real anyways
-- 
2.4.5

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH V2 2/2] powerpc/configs: Replace pseries_le_defconfig with a Makefile target using merge_config

2015-05-25 Thread Samuel Mendoza-Jonas
Reviewed-by: Samuel Mendoza-Jonas sam...@au1.ibm.com

On 26/05/15 11:36, Cyril Bur wrote:
 Rather than continuing to maintain a copy of pseries_defconfig with enabled
 CONFIG_CPU_LITTLE_ENDIAN, use the generic merge_config script and use an
 le.config to enable little endian on top of pseries_defconfig without the
 need for a duplicated _defconfig file.
 
 This method will require less maintenance in the future and will ensure
 that both 'defconfigs' are always in sync.
 
 It is worth noting that the seemingly more simple approach of:
 pseries_le_defconfig: pseries_defconfig
   $(Q)$(MAKE) le.config
 Will not work when building using O=builddir.
 The obvious fix to that
 pseries_le_defconfig:
   $(Q)$(MAKE) -f $(srctree)/Makefile pseries_defconfig le.config
 Will result in options that get selected by other options having 'select
 CONFIG_FOO' in the defconfig file possibly remaining selected after the
 merge with le.config, when they would not have been set by using an actual
 pseries_le_defconfig file. As a result this has caused differences in the
 generated .config files from when there were actual pseries_le_defconfig
 and pseries_defconfg files.
 
 The solution is to ensure to only invoke a config target once so that it
 has all the information it needs to correctly set all the parameters. This
 is done through the explicit call to make olddefconfig
 
 Signed-off-by: Cyril Bur cyril...@gmail.com
 ---
 V2: Rework to have olddefconfig (or equivalent) only called once.
 Improved to make writing *_defconfig targets easier and have the
   targets look cleaner.
 
  arch/powerpc/Makefile |  15 ++
  arch/powerpc/configs/le.config|   1 +
  arch/powerpc/configs/pseries_le_defconfig | 319 
 --
  3 files changed, 16 insertions(+), 319 deletions(-)
  create mode 100644 arch/powerpc/configs/le.config
  delete mode 100644 arch/powerpc/configs/pseries_le_defconfig
 
 diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
 index 07a4808..2cafce6 100644
 --- a/arch/powerpc/Makefile
 +++ b/arch/powerpc/Makefile
 @@ -269,6 +269,21 @@ bootwrapper_install:
  %.dtb: scripts
   $(Q)$(MAKE) ARCH=ppc64 $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
  
 +#Used to create 'merged defconfigs'
 +#Should be $(call)'ed with the first argument as the defconfig on which to
 +#base and with a space separated list of .config files to merge, without
 +#the .config suffix.
 +define merge_into_defconfig
 +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh \
 + -m -O $(objtree) $(srctree)/arch/$(SRCARCH)/configs/$(1) \
 + $(foreach 
 config,$(2),$(srctree)/arch/$(SRCARCH)/configs/$(config).config)
 +$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
 +endef
 +
 +PHONY += pseries_le_defconfig
 +pseries_le_defconfig:
 + $(call merge_into_defconfig,pseries_defconfig,le)
 +
  define archhelp
@echo '* zImage  - Build default images selected by kernel config'
@echo '  zImage.*- Compressed kernel image 
 (arch/$(ARCH)/boot/zImage.*)'
 diff --git a/arch/powerpc/configs/le.config b/arch/powerpc/configs/le.config
 new file mode 100644
 index 000..ee43fdb
 --- /dev/null
 +++ b/arch/powerpc/configs/le.config
 @@ -0,0 +1 @@
 +CONFIG_CPU_LITTLE_ENDIAN=y
 diff --git a/arch/powerpc/configs/pseries_le_defconfig 
 b/arch/powerpc/configs/pseries_le_defconfig
 deleted file mode 100644
 index 09bc96e..000
 --- a/arch/powerpc/configs/pseries_le_defconfig
 +++ /dev/null
 @@ -1,319 +0,0 @@
 -CONFIG_PPC64=y
 -CONFIG_SMP=y
 -CONFIG_NR_CPUS=2048
 -CONFIG_CPU_LITTLE_ENDIAN=y
 -CONFIG_SYSVIPC=y
 -CONFIG_POSIX_MQUEUE=y
 -CONFIG_FHANDLE=y
 -CONFIG_AUDIT=y
 -CONFIG_AUDITSYSCALL=y
 -CONFIG_IRQ_DOMAIN_DEBUG=y
 -CONFIG_NO_HZ=y
 -CONFIG_HIGH_RES_TIMERS=y
 -CONFIG_TASKSTATS=y
 -CONFIG_TASK_DELAY_ACCT=y
 -CONFIG_TASK_XACCT=y
 -CONFIG_TASK_IO_ACCOUNTING=y
 -CONFIG_IKCONFIG=y
 -CONFIG_IKCONFIG_PROC=y
 -CONFIG_NUMA_BALANCING=y
 -CONFIG_NUMA_BALANCING_DEFAULT_ENABLED=y
 -CONFIG_CGROUPS=y
 -CONFIG_CGROUP_FREEZER=y
 -CONFIG_CGROUP_DEVICE=y
 -CONFIG_CPUSETS=y
 -CONFIG_CGROUP_CPUACCT=y
 -CONFIG_MEMCG=y
 -CONFIG_MEMCG_SWAP=y
 -CONFIG_CGROUP_PERF=y
 -CONFIG_CGROUP_SCHED=y
 -CONFIG_USER_NS=y
 -CONFIG_BLK_DEV_INITRD=y
 -# CONFIG_COMPAT_BRK is not set
 -CONFIG_PROFILING=y
 -CONFIG_OPROFILE=y
 -CONFIG_KPROBES=y
 -CONFIG_JUMP_LABEL=y
 -CONFIG_MODULES=y
 -CONFIG_MODULE_UNLOAD=y
 -CONFIG_MODVERSIONS=y
 -CONFIG_MODULE_SRCVERSION_ALL=y
 -CONFIG_PARTITION_ADVANCED=y
 -CONFIG_PPC_SPLPAR=y
 -CONFIG_SCANLOG=m
 -CONFIG_PPC_SMLPAR=y
 -CONFIG_DTL=y
 -# CONFIG_PPC_PMAC is not set
 -CONFIG_RTAS_FLASH=m
 -CONFIG_IBMEBUS=y
 -CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
 -CONFIG_HZ_100=y
 -CONFIG_BINFMT_MISC=m
 -CONFIG_PPC_TRANSACTIONAL_MEM=y
 -CONFIG_KEXEC=y
 -CONFIG_IRQ_ALL_CPUS=y
 -CONFIG_MEMORY_HOTPLUG=y
 -CONFIG_MEMORY_HOTREMOVE=y
 -CONFIG_KSM=y
 -CONFIG_TRANSPARENT_HUGEPAGE=y
 -CONFIG_PPC_64K_PAGES=y
 -CONFIG_PPC_SUBPAGE_PROT=y
 -CONFIG_SCHED_SMT=y
 -CONFIG_HOTPLUG_PCI=y