Re: Coccinelle: Checking of_node_put() calls with SmPL

2019-07-10 Thread Julia Lawall


On Thu, 11 Jul 2019, wen.yan...@zte.com.cn wrote:

> > > we developed a coccinelle script to detect such problems.
> >
> > Would you find the implementation of the function “dt_init_idle_driver”
> > suspicious according to discussed source code search patterns?
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/cpuidle/dt_idle_states.c?id=e9a83bd2322035ed9d7dcf35753d3f984d76c6a5#n208
> > https://elixir.bootlin.com/linux/v5.2/source/drivers/cpuidle/dt_idle_states.c#L208
> >
> >
> > > This script is still being improved.
> >
> > Will corresponding software development challenges become more interesting?
>
> Hello Markus,
> This is the simplified code pattern for it:
>
> 172 for (i = 0; ; i++) {
> 173 state_node = of_parse_phandle(...); ---> Obtain here
> ...
> 177 match_id = of_match_node(matches, state_node);
> 178 if (!match_id) {
> 179 err = -ENODEV;
> 180 break; --->  Jump out of 
> the loop without releasing it
> 181 }
> 182
> 183 if (!of_device_is_available(state_node)) {
> 184 of_node_put(state_node);
> 185 continue;--->  Release the 
> object references within a loop
> 186 }
> ...
> 208 of_node_put(state_node);  -->  Release the object 
> references within a loop
> 209 }
> 210
> 211 of_node_put(state_node);   -->There may be double free 
> here.
>
> This code pattern is very interesting and the coccinelle software should also 
> recognize this pattern.

In my experience, when you start looking at these of_node_put things, all
sorts of strange things appear...

julia

Re: Coccinelle: Checking of_node_put() calls with SmPL

2019-07-10 Thread wen.yang99
> > we developed a coccinelle script to detect such problems.
> 
> Would you find the implementation of the function “dt_init_idle_driver”
> suspicious according to discussed source code search patterns?
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/cpuidle/dt_idle_states.c?id=e9a83bd2322035ed9d7dcf35753d3f984d76c6a5#n208
> https://elixir.bootlin.com/linux/v5.2/source/drivers/cpuidle/dt_idle_states.c#L208
> 
> 
> > This script is still being improved.
> 
> Will corresponding software development challenges become more interesting?

Hello Markus,
This is the simplified code pattern for it:

172 for (i = 0; ; i++) {
173 state_node = of_parse_phandle(...); ---> Obtain here
...
177 match_id = of_match_node(matches, state_node);
178 if (!match_id) {
179 err = -ENODEV;  
180 break; --->  Jump out of 
the loop without releasing it
181 }
182 
183 if (!of_device_is_available(state_node)) {
184 of_node_put(state_node);
185 continue;--->  Release the 
object references within a loop
186 }
...
208 of_node_put(state_node);  -->  Release the object 
references within a loop
209 }
210 
211 of_node_put(state_node);   -->There may be double free here.

This code pattern is very interesting and the coccinelle software should also 
recognize this pattern.

Regards,
Wen

Re: [PATCH V3 2/2] ASoC: fsl_esai: recover the channel swap after xrun

2019-07-10 Thread S.j. Wang


> 
> Hi Shengjiu,
> 
> Mostly looks good to me, just some small comments.
> 
> On Mon, Jul 08, 2019 at 02:38:52PM +0800, shengjiu.w...@nxp.com wrote:
> 
> > +static void fsl_esai_hw_reset(unsigned long arg) {
> > + struct fsl_esai *esai_priv = (struct fsl_esai *)arg;
> > + u32 saisr, tfcr, rfcr;
> > + bool tx = true, rx = false, enabled[2];
> 
> Could we swap the lines of u32 and bool? It'd look better.
> 
> > + regmap_update_bits(esai_priv->regmap, REG_ESAI_TCR,
> > +ESAI_xCR_xPR_MASK, ESAI_xCR_xPR);
> > + regmap_update_bits(esai_priv->regmap, REG_ESAI_RCR,
> > +ESAI_xCR_xPR_MASK, ESAI_xCR_xPR);
> 
> Let's add a line of comments for these two:
> /* Enforce ESAI personal resets for both TX and RX */
> 
> > + /*
> > +  * Restore registers by regcache_sync, and ignore
> > +  * return value
> > +  */
> 
> Could fit into single-line?
> 
> > + regmap_update_bits(esai_priv->regmap, REG_ESAI_TCR,
> > +ESAI_xCR_xPR_MASK, 0);
> > + regmap_update_bits(esai_priv->regmap, REG_ESAI_RCR,
> > +ESAI_xCR_xPR_MASK, 0);
> > +
> > + regmap_update_bits(esai_priv->regmap, REG_ESAI_PRRC,
> > +ESAI_PRRC_PDC_MASK, ESAI_PRRC_PDC(ESAI_GPIO));
> > + regmap_update_bits(esai_priv->regmap, REG_ESAI_PCRC,
> > +ESAI_PCRC_PC_MASK, ESAI_PCRC_PC(ESAI_GPIO));
> 
> Could remove the blank line and add a line of comments:
> /* Remove ESAI personal resets by configuring PCRC and PRRC also */
> 
> Btw, I still feel this personal reset can be stuffed into one of the wrapper
> functions. But let's keep this simple for now.
> 
> > + regmap_read(esai_priv->regmap, REG_ESAI_SAISR, &saisr);
> 
> Why do we read saisr here? All its bits would get cleared by the hardware
> reset. If it's a must to clear again, we should add a line of comments to
> emphasize it.

This line can be removed. 

Best regards
Wang Shengjiu


Re: [PATCH v5 1/7] kvmppc: HMM backend driver to manage pages of secure guest

2019-07-10 Thread Bharata B Rao
On Wed, Jul 10, 2019 at 10:47:34AM -0300, Jason Gunthorpe wrote:
> On Tue, Jul 09, 2019 at 01:55:28PM -0500, janani wrote:
> 
> > > +int kvmppc_hmm_init(void)
> > > +{
> > > + int ret = 0;
> > > + unsigned long size;
> > > +
> > > + size = kvmppc_get_secmem_size();
> > > + if (!size) {
> > > + ret = -ENODEV;
> > > + goto out;
> > > + }
> > > +
> > > + kvmppc_hmm.device = hmm_device_new(NULL);
> > > + if (IS_ERR(kvmppc_hmm.device)) {
> > > + ret = PTR_ERR(kvmppc_hmm.device);
> > > + goto out;
> > > + }
> > > +
> > > + kvmppc_hmm.devmem = hmm_devmem_add(&kvmppc_hmm_devmem_ops,
> > > +&kvmppc_hmm.device->device, size);
> > > + if (IS_ERR(kvmppc_hmm.devmem)) {
> > > + ret = PTR_ERR(kvmppc_hmm.devmem);
> > > + goto out_device;
> > > + }
> 
> This 'hmm_device' API family was recently deleted from hmm:

Hmmm... I still find it in upstream, guess it will be removed soon?

I find the below commit in mmotm.

> 
> commit 07ec38917e68f0114b9c8aeeb1c584b5e73e4dd6
> Author: Christoph Hellwig 
> Date:   Wed Jun 26 14:27:01 2019 +0200
> 
> mm: remove the struct hmm_device infrastructure
> 
> This code is a trivial wrapper around device model helpers, which
> should have been integrated into the driver device model usage from
> the start.  Assuming it actually had users, which it never had since
> the code was added more than 1 1/2 years ago.
> 
> This patch should use the driver core directly instead.
> 
> Regards,
> Jason



Re: [PATCH v2] powerpc/imc: Dont create debugfs files for cpu-less nodes

2019-07-10 Thread Michael Ellerman
Hi Maddy,

Madhavan Srinivasan  writes:
> diff --git a/arch/powerpc/platforms/powernv/opal-imc.c 
> b/arch/powerpc/platforms/powernv/opal-imc.c
> index 186109bdd41b..e04b20625cb9 100644
> --- a/arch/powerpc/platforms/powernv/opal-imc.c
> +++ b/arch/powerpc/platforms/powernv/opal-imc.c
> @@ -69,20 +69,20 @@ static void export_imc_mode_and_cmd(struct device_node 
> *node,
>   if (of_property_read_u32(node, "cb_offset", &cb_offset))
>   cb_offset = IMC_CNTL_BLK_OFFSET;
>  
> - for_each_node(nid) {
> - loc = (u64)(pmu_ptr->mem_info[chip].vbase) + cb_offset;
> + while (ptr->vbase != NULL) {

This means you'll bail out as soon as you find a node with no vbase, but
it's possible we could have a CPU-less node intermingled with other
nodes.

So I think you want to keep the for loop, but continue if you see a NULL
vbase?


> + loc = (u64)(ptr->vbase) + cb_offset;
>   imc_mode_addr = (u64 *)(loc + IMC_CNTL_BLK_MODE_OFFSET);
> - sprintf(mode, "imc_mode_%d", nid);
> + sprintf(mode, "imc_mode_%d", (u32)(ptr->id));
>   if (!imc_debugfs_create_x64(mode, 0600, imc_debugfs_parent,
>   imc_mode_addr))
>   goto err;
>  
>   imc_cmd_addr = (u64 *)(loc + IMC_CNTL_BLK_CMD_OFFSET);
> - sprintf(cmd, "imc_cmd_%d", nid);
> + sprintf(cmd, "imc_cmd_%d", (u32)(ptr->id));
>   if (!imc_debugfs_create_x64(cmd, 0600, imc_debugfs_parent,
>   imc_cmd_addr))
>   goto err;
> - chip++;
> + ptr++;
>   }
>   return;

cheers


[PATCH 1/2] powerpc/64s: remplement power4_idle code in C

2019-07-10 Thread Nicholas Piggin
This implements the tricky tracing and soft irq handling bits in C,
leaving the low level bit to asm.

A functional difference is that this redirects the interrupt exit to
a return stub to execute blr, rather than the lr address itself. This
is probably barely measurable on real hardware, but it keeps the link
stack balanced.

Tested with QEMU.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/processor.h |  3 +
 arch/powerpc/kernel/Makefile |  3 +-
 arch/powerpc/kernel/exceptions-64s.S |  9 ---
 arch/powerpc/kernel/idle.c   | 25 
 arch/powerpc/kernel/idle_book3s.S| 35 +++
 arch/powerpc/kernel/idle_power4.S| 87 
 arch/powerpc/platforms/Kconfig   |  4 ++
 7 files changed, 68 insertions(+), 98 deletions(-)
 delete mode 100644 arch/powerpc/kernel/idle_power4.S

diff --git a/arch/powerpc/include/asm/processor.h 
b/arch/powerpc/include/asm/processor.h
index 706ac5df546f..c0d870c57061 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -418,6 +418,9 @@ static inline unsigned long get_clean_sp(unsigned long sp, 
int is_32)
 extern unsigned long isa300_idle_stop_noloss(unsigned long psscr_val);
 extern unsigned long isa300_idle_stop_mayloss(unsigned long psscr_val);
 extern unsigned long isa206_idle_insn_mayloss(unsigned long type);
+#ifdef CONFIG_PPC_970_NAP
+extern void power4_idle_nap(void);
+#endif
 
 extern unsigned long cpuidle_disable;
 enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_POWERSAVE_OFF};
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 56dfa7a2a6f2..04c6d8cc241b 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -64,8 +64,7 @@ obj-$(CONFIG_PPC_BOOK3E_64)   += exceptions-64e.o 
idle_book3e.o
 obj-$(CONFIG_PPC_BARRIER_NOSPEC) += security.o
 obj-$(CONFIG_PPC64)+= vdso64/
 obj-$(CONFIG_ALTIVEC)  += vecemu.o
-obj-$(CONFIG_PPC_970_NAP)  += idle_power4.o
-obj-$(CONFIG_PPC_P7_NAP)   += idle_book3s.o
+obj-$(CONFIG_PPC_BOOK3S_IDLE)  += idle_book3s.o
 procfs-y   := proc_powerpc.o
 obj-$(CONFIG_PROC_FS)  += $(procfs-y)
 rtaspci-$(CONFIG_PPC64)-$(CONFIG_PCI)  := rtas_pci.o
diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index eee5bef736c8..64d5ffbb07d1 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -2286,15 +2286,6 @@ USE_FIXED_SECTION(virt_trampolines)
 __end_interrupts:
 DEFINE_FIXED_SYMBOL(__end_interrupts)
 
-#ifdef CONFIG_PPC_970_NAP
-EXC_COMMON_BEGIN(power4_fixup_nap)
-   andcr9,r9,r10
-   std r9,TI_LOCAL_FLAGS(r11)
-   ld  r10,_LINK(r1)   /* make idle task do the */
-   std r10,_NIP(r1)/* equivalent of a blr */
-   blr
-#endif
-
 CLOSE_FIXED_SECTION(real_vectors);
 CLOSE_FIXED_SECTION(real_trampolines);
 CLOSE_FIXED_SECTION(virt_vectors);
diff --git a/arch/powerpc/kernel/idle.c b/arch/powerpc/kernel/idle.c
index d7216c9abda1..605defde43b9 100644
--- a/arch/powerpc/kernel/idle.c
+++ b/arch/powerpc/kernel/idle.c
@@ -81,6 +81,31 @@ void arch_cpu_idle(void)
 
 int powersave_nap;
 
+#ifdef CONFIG_PPC_970_NAP
+void power4_idle(void)
+{
+   if (!cpu_has_feature(CPU_FTR_CAN_NAP))
+   return;
+
+   if (!powersave_nap)
+   return;
+
+   if (!prep_irq_for_idle())
+   return;
+
+   if (cpu_has_feature(CPU_FTR_ALTIVEC))
+   asm volatile("DSSALL ; sync" ::: "memory");
+
+   power4_idle_nap();
+
+   /*
+* power4_idle_nap returns with interrupts enabled (soft and hard).
+* to our caller with interrupts enabled (soft and hard). Our caller
+* can cope with either interrupts disabled or enabled upon return.
+*/
+}
+#endif
+
 #ifdef CONFIG_SYSCTL
 /*
  * Register the sysctl to set/clear powersave_nap.
diff --git a/arch/powerpc/kernel/idle_book3s.S 
b/arch/powerpc/kernel/idle_book3s.S
index 2dfbd5d5b932..5afac9177fec 100644
--- a/arch/powerpc/kernel/idle_book3s.S
+++ b/arch/powerpc/kernel/idle_book3s.S
@@ -19,7 +19,9 @@
 #include 
 #include 
 #include 
+#include  /* TLF_NAPPING */
 
+#ifdef CONFIG_PPC_P7_NAP
 /*
  * Desired PSSCR in r3
  *
@@ -185,4 +187,37 @@ _GLOBAL(isa206_idle_insn_mayloss)
bne 2f
IDLE_STATE_ENTER_SEQ_NORET(PPC_SLEEP)
 2: IDLE_STATE_ENTER_SEQ_NORET(PPC_WINKLE)
+#endif
 
+#ifdef CONFIG_PPC_970_NAP
+_GLOBAL(power4_idle_nap)
+   LOAD_REG_IMMEDIATE(r7, MSR_KERNEL|MSR_EE|MSR_POW)
+   ld  r9,PACA_THREAD_INFO(r13)
+   ld  r8,TI_LOCAL_FLAGS(r9)
+   ori r8,r8,_TLF_NAPPING
+   std r8,TI_LOCAL_FLAGS(r9)
+   /*
+* NAPPING bit is set, from this point onward power4_fixup_nap
+* will cause exceptions to return to power4_idle_nap_return.
+*/
+1: sync
+   isync
+   mtmsrd  r7
+   isync
+   b   1b
+power4_idle_nap_return

[PATCH 2/2] powerpc/64s: Remove idle workaround code from restore_cpu_cpufeatures

2019-07-10 Thread Nicholas Piggin
Idle code no longer uses the .cpu_restore CPU operation to restore
SPRs, so this workaround is no longer required.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/dt_cpu_ftrs.c | 21 +
 1 file changed, 1 insertion(+), 20 deletions(-)

diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c 
b/arch/powerpc/kernel/dt_cpu_ftrs.c
index c66fd3ce6478..78db3e6eb45e 100644
--- a/arch/powerpc/kernel/dt_cpu_ftrs.c
+++ b/arch/powerpc/kernel/dt_cpu_ftrs.c
@@ -71,7 +71,6 @@ static int hv_mode;
 
 static struct {
u64 lpcr;
-   u64 lpcr_clear;
u64 hfscr;
u64 fscr;
 } system_registers;
@@ -80,24 +79,7 @@ static void (*init_pmu_registers)(void);
 
 static void __restore_cpu_cpufeatures(void)
 {
-   u64 lpcr;
-
-   /*
-* LPCR is restored by the power on engine already. It can be changed
-* after early init e.g., by radix enable, and we have no unified API
-* for saving and restoring such SPRs.
-*
-* This ->restore hook should really be removed from idle and register
-* restore moved directly into the idle restore code, because this code
-* doesn't know how idle is implemented or what it needs restored here.
-*
-* The best we can do to accommodate secondary boot and idle restore
-* for now is "or" LPCR with existing.
-*/
-   lpcr = mfspr(SPRN_LPCR);
-   lpcr |= system_registers.lpcr;
-   lpcr &= ~system_registers.lpcr_clear;
-   mtspr(SPRN_LPCR, lpcr);
+   mtspr(SPRN_LPCR, system_registers.lpcr);
if (hv_mode) {
mtspr(SPRN_LPID, 0);
mtspr(SPRN_HFSCR, system_registers.hfscr);
@@ -318,7 +300,6 @@ static int __init feat_enable_mmu_hash_v3(struct 
dt_cpu_feature *f)
 {
u64 lpcr;
 
-   system_registers.lpcr_clear |= (LPCR_ISL | LPCR_UPRT | LPCR_HR);
lpcr = mfspr(SPRN_LPCR);
lpcr &= ~(LPCR_ISL | LPCR_UPRT | LPCR_HR);
mtspr(SPRN_LPCR, lpcr);
-- 
2.20.1



Re: pata-macio on PowerBook G3: stuck interrupt with MATSHITA CR-174 CD-ROM

2019-07-10 Thread Finn Thain
On Fri, 28 Jun 2019, Finn Thain wrote:

> Hi All,
> 
> I've received a bug report concerning the pata-macio driver, when running 
> on a PowerBook G3 (Wallstreet).
> 
> With CONFIG_PATA_MACIO=n && CONFIG_BLK_DEV_IDE_PMAC=y, everything works.
> 
> With CONFIG_PATA_MACIO=y && CONFIG_BLK_DEV_IDE_PMAC=n, the CD-ROM fails.
> 
> When the CD-ROM mediabay module is swapped for a DVD-ROM mediabay module, 
> everything works (either pata-macio or ide-pmac driver works fine).
> 
> I'm not familiar with ATA device drivers or the "Heathrow" chipset and its 
> ATA interfaces so any hints as to how to debug this would be appreciated.
> 
...
> 
> These logs are from v4.20 but the problem is the same in v5.2-rc2.
> 

In the linux-ide list archive I found the same bug reported in 2.6.33-rc2, 
shortly after the pata-macio driver was merged.

https://lore.kernel.org/linux-ide/19254.17766.674348.933...@pilspetsen.it.uu.se/

That report also involves a Matshita CD-ROM and a Heathrow controller 
(beige G3).

In that thread Ben suggested that the cause may be a firmware bug in the 
drive. Is there a quirk or other workaround for that kind of bug?

I tried removing the controller reset but there was no improvement...

diff --git a/drivers/ata/pata_macio.c b/drivers/ata/pata_macio.c
index 57f2ec71cfc3..b2fd5e20367f 100644
--- a/drivers/ata/pata_macio.c
+++ b/drivers/ata/pata_macio.c
@@ -1096,7 +1096,7 @@ static int pata_macio_common_init(struct pata_macio_priv 
*priv,
priv->host->ports[0]->private_data = priv;
 
/* hard-reset the controller */
-   pata_macio_reset_hw(priv, 0);
+// pata_macio_reset_hw(priv, 0);
pata_macio_apply_timings(priv->host->ports[0], 0);
 
/* Enable bus master if necessary */

-- 


Re: [PATCH V3 2/2] ASoC: fsl_esai: recover the channel swap after xrun

2019-07-10 Thread Nicolin Chen
Hi Shengjiu,

Mostly looks good to me, just some small comments.

On Mon, Jul 08, 2019 at 02:38:52PM +0800, shengjiu.w...@nxp.com wrote:
  
> +static void fsl_esai_hw_reset(unsigned long arg)
> +{
> + struct fsl_esai *esai_priv = (struct fsl_esai *)arg;
> + u32 saisr, tfcr, rfcr;
> + bool tx = true, rx = false, enabled[2];

Could we swap the lines of u32 and bool? It'd look better.

> + regmap_update_bits(esai_priv->regmap, REG_ESAI_TCR,
> +ESAI_xCR_xPR_MASK, ESAI_xCR_xPR);
> + regmap_update_bits(esai_priv->regmap, REG_ESAI_RCR,
> +ESAI_xCR_xPR_MASK, ESAI_xCR_xPR);

Let's add a line of comments for these two:
/* Enforce ESAI personal resets for both TX and RX */

> + /*
> +  * Restore registers by regcache_sync, and ignore
> +  * return value
> +  */

Could fit into single-line?

> + regmap_update_bits(esai_priv->regmap, REG_ESAI_TCR,
> +ESAI_xCR_xPR_MASK, 0);
> + regmap_update_bits(esai_priv->regmap, REG_ESAI_RCR,
> +ESAI_xCR_xPR_MASK, 0);
> +
> + regmap_update_bits(esai_priv->regmap, REG_ESAI_PRRC,
> +ESAI_PRRC_PDC_MASK, ESAI_PRRC_PDC(ESAI_GPIO));
> + regmap_update_bits(esai_priv->regmap, REG_ESAI_PCRC,
> +ESAI_PCRC_PC_MASK, ESAI_PCRC_PC(ESAI_GPIO));

Could remove the blank line and add a line of comments:
/* Remove ESAI personal resets by configuring PCRC and PRRC also */

Btw, I still feel this personal reset can be stuffed into one
of the wrapper functions. But let's keep this simple for now.

> + regmap_read(esai_priv->regmap, REG_ESAI_SAISR, &saisr);

Why do we read saisr here? All its bits would get cleared by
the hardware reset. If it's a must to clear again, we should
add a line of comments to emphasize it.

Thank you


Re: [PATCH v3 5/7] kexec_elf: remove elf_addr_to_cpu macro

2019-07-10 Thread Sven Schnelle
Hi Christophe,

On Wed, Jul 10, 2019 at 05:09:29PM +0200, Christophe Leroy wrote:
> 
> 
> Le 10/07/2019 à 16:29, Sven Schnelle a écrit :
> > It had only one definition, so just use the function directly.
> 
> It had only one definition because it was for ppc64 only.
> But as far as I understand (at least from the name of the new file), you
> want it to be generic, don't you ? Therefore I get on 32 bits it would be
> elf32_to_cpu().

That brings up the question whether we need those endianess conversions. I would
assume that the ELF file has always the same endianess as the running kernel. So
i think we could just drop them. What do you think?

Regards
Sven


Re: [PATCH v4 5/8] KVM: PPC: Ultravisor: Restrict flush of the partition tlb cache

2019-07-10 Thread Ram Pai
On Mon, Jul 08, 2019 at 02:54:52PM -0500, janani wrote:
> On 2019-06-28 15:08, Claudio Carvalho wrote:
> >From: Ram Pai 
> >
> >Ultravisor is responsible for flushing the tlb cache, since it manages
> >the PATE entries. Hence skip tlb flush, if the ultravisor firmware is
> >available.
> >
> >Signed-off-by: Ram Pai 
> >Signed-off-by: Claudio Carvalho 
> >---
> > arch/powerpc/mm/book3s64/pgtable.c | 33 +-
> > 1 file changed, 19 insertions(+), 14 deletions(-)
> >
> >diff --git a/arch/powerpc/mm/book3s64/pgtable.c
> >b/arch/powerpc/mm/book3s64/pgtable.c
> >index 224c5c7c2e3d..bc8eb2bf9810 100644
> >--- a/arch/powerpc/mm/book3s64/pgtable.c
> >+++ b/arch/powerpc/mm/book3s64/pgtable.c
> >@@ -224,6 +224,23 @@ void __init mmu_partition_table_init(void)
> > powernv_set_nmmu_ptcr(ptcr);
> > }
> >
> >+static void flush_partition(unsigned int lpid, unsigned long dw0)
> >+{
> >+if (dw0 & PATB_HR) {
> >+asm volatile(PPC_TLBIE_5(%0, %1, 2, 0, 1) : :
> >+ "r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
> >+asm volatile(PPC_TLBIE_5(%0, %1, 2, 1, 1) : :
> >+ "r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
> >+trace_tlbie(lpid, 0, TLBIEL_INVAL_SET_LPID, lpid, 2, 0, 1);
> >+} else {
> >+asm volatile(PPC_TLBIE_5(%0, %1, 2, 0, 0) : :
> >+ "r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
> >+trace_tlbie(lpid, 0, TLBIEL_INVAL_SET_LPID, lpid, 2, 0, 0);
> >+}
> >+/* do we need fixup here ?*/
> >+asm volatile("eieio; tlbsync; ptesync" : : : "memory");
> >+}
> >+
> > static void __mmu_partition_table_set_entry(unsigned int lpid,
> > unsigned long dw0,
> > unsigned long dw1)
> >@@ -238,20 +255,8 @@ static void
> >__mmu_partition_table_set_entry(unsigned int lpid,
> >  * The type of flush (hash or radix) depends on what the previous
> >  * use of this partition ID was, not the new use.
> >  */
> >-asm volatile("ptesync" : : : "memory");
>  Doesn't the line above that was deleted need to be added to the
> beginning of flush_partition()

It has to. It got dropped erroneously.

This is a good catch!

Thanks,
RP



[Bug 204125] FTBFS on ppc64 big endian and gcc9 because of -mcall-aixdesc and missing __linux__

2019-07-10 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=204125

--- Comment #4 from Segher Boessenkool (seg...@kernel.crashing.org) ---
I meant GNU userland.  I don't know any project that officially support
BE ELFv2.  No BE ELFv2 Linux ABI is defined, either, as far as I know.

It's great to hear that a lot of it works fine though :-)

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

[Bug 204125] FTBFS on ppc64 big endian and gcc9 because of -mcall-aixdesc and missing __linux__

2019-07-10 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=204125

--- Comment #5 from Daniel Kolesa (li...@octaforge.org) ---
I have an entire distro built with it. A small number of things require minor
patches. Some of these have been upstreamed, some of these are pending (for
example, to make OpenSSL assembly work on BE/ELFv2, it requires about 5 lines
of changes to pass all of the testsuite, and a PR for that is up). Glibc used
to not work about a year ago I think, these days it works perfectly fine and we
generally have no major issues with any software that already worked on BE in
the first place.

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

[Bug 204125] FTBFS on ppc64 big endian and gcc9 because of -mcall-aixdesc and missing __linux__

2019-07-10 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=204125

--- Comment #3 from Daniel Kolesa (li...@octaforge.org) ---
Also, reported in gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91135

Let's see what the compiler people have to say...

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

[Bug 204125] FTBFS on ppc64 big endian and gcc9 because of -mcall-aixdesc and missing __linux__

2019-07-10 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=204125

--- Comment #2 from Daniel Kolesa (li...@octaforge.org) ---
ELFv2 works perfectly fine in BE userland, the musl libc *requires* ELFv2 on
both endians and glibc works okay using either. ELFv2 was defined for both
endians and there are distros that make use of it on BE (Adélie Linux supports
only BE with musl libc and ELFv2, Void Linux has both BE and LE on musl and
glibc, all using ELFv2).

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

[Bug 204125] FTBFS on ppc64 big endian and gcc9 because of -mcall-aixdesc and missing __linux__

2019-07-10 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=204125

Segher Boessenkool (seg...@kernel.crashing.org) changed:

   What|Removed |Added

 CC||seg...@kernel.crashing.org

--- Comment #1 from Segher Boessenkool (seg...@kernel.crashing.org) ---
(In reply to Daniel Kolesa from comment #0)
> On ppc64 big endian, the kernel builds with `-mcall-aixdesc` which since gcc
> 9.x removes `__linux__` from the list of macros being defined.

This is a bug.  Please report at https://gcc.gnu.org/bugzilla .

> This behavior
> is supposed to be more correct (as it's in this case nothing but a hack, the
> flag should apparently only be used when building for AIX)

What makes you think that?

OTOH, why does the kernel use that option?

> but sadly it
> breaks build since several things within the tree rely on `__linux__` being
> defined and `#ifdef` some of their code based on said macro.

Those are bugs as well, then.

> Just removing `-mcall-aixdesc` (and using just `-mabi=elfv1`) is however not
> enough, as that instead causes countless undefined references to just about
> every symbol when linking `vmlinux`. It would seem that `-mcall-aixdesc`
> changes the way symbols are declared in a way that is not expected.

> Little endian is not affected because that one uses `-mabi=elfv2`
> exclusively.

Of course, that is the only defined ABI for powerpc64le after all.

> Also, is there any reason not to allow an ELFv2 kernel to be built on big
> endian?

Building it _on_ BE works just fine, of course.  But you mean building a BE
kernel using the ELFv2 ABI.  This is not supported; it would require writing
other versions for various low-level things.

ELFv2 is not supported in BE userland, either, btw.

> There are some supposed performance benefits, and ELFv2 itself
> supports either endianness. The current kbuild logic pretty much forces
> ELFv1 for big endian and ELFv2 for little endian.

ELFv2 has a few little benefits; it is newer, there were lessons learnt.  It
would be surprising if it has better than trivial advantages for the BE kernel
though.  But feel free to try, of course :-)

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

[PATCH v2 16/16] powerpc/64s/exception: machine check improve labels and comments

2019-07-10 Thread Nicholas Piggin
Short forward and backward branches can be given number labels,
but larger significant divergences in code path a more readable
if they're given descriptive names.

Also adjusts a comment to account for guest delivery.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index d196558d4243..a69f4599e304 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1052,7 +1052,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
 */
lbz r11,HSTATE_IN_GUEST(r13)
cmpwi   r11,0   /* Check if coming from guest */
-   bne 9f  /* continue if we are. */
+   bne mce_deliver /* continue if we are. */
 #endif
 
/*
@@ -1060,7 +1060,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
 * exception handler which will deliver the MC event to this kernel.
 */
andi.   r11,r12,MSR_PR  /* See if coming from user. */
-   bne 9f  /* continue in V mode if we are. */
+   bne mce_deliver /* continue in V mode if we are. */
 
/*
 * At this point we are coming from kernel context.
@@ -1088,8 +1088,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
MACHINE_CHECK_HANDLER_WINDUP
RFI_TO_KERNEL
 
-9:
-   /* Deliver the machine check to host kernel in V mode. */
+mce_deliver:
+   /*
+* This is a host user or guest MCE. Restore all registers, then
+* run the "late" handler. For host user, this will run the
+* machine_check_exception handler in virtual mode like a normal
+* interrupt handler. For guest, this will trigger the KVM test
+* and branch to the KVM interrupt similarly to other interrupts.
+*/
 BEGIN_FTR_SECTION
ld  r10,ORIG_GPR3(r1)
mtspr   SPRN_CFAR,r10
-- 
2.20.1



[PATCH v2 15/16] powerpc/64s/exception: untangle early machine check handler branch

2019-07-10 Thread Nicholas Piggin
machine_check_early_common now branches to machine_check_handle_early
which is its only caller.

Move interleaving code out of the way, and remove the branch.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 129 +--
 1 file changed, 62 insertions(+), 67 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 95dd7ff3ef04..d196558d4243 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -956,6 +956,16 @@ TRAMP_REAL_BEGIN(machine_check_fwnmi)
 
 TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
 
+#define MACHINE_CHECK_HANDLER_WINDUP   \
+   /* Clear MSR_RI before setting SRR0 and SRR1. */\
+   li  r9,0;   \
+   mtmsrd  r9,1;   /* Clear MSR_RI */  \
+   /* Decrement paca->in_mce now RI is clear. */   \
+   lhz r12,PACA_IN_MCE(r13);   \
+   subir12,r12,1;  \
+   sth r12,PACA_IN_MCE(r13);   \
+   EXCEPTION_RESTORE_REGS EXC_STD
+
 EXC_COMMON_BEGIN(machine_check_early_common)
mtctr   r10 /* Restore ctr */
mfspr   r11,SPRN_SRR0
@@ -1011,74 +1021,7 @@ BEGIN_FTR_SECTION
 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
li  r10,MSR_RI
mtmsrd  r10,1
-   b   machine_check_handle_early
 
-EXC_COMMON_BEGIN(machine_check_common)
-   /*
-* Machine check is different because we use a different
-* save area: PACA_EXMC instead of PACA_EXGEN.
-*/
-   EXCEPTION_COMMON(PACA_EXMC, 0x200)
-   FINISH_NAP
-   RECONCILE_IRQ_STATE(r10, r11)
-   ld  r3,PACA_EXMC+EX_DAR(r13)
-   lwz r4,PACA_EXMC+EX_DSISR(r13)
-   /* Enable MSR_RI when finished with PACA_EXMC */
-   li  r10,MSR_RI
-   mtmsrd  r10,1
-   std r3,_DAR(r1)
-   std r4,_DSISR(r1)
-   bl  save_nvgprs
-   addir3,r1,STACK_FRAME_OVERHEAD
-   bl  machine_check_exception
-   b   ret_from_except
-
-#define MACHINE_CHECK_HANDLER_WINDUP   \
-   /* Clear MSR_RI before setting SRR0 and SRR1. */\
-   li  r9,0;   \
-   mtmsrd  r9,1;   /* Clear MSR_RI */  \
-   /* Decrement paca->in_mce now RI is clear. */   \
-   lhz r12,PACA_IN_MCE(r13);   \
-   subir12,r12,1;  \
-   sth r12,PACA_IN_MCE(r13);   \
-   EXCEPTION_RESTORE_REGS EXC_STD
-
-#ifdef CONFIG_PPC_P7_NAP
-/*
- * This is an idle wakeup. Low level machine check has already been
- * done. Queue the event then call the idle code to do the wake up.
- */
-EXC_COMMON_BEGIN(machine_check_idle_common)
-   bl  machine_check_queue_event
-
-   /*
-* We have not used any non-volatile GPRs here, and as a rule
-* most exception code including machine check does not.
-* Therefore PACA_NAPSTATELOST does not need to be set. Idle
-* wakeup will restore volatile registers.
-*
-* Load the original SRR1 into r3 for pnv_powersave_wakeup_mce.
-*
-* Then decrement MCE nesting after finishing with the stack.
-*/
-   ld  r3,_MSR(r1)
-   ld  r4,_LINK(r1)
-
-   lhz r11,PACA_IN_MCE(r13)
-   subir11,r11,1
-   sth r11,PACA_IN_MCE(r13)
-
-   mtlrr4
-   rlwinm  r10,r3,47-31,30,31
-   cmpwi   cr1,r10,2
-   bltlr   cr1 /* no state loss, return to idle caller */
-   b   idle_return_gpr_loss
-#endif
-   /*
-* Handle machine check early in real mode. We come here with
-* ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
-*/
-EXC_COMMON_BEGIN(machine_check_handle_early)
bl  save_nvgprs
addir3,r1,STACK_FRAME_OVERHEAD
bl  machine_check_early
@@ -1157,6 +1100,58 @@ END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 1, 0x200, 1, 1, 0
EXCEPTION_PROLOG_2_REAL machine_check_common, EXC_STD, 0
 
+EXC_COMMON_BEGIN(machine_check_common)
+   /*
+* Machine check is different because we use a different
+* save area: PACA_EXMC instead of PACA_EXGEN.
+*/
+   EXCEPTION_COMMON(PACA_EXMC, 0x200)
+   FINISH_NAP
+   RECONCILE_IRQ_STATE(r10, r11)
+   ld  r3,PACA_EXMC+EX_DAR(r13)
+   lwz r4,PACA_EXMC+EX_DSISR(r13)
+   /* Enable MSR_RI when finished with PACA_EXMC */
+   li  r10,MSR_RI
+   mtmsrd  r10,1
+   std r3,_DAR(r1)
+   std r4,_DSISR(r1)
+   bl  save_nvgprs
+   addir3,r1,STACK_FRAME_OVERHEAD
+   bl  machine_check_exception
+   b   ret_from_except
+
+#ifdef CONFIG_PPC_P7_NAP
+/*
+ * This is an idle wakeup. Low level machine check has already been
+ * done. Queue the event then c

[PATCH v2 14/16] powerpc/64s/exception: machine check move unrecoverable handling out of line

2019-07-10 Thread Nicholas Piggin
Similarly to the previous change, all callers of the unrecoverable
handler run relocated so can reach it with a direct branch. This makes
it easy to move out of line, which makes the "normal" path less
cluttered and easier to follow.

MSR[ME] manipulation still requires the rfi, so that is moved out of
line to its own function.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 87 ++--
 1 file changed, 44 insertions(+), 43 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 2a17275296d5..95dd7ff3ef04 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -992,9 +992,9 @@ EXC_COMMON_BEGIN(machine_check_early_common)
bne 1f
/* First machine check entry */
ld  r1,PACAMCEMERGSP(r13)   /* Use MC emergency stack */
-1: subir1,r1,INT_FRAME_SIZE/* alloc stack frame */
-   /* Limit nested MCE to level 4 to avoid stack overflow */
-   bge cr1,2f  /* Check if we hit limit of 4 */
+1: /* Limit nested MCE to level 4 to avoid stack overflow */
+   bgt cr1,unrecoverable_mce   /* Check if we hit limit of 4 */
+   subir1,r1,INT_FRAME_SIZE/* alloc stack frame */
 
EXCEPTION_PROLOG_COMMON_1()
/* We don't touch AMR here, we never go to virtual mode */
@@ -1013,21 +1013,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
mtmsrd  r10,1
b   machine_check_handle_early
 
-2:
-   /* Stack overflow. Stay on emergency stack and panic.
-* Keep the ME bit off while panic-ing, so that if we hit
-* another machine check we checkstop.
-*/
-   addir1,r1,INT_FRAME_SIZE/* go back to previous stack frame */
-   ld  r11,PACAKMSR(r13)
-   LOAD_HANDLER(r12, unrecover_mce)
-   li  r10,MSR_ME
-   andcr11,r11,r10 /* Turn off MSR_ME */
-   mtspr   SPRN_SRR0,r12
-   mtspr   SPRN_SRR1,r11
-   RFI_TO_KERNEL
-   b   .   /* prevent speculative execution */
-
 EXC_COMMON_BEGIN(machine_check_common)
/*
 * Machine check is different because we use a different
@@ -1141,32 +1126,15 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
 * If yes, then stay on emergency stack and panic.
 */
andi.   r11,r12,MSR_RI
-   bne 2f
-1: mfspr   r11,SPRN_SRR0
-   LOAD_HANDLER(r10,unrecover_mce)
-   mtspr   SPRN_SRR0,r10
-   ld  r10,PACAKMSR(r13)
-   /*
-* We are going down. But there are chances that we might get hit by
-* another MCE during panic path and we may run into unstable state
-* with no way out. Hence, turn ME bit off while going down, so that
-* when another MCE is hit during panic path, system will checkstop
-* and hypervisor will get restarted cleanly by SP.
-*/
-   li  r3,MSR_ME
-   andcr10,r10,r3  /* Turn off MSR_ME */
-   mtspr   SPRN_SRR1,r10
-   RFI_TO_KERNEL
-   b   .
-2:
+   beq unrecoverable_mce
+
/*
 * Check if we have successfully handled/recovered from error, if not
 * then stay on emergency stack and panic.
 */
ld  r3,RESULT(r1)   /* Load result */
cmpdi   r3,0/* see if we handled MCE successfully */
-
-   beq 1b  /* if !handled then panic */
+   beq unrecoverable_mce /* if !handled then panic */
 
/*
 * Return from MC interrupt.
@@ -1189,17 +1157,35 @@ END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 1, 0x200, 1, 1, 0
EXCEPTION_PROLOG_2_REAL machine_check_common, EXC_STD, 0
 
-EXC_COMMON_BEGIN(unrecover_mce)
+EXC_COMMON_BEGIN(unrecoverable_mce)
+   /*
+* We are going down. But there are chances that we might get hit by
+* another MCE during panic path and we may run into unstable state
+* with no way out. Hence, turn ME bit off while going down, so that
+* when another MCE is hit during panic path, system will checkstop
+* and hypervisor will get restarted cleanly by SP.
+*/
+BEGIN_FTR_SECTION
+   li  r10,0 /* clear MSR_RI */
+   mtmsrd  r10,1
+   bl  disable_machine_check
+END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
+   ld  r10,PACAKMSR(r13)
+   li  r3,MSR_ME
+   andcr10,r10,r3
+   mtmsrd  r10
+
/* Invoke machine_check_exception to print MCE event and panic. */
addir3,r1,STACK_FRAME_OVERHEAD
bl  machine_check_exception
+
/*
-* We will not reach here. Even if we did, there is no way out. Call
-* unrecoverable_exception and die.
+* We will not reach here. Even if we did, there is no way out.
+* Call unrecoverable_exception and die.
 */
-1: addir3,r1,STACK_FRAME_OVERHEAD
+ 

[PATCH v2 13/16] powerpc/64s/exception: simplify machine check early path

2019-07-10 Thread Nicholas Piggin
machine_check_handle_early_common can reach machine_check_handle_early
directly now that it runs at the relocated address, so just branch
directly.

The rfi sequence is required to enable MSR[ME] but that step is moved
into a helper function, making the code easier to follow.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 31 
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 9bb8c89e9e77..2a17275296d5 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1006,16 +1006,13 @@ EXC_COMMON_BEGIN(machine_check_early_common)
std r3,_DAR(r1)
std r4,_DSISR(r1)
 
-   mfmsr   r11 /* get MSR value */
 BEGIN_FTR_SECTION
-   ori r11,r11,MSR_ME  /* turn on ME bit */
+   bl  enable_machine_check
 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
-   ori r11,r11,MSR_RI  /* turn on RI bit */
-   LOAD_HANDLER(r12, machine_check_handle_early)
-1: mtspr   SPRN_SRR0,r12
-   mtspr   SPRN_SRR1,r11
-   RFI_TO_KERNEL
-   b   .   /* prevent speculative execution */
+   li  r10,MSR_RI
+   mtmsrd  r10,1
+   b   machine_check_handle_early
+
 2:
/* Stack overflow. Stay on emergency stack and panic.
 * Keep the ME bit off while panic-ing, so that if we hit
@@ -1026,7 +1023,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
LOAD_HANDLER(r12, unrecover_mce)
li  r10,MSR_ME
andcr11,r11,r10 /* Turn off MSR_ME */
-   b   1b
+   mtspr   SPRN_SRR0,r12
+   mtspr   SPRN_SRR1,r11
+   RFI_TO_KERNEL
b   .   /* prevent speculative execution */
 
 EXC_COMMON_BEGIN(machine_check_common)
@@ -2270,6 +2269,20 @@ CLOSE_FIXED_SECTION(virt_trampolines);
 
 USE_TEXT_SECTION()
 
+/* MSR[RI] should be clear because this uses SRR[01] */
+enable_machine_check:
+   mflrr0
+   bcl 20,31,$+4
+0: mflrr3
+   addir3,r3,(1f - 0b)
+   mtspr   SPRN_SRR0,r3
+   mfmsr   r3
+   ori r3,r3,MSR_ME
+   mtspr   SPRN_SRR1,r3
+   RFI_TO_KERNEL
+1: mtlrr0
+   blr
+
 /*
  * Hash table stuff
  */
-- 
2.20.1



[PATCH v2 12/16] powerpc/64s/exception: machine check move tramp code

2019-07-10 Thread Nicholas Piggin
Following convention, move the tramp code (unrelocated) above the
common handlers (relocated).

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 3cc5ee6e4b56..9bb8c89e9e77 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -945,6 +945,17 @@ EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
 EXC_REAL_END(machine_check, 0x200, 0x100)
 EXC_VIRT_NONE(0x4200, 0x100)
 
+#ifdef CONFIG_PPC_PSERIES
+TRAMP_REAL_BEGIN(machine_check_fwnmi)
+   /* See comment at machine_check exception, don't turn on RI */
+   EXCEPTION_PROLOG_0 PACA_EXMC
+   EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 0, 0x200, 1, 1, 0
+   mfctr   r10 /* save ctr */
+   BRANCH_TO_C000(r11, machine_check_early_common)
+#endif
+
+TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
+
 EXC_COMMON_BEGIN(machine_check_early_common)
mtctr   r10 /* Restore ctr */
mfspr   r11,SPRN_SRR0
@@ -1018,17 +1029,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
b   1b
b   .   /* prevent speculative execution */
 
-#ifdef CONFIG_PPC_PSERIES
-TRAMP_REAL_BEGIN(machine_check_fwnmi)
-   /* See comment at machine_check exception, don't turn on RI */
-   EXCEPTION_PROLOG_0 PACA_EXMC
-   EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 0, 0x200, 1, 1, 0
-   mfctr   r10 /* save ctr */
-   BRANCH_TO_C000(r11, machine_check_early_common)
-#endif
-
-TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
-
 EXC_COMMON_BEGIN(machine_check_common)
/*
 * Machine check is different because we use a different
-- 
2.20.1



[PATCH v2 11/16] powerpc/64s/exception: machine check restructure to reuse common macros

2019-07-10 Thread Nicholas Piggin
Follow the pattern of sreset and HMI handlers more closely: use
EXCEPTION_PROLOG_COMMON_1 rather than open-coding it, and run the
handler at the relocated location.

This helps later simplification and code sharing.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 71 ++--
 1 file changed, 36 insertions(+), 35 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index ac7b5bb614d9..3cc5ee6e4b56 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -934,17 +934,23 @@ EXC_COMMON_BEGIN(system_reset_common)
 
 EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
EXCEPTION_PROLOG_0 PACA_EXMC
-   b   machine_check_common_early
+   EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 0, 0x200, 1, 1, 0
+   mfctr   r10 /* save ctr, even for !RELOCATABLE */
+   BRANCH_TO_C000(r11, machine_check_early_common)
+   /*
+* MSR_RI is not enabled, because PACA_EXMC is being used, so a
+* nested machine check corrupts it. machine_check_common enables
+* MSR_RI.
+*/
 EXC_REAL_END(machine_check, 0x200, 0x100)
 EXC_VIRT_NONE(0x4200, 0x100)
-TRAMP_REAL_BEGIN(machine_check_common_early)
-   EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 0, 0x200, 0, 0, 0
+
+EXC_COMMON_BEGIN(machine_check_early_common)
+   mtctr   r10 /* Restore ctr */
+   mfspr   r11,SPRN_SRR0
+   mfspr   r12,SPRN_SRR1
+
/*
-* Register contents:
-* R13  = PACA
-* R9   = CR
-* Original R9 to R13 is saved on PACA_EXMC
-*
 * Switch to mc_emergency stack and handle re-entrancy (we limit
 * the nested MCE upto level 4 to avoid stack overflow).
 * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
@@ -965,32 +971,30 @@ TRAMP_REAL_BEGIN(machine_check_common_early)
 * the machine check is handled then the idle wakeup code is called
 * to restore state.
 */
-   mr  r11,r1  /* Save r1 */
lhz r10,PACA_IN_MCE(r13)
cmpwi   r10,0   /* Are we in nested machine check */
-   bne 0f  /* Yes, we are. */
-   /* First machine check entry */
-   ld  r1,PACAMCEMERGSP(r13)   /* Use MC emergency stack */
-0: subir1,r1,INT_FRAME_SIZE/* alloc stack frame */
+   cmpwi   cr1,r10,MAX_MCE_DEPTH   /* Are we at maximum nesting */
addir10,r10,1   /* increment paca->in_mce */
sth r10,PACA_IN_MCE(r13)
+
+   mr  r10,r1  /* Save r1 */
+   bne 1f
+   /* First machine check entry */
+   ld  r1,PACAMCEMERGSP(r13)   /* Use MC emergency stack */
+1: subir1,r1,INT_FRAME_SIZE/* alloc stack frame */
/* Limit nested MCE to level 4 to avoid stack overflow */
-   cmpwi   r10,MAX_MCE_DEPTH
-   bgt 2f  /* Check if we hit limit of 4 */
-   std r11,GPR1(r1)/* Save r1 on the stack. */
-   std r11,0(r1)   /* make stack chain pointer */
-   mfspr   r11,SPRN_SRR0   /* Save SRR0 */
-   std r11,_NIP(r1)
-   mfspr   r11,SPRN_SRR1   /* Save SRR1 */
-   std r11,_MSR(r1)
-   mfspr   r11,SPRN_DAR/* Save DAR */
-   std r11,_DAR(r1)
-   mfspr   r11,SPRN_DSISR  /* Save DSISR */
-   std r11,_DSISR(r1)
-   std r9,_CCR(r1) /* Save CR in stackframe */
+   bge cr1,2f  /* Check if we hit limit of 4 */
+
+   EXCEPTION_PROLOG_COMMON_1()
/* We don't touch AMR here, we never go to virtual mode */
-   /* Save r9 through r13 from EXMC save area to stack frame. */
EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
+   EXCEPTION_PROLOG_COMMON_3(0x200)
+
+   ld  r3,PACA_EXMC+EX_DAR(r13)
+   lwz r4,PACA_EXMC+EX_DSISR(r13)
+   std r3,_DAR(r1)
+   std r4,_DSISR(r1)
+
mfmsr   r11 /* get MSR value */
 BEGIN_FTR_SECTION
ori r11,r11,MSR_ME  /* turn on ME bit */
@@ -1016,8 +1020,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
 
 #ifdef CONFIG_PPC_PSERIES
 TRAMP_REAL_BEGIN(machine_check_fwnmi)
+   /* See comment at machine_check exception, don't turn on RI */
EXCEPTION_PROLOG_0 PACA_EXMC
-   b   machine_check_common_early
+   EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 0, 0x200, 1, 1, 0
+   mfctr   r10 /* save ctr */
+   BRANCH_TO_C000(r11, machine_check_early_common)
 #endif
 
 TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
@@ -1088,8 +1095,6 @@ EXC_COMMON_BEGIN(machine_check_idle_common)
 * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
 */
 EXC_COMMON_BEGIN(machine_check_handle_early)
-   std r0,GPR0(r1) /* Save r0 */
-   EXCEPTION_P

[PATCH v2 10/16] powerpc/64s/exception: machine check pseries should skip the late handler for host kernel MCEs

2019-07-10 Thread Nicholas Piggin
The powernv machine check handler copes with taking a MCE from one of
three contexts, guest, host kernel, and host user. In each case the
early handler runs first on a special stack. Then:

- The guest case branches to the KVM interrupt handler (via standard
  interrupt macros).
- The host user case will run the "late" handler which is like a
  normal interrupt that runs in virtual mode and uses the regular
  kernel stack.
- The host kernel case queues the event and schedules it for
  processing with irq work.

The last case is important, it must not enable virtual memory because
the MMU state may not be set up to deal with that (e.g., SLB might be
clear), it must not use the regular kernel stack for similar reasons
(e.g., might be in OPAL with OPAL stack in r1), and the kernel does
not expect anything to touch its stack if interrupts are disabled.

The pseries handler does not do this queueing, but instead it always
runs the late handler for host MCEs, which has some of the same
problems.

Now that pseries is using machine_check_events, it can just do the
same as powernv and queue up kernel-mode MCE events.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 22 ++
 1 file changed, 2 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index f2c24a4ae723..ac7b5bb614d9 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1163,7 +1163,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
cmpdi   r3,0/* see if we handled MCE successfully */
 
beq 1b  /* if !handled then panic */
-BEGIN_FTR_SECTION
+
/*
 * Return from MC interrupt.
 * Queue up the MCE event so that we can log it later, while
@@ -1172,18 +1172,7 @@ BEGIN_FTR_SECTION
bl  machine_check_queue_event
MACHINE_CHECK_HANDLER_WINDUP
RFI_TO_KERNEL
-FTR_SECTION_ELSE
-   /*
-* pSeries: Return from MC interrupt. Before that stay on emergency
-* stack and call machine_check_exception to log the MCE event.
-*/
-   LOAD_HANDLER(r10,mce_return)
-   mtspr   SPRN_SRR0,r10
-   ld  r10,PACAKMSR(r13)
-   mtspr   SPRN_SRR1,r10
-   RFI_TO_KERNEL
-   b   .
-ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
+
 9:
/* Deliver the machine check to host kernel in V mode. */
 BEGIN_FTR_SECTION
@@ -1212,13 +1201,6 @@ EXC_COMMON_BEGIN(unrecover_mce)
bl  unrecoverable_exception
b   1b
 
-EXC_COMMON_BEGIN(mce_return)
-   /* Invoke machine_check_exception to print MCE event and return. */
-   addir3,r1,STACK_FRAME_OVERHEAD
-   bl  machine_check_exception
-   MACHINE_CHECK_HANDLER_WINDUP
-   RFI_TO_KERNEL
-   b   .
 
 EXC_REAL_BEGIN(data_access, 0x300, 0x80)
EXCEPTION_PROLOG_0 PACA_EXGEN
-- 
2.20.1



[PATCH v2 09/16] powerpc/64s/pseries: machine check convert to use common event code

2019-07-10 Thread Nicholas Piggin
The common machine_check_event data structures and queues are mostly
platform independent, with powernv decoding SRR1/DSISR/etc., into
machine_check_event objects.

This patch converts pseries to use this infrastructure by decoding
fwnmi/rtas data into machine_check_event objects.

This allows queueing to be used by a subsequent change to delay the
virtual mode handling of machine checks that occur in kernel space
where it is unsafe to switch immediately to virtual mode, similarly
to powernv.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/mce.h   |   6 +
 arch/powerpc/kernel/mce.c|  34 +-
 arch/powerpc/platforms/pseries/ras.c | 457 +++
 3 files changed, 230 insertions(+), 267 deletions(-)

diff --git a/arch/powerpc/include/asm/mce.h b/arch/powerpc/include/asm/mce.h
index a4c6a74ad2fb..6f56b2d350b2 100644
--- a/arch/powerpc/include/asm/mce.h
+++ b/arch/powerpc/include/asm/mce.h
@@ -30,6 +30,10 @@ enum MCE_Disposition {
 enum MCE_Initiator {
MCE_INITIATOR_UNKNOWN = 0,
MCE_INITIATOR_CPU = 1,
+   MCE_INITIATOR_PCI = 2,
+   MCE_INITIATOR_ISA = 3,
+   MCE_INITIATOR_MEMORY= 4,
+   MCE_INITIATOR_POWERMGM = 5,
 };
 
 enum MCE_ErrorType {
@@ -41,6 +45,8 @@ enum MCE_ErrorType {
MCE_ERROR_TYPE_USER = 5,
MCE_ERROR_TYPE_RA = 6,
MCE_ERROR_TYPE_LINK = 7,
+   MCE_ERROR_TYPE_DCACHE = 8,
+   MCE_ERROR_TYPE_ICACHE = 9,
 };
 
 enum MCE_ErrorClass {
diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
index 38b560f92d12..5b4f766a68e9 100644
--- a/arch/powerpc/kernel/mce.c
+++ b/arch/powerpc/kernel/mce.c
@@ -300,7 +300,7 @@ static void machine_check_process_queued_event(struct 
irq_work *work)
 void machine_check_print_event_info(struct machine_check_event *evt,
bool user_mode, bool in_guest)
 {
-   const char *level, *sevstr, *subtype, *err_type;
+   const char *level, *sevstr, *subtype, *err_type, *initiator;
uint64_t ea = 0, pa = 0;
int n = 0;
char dar_str[50];
@@ -385,6 +385,28 @@ void machine_check_print_event_info(struct 
machine_check_event *evt,
break;
}
 
+   switch(evt->initiator) {
+   case MCE_INITIATOR_CPU:
+   initiator = "CPU";
+   break;
+   case MCE_INITIATOR_PCI:
+   initiator = "PCI";
+   break;
+   case MCE_INITIATOR_ISA:
+   initiator = "ISA";
+   break;
+   case MCE_INITIATOR_MEMORY:
+   initiator = "Memory";
+   break;
+   case MCE_INITIATOR_POWERMGM:
+   initiator = "Power Management";
+   break;
+   case MCE_INITIATOR_UNKNOWN:
+   default:
+   initiator = "Unknown";
+   break;
+   }
+
switch (evt->error_type) {
case MCE_ERROR_TYPE_UE:
err_type = "UE";
@@ -451,6 +473,14 @@ void machine_check_print_event_info(struct 
machine_check_event *evt,
if (evt->u.link_error.effective_address_provided)
ea = evt->u.link_error.effective_address;
break;
+   case MCE_ERROR_TYPE_DCACHE:
+   err_type = "D-Cache";
+   subtype = "Unknown";
+   break;
+   case MCE_ERROR_TYPE_ICACHE:
+   err_type = "I-Cache";
+   subtype = "Unknown";
+   break;
default:
case MCE_ERROR_TYPE_UNKNOWN:
err_type = "Unknown";
@@ -483,6 +513,8 @@ void machine_check_print_event_info(struct 
machine_check_event *evt,
level, evt->cpu, evt->srr0, (void *)evt->srr0, pa_str);
}
 
+   printk("%sMCE: CPU%d: Initiator %s\n", level, evt->cpu, initiator);
+
subtype = evt->error_class < ARRAY_SIZE(mc_error_class) ?
mc_error_class[evt->error_class] : "Unknown";
printk("%sMCE: CPU%d: %s\n", level, evt->cpu, subtype);
diff --git a/arch/powerpc/platforms/pseries/ras.c 
b/arch/powerpc/platforms/pseries/ras.c
index f16fdd0f71f7..e03c3389692e 100644
--- a/arch/powerpc/platforms/pseries/ras.c
+++ b/arch/powerpc/platforms/pseries/ras.c
@@ -76,6 +76,7 @@ struct pseries_mc_errorlog {
 #define MC_ERROR_TYPE_UE   0x00
 #define MC_ERROR_TYPE_SLB  0x01
 #define MC_ERROR_TYPE_ERAT 0x02
+#define MC_ERROR_TYPE_UNKNOWN  0x03
 #define MC_ERROR_TYPE_TLB  0x04
 #define MC_ERROR_TYPE_D_CACHE  0x05
 #define MC_ERROR_TYPE_I_CACHE  0x07
@@ -87,6 +88,9 @@ struct pseries_mc_errorlog {
 #define MC_ERROR_UE_LOAD_STORE 3
 #define MC_ERROR_UE_PAGE_TABLE_WALK_LOAD_STORE 4
 
+#define UE_EFFECTIVE_ADDR_PROVIDED 0x40
+#define UE_LOGICAL_ADDR_PROVIDED   0x20
+
 #define MC_ERROR_SLB_PARITY0
 #define MC_ERROR_SLB_MULTIHIT  1
 #define MC_ERROR_SLB_INDETERMINATE 2
@@ -113,27 +117,6 @@ static inline u8 rtas_m

[PATCH v2 08/16] powerpc/64s/powernv: machine check dump SLB contents

2019-07-10 Thread Nicholas Piggin
Re-use the code introduced in pseries to save and dump the contents
of the SLB in the case of an SLB involved machine check exception.

This patch also avoids allocating the SLB save array on pseries radix.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/mce.c  |  6 ++
 arch/powerpc/kernel/mce_power.c|  4 
 arch/powerpc/platforms/powernv/setup.c |  9 +
 arch/powerpc/platforms/pseries/setup.c | 24 +---
 4 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
index b18df633eae9..38b560f92d12 100644
--- a/arch/powerpc/kernel/mce.c
+++ b/arch/powerpc/kernel/mce.c
@@ -486,6 +486,12 @@ void machine_check_print_event_info(struct 
machine_check_event *evt,
subtype = evt->error_class < ARRAY_SIZE(mc_error_class) ?
mc_error_class[evt->error_class] : "Unknown";
printk("%sMCE: CPU%d: %s\n", level, evt->cpu, subtype);
+
+#ifdef CONFIG_PPC_BOOK3S_64
+   /* Display faulty slb contents for SLB errors. */
+   if (evt->error_type == MCE_ERROR_TYPE_SLB)
+   slb_dump_contents(local_paca->mce_faulty_slbs);
+#endif
 }
 EXPORT_SYMBOL_GPL(machine_check_print_event_info);
 
diff --git a/arch/powerpc/kernel/mce_power.c b/arch/powerpc/kernel/mce_power.c
index e39536aad30d..c4d0e0c6e7d3 100644
--- a/arch/powerpc/kernel/mce_power.c
+++ b/arch/powerpc/kernel/mce_power.c
@@ -398,6 +398,8 @@ static int mce_handle_ierror(struct pt_regs *regs,
/* attempt to correct the error */
switch (table[i].error_type) {
case MCE_ERROR_TYPE_SLB:
+   if (local_paca->in_mce == 1)
+   slb_save_contents(local_paca->mce_faulty_slbs);
handled = mce_flush(MCE_FLUSH_SLB);
break;
case MCE_ERROR_TYPE_ERAT:
@@ -483,6 +485,8 @@ static int mce_handle_derror(struct pt_regs *regs,
/* attempt to correct the error */
switch (table[i].error_type) {
case MCE_ERROR_TYPE_SLB:
+   if (local_paca->in_mce == 1)
+   slb_save_contents(local_paca->mce_faulty_slbs);
if (mce_flush(MCE_FLUSH_SLB))
handled = 1;
break;
diff --git a/arch/powerpc/platforms/powernv/setup.c 
b/arch/powerpc/platforms/powernv/setup.c
index a5e52f9eed3c..83498604d322 100644
--- a/arch/powerpc/platforms/powernv/setup.c
+++ b/arch/powerpc/platforms/powernv/setup.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -166,6 +167,14 @@ static void __init pnv_init(void)
else
 #endif
add_preferred_console("hvc", 0, NULL);
+
+   if (!radix_enabled()) {
+   int i;
+
+   /* Allocate per cpu area to save old slb contents during MCE */
+   for_each_possible_cpu(i)
+   paca_ptrs[i]->mce_faulty_slbs = 
memblock_alloc_node(mmu_slb_size, __alignof__(*paca_ptrs[i]->mce_faulty_slbs), 
cpu_to_node(i));
+   }
 }
 
 static void __init pnv_init_IRQ(void)
diff --git a/arch/powerpc/platforms/pseries/setup.c 
b/arch/powerpc/platforms/pseries/setup.c
index ab38a6c8dffb..637d59f4c5ce 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -139,17 +139,19 @@ static void __init fwnmi_init(void)
}
 
 #ifdef CONFIG_PPC_BOOK3S_64
-   /* Allocate per cpu slb area to save old slb contents during MCE */
-   size = sizeof(struct slb_entry) * mmu_slb_size * nr_cpus;
-   slb_ptr = memblock_alloc_try_nid_raw(size, sizeof(struct slb_entry),
-   MEMBLOCK_LOW_LIMIT, ppc64_rma_size,
-   NUMA_NO_NODE);
-   if (!slb_ptr)
-   panic("Failed to allocate %zu bytes below %pa for slb area\n",
- size, &ppc64_rma_size);
-
-   for_each_possible_cpu(i)
-   paca_ptrs[i]->mce_faulty_slbs = slb_ptr + (mmu_slb_size * i);
+   if (!radix_enabled()) {
+   /* Allocate per cpu area to save old slb contents during MCE */
+   size = sizeof(struct slb_entry) * mmu_slb_size * nr_cpus;
+   slb_ptr = memblock_alloc_try_nid_raw(size,
+   sizeof(struct slb_entry), MEMBLOCK_LOW_LIMIT,
+   ppc64_rma_size, NUMA_NO_NODE);
+   if (!slb_ptr)
+   panic("Failed to allocate %zu bytes below %pa for slb 
area\n",
+ size, &ppc64_rma_size);
+
+   for_each_possible_cpu(i)
+   paca_ptrs[i]->mce_faulty_slbs = slb_ptr + (mmu_slb_size 
* i);
+   }
 #endif
 }
 
-- 
2.20.1



[PATCH v2 07/16] powerpc/64s/exception: machine check use correct cfar for late handler

2019-07-10 Thread Nicholas Piggin
Bare metal machine checks run an "early" handler in real mode before
running the main handler which reports the event.

The main handler runs exactly as a normal interrupt handler, after the
"windup" which sets registers back as they were at interrupt entry.
CFAR does not get restored by the windup code, so that will be wrong
when the handler is run.

Restore the CFAR to the saved value before running the late handler.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 54ca2b189d43..f2c24a4ae723 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1186,6 +1186,10 @@ FTR_SECTION_ELSE
 ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
 9:
/* Deliver the machine check to host kernel in V mode. */
+BEGIN_FTR_SECTION
+   ld  r10,ORIG_GPR3(r1)
+   mtspr   SPRN_CFAR,r10
+END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
MACHINE_CHECK_HANDLER_WINDUP
EXCEPTION_PROLOG_0 PACA_EXMC
EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 1, 0x200, 1, 1, 0
-- 
2.20.1



[PATCH v2 06/16] powerpc/64s/exception: machine check remove machine_check_pSeries_0 branch

2019-07-10 Thread Nicholas Piggin
This label has only one caller, so unwind the branch and move it
inline. The location of the comment is adjusted to match similar
one in system reset.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 23 ++-
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index a69ceb28cf4c..54ca2b189d43 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1014,20 +1014,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
b   1b
b   .   /* prevent speculative execution */
 
-TRAMP_REAL_BEGIN(machine_check_pSeries)
-   .globl machine_check_fwnmi
-machine_check_fwnmi:
+#ifdef CONFIG_PPC_PSERIES
+TRAMP_REAL_BEGIN(machine_check_fwnmi)
EXCEPTION_PROLOG_0 PACA_EXMC
b   machine_check_common_early
-
-machine_check_pSeries_0:
-   EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 1, 0x200, 1, 1, 0
-   /*
-* MSR_RI is not enabled, because PACA_EXMC is being used, so a
-* nested machine check corrupts it. machine_check_common enables
-* MSR_RI.
-*/
-   EXCEPTION_PROLOG_2_REAL machine_check_common, EXC_STD, 0
+#endif
 
 TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
 
@@ -1197,7 +1188,13 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
/* Deliver the machine check to host kernel in V mode. */
MACHINE_CHECK_HANDLER_WINDUP
EXCEPTION_PROLOG_0 PACA_EXMC
-   b   machine_check_pSeries_0
+   EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 1, 0x200, 1, 1, 0
+   EXCEPTION_PROLOG_2_REAL machine_check_common, EXC_STD, 0
+   /*
+* MSR_RI is not enabled, because PACA_EXMC is being used, so a
+* nested machine check corrupts it. machine_check_common enables
+* MSR_RI.
+*/
 
 EXC_COMMON_BEGIN(unrecover_mce)
/* Invoke machine_check_exception to print MCE event and panic. */
-- 
2.20.1



[PATCH v2 05/16] powerpc/64s/exception: machine check pseries should always run the early handler

2019-07-10 Thread Nicholas Piggin
Now that pseries with fwnmi registered runs the early machine check
handler, there is no good reason to special case the non-fwnmi case
and skip the early handler. Reducing the code and number of paths is
a top priority for asm code, it's better to handle this in C where
possible (and the pseries early handler is a no-op if fwnmi is not
registered).

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 4 
 1 file changed, 4 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 0186a44bb981..a69ceb28cf4c 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -934,11 +934,7 @@ EXC_COMMON_BEGIN(system_reset_common)
 
 EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
EXCEPTION_PROLOG_0 PACA_EXMC
-BEGIN_FTR_SECTION
b   machine_check_common_early
-FTR_SECTION_ELSE
-   b   machine_check_pSeries_0
-ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
 EXC_REAL_END(machine_check, 0x200, 0x100)
 EXC_VIRT_NONE(0x4200, 0x100)
 TRAMP_REAL_BEGIN(machine_check_common_early)
-- 
2.20.1



[PATCH v2 04/16] powerpc/64s/exception: machine check adjust RFI target

2019-07-10 Thread Nicholas Piggin
The host kernel delivery case for powernv does RFI_TO_USER_OR_KERNEL,
but should just use RFI_TO_KERNEL which makes it clear this is not a
user case.

This is not a bug because RFI_TO_USER_OR_KERNEL deals with kernel
returns just fine.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 5789a00691f9..0186a44bb981 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1184,7 +1184,7 @@ BEGIN_FTR_SECTION
 */
bl  machine_check_queue_event
MACHINE_CHECK_HANDLER_WINDUP
-   RFI_TO_USER_OR_KERNEL
+   RFI_TO_KERNEL
 FTR_SECTION_ELSE
/*
 * pSeries: Return from MC interrupt. Before that stay on emergency
-- 
2.20.1



[PATCH v2 03/16] powerpc/64s/exception: machine check fix KVM guest test

2019-07-10 Thread Nicholas Piggin
The machine_check_handle_early hypervisor guest test is skipped if
!HVMODE or MSR[HV]=0, which is wrong for PR or nested hypervisors
that could be running a guest in this state.

Test HSTATE_IN_GUEST up front and use that to branch out to the KVM
handler, then MSR[PR] alone can test for this kernel's userspace.
This matches all other interrupt handling.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 33 +++-
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index e8734a1dfdb9..5789a00691f9 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1108,11 +1108,8 @@ EXC_COMMON_BEGIN(machine_check_handle_early)
bl  machine_check_early
std r3,RESULT(r1)   /* Save result */
ld  r12,_MSR(r1)
-BEGIN_FTR_SECTION
-   b   4f
-END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)
 
-#ifdef CONFIG_PPC_P7_NAP
+#ifdef CONFIG_PPC_P7_NAP
/*
 * Check if thread was in power saving mode. We come here when any
 * of the following is true:
@@ -1128,30 +1125,26 @@ BEGIN_FTR_SECTION
 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
 #endif
 
-   /*
-* Check if we are coming from hypervisor userspace. If yes then we
-* continue in host kernel in V mode to deliver the MC event.
-*/
-   rldicl. r11,r12,4,63/* See if MC hit while in HV mode. */
-   beq 5f
-4: andi.   r11,r12,MSR_PR  /* See if coming from user. */
-   bne 9f  /* continue in V mode if we are. */
-
-5:
 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
-BEGIN_FTR_SECTION
/*
-* We are coming from kernel context. Check if we are coming from
-* guest. if yes, then we can continue. We will fall through
-* do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
+* Check if we are coming from guest. If yes, then run the normal
+* exception handler which will take the do_kvm_200->kvmppc_interrupt
+* branch to deliver the MC event to guest.
 */
lbz r11,HSTATE_IN_GUEST(r13)
cmpwi   r11,0   /* Check if coming from guest */
bne 9f  /* continue if we are. */
-END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
 #endif
+
+   /*
+* Check if we are coming from userspace. If yes, then run the normal
+* exception handler which will deliver the MC event to this kernel.
+*/
+   andi.   r11,r12,MSR_PR  /* See if coming from user. */
+   bne 9f  /* continue in V mode if we are. */
+
/*
-* At this point we are not sure about what context we come from.
+* At this point we are coming from kernel context.
 * Queue up the MCE event and return from the interrupt.
 * But before that, check if this is an un-recoverable exception.
 * If yes, then stay on emergency stack and panic.
-- 
2.20.1



[PATCH v2 02/16] powerpc/64s/exception: machine check remove bitrotted comment

2019-07-10 Thread Nicholas Piggin
Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 4 
 1 file changed, 4 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index db7ef8c8566f..e8734a1dfdb9 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -933,10 +933,6 @@ EXC_COMMON_BEGIN(system_reset_common)
 
 
 EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
-   /* This is moved out of line as it can be patched by FW, but
-* some code path might still want to branch into the original
-* vector
-*/
EXCEPTION_PROLOG_0 PACA_EXMC
 BEGIN_FTR_SECTION
b   machine_check_common_early
-- 
2.20.1



[PATCH v2 01/16] powerpc/64s/exception: machine check fwnmi remove HV case

2019-07-10 Thread Nicholas Piggin
fwnmi does not trigger in HV mode, so remove always-true feature test.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 53c1b0a2ebce..db7ef8c8566f 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1026,9 +1026,8 @@ TRAMP_REAL_BEGIN(machine_check_pSeries)
.globl machine_check_fwnmi
 machine_check_fwnmi:
EXCEPTION_PROLOG_0 PACA_EXMC
-BEGIN_FTR_SECTION
b   machine_check_common_early
-END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)
+
 machine_check_pSeries_0:
EXCEPTION_PROLOG_1 EXC_STD, PACA_EXMC, 1, 0x200, 1, 1, 0
/*
-- 
2.20.1



[PATCH v2 00/16] powerpc/64s: machine check cleanup series

2019-07-10 Thread Nicholas Piggin
This series is mostly unchanged from last time, except that it
adjusts the pseries machine check handler to use machine check events
for queueing, which fixes some corner cases and allows the interrupt
code to be consolidated nicely.

Thanks,
Nick

Nicholas Piggin (16):
  powerpc/64s/exception: machine check fwnmi remove HV case
  powerpc/64s/exception: machine check remove bitrotted comment
  powerpc/64s/exception: machine check fix KVM guest test
  powerpc/64s/exception: machine check adjust RFI target
  powerpc/64s/exception: machine check pseries should always run the
early handler
  powerpc/64s/exception: machine check remove machine_check_pSeries_0
branch
  powerpc/64s/exception: machine check use correct cfar for late handler
  powerpc/64s/powernv: machine check dump SLB contents
  powerpc/64s/pseries: machine check convert to use common event code
  powerpc/64s/exception: machine check pseries should skip the late
handler for host kernel MCEs
  powerpc/64s/exception: machine check restructure to reuse common
macros
  powerpc/64s/exception: machine check move tramp code
  powerpc/64s/exception: simplify machine check early path
  powerpc/64s/exception: machine check move unrecoverable handling out
of line
  powerpc/64s/exception: untangle early machine check handler branch
  powerpc/64s/exception: machine check improve labels and comments

 arch/powerpc/include/asm/mce.h |   6 +
 arch/powerpc/kernel/exceptions-64s.S   | 371 ++--
 arch/powerpc/kernel/mce.c  |  40 ++-
 arch/powerpc/kernel/mce_power.c|   4 +
 arch/powerpc/platforms/powernv/setup.c |   9 +
 arch/powerpc/platforms/pseries/ras.c   | 457 +++--
 arch/powerpc/platforms/pseries/setup.c |  24 +-
 7 files changed, 439 insertions(+), 472 deletions(-)

-- 
2.20.1



Re: Coccinelle: Checking of_node_put() calls with SmPL

2019-07-10 Thread Markus Elfring
> we developed a coccinelle script to detect such problems.

Would you find the implementation of the function “dt_init_idle_driver”
suspicious according to discussed source code search patterns?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/cpuidle/dt_idle_states.c?id=e9a83bd2322035ed9d7dcf35753d3f984d76c6a5#n208
https://elixir.bootlin.com/linux/v5.2/source/drivers/cpuidle/dt_idle_states.c#L208


> This script is still being improved.

Will corresponding software development challenges become more interesting?

Regards,
Markus


Re: [PATCH v3 5/7] kexec_elf: remove elf_addr_to_cpu macro

2019-07-10 Thread Christophe Leroy




Le 10/07/2019 à 16:29, Sven Schnelle a écrit :

It had only one definition, so just use the function directly.


It had only one definition because it was for ppc64 only.
But as far as I understand (at least from the name of the new file), you 
want it to be generic, don't you ? Therefore I get on 32 bits it would 
be elf32_to_cpu().


Christophe



Signed-off-by: Sven Schnelle 
---
  kernel/kexec_elf.c | 20 +---
  1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
index 70d31b8feeae..99e6d63b5dfc 100644
--- a/kernel/kexec_elf.c
+++ b/kernel/kexec_elf.c
@@ -8,8 +8,6 @@
  #include 
  #include 
  
-#define elf_addr_to_cpu	elf64_to_cpu

-
  #ifndef Elf_Rel
  #define Elf_Rel   Elf64_Rel
  #endif /* Elf_Rel */
@@ -143,9 +141,9 @@ static int elf_read_ehdr(const char *buf, size_t len, 
struct elfhdr *ehdr)
ehdr->e_type  = elf16_to_cpu(ehdr, buf_ehdr->e_type);
ehdr->e_machine   = elf16_to_cpu(ehdr, buf_ehdr->e_machine);
ehdr->e_version   = elf32_to_cpu(ehdr, buf_ehdr->e_version);
-   ehdr->e_entry = elf_addr_to_cpu(ehdr, buf_ehdr->e_entry);
-   ehdr->e_phoff = elf_addr_to_cpu(ehdr, buf_ehdr->e_phoff);
-   ehdr->e_shoff = elf_addr_to_cpu(ehdr, buf_ehdr->e_shoff);
+   ehdr->e_entry = elf64_to_cpu(ehdr, buf_ehdr->e_entry);
+   ehdr->e_phoff = elf64_to_cpu(ehdr, buf_ehdr->e_phoff);
+   ehdr->e_shoff = elf64_to_cpu(ehdr, buf_ehdr->e_shoff);
ehdr->e_flags = elf32_to_cpu(ehdr, buf_ehdr->e_flags);
ehdr->e_phentsize = elf16_to_cpu(ehdr, buf_ehdr->e_phentsize);
ehdr->e_phnum = elf16_to_cpu(ehdr, buf_ehdr->e_phnum);
@@ -190,18 +188,18 @@ static int elf_read_phdr(const char *buf, size_t len,
buf_phdr = (struct elf_phdr *) pbuf;
  
  	phdr->p_type   = elf32_to_cpu(elf_info->ehdr, buf_phdr->p_type);

-   phdr->p_offset = elf_addr_to_cpu(elf_info->ehdr, buf_phdr->p_offset);
-   phdr->p_paddr  = elf_addr_to_cpu(elf_info->ehdr, buf_phdr->p_paddr);
-   phdr->p_vaddr  = elf_addr_to_cpu(elf_info->ehdr, buf_phdr->p_vaddr);
+   phdr->p_offset = elf64_to_cpu(elf_info->ehdr, buf_phdr->p_offset);
+   phdr->p_paddr  = elf64_to_cpu(elf_info->ehdr, buf_phdr->p_paddr);
+   phdr->p_vaddr  = elf64_to_cpu(elf_info->ehdr, buf_phdr->p_vaddr);
phdr->p_flags  = elf32_to_cpu(elf_info->ehdr, buf_phdr->p_flags);
  
  	/*

 * The following fields have a type equivalent to Elf_Addr
 * both in 32 bit and 64 bit ELF.
 */
-   phdr->p_filesz = elf_addr_to_cpu(elf_info->ehdr, buf_phdr->p_filesz);
-   phdr->p_memsz  = elf_addr_to_cpu(elf_info->ehdr, buf_phdr->p_memsz);
-   phdr->p_align  = elf_addr_to_cpu(elf_info->ehdr, buf_phdr->p_align);
+   phdr->p_filesz = elf64_to_cpu(elf_info->ehdr, buf_phdr->p_filesz);
+   phdr->p_memsz  = elf64_to_cpu(elf_info->ehdr, buf_phdr->p_memsz);
+   phdr->p_align  = elf64_to_cpu(elf_info->ehdr, buf_phdr->p_align);
  
  	return elf_is_phdr_sane(phdr, len) ? 0 : -ENOEXEC;

  }



Re: [PATCH] powerpc/irq: Don't WARN continuously in arch_local_irq_restore()

2019-07-10 Thread Michael Ellerman
On Mon, 2019-07-08 at 06:10:46 UTC, Michael Ellerman wrote:
> When CONFIG_PPC_IRQ_SOFT_MASK_DEBUG is enabled (uncommon), we have a
> series of WARN_ON's in arch_local_irq_restore().
> 
> These are "should never happen" conditions, but if they do happen they
> can flood the console and render the system unusable. So switch them
> to WARN_ON_ONCE().
> 
> Fixes: e2b36d591720 ("powerpc/64: Don't trace code that runs with the soft 
> irq mask unreconciled")
> Fixes: 9b81c0211c24 ("powerpc/64s: make PACA_IRQ_HARD_DIS track MSR[EE] 
> closely")
> Fixes: 7c0482e3d055 ("powerpc/irq: Fix another case of lazy IRQ state getting 
> out of sync")
> Signed-off-by: Michael Ellerman 

Applied to powerpc next.

https://git.kernel.org/powerpc/c/0fc12c022ad25532b66bf6f6c818ee1c1d63e702

cheers


[PATCH] powerpc/eeh: Handle hugepages in ioremap space

2019-07-10 Thread Oliver O'Halloran
In commit 4a7b06c157a2 ("powerpc/eeh: Handle hugepages in ioremap
space") support for using hugepages in the vmalloc and ioremap areas was
enabled for radix. Unfortunately this broke EEH MMIO error checking.

Detection works by inserting a hook which checks the results of the
ioreadXX() set of functions.  When a read returns a 0xFFs response we
need to check for an error which we do by mapping the (virtual) MMIO
address back to a physical address, then mapping physical address to a
PCI device via an interval tree.

When translating virt -> phys we currently assume the ioremap space is
only populated by PAGE_SIZE mappings. If a hugepage mapping is found we
emit a WARN_ON(), but otherwise handles the check as though a normal
page was found. In pathalogical cases such as copying a buffer
containing a lot of 0xFFs from BAR memory this can result in the system
not booting because it's too busy printing WARN_ON()s.

There's no real reason to assume huge pages can't be present and we're
prefectly capable of handling them, so do that.

Cc: Nicholas Piggin 
Fixes: 4a7b06c157a2 ("powerpc/eeh: Handle hugepages in ioremap space")
Reported-by: Sachin Sant 
Signed-off-by: Oliver O'Halloran 
---
I'm assuming that we aren't going to be doing THP in the ioremap area.
---
 arch/powerpc/kernel/eeh.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c
index 4557fb1aeb2c..976ca0496442 100644
--- a/arch/powerpc/kernel/eeh.c
+++ b/arch/powerpc/kernel/eeh.c
@@ -354,10 +354,19 @@ static inline unsigned long eeh_token_to_phys(unsigned 
long token)
ptep = find_init_mm_pte(token, &hugepage_shift);
if (!ptep)
return token;
-   WARN_ON(hugepage_shift);
-   pa = pte_pfn(*ptep) << PAGE_SHIFT;
 
-   return pa | (token & (PAGE_SIZE-1));
+   pa = pte_pfn(*ptep);
+
+   /* On radix we can do hugepage mappings for io, so handle that */
+   if (hugepage_shift) {
+   pa <<= hugepage_shift;
+   pa |= token & ((1ul << hugepage_shift) - 1);
+   } else {
+   pa <<= PAGE_SHIFT;
+   pa |= token & (PAGE_SIZE - 1);
+   }
+
+   return pa;
 }
 
 /*
-- 
2.21.0



Re: [PATCH v3 1/2] powerpc/boot: add {get, put}_unaligned_be32 to xz_config.h

2019-07-10 Thread Michael Ellerman
On Fri, 2019-07-05 at 10:01:43 UTC, Masahiro Yamada wrote:
> The next commit will make the way of passing CONFIG options more robust.
> Unfortunately, it would uncover another hidden issue; without this
> commit, skiroot_defconfig would be broken like this:
> 
> |   WRAParch/powerpc/boot/zImage.pseries
> | arch/powerpc/boot/wrapper.a(decompress.o): In function 
> `bcj_powerpc.isra.10':
> | decompress.c:(.text+0x720): undefined reference to `get_unaligned_be32'
> | decompress.c:(.text+0x7a8): undefined reference to `put_unaligned_be32'
> | make[1]: *** [arch/powerpc/boot/Makefile;383: 
> arch/powerpc/boot/zImage.pseries] Error 1
> | make: *** [arch/powerpc/Makefile;295: zImage] Error 2
> 
> skiroot_defconfig is the only defconfig that enables CONFIG_KERNEL_XZ
> for ppc, which has never been correctly built before.
> 
> I figured out the root cause in lib/decompress_unxz.c:
> 
> | #ifdef CONFIG_PPC
> | #  define XZ_DEC_POWERPC
> | #endif
> 
> CONFIG_PPC is undefined here in the ppc bootwrapper because autoconf.h
> is not included except by arch/powerpc/boot/serial.c
> 
> XZ_DEC_POWERPC is not defined, therefore, bcj_powerpc() is not compiled
> for the bootwrapper.
> 
> With the next commit passing CONFIG_PPC correctly, we would realize that
> {get,put}_unaligned_be32 was missing.
> 
> Unlike the other decompressors, the ppc bootwrapper duplicates all the
> necessary helpers in arch/powerpc/boot/.
> 
> The other architectures define __KERNEL__ and pull in helpers for
> building the decompressors.
> 
> If ppc bootwrapper had defined __KERNEL__, lib/xz/xz_private.h would
> have included :
> 
> | #ifdef __KERNEL__
> | #   include 
> | #   include 
> | #   include 
> 
> However, doing so would cause tons of definition conflicts since the
> bootwrapper has duplicated everything.
> 
> I just added copies of {get,put}_unaligned_be32, following the
> bootwrapper coding convention.
> 
> Signed-off-by: Masahiro Yamada 

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/9e005b761e7ad153dcf40a6cba1d681fe0830ac6

cheers


Re: [PATCH] ocxl: Update for AFU descriptor template version 1.1

2019-07-10 Thread Michael Ellerman
On Wed, 2019-06-05 at 11:15:45 UTC, Frederic Barrat wrote:
> From: Alastair D'Silva 
> 
> The OpenCAPI discovery and configuration specification has been
> updated and introduces version 1.1 of the AFU descriptor template,
> with new fields to better define the memory layout of an OpenCAPI
> adapter.
> 
> The ocxl driver doesn't do much yet to support LPC memory but as we
> start seeing (non-LPC) AFU images using the new template, this patch
> updates the config space parsing code to avoid spitting a warning.
> 
> Signed-off-by: Alastair D'Silva 
> Signed-off-by: Frederic Barrat 
> Reviewed-by: Christophe Lombard 
> Acked-by: Andrew Donnellan 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/73a2b047c81046a7f734a5759ab5fdedbb6968fd

cheers


Re: [PATCH v3 6/7] kexec_elf: remove Elf_Rel macro

2019-07-10 Thread Christophe Leroy




Le 10/07/2019 à 16:29, Sven Schnelle a écrit :

It wasn't used anywhere, so lets drop it.


And also, it is already defined in asm-generic/module.h



Signed-off-by: Sven Schnelle 


Reviewed-by: Christophe Leroy 


---
  kernel/kexec_elf.c | 4 
  1 file changed, 4 deletions(-)

diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
index 99e6d63b5dfc..b7e47ddd7cad 100644
--- a/kernel/kexec_elf.c
+++ b/kernel/kexec_elf.c
@@ -8,10 +8,6 @@
  #include 
  #include 
  
-#ifndef Elf_Rel

-#define Elf_RelElf64_Rel
-#endif /* Elf_Rel */
-
  static inline bool elf_is_elf_file(const struct elfhdr *ehdr)
  {
return memcmp(ehdr->e_ident, ELFMAG, SELFMAG) == 0;



Re: [PATCH v3 7/7] kexec_elf: remove unused variable in kexec_elf_load()

2019-07-10 Thread Christophe Leroy




Le 10/07/2019 à 16:29, Sven Schnelle a écrit :

base was never unsigned, so we can remove it.


Do you mean never assigned ?




Signed-off-by: Sven Schnelle 


Reviewed-by: Christophe Leroy 


---
  kernel/kexec_elf.c | 7 ++-
  1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
index b7e47ddd7cad..a56ec5481e71 100644
--- a/kernel/kexec_elf.c
+++ b/kernel/kexec_elf.c
@@ -348,7 +348,7 @@ int kexec_elf_load(struct kimage *image, struct elfhdr 
*ehdr,
 struct kexec_buf *kbuf,
 unsigned long *lowest_load_addr)
  {
-   unsigned long base = 0, lowest_addr = UINT_MAX;
+   unsigned long lowest_addr = UINT_MAX;
int ret;
size_t i;
  
@@ -370,7 +370,7 @@ int kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,

kbuf->bufsz = size;
kbuf->memsz = phdr->p_memsz;
kbuf->buf_align = phdr->p_align;
-   kbuf->buf_min = phdr->p_paddr + base;
+   kbuf->buf_min = phdr->p_paddr;
ret = kexec_add_buffer(kbuf);
if (ret)
goto out;
@@ -380,9 +380,6 @@ int kexec_elf_load(struct kimage *image, struct elfhdr 
*ehdr,
lowest_addr = load_addr;
}
  
-	/* Update entry point to reflect new load address. */

-   ehdr->e_entry += base;
-
*lowest_load_addr = lowest_addr;
ret = 0;
   out:



[PATCH v3 3/7] kexec_elf: remove parsing of section headers

2019-07-10 Thread Sven Schnelle
We're not using them, so we can drop the parsing.

Signed-off-by: Sven Schnelle 
---
 include/linux/kexec.h |   1 -
 kernel/kexec_elf.c| 137 --
 2 files changed, 138 deletions(-)

diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index da2a6b1d69e7..f0b809258ed3 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -226,7 +226,6 @@ struct kexec_elf_info {
 
const struct elfhdr *ehdr;
const struct elf_phdr *proghdrs;
-   struct elf_shdr *sechdrs;
 };
 
 int kexec_build_elf_info(const char *buf, size_t len, struct elfhdr *ehdr,
diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
index 76e7df64d715..effe9dc0b055 100644
--- a/kernel/kexec_elf.c
+++ b/kernel/kexec_elf.c
@@ -244,134 +244,6 @@ static int elf_read_phdrs(const char *buf, size_t len,
return 0;
 }
 
-/**
- * elf_is_shdr_sane - check that it is safe to use the section header
- * @buf_len:   size of the buffer in which the ELF file is loaded.
- */
-static bool elf_is_shdr_sane(const struct elf_shdr *shdr, size_t buf_len)
-{
-   bool size_ok;
-
-   /* SHT_NULL headers have undefined values, so we can't check them. */
-   if (shdr->sh_type == SHT_NULL)
-   return true;
-
-   /* Now verify sh_entsize */
-   switch (shdr->sh_type) {
-   case SHT_SYMTAB:
-   size_ok = shdr->sh_entsize == sizeof(Elf_Sym);
-   break;
-   case SHT_RELA:
-   size_ok = shdr->sh_entsize == sizeof(Elf_Rela);
-   break;
-   case SHT_DYNAMIC:
-   size_ok = shdr->sh_entsize == sizeof(Elf_Dyn);
-   break;
-   case SHT_REL:
-   size_ok = shdr->sh_entsize == sizeof(Elf_Rel);
-   break;
-   case SHT_NOTE:
-   case SHT_PROGBITS:
-   case SHT_HASH:
-   case SHT_NOBITS:
-   default:
-   /*
-* This is a section whose entsize requirements
-* I don't care about.  If I don't know about
-* the section I can't care about it's entsize
-* requirements.
-*/
-   size_ok = true;
-   break;
-   }
-
-   if (!size_ok) {
-   pr_debug("ELF section with wrong entry size.\n");
-   return false;
-   } else if (shdr->sh_addr + shdr->sh_size < shdr->sh_addr) {
-   pr_debug("ELF section address wraps around.\n");
-   return false;
-   }
-
-   if (shdr->sh_type != SHT_NOBITS) {
-   if (shdr->sh_offset + shdr->sh_size < shdr->sh_offset) {
-   pr_debug("ELF section location wraps around.\n");
-   return false;
-   } else if (shdr->sh_offset + shdr->sh_size > buf_len) {
-   pr_debug("ELF section not in file.\n");
-   return false;
-   }
-   }
-
-   return true;
-}
-
-static int elf_read_shdr(const char *buf, size_t len,
-struct kexec_elf_info *elf_info,
-int idx)
-{
-   struct elf_shdr *shdr = &elf_info->sechdrs[idx];
-   const struct elfhdr *ehdr = elf_info->ehdr;
-   const char *sbuf;
-   struct elf_shdr *buf_shdr;
-
-   sbuf = buf + ehdr->e_shoff + idx * sizeof(*buf_shdr);
-   buf_shdr = (struct elf_shdr *) sbuf;
-
-   shdr->sh_name  = elf32_to_cpu(ehdr, buf_shdr->sh_name);
-   shdr->sh_type  = elf32_to_cpu(ehdr, buf_shdr->sh_type);
-   shdr->sh_addr  = elf_addr_to_cpu(ehdr, buf_shdr->sh_addr);
-   shdr->sh_offset= elf_addr_to_cpu(ehdr, buf_shdr->sh_offset);
-   shdr->sh_link  = elf32_to_cpu(ehdr, buf_shdr->sh_link);
-   shdr->sh_info  = elf32_to_cpu(ehdr, buf_shdr->sh_info);
-
-   /*
-* The following fields have a type equivalent to Elf_Addr
-* both in 32 bit and 64 bit ELF.
-*/
-   shdr->sh_flags = elf_addr_to_cpu(ehdr, buf_shdr->sh_flags);
-   shdr->sh_size  = elf_addr_to_cpu(ehdr, buf_shdr->sh_size);
-   shdr->sh_addralign = elf_addr_to_cpu(ehdr, buf_shdr->sh_addralign);
-   shdr->sh_entsize   = elf_addr_to_cpu(ehdr, buf_shdr->sh_entsize);
-
-   return elf_is_shdr_sane(shdr, len) ? 0 : -ENOEXEC;
-}
-
-/**
- * elf_read_shdrs - read the section headers from the buffer
- *
- * This function assumes that the section header table was checked for sanity.
- * Use elf_is_ehdr_sane() if it wasn't.
- */
-static int elf_read_shdrs(const char *buf, size_t len,
- struct kexec_elf_info *elf_info)
-{
-   size_t shdr_size, i;
-
-   /*
-* e_shnum is at most 65536 so calculating
-* the size of the section header cannot overflow.
-*/
-   shdr_size = sizeof(struct elf_shdr) * elf_info->ehdr->e_shnum;
-
-   elf_info->sechdrs = kzalloc(shdr_size, GFP_KERNEL);
-   if (!elf_info->sechdrs)
-   return -ENOMEM;
-
-   for (i =

[PATCH v3 7/7] kexec_elf: remove unused variable in kexec_elf_load()

2019-07-10 Thread Sven Schnelle
base was never unsigned, so we can remove it.

Signed-off-by: Sven Schnelle 
---
 kernel/kexec_elf.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
index b7e47ddd7cad..a56ec5481e71 100644
--- a/kernel/kexec_elf.c
+++ b/kernel/kexec_elf.c
@@ -348,7 +348,7 @@ int kexec_elf_load(struct kimage *image, struct elfhdr 
*ehdr,
 struct kexec_buf *kbuf,
 unsigned long *lowest_load_addr)
 {
-   unsigned long base = 0, lowest_addr = UINT_MAX;
+   unsigned long lowest_addr = UINT_MAX;
int ret;
size_t i;
 
@@ -370,7 +370,7 @@ int kexec_elf_load(struct kimage *image, struct elfhdr 
*ehdr,
kbuf->bufsz = size;
kbuf->memsz = phdr->p_memsz;
kbuf->buf_align = phdr->p_align;
-   kbuf->buf_min = phdr->p_paddr + base;
+   kbuf->buf_min = phdr->p_paddr;
ret = kexec_add_buffer(kbuf);
if (ret)
goto out;
@@ -380,9 +380,6 @@ int kexec_elf_load(struct kimage *image, struct elfhdr 
*ehdr,
lowest_addr = load_addr;
}
 
-   /* Update entry point to reflect new load address. */
-   ehdr->e_entry += base;
-
*lowest_load_addr = lowest_addr;
ret = 0;
  out:
-- 
2.20.1



[PATCH v3 5/7] kexec_elf: remove elf_addr_to_cpu macro

2019-07-10 Thread Sven Schnelle
It had only one definition, so just use the function directly.

Signed-off-by: Sven Schnelle 
---
 kernel/kexec_elf.c | 20 +---
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
index 70d31b8feeae..99e6d63b5dfc 100644
--- a/kernel/kexec_elf.c
+++ b/kernel/kexec_elf.c
@@ -8,8 +8,6 @@
 #include 
 #include 
 
-#define elf_addr_to_cpuelf64_to_cpu
-
 #ifndef Elf_Rel
 #define Elf_RelElf64_Rel
 #endif /* Elf_Rel */
@@ -143,9 +141,9 @@ static int elf_read_ehdr(const char *buf, size_t len, 
struct elfhdr *ehdr)
ehdr->e_type  = elf16_to_cpu(ehdr, buf_ehdr->e_type);
ehdr->e_machine   = elf16_to_cpu(ehdr, buf_ehdr->e_machine);
ehdr->e_version   = elf32_to_cpu(ehdr, buf_ehdr->e_version);
-   ehdr->e_entry = elf_addr_to_cpu(ehdr, buf_ehdr->e_entry);
-   ehdr->e_phoff = elf_addr_to_cpu(ehdr, buf_ehdr->e_phoff);
-   ehdr->e_shoff = elf_addr_to_cpu(ehdr, buf_ehdr->e_shoff);
+   ehdr->e_entry = elf64_to_cpu(ehdr, buf_ehdr->e_entry);
+   ehdr->e_phoff = elf64_to_cpu(ehdr, buf_ehdr->e_phoff);
+   ehdr->e_shoff = elf64_to_cpu(ehdr, buf_ehdr->e_shoff);
ehdr->e_flags = elf32_to_cpu(ehdr, buf_ehdr->e_flags);
ehdr->e_phentsize = elf16_to_cpu(ehdr, buf_ehdr->e_phentsize);
ehdr->e_phnum = elf16_to_cpu(ehdr, buf_ehdr->e_phnum);
@@ -190,18 +188,18 @@ static int elf_read_phdr(const char *buf, size_t len,
buf_phdr = (struct elf_phdr *) pbuf;
 
phdr->p_type   = elf32_to_cpu(elf_info->ehdr, buf_phdr->p_type);
-   phdr->p_offset = elf_addr_to_cpu(elf_info->ehdr, buf_phdr->p_offset);
-   phdr->p_paddr  = elf_addr_to_cpu(elf_info->ehdr, buf_phdr->p_paddr);
-   phdr->p_vaddr  = elf_addr_to_cpu(elf_info->ehdr, buf_phdr->p_vaddr);
+   phdr->p_offset = elf64_to_cpu(elf_info->ehdr, buf_phdr->p_offset);
+   phdr->p_paddr  = elf64_to_cpu(elf_info->ehdr, buf_phdr->p_paddr);
+   phdr->p_vaddr  = elf64_to_cpu(elf_info->ehdr, buf_phdr->p_vaddr);
phdr->p_flags  = elf32_to_cpu(elf_info->ehdr, buf_phdr->p_flags);
 
/*
 * The following fields have a type equivalent to Elf_Addr
 * both in 32 bit and 64 bit ELF.
 */
-   phdr->p_filesz = elf_addr_to_cpu(elf_info->ehdr, buf_phdr->p_filesz);
-   phdr->p_memsz  = elf_addr_to_cpu(elf_info->ehdr, buf_phdr->p_memsz);
-   phdr->p_align  = elf_addr_to_cpu(elf_info->ehdr, buf_phdr->p_align);
+   phdr->p_filesz = elf64_to_cpu(elf_info->ehdr, buf_phdr->p_filesz);
+   phdr->p_memsz  = elf64_to_cpu(elf_info->ehdr, buf_phdr->p_memsz);
+   phdr->p_align  = elf64_to_cpu(elf_info->ehdr, buf_phdr->p_align);
 
return elf_is_phdr_sane(phdr, len) ? 0 : -ENOEXEC;
 }
-- 
2.20.1



[PATCH v3 4/7] kexec_elf: remove PURGATORY_STACK_SIZE

2019-07-10 Thread Sven Schnelle
It's not used anywhere so just drop it.

Signed-off-by: Sven Schnelle 
---
 kernel/kexec_elf.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
index effe9dc0b055..70d31b8feeae 100644
--- a/kernel/kexec_elf.c
+++ b/kernel/kexec_elf.c
@@ -8,8 +8,6 @@
 #include 
 #include 
 
-#define PURGATORY_STACK_SIZE   (16 * 1024)
-
 #define elf_addr_to_cpuelf64_to_cpu
 
 #ifndef Elf_Rel
-- 
2.20.1



[PATCH v3 2/7] kexec_elf: change order of elf_*_to_cpu() functions

2019-07-10 Thread Sven Schnelle
Change the order to have a 64/32/16 order, no functional change.

Signed-off-by: Sven Schnelle 
---
 kernel/kexec_elf.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
index 6e9f52171ede..76e7df64d715 100644
--- a/kernel/kexec_elf.c
+++ b/kernel/kexec_elf.c
@@ -31,22 +31,22 @@ static uint64_t elf64_to_cpu(const struct elfhdr *ehdr, 
uint64_t value)
return value;
 }
 
-static uint16_t elf16_to_cpu(const struct elfhdr *ehdr, uint16_t value)
+static uint32_t elf32_to_cpu(const struct elfhdr *ehdr, uint32_t value)
 {
if (ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
-   value = le16_to_cpu(value);
+   value = le32_to_cpu(value);
else if (ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
-   value = be16_to_cpu(value);
+   value = be32_to_cpu(value);
 
return value;
 }
 
-static uint32_t elf32_to_cpu(const struct elfhdr *ehdr, uint32_t value)
+static uint16_t elf16_to_cpu(const struct elfhdr *ehdr, uint16_t value)
 {
if (ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
-   value = le32_to_cpu(value);
+   value = le16_to_cpu(value);
else if (ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
-   value = be32_to_cpu(value);
+   value = be16_to_cpu(value);
 
return value;
 }
-- 
2.20.1



[PATCH v3 1/7] kexec: add KEXEC_ELF

2019-07-10 Thread Sven Schnelle
Right now powerpc provides an implementation to read elf files
with the kexec_file() syscall. Make that available as a public
kexec interface so it can be re-used on other architectures.

Signed-off-by: Sven Schnelle 
---
 arch/Kconfig  |   3 +
 arch/powerpc/Kconfig  |   1 +
 arch/powerpc/kernel/kexec_elf_64.c| 551 +-
 include/linux/kexec.h |  24 +
 kernel/Makefile   |   1 +
 .../kexec_elf_64.c => kernel/kexec_elf.c  | 199 ++-
 6 files changed, 75 insertions(+), 704 deletions(-)
 copy arch/powerpc/kernel/kexec_elf_64.c => kernel/kexec_elf.c (71%)

diff --git a/arch/Kconfig b/arch/Kconfig
index c47b328eada0..30694aca4316 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -18,6 +18,9 @@ config KEXEC_CORE
select CRASH_CORE
bool
 
+config KEXEC_ELF
+   bool
+
 config HAVE_IMA_KEXEC
bool
 
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 12cee37f15c4..addc2dad78e0 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -510,6 +510,7 @@ config KEXEC_FILE
select KEXEC_CORE
select HAVE_IMA_KEXEC
select BUILD_BIN2C
+   select KEXEC_ELF
depends on PPC64
depends on CRYPTO=y
depends on CRYPTO_SHA256=y
diff --git a/arch/powerpc/kernel/kexec_elf_64.c 
b/arch/powerpc/kernel/kexec_elf_64.c
index ba4f18a43ee8..30bd57a93c17 100644
--- a/arch/powerpc/kernel/kexec_elf_64.c
+++ b/arch/powerpc/kernel/kexec_elf_64.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Load ELF vmlinux file for the kexec_file_load syscall.
  *
@@ -10,15 +11,6 @@
  * Based on kexec-tools' kexec-elf-exec.c and kexec-elf-ppc64.c.
  * Heavily modified for the kernel by
  * Thiago Jung Bauermann .
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation (version 2 of the License).
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
  */
 
 #define pr_fmt(fmt)"kexec_elf: " fmt
@@ -39,532 +31,6 @@
 #define Elf_RelElf64_Rel
 #endif /* Elf_Rel */
 
-struct elf_info {
-   /*
-* Where the ELF binary contents are kept.
-* Memory managed by the user of the struct.
-*/
-   const char *buffer;
-
-   const struct elfhdr *ehdr;
-   const struct elf_phdr *proghdrs;
-   struct elf_shdr *sechdrs;
-};
-
-static inline bool elf_is_elf_file(const struct elfhdr *ehdr)
-{
-   return memcmp(ehdr->e_ident, ELFMAG, SELFMAG) == 0;
-}
-
-static uint64_t elf64_to_cpu(const struct elfhdr *ehdr, uint64_t value)
-{
-   if (ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
-   value = le64_to_cpu(value);
-   else if (ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
-   value = be64_to_cpu(value);
-
-   return value;
-}
-
-static uint16_t elf16_to_cpu(const struct elfhdr *ehdr, uint16_t value)
-{
-   if (ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
-   value = le16_to_cpu(value);
-   else if (ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
-   value = be16_to_cpu(value);
-
-   return value;
-}
-
-static uint32_t elf32_to_cpu(const struct elfhdr *ehdr, uint32_t value)
-{
-   if (ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
-   value = le32_to_cpu(value);
-   else if (ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
-   value = be32_to_cpu(value);
-
-   return value;
-}
-
-/**
- * elf_is_ehdr_sane - check that it is safe to use the ELF header
- * @buf_len:   size of the buffer in which the ELF file is loaded.
- */
-static bool elf_is_ehdr_sane(const struct elfhdr *ehdr, size_t buf_len)
-{
-   if (ehdr->e_phnum > 0 && ehdr->e_phentsize != sizeof(struct elf_phdr)) {
-   pr_debug("Bad program header size.\n");
-   return false;
-   } else if (ehdr->e_shnum > 0 &&
-  ehdr->e_shentsize != sizeof(struct elf_shdr)) {
-   pr_debug("Bad section header size.\n");
-   return false;
-   } else if (ehdr->e_ident[EI_VERSION] != EV_CURRENT ||
-  ehdr->e_version != EV_CURRENT) {
-   pr_debug("Unknown ELF version.\n");
-   return false;
-   }
-
-   if (ehdr->e_phoff > 0 && ehdr->e_phnum > 0) {
-   size_t phdr_size;
-
-   /*
-* e_phnum is at most 65535 so calculating the size of the
-* program header cannot overflow.
-*/
-   phdr_size = sizeof(struct elf_phdr) * ehdr->e_phnum;
-
-   /* Sanity check the program header table location. */
-   if (ehdr->e_phoff + phdr_size < ehdr->e_

[PATCH v3 6/7] kexec_elf: remove Elf_Rel macro

2019-07-10 Thread Sven Schnelle
It wasn't used anywhere, so lets drop it.

Signed-off-by: Sven Schnelle 
---
 kernel/kexec_elf.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
index 99e6d63b5dfc..b7e47ddd7cad 100644
--- a/kernel/kexec_elf.c
+++ b/kernel/kexec_elf.c
@@ -8,10 +8,6 @@
 #include 
 #include 
 
-#ifndef Elf_Rel
-#define Elf_RelElf64_Rel
-#endif /* Elf_Rel */
-
 static inline bool elf_is_elf_file(const struct elfhdr *ehdr)
 {
return memcmp(ehdr->e_ident, ELFMAG, SELFMAG) == 0;
-- 
2.20.1



[PATCH v3 0/7] kexec: add generic support for elf kernel images

2019-07-10 Thread Sven Schnelle
Hi List,

this is the same changeset as v2, but (hopefully) with git format-patch -C.

Changes to v2:
 - use git format-patch -C

Changes to v1:
 - split up patch into smaller pieces
 - rebase onto powerpc/next
 - remove unused variable in kexec_elf_load()

Changes to RFC version:
 - remove unused Elf_Rel macro
 - remove section header parsing
 - remove PURGATORY_STACK_SIZE
 - change order of elf_*_to_cpu() functions
 - remove elf_addr_to_cpu macro

Sven Schnelle (7):
  kexec: add KEXEC_ELF
  kexec_elf: change order of elf_*_to_cpu() functions
  kexec_elf: remove parsing of section headers
  kexec_elf: remove PURGATORY_STACK_SIZE
  kexec_elf: remove elf_addr_to_cpu macro
  kexec_elf: remove Elf_Rel macro
  kexec_elf: remove unused variable in kexec_elf_load()

 arch/Kconfig   |   3 +
 arch/powerpc/Kconfig   |   1 +
 arch/powerpc/kernel/kexec_elf_64.c | 551 +
 include/linux/kexec.h  |  23 ++
 kernel/Makefile|   1 +
 kernel/kexec_elf.c | 389 
 6 files changed, 427 insertions(+), 541 deletions(-)
 create mode 100644 kernel/kexec_elf.c

-- 
2.20.1



Re: [PATCH v2 1/7] kexec: add KEXEC_ELF

2019-07-10 Thread Sven Schnelle
Hi Christophe,

On Wed, Jul 10, 2019 at 01:19:13PM +, Christophe Leroy wrote:
> Hi Sven,
> 
> On 07/09/2019 07:43 PM, Sven Schnelle wrote:
> > Right now powerpc provides an implementation to read elf files
> > with the kexec_file() syscall. Make that available as a public
> > kexec interface so it can be re-used on other architectures.
> > 
> > Signed-off-by: Sven Schnelle 
> > ---
> >   arch/Kconfig   |   3 +
> >   arch/powerpc/Kconfig   |   1 +
> >   arch/powerpc/kernel/kexec_elf_64.c | 551 +
> >   include/linux/kexec.h  |  24 ++
> >   kernel/Makefile|   1 +
> >   kernel/kexec_elf.c | 537 
> >   6 files changed, 576 insertions(+), 541 deletions(-)
> >   create mode 100644 kernel/kexec_elf.c
> 
> Why are you persisting at not using -C when creating your patch ? Do you
> want to hide the changes you did while copying
> arch/powerpc/kernel/kexec_elf_64.c to kernel/kexec_elf.c ?
> Or you want to make life harder for the reviewers ?

Sorry, never used -C before. I used:

git send-email --annotate -v2 -7 --to ke...@lists.infradead.org --cc 
del...@gmx.de,linuxppc-dev@lists.ozlabs.org -v --format-patch -C -M

However, it looks like it only works when started this way:

git send-email --format-patch -M -C --annotate -v2 -7 --to 
ke...@lists.infradead.org --cc del...@gmx.de,linuxppc-dev@lists.ozlabs.org -v

I'll resend v2.

Best Regards,
Sven


Re: [PATCH] powerpc: mm: Limit rma_size to 1TB when running without HV mode

2019-07-10 Thread David Gibson
On Wed, Jul 10, 2019 at 03:20:18PM +1000, Suraj Jitindar Singh wrote:
> The virtual real mode addressing (VRMA) mechanism is used when a
> partition is using HPT (Hash Page Table) translation and performs
> real mode accesses (MSR[IR|DR] = 0) in non-hypervisor mode. In this
> mode effective address bits 0:23 are treated as zero (i.e. the access
> is aliased to 0) and the access is performed using an implicit 1TB SLB
> entry.
> 
> The size of the RMA (Real Memory Area) is communicated to the guest as
> the size of the first memory region in the device tree. And because of
> the mechanism described above can be expected to not exceed 1TB. In the
> event that the host erroneously represents the RMA as being larger than
> 1TB, guest accesses in real mode to memory addresses above 1TB will be
> aliased down to below 1TB. This means that a memory access performed in
> real mode may differ to one performed in virtual mode for the same memory
> address, which would likely have unintended consequences.
> 
> To avoid this outcome have the guest explicitly limit the size of the
> RMA to the current maximum, which is 1TB. This means that even if the
> first memory block is larger than 1TB, only the first 1TB should be
> accessed in real mode.
> 
> Signed-off-by: Suraj Jitindar Singh 

Reviewed-by: David Gibson 

Although I'd really like to also see some comments added in
allocate_paca_ptrs() explaining the constraints there.

Oh, also, basing this on the non-compat PVR is bogus, but it's still
better than what we had.

> ---
>  arch/powerpc/mm/book3s64/hash_utils.c | 8 
>  1 file changed, 8 insertions(+)
> 
> diff --git a/arch/powerpc/mm/book3s64/hash_utils.c 
> b/arch/powerpc/mm/book3s64/hash_utils.c
> index 28ced26f2a00..4d0e2cce9cd5 100644
> --- a/arch/powerpc/mm/book3s64/hash_utils.c
> +++ b/arch/powerpc/mm/book3s64/hash_utils.c
> @@ -1901,11 +1901,19 @@ void hash__setup_initial_memory_limit(phys_addr_t 
> first_memblock_base,
>*
>* For guests on platforms before POWER9, we clamp the it limit to 1G
>* to avoid some funky things such as RTAS bugs etc...
> +  * On POWER9 we limit to 1TB in case the host erroneously told us that
> +  * the RMA was >1TB. Effective address bits 0:23 are treated as zero
> +  * (meaning the access is aliased to zero i.e. addr = addr % 1TB)
> +  * for virtual real mode addressing and so it doesn't make sense to
> +  * have an area larger than 1TB as it can't be addressed.
>*/
>   if (!early_cpu_has_feature(CPU_FTR_HVMODE)) {
>   ppc64_rma_size = first_memblock_size;
>   if (!early_cpu_has_feature(CPU_FTR_ARCH_300))
>   ppc64_rma_size = min_t(u64, ppc64_rma_size, 0x4000);
> + else
> + ppc64_rma_size = min_t(u64, ppc64_rma_size,
> +1UL << SID_SHIFT_1T);
>  
>   /* Finally limit subsequent allocations */
>   memblock_set_current_limit(ppc64_rma_size);

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [PATCH v5 7/7] KVM: PPC: Ultravisor: Add PPC_UV config option

2019-07-10 Thread Jason Gunthorpe
On Wed, Jul 10, 2019 at 08:24:56AM -0500, janani wrote:
> On 2019-07-09 05:25, Bharata B Rao wrote:
> > From: Anshuman Khandual 
> > 
> > CONFIG_PPC_UV adds support for ultravisor.
> > 
> > Signed-off-by: Anshuman Khandual 
> > Signed-off-by: Bharata B Rao 
> > Signed-off-by: Ram Pai 
> > [ Update config help and commit message ]
> > Signed-off-by: Claudio Carvalho 
>  Reviewed-by: Janani Janakiraman 
> >  arch/powerpc/Kconfig | 20 
> >  1 file changed, 20 insertions(+)
> > 
> > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> > index f0e5b38d52e8..20c6c213d2be 100644
> > +++ b/arch/powerpc/Kconfig
> > @@ -440,6 +440,26 @@ config PPC_TRANSACTIONAL_MEM
> >   Support user-mode Transactional Memory on POWERPC.
> > 
> > +config PPC_UV
> > +   bool "Ultravisor support"
> > +   depends on KVM_BOOK3S_HV_POSSIBLE
> > +   select HMM_MIRROR
> > +   select HMM
> > +   select ZONE_DEVICE

These configs have also been changed lately, I didn't see any calls to
hmm_mirror in this patchset, so most likely the two HMM selects should
be dropped and all you'll need is ZONE_DEVICE..

Jason


Re: [PATCH v5 1/7] kvmppc: HMM backend driver to manage pages of secure guest

2019-07-10 Thread Jason Gunthorpe
On Tue, Jul 09, 2019 at 01:55:28PM -0500, janani wrote:

> > +int kvmppc_hmm_init(void)
> > +{
> > +   int ret = 0;
> > +   unsigned long size;
> > +
> > +   size = kvmppc_get_secmem_size();
> > +   if (!size) {
> > +   ret = -ENODEV;
> > +   goto out;
> > +   }
> > +
> > +   kvmppc_hmm.device = hmm_device_new(NULL);
> > +   if (IS_ERR(kvmppc_hmm.device)) {
> > +   ret = PTR_ERR(kvmppc_hmm.device);
> > +   goto out;
> > +   }
> > +
> > +   kvmppc_hmm.devmem = hmm_devmem_add(&kvmppc_hmm_devmem_ops,
> > +  &kvmppc_hmm.device->device, size);
> > +   if (IS_ERR(kvmppc_hmm.devmem)) {
> > +   ret = PTR_ERR(kvmppc_hmm.devmem);
> > +   goto out_device;
> > +   }

This 'hmm_device' API family was recently deleted from hmm:

commit 07ec38917e68f0114b9c8aeeb1c584b5e73e4dd6
Author: Christoph Hellwig 
Date:   Wed Jun 26 14:27:01 2019 +0200

mm: remove the struct hmm_device infrastructure

This code is a trivial wrapper around device model helpers, which
should have been integrated into the driver device model usage from
the start.  Assuming it actually had users, which it never had since
the code was added more than 1 1/2 years ago.

This patch should use the driver core directly instead.

Regards,
Jason


Re: [RFC PATCH v5 6/7] kvmppc: Support reset of secure guest

2019-07-10 Thread janani

On 2019-07-09 05:25, Bharata B Rao wrote:

Add support for reset of secure guest via a new ioctl KVM_PPC_SVM_OFF.
This ioctl will be issued by QEMU during reset and includes the
the following steps:

- Ask UV to terminate the guest via UV_SVM_TERMINATE ucall
- Unpin the VPA pages so that they can be migrated back to secure
  side when guest becomes secure again. This is required because
  pinned pages can't be migrated.
- Reinitialize guest's partitioned scoped page tables. These are
  freed when guest become secure (H_SVM_INIT_DONE)
- Release all HMM pages of the secure guest.

After these steps, guest is ready to issue UV_ESM call once again
to switch to secure mode.

Signed-off-by: Bharata B Rao 
Signed-off-by: Sukadev Bhattiprolu 
[Implementation of uv_svm_terminate() and its call from
guest shutdown path]
Signed-off-by: Ram Pai 
[Unpinning of VPA pages]

 Reviewed-by: Janani Janakiraman 

---
 Documentation/virtual/kvm/api.txt | 19 ++
 arch/powerpc/include/asm/kvm_book3s_hmm.h |  7 +++
 arch/powerpc/include/asm/kvm_ppc.h|  2 +
 arch/powerpc/include/asm/ultravisor-api.h |  1 +
 arch/powerpc/include/asm/ultravisor.h |  7 +++
 arch/powerpc/kvm/book3s_hv.c  | 70 +++
 arch/powerpc/kvm/book3s_hv_hmm.c  | 60 +++
 arch/powerpc/kvm/powerpc.c| 12 
 include/uapi/linux/kvm.h  |  1 +
 tools/include/uapi/linux/kvm.h|  1 +
 10 files changed, 180 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt
b/Documentation/virtual/kvm/api.txt
index ba6c42c576dd..c89c24ad86ed 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -4065,6 +4065,25 @@ KVM_ARM_VCPU_FINALIZE call.
 See KVM_ARM_VCPU_INIT for details of vcpu features that require 
finalization

 using this ioctl.

+4.120 KVM_PPC_SVM_OFF
+
+Capability: basic
+Architectures: powerpc
+Type: vm ioctl
+Parameters: none
+Returns: 0 on successful completion,
+Errors:
+  EINVAL:if ultravisor failed to terminate the secure guest
+  ENOMEM:if hypervisor failed to allocate new radix page tables 
for guest

+
+This ioctl is used to turn off the secure mode of the guest or 
transition
+the guest from secure mode to normal mode. This is invoked when the 
guest

+is reset. This has no effect if called for a normal guest.
+
+This ioctl issues an ultravisor call to terminate the secure guest,
+unpin the VPA pages, reinitialize guest's partition scoped page
+tables and releases all the HMM pages that is associated with this 
guest.

+
 5. The kvm_run structure
 

diff --git a/arch/powerpc/include/asm/kvm_book3s_hmm.h
b/arch/powerpc/include/asm/kvm_book3s_hmm.h
index 8c7aacabb2e0..cd2b0f927766 100644
--- a/arch/powerpc/include/asm/kvm_book3s_hmm.h
+++ b/arch/powerpc/include/asm/kvm_book3s_hmm.h
@@ -13,6 +13,8 @@ extern unsigned long kvmppc_h_svm_page_out(struct kvm 
*kvm,

  unsigned long page_shift);
 extern unsigned long kvmppc_h_svm_init_start(struct kvm *kvm);
 extern unsigned long kvmppc_h_svm_init_done(struct kvm *kvm);
+extern void kvmppc_hmm_free_memslot_pfns(struct kvm *kvm,
+   struct kvm_memslots *slots);
 #else
 static inline unsigned long
 kvmppc_h_svm_page_in(struct kvm *kvm, unsigned long gra,
@@ -37,5 +39,10 @@ static inline unsigned long
kvmppc_h_svm_init_done(struct kvm *kvm)
 {
return H_UNSUPPORTED;
 }
+
+static inline void kvmppc_hmm_free_memslot_pfns(struct kvm *kvm,
+   struct kvm_memslots *slots)
+{
+}
 #endif /* CONFIG_PPC_UV */
 #endif /* __POWERPC_KVM_PPC_HMM_H__ */
diff --git a/arch/powerpc/include/asm/kvm_ppc.h
b/arch/powerpc/include/asm/kvm_ppc.h
index bc892380e6cd..d80ece28d65d 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -188,6 +188,7 @@ extern void
kvm_spapr_tce_release_iommu_group(struct kvm *kvm,
 extern int kvmppc_switch_mmu_to_hpt(struct kvm *kvm);
 extern int kvmppc_switch_mmu_to_radix(struct kvm *kvm);
 extern void kvmppc_setup_partition_table(struct kvm *kvm);
+extern int kvmppc_reinit_partition_table(struct kvm *kvm);

 extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
struct kvm_create_spapr_tce_64 *args);
@@ -332,6 +333,7 @@ struct kvmppc_ops {
   int size);
int (*store_to_eaddr)(struct kvm_vcpu *vcpu, ulong *eaddr, void *ptr,
  int size);
+   int (*svm_off)(struct kvm *kvm);
 };

 extern struct kvmppc_ops *kvmppc_hv_ops;
diff --git a/arch/powerpc/include/asm/ultravisor-api.h
b/arch/powerpc/include/asm/ultravisor-api.h
index 9f5510b55892..c8180427fa01 100644
--- a/arch/powerpc/include/asm/ultravisor-api.h
+++ b/arch/powerpc/include/asm/ultravisor-api.h
@@ -25,5 +25,6 @@
 #define UV_PAGE_IN 0xF128
 #define UV_PAGE_OUT0xF12C
 #define UV_PAGE_INVAL   

[Bug 204125] New: FTBFS on ppc64 big endian and gcc9 because of -mcall-aixdesc and missing __linux__

2019-07-10 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=204125

Bug ID: 204125
   Summary: FTBFS on ppc64 big endian and gcc9 because of
-mcall-aixdesc and missing __linux__
   Product: Platform Specific/Hardware
   Version: 2.5
Kernel Version: any
  Hardware: PPC-64
OS: Linux
  Tree: Mainline
Status: NEW
  Severity: high
  Priority: P1
 Component: PPC-64
  Assignee: platform_ppc...@kernel-bugs.osdl.org
  Reporter: li...@octaforge.org
Regression: No

On ppc64 big endian, the kernel builds with `-mcall-aixdesc` which since gcc
9.x removes `__linux__` from the list of macros being defined. This behavior is
supposed to be more correct (as it's in this case nothing but a hack, the flag
should apparently only be used when building for AIX) but sadly it breaks build
since several things within the tree rely on `__linux__` being defined and
`#ifdef` some of their code based on said macro.

Just removing `-mcall-aixdesc` (and using just `-mabi=elfv1`) is however not
enough, as that instead causes countless undefined references to just about
every symbol when linking `vmlinux`. It would seem that `-mcall-aixdesc`
changes the way symbols are declared in a way that is not expected.

Little endian is not affected because that one uses `-mabi=elfv2` exclusively.

For now I worked around it in my distro by explicitly adding `-D__linux__` in
the kbuild where `-mcall-aixdesc` is inserted into flags, and it works, but
that's obviously just a workaround.

I'm not sure what the proper fix would be.

Also, is there any reason not to allow an ELFv2 kernel to be built on big
endian? There are some supposed performance benefits, and ELFv2 itself supports
either endianness. The current kbuild logic pretty much forces ELFv1 for big
endian and ELFv2 for little endian.

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

Re: [PATCH v2 1/7] kexec: add KEXEC_ELF

2019-07-10 Thread Christophe Leroy

Hi Sven,

On 07/09/2019 07:43 PM, Sven Schnelle wrote:

Right now powerpc provides an implementation to read elf files
with the kexec_file() syscall. Make that available as a public
kexec interface so it can be re-used on other architectures.

Signed-off-by: Sven Schnelle 
---
  arch/Kconfig   |   3 +
  arch/powerpc/Kconfig   |   1 +
  arch/powerpc/kernel/kexec_elf_64.c | 551 +
  include/linux/kexec.h  |  24 ++
  kernel/Makefile|   1 +
  kernel/kexec_elf.c | 537 
  6 files changed, 576 insertions(+), 541 deletions(-)
  create mode 100644 kernel/kexec_elf.c


Why are you persisting at not using -C when creating your patch ? Do you 
want to hide the changes you did while copying 
arch/powerpc/kernel/kexec_elf_64.c to kernel/kexec_elf.c ?

Or you want to make life harder for the reviewers ?

git format-patch -C shows:

 arch/Kconfig   |   3 +
 arch/powerpc/Kconfig   |   1 +
 arch/powerpc/kernel/kexec_elf_64.c | 551 
+

 include/linux/kexec.h  |  24 +
 kernel/Makefile|   1 +
 .../kernel/kexec_elf_64.c => kernel/kexec_elf.c| 199 ++--
 6 files changed, 75 insertions(+), 704 deletions(-)
 copy arch/powerpc/kernel/kexec_elf_64.c => kernel/kexec_elf.c (71%)

I mentionned it a couple of times, I even resent your last patch 
formatted that way to show the advantage. I can ear if you find it 
worthless, but tell what your concern are with that, don't just ignore 
it please.


Cheers
Christophe



diff --git a/arch/Kconfig b/arch/Kconfig
index c47b328eada0..30694aca4316 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -18,6 +18,9 @@ config KEXEC_CORE
select CRASH_CORE
bool
  
+config KEXEC_ELF

+   bool
+
  config HAVE_IMA_KEXEC
bool
  
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig

index 12cee37f15c4..addc2dad78e0 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -510,6 +510,7 @@ config KEXEC_FILE
select KEXEC_CORE
select HAVE_IMA_KEXEC
select BUILD_BIN2C
+   select KEXEC_ELF
depends on PPC64
depends on CRYPTO=y
depends on CRYPTO_SHA256=y
diff --git a/arch/powerpc/kernel/kexec_elf_64.c 
b/arch/powerpc/kernel/kexec_elf_64.c
index ba4f18a43ee8..30bd57a93c17 100644
--- a/arch/powerpc/kernel/kexec_elf_64.c
+++ b/arch/powerpc/kernel/kexec_elf_64.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
  /*
   * Load ELF vmlinux file for the kexec_file_load syscall.
   *
@@ -10,15 +11,6 @@
   * Based on kexec-tools' kexec-elf-exec.c and kexec-elf-ppc64.c.
   * Heavily modified for the kernel by
   * Thiago Jung Bauermann .
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation (version 2 of the License).
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
   */
  
  #define pr_fmt(fmt)	"kexec_elf: " fmt

@@ -39,532 +31,6 @@
  #define Elf_Rel   Elf64_Rel
  #endif /* Elf_Rel */
  
-struct elf_info {

-   /*
-* Where the ELF binary contents are kept.
-* Memory managed by the user of the struct.
-*/
-   const char *buffer;
-
-   const struct elfhdr *ehdr;
-   const struct elf_phdr *proghdrs;
-   struct elf_shdr *sechdrs;
-};
-
-static inline bool elf_is_elf_file(const struct elfhdr *ehdr)
-{
-   return memcmp(ehdr->e_ident, ELFMAG, SELFMAG) == 0;
-}
-
-static uint64_t elf64_to_cpu(const struct elfhdr *ehdr, uint64_t value)
-{
-   if (ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
-   value = le64_to_cpu(value);
-   else if (ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
-   value = be64_to_cpu(value);
-
-   return value;
-}
-
-static uint16_t elf16_to_cpu(const struct elfhdr *ehdr, uint16_t value)
-{
-   if (ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
-   value = le16_to_cpu(value);
-   else if (ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
-   value = be16_to_cpu(value);
-
-   return value;
-}
-
-static uint32_t elf32_to_cpu(const struct elfhdr *ehdr, uint32_t value)
-{
-   if (ehdr->e_ident[EI_DATA] == ELFDATA2LSB)
-   value = le32_to_cpu(value);
-   else if (ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
-   value = be32_to_cpu(value);
-
-   return value;
-}
-
-/**
- * elf_is_ehdr_sane - check that it is safe to use the ELF header
- * @buf_len:   size of the buffer in which the ELF file is loaded.
- */
-static bool elf_is_ehdr_sane(const struct elfhdr *ehdr, size_

Re: [PATCH v5 7/7] KVM: PPC: Ultravisor: Add PPC_UV config option

2019-07-10 Thread janani

On 2019-07-09 05:25, Bharata B Rao wrote:

From: Anshuman Khandual 

CONFIG_PPC_UV adds support for ultravisor.

Signed-off-by: Anshuman Khandual 
Signed-off-by: Bharata B Rao 
Signed-off-by: Ram Pai 
[ Update config help and commit message ]
Signed-off-by: Claudio Carvalho 

 Reviewed-by: Janani Janakiraman 

---
 arch/powerpc/Kconfig | 20 
 1 file changed, 20 insertions(+)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index f0e5b38d52e8..20c6c213d2be 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -440,6 +440,26 @@ config PPC_TRANSACTIONAL_MEM
---help---
  Support user-mode Transactional Memory on POWERPC.

+config PPC_UV
+   bool "Ultravisor support"
+   depends on KVM_BOOK3S_HV_POSSIBLE
+   select HMM_MIRROR
+   select HMM
+   select ZONE_DEVICE
+   select MIGRATE_VMA_HELPER
+   select DEV_PAGEMAP_OPS
+   select DEVICE_PRIVATE
+   select MEMORY_HOTPLUG
+   select MEMORY_HOTREMOVE
+   default n
+   help
+	  This option paravirtualizes the kernel to run in POWER platforms 
that

+ supports the Protected Execution Facility (PEF). In such platforms,
+ the ultravisor firmware runs at a privilege level above the
+ hypervisor.
+
+ If unsure, say "N".
+
 config LD_HEAD_STUB_CATCH
 	bool "Reserve 256 bytes to cope with linker stubs in HEAD text" if 
EXPERT

depends on PPC64




Re: [PATCH v5] cpufreq/pasemi: fix an use-after-free in pas_cpufreq_cpu_init()

2019-07-10 Thread Rafael J. Wysocki
On Tuesday, July 9, 2019 10:12:05 AM CEST Viresh Kumar wrote:
> On 09-07-19, 16:04, Wen Yang wrote:
> > The cpu variable is still being used in the of_get_property() call
> > after the of_node_put() call, which may result in use-after-free.
> > 
> > Fixes: a9acc26b75f ("cpufreq/pasemi: fix possible object reference leak")
> > Signed-off-by: Wen Yang 
> > Cc: "Rafael J. Wysocki" 
> > Cc: Viresh Kumar 
> > Cc: Michael Ellerman 
> > Cc: linuxppc-dev@lists.ozlabs.org
> > Cc: linux...@vger.kernel.org
> > Cc: linux-ker...@vger.kernel.org

Patch applied.

> > ---
> > v5: put together the code to get, use, and release cpu device_node.
> > v4: restore the blank line.
> > v3: fix a leaked reference.
> > v2: clean up the code according to the advice of viresh.
> > 
> >  drivers/cpufreq/pasemi-cpufreq.c | 21 +
> >  1 file changed, 9 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/cpufreq/pasemi-cpufreq.c 
> > b/drivers/cpufreq/pasemi-cpufreq.c
> > index 6b1e4ab..1f0beb7 100644
> > --- a/drivers/cpufreq/pasemi-cpufreq.c
> > +++ b/drivers/cpufreq/pasemi-cpufreq.c
> > @@ -131,10 +131,17 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy 
> > *policy)
> > int err = -ENODEV;
> >  
> > cpu = of_get_cpu_node(policy->cpu, NULL);
> > -
> > -   of_node_put(cpu);
> > if (!cpu)
> > goto out;
> 
> I would have loved a blank line here :)

And I added the blank line.

> > +   max_freqp = of_get_property(cpu, "clock-frequency", NULL);
> > +   of_node_put(cpu);
> > +   if (!max_freqp) {
> > +   err = -EINVAL;
> > +   goto out;
> > +   }
> > +
> > +   /* we need the freq in kHz */
> > +   max_freq = *max_freqp / 1000;
> >  
> > dn = of_find_compatible_node(NULL, NULL, "1682m-sdc");
> > if (!dn)
> > @@ -171,16 +178,6 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy 
> > *policy)
> > }
> >  
> > pr_debug("init cpufreq on CPU %d\n", policy->cpu);
> > -
> > -   max_freqp = of_get_property(cpu, "clock-frequency", NULL);
> > -   if (!max_freqp) {
> > -   err = -EINVAL;
> > -   goto out_unmap_sdcpwr;
> > -   }
> > -
> > -   /* we need the freq in kHz */
> > -   max_freq = *max_freqp / 1000;
> > -
> > pr_debug("max clock-frequency is at %u kHz\n", max_freq);
> > pr_debug("initializing frequency table\n");
> 
> Though, enough versions have happened now.
> 
> Acked-by: Viresh Kumar 
> 
> 

Thanks!





Re: [PATCH] sound: ppc: snd_ps3: Remove Unneeded variable: "ret"

2019-07-10 Thread Takashi Iwai
On Wed, 10 Jul 2019 04:39:46 +0200,
Hariprasad Kelam wrote:
> 
> This patch fixes below issue reported by coccicheck
> sound/ppc/snd_ps3.c:631:5-8: Unneeded variable: "ret". Return "0" on
> line 668
> 
> We cannot change return type of snd_ps3_pcm_trigger as it is registered
> with snd_pcm_ops->trigger
> 
> Signed-off-by: Hariprasad Kelam 

Applied (with the correction of the description again).


thanks,

Takashi


Re: [1/2] powerpc/83xx: fix use-after-free in mpc831x_usb_cfg()

2019-07-10 Thread Markus Elfring
> we developed a coccinelle script to detect such problems.

How do you think about to give any attribution to this development software
in your commit descriptions?


> After a period of testing, we will send it to the LMKL mailing list later.

I am also curious then on how this area will evolve further.

Regards,
Markus


[PATCH v3] cpufreq/pasemi: fix an use-after-free inpas_cpufreq_cpu_init()

2019-07-10 Thread Christian Zigotzky
Is a final patch available for testing? Please do not release it without 
testing.


- Christian

On 09-07-19, 16:04, Wen Yang wrote:
> The cpu variable is still being used in the of_get_property() call
> after the of_node_put() call, which may result in use-after-free.
>
> Fixes: a9acc26b75f ("cpufreq/pasemi: fix possible object reference leak")
> Signed-off-by: Wen Yang 
> Cc: "Rafael J. Wysocki" 
> Cc: Viresh Kumar 
> Cc: Michael Ellerman 
> Cc: linuxppc-dev at lists.ozlabs.org
> Cc: linux-pm at vger.kernel.org
> Cc: linux-kernel at vger.kernel.org
> ---
> v5: put together the code to get, use, and release cpu device_node.
> v4: restore the blank line.
> v3: fix a leaked reference.
> v2: clean up the code according to the advice of viresh.
>
>  drivers/cpufreq/pasemi-cpufreq.c | 21 +
>  1 file changed, 9 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/cpufreq/pasemi-cpufreq.c 
b/drivers/cpufreq/pasemi-cpufreq.c

> index 6b1e4ab..1f0beb7 100644
> --- a/drivers/cpufreq/pasemi-cpufreq.c
> +++ b/drivers/cpufreq/pasemi-cpufreq.c
> @@ -131,10 +131,17 @@ static int pas_cpufreq_cpu_init(struct 
cpufreq_policy *policy)

>      int err = -ENODEV;
>
>      cpu = of_get_cpu_node(policy->cpu, NULL);
> -
> -    of_node_put(cpu);
>      if (!cpu)
>          goto out;

I would have loved a blank line here :)

> +    max_freqp = of_get_property(cpu, "clock-frequency", NULL);
> +    of_node_put(cpu);
> +    if (!max_freqp) {
> +        err = -EINVAL;
> +        goto out;
> +    }
> +
> +    /* we need the freq in kHz */
> +    max_freq = *max_freqp / 1000;
>
>      dn = of_find_compatible_node(NULL, NULL, "1682m-sdc");
>      if (!dn)
> @@ -171,16 +178,6 @@ static int pas_cpufreq_cpu_init(struct 
cpufreq_policy *policy)

>      }
>
>      pr_debug("init cpufreq on CPU %d\n", policy->cpu);
> -
> -    max_freqp = of_get_property(cpu, "clock-frequency", NULL);
> -    if (!max_freqp) {
> -        err = -EINVAL;
> -        goto out_unmap_sdcpwr;
> -    }
> -
> -    /* we need the freq in kHz */
> -    max_freq = *max_freqp / 1000;
> -
>      pr_debug("max clock-frequency is at %u kHz\n", max_freq);
>      pr_debug("initializing frequency table\n");

Though, enough versions have happened now.

Acked-by: Viresh Kumar 

--
viresh


Re: [1/2] powerpc/83xx: fix use-after-free in mpc831x_usb_cfg()

2019-07-10 Thread wen.yang99
> > The immr_node variable is still being used after the of_node_put() call,
> > which may result in use-after-free.
> 
> Was any known source code analysis tool involved to point such
> a questionable implementation detail out for further software
> development considerations?

Hi Markus, 
we developed a coccinelle script to detect such problems. 
This script is still being improved.
After a period of testing, we will send it to the LMKL mailing list later.

--
Regards,
Wen

Re: [PATCH] powerpc: mm: Limit rma_size to 1TB when running without HV mode

2019-07-10 Thread Satheesh Rajendran
On Wed, Jul 10, 2019 at 03:20:18PM +1000, Suraj Jitindar Singh wrote:
> The virtual real mode addressing (VRMA) mechanism is used when a
> partition is using HPT (Hash Page Table) translation and performs
> real mode accesses (MSR[IR|DR] = 0) in non-hypervisor mode. In this
> mode effective address bits 0:23 are treated as zero (i.e. the access
> is aliased to 0) and the access is performed using an implicit 1TB SLB
> entry.
> 
> The size of the RMA (Real Memory Area) is communicated to the guest as
> the size of the first memory region in the device tree. And because of
> the mechanism described above can be expected to not exceed 1TB. In the
> event that the host erroneously represents the RMA as being larger than
> 1TB, guest accesses in real mode to memory addresses above 1TB will be
> aliased down to below 1TB. This means that a memory access performed in
> real mode may differ to one performed in virtual mode for the same memory
> address, which would likely have unintended consequences.
> 
> To avoid this outcome have the guest explicitly limit the size of the
> RMA to the current maximum, which is 1TB. This means that even if the
> first memory block is larger than 1TB, only the first 1TB should be
> accessed in real mode.
> 
> Signed-off-by: Suraj Jitindar Singh 
> ---
>  arch/powerpc/mm/book3s64/hash_utils.c | 8 
>  1 file changed, 8 insertions(+)

Hi,

Tested this patch and now Power8 compat guest boots fine with mem >1024G on 
Power9 host.

Tested-by: Satheesh Rajendran 

Host: P9; kernel: 5.2.0-00915-g5ad18b2e60b7

Before this patch:
Guest crashes..
[0.00] BUG: Kernel NULL pointer dereference at 0x0028
[0.00] Faulting instruction address: 0xc102caa0
[0.00] Oops: Kernel access of bad area, sig: 11 [#1]
[0.00] LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries
[0.00] Modules linked in:
[0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 5.2.0-03135-ge9a83bd23220 #24
[0.00] NIP:  c102caa0 LR: c102ca84 CTR: 
[0.00] REGS: c1603ba0 TRAP: 0380   Not tainted  
(5.2.0-03135-ge9a83bd23220)
[0.00] MSR:  80001033   CR: 24000428  XER: 
2000
[0.00] CFAR: c102c1d8 IRQMASK: 1 
[0.00] GPR00: c102ca84 c1603e30 c1605300 
0100 
[0.00] GPR04:   c0ff8000 
c1863dc8 
[0.00] GPR08: 2028  c0ff8000 
0009 
[0.00] GPR12:  c18f 7dc5fef0 
012e1220 
[0.00] GPR16: 012e10a0 fffd 7dc5fef0 
0130fcc0 
[0.00] GPR20: 0014 01a8 2fff 
fffd 
[0.00] GPR24: 01dc c000 c1641ed8 
c1641b78 
[0.00] GPR28:   0100 
 
[0.00] NIP [c102caa0] emergency_stack_init+0xb8/0x118
[0.00] LR [c102ca84] emergency_stack_init+0x9c/0x118
[0.00] Call Trace:
[0.00] [c1603e30] [c102ca84] 
emergency_stack_init+0x9c/0x118 (unreliable)
[0.00] [c1603e80] [c102bd54] setup_arch+0x2fc/0x388
[0.00] [c1603ef0] [c1023ccc] start_kernel+0xa4/0x660
[0.00] [c1603f90] [c000b774] start_here_common+0x1c/0x528
[0.00] Instruction dump:
[0.00] 7ffc07b4 7fc3f378 7bfd1f24 7f84e378 4bfff6e9 3f620004 3b7bc878 
7f84e378 
[0.00] 39434000 7fc3f378 e93b 7d29e82a  4bfff6c5 e93b 
7f84e378 
[0.00] random: get_random_bytes called from print_oops_end_marker+0x6c/0xa0 
with crng_init=0
[0.00] ---[ end trace  ]---
[0.00] 
[0.00] Kernel panic - not syncing: Attempted to kill the idle task!

-
With this patch:
# virsh start --console p8
Domain p8 started
Connected to domain p8
..
..
Fedora 27 (Twenty Seven)
Kernel 5.2.0-03136-gf709b0494ad9 on an ppc64le (hvc0)

atest-guest login: 
# free -g
  totalusedfree  shared  buff/cache   available
Mem:   1028   01027   0   01025
Swap: 0   0 

Regards,
-Satheesh.

> 
> diff --git a/arch/powerpc/mm/book3s64/hash_utils.c 
> b/arch/powerpc/mm/book3s64/hash_utils.c
> index 28ced26f2a00..4d0e2cce9cd5 100644
> --- a/arch/powerpc/mm/book3s64/hash_utils.c
> +++ b/arch/powerpc/mm/book3s64/hash_utils.c
> @@ -1901,11 +1901,19 @@ void hash__setup_initial_memory_limit(phys_addr_t 
> first_memblock_base,
>*
>* For guests on platforms before POWER9, we clamp the it limit to 1G
>* to avoid some funky things such as RTAS bugs etc...
> +  * On POWER9 we limit to 1TB in case the host erroneously told us that
> +  * the RMA was >1TB. Effective address bits 0:23 are treated as zero
> +  * (meaning the access is aliased to zero i.e. addr = addr % 1TB)
> +  * for vi

Re: [1/2] powerpc/83xx: fix use-after-free in mpc831x_usb_cfg()

2019-07-10 Thread Markus Elfring
> The immr_node variable is still being used after the of_node_put() call,
> which may result in use-after-free.

Was any known source code analysis tool involved to point such
a questionable implementation detail out for further software
development considerations?

Regards,
Markus