Re: [PATCHv3, resend] powerpc: mm: radix_tlb: rearrange the if-else block

2022-08-11 Thread Anders Roxell
On Thu, 11 Aug 2022 at 11:41, Michael Ellerman  wrote:
>
> Anders Roxell  writes:
> > Clang warns:
> >
> > arch/powerpc/mm/book3s64/radix_tlb.c:1191:23: error: variable 'hstart' is 
> > uninitialized when used here [-Werror,-Wuninitialized]
> > __tlbiel_va_range(hstart, hend, pid,
> >   ^~
> > arch/powerpc/mm/book3s64/radix_tlb.c:1175:23: note: initialize the variable 
> > 'hstart' to silence this warning
> > unsigned long hstart, hend;
> > ^
> >  = 0
> > arch/powerpc/mm/book3s64/radix_tlb.c:1191:31: error: variable 'hend' is 
> > uninitialized when used here [-Werror,-Wuninitialized]
> > __tlbiel_va_range(hstart, hend, pid,
> >   ^~~~
> > arch/powerpc/mm/book3s64/radix_tlb.c:1175:29: note: initialize the variable 
> > 'hend' to silence this warning
> > unsigned long hstart, hend;
> >   ^
> >= 0
> > 2 errors generated.
>
> Which version & config are you building?

clang-13, clang-14 and clang-nightly, configs are cell_defconfig and
maple_defconfig

I'm building with tuxmake [1] like this:
$ tuxmake --runtime podman --target-arch powerpc --toolchain clang-14
--kconfig cell_defconfig

Cheers,
Anders
[1] https://tuxmake.org/


[PATCHv3, resend] powerpc: mm: radix_tlb: rearrange the if-else block

2022-08-10 Thread Anders Roxell
Clang warns:

arch/powerpc/mm/book3s64/radix_tlb.c:1191:23: error: variable 'hstart' is 
uninitialized when used here [-Werror,-Wuninitialized]
__tlbiel_va_range(hstart, hend, pid,
  ^~
arch/powerpc/mm/book3s64/radix_tlb.c:1175:23: note: initialize the variable 
'hstart' to silence this warning
unsigned long hstart, hend;
^
 = 0
arch/powerpc/mm/book3s64/radix_tlb.c:1191:31: error: variable 'hend' is 
uninitialized when used here [-Werror,-Wuninitialized]
__tlbiel_va_range(hstart, hend, pid,
  ^~~~
arch/powerpc/mm/book3s64/radix_tlb.c:1175:29: note: initialize the variable 
'hend' to silence this warning
unsigned long hstart, hend;
  ^
   = 0
2 errors generated.

Rework the 'if (IS_ENABLE(CONFIG_TRANSPARENT_HUGEPAGE))' so hstart/hend
always gets initialized, this will silence the warnings. That will also
simplify the 'else' path. Clang is getting confused with these warnings,
but the warnings is a false-positive.

Suggested-by: Arnd Bergmann 
Suggested-by: Nathan Chancellor 
Reviewed-by: Christophe Leroy 
Reviewed-by: Nathan Chancellor 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/mm/book3s64/radix_tlb.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/radix_tlb.c 
b/arch/powerpc/mm/book3s64/radix_tlb.c
index 4e29b619578c..6d7a1ef723e6 100644
--- a/arch/powerpc/mm/book3s64/radix_tlb.c
+++ b/arch/powerpc/mm/book3s64/radix_tlb.c
@@ -1179,15 +1179,12 @@ static inline void __radix__flush_tlb_range(struct 
mm_struct *mm,
}
}
} else {
-   bool hflush = false;
+   bool hflush;
unsigned long hstart, hend;
 
-   if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
-   hstart = (start + PMD_SIZE - 1) & PMD_MASK;
-   hend = end & PMD_MASK;
-   if (hstart < hend)
-   hflush = true;
-   }
+   hstart = (start + PMD_SIZE - 1) & PMD_MASK;
+   hend = end & PMD_MASK;
+   hflush = IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && hstart < 
hend;
 
if (type == FLUSH_TYPE_LOCAL) {
asm volatile("ptesync": : :"memory");
-- 
2.35.1



[PATCHv2 2/3] powerpc: fix build errors

2022-02-24 Thread Anders Roxell
Building tinyconfig with gcc (Debian 11.2.0-16) and assembler (Debian
2.37.90.20220207) the following build error shows up:

 {standard input}: Assembler messages:
 {standard input}:1190: Error: unrecognized opcode: `stbcix'
 {standard input}:1433: Error: unrecognized opcode: `lwzcix'
 {standard input}:1453: Error: unrecognized opcode: `stbcix'
 {standard input}:1460: Error: unrecognized opcode: `stwcix'
 {standard input}:1596: Error: unrecognized opcode: `stbcix'
 ...

Rework to add assembler directives [1] around the instruction. Going
through the them one by one shows that the changes should be safe.  Like
__get_user_atomic_128_aligned() is only called in p9_hmi_special_emu(),
which according to the name is specific to power9.  And __raw_rm_read*()
are only called in things that are powernv or book3s_hv specific.

[1] 
https://sourceware.org/binutils/docs/as/PowerPC_002dPseudo.html#PowerPC_002dPseudo

Cc: 
Co-developed-by: Arnd Bergmann 
Signed-off-by: Arnd Bergmann 
Reviewed-by: Segher Boessenkool 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/include/asm/io.h| 40 ++--
 arch/powerpc/include/asm/uaccess.h   |  3 +++
 arch/powerpc/platforms/powernv/rng.c |  6 -
 3 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h
index beba4979bff9..fee979d3a1aa 100644
--- a/arch/powerpc/include/asm/io.h
+++ b/arch/powerpc/include/asm/io.h
@@ -359,25 +359,37 @@ static inline void __raw_writeq_be(unsigned long v, 
volatile void __iomem *addr)
  */
 static inline void __raw_rm_writeb(u8 val, volatile void __iomem *paddr)
 {
-   __asm__ __volatile__("stbcix %0,0,%1"
+   __asm__ __volatile__(".machine push;   \
+ .machine power6; \
+ stbcix %0,0,%1;  \
+ .machine pop;"
: : "r" (val), "r" (paddr) : "memory");
 }
 
 static inline void __raw_rm_writew(u16 val, volatile void __iomem *paddr)
 {
-   __asm__ __volatile__("sthcix %0,0,%1"
+   __asm__ __volatile__(".machine push;   \
+ .machine power6; \
+ sthcix %0,0,%1;  \
+ .machine pop;"
: : "r" (val), "r" (paddr) : "memory");
 }
 
 static inline void __raw_rm_writel(u32 val, volatile void __iomem *paddr)
 {
-   __asm__ __volatile__("stwcix %0,0,%1"
+   __asm__ __volatile__(".machine push;   \
+ .machine power6; \
+ stwcix %0,0,%1;  \
+ .machine pop;"
: : "r" (val), "r" (paddr) : "memory");
 }
 
 static inline void __raw_rm_writeq(u64 val, volatile void __iomem *paddr)
 {
-   __asm__ __volatile__("stdcix %0,0,%1"
+   __asm__ __volatile__(".machine push;   \
+ .machine power6; \
+ stdcix %0,0,%1;  \
+ .machine pop;"
: : "r" (val), "r" (paddr) : "memory");
 }
 
@@ -389,7 +401,10 @@ static inline void __raw_rm_writeq_be(u64 val, volatile 
void __iomem *paddr)
 static inline u8 __raw_rm_readb(volatile void __iomem *paddr)
 {
u8 ret;
-   __asm__ __volatile__("lbzcix %0,0, %1"
+   __asm__ __volatile__(".machine push;   \
+ .machine power6; \
+ lbzcix %0,0, %1; \
+ .machine pop;"
 : "=r" (ret) : "r" (paddr) : "memory");
return ret;
 }
@@ -397,7 +412,10 @@ static inline u8 __raw_rm_readb(volatile void __iomem 
*paddr)
 static inline u16 __raw_rm_readw(volatile void __iomem *paddr)
 {
u16 ret;
-   __asm__ __volatile__("lhzcix %0,0, %1"
+   __asm__ __volatile__(".machine push;   \
+ .machine power6; \
+ lhzcix %0,0, %1; \
+ .machine pop;"
 : "=r" (ret) : "r" (paddr) : "memory");
return ret;
 }
@@ -405,7 +423,10 @@ static inline u16 __raw_rm_readw(volatile void __iomem 
*paddr)
 static inline u32 __raw_rm_readl(volatile void __iomem *paddr)
 {
u32 ret;
-   __asm__ __volatile__("lwzcix %0,0, %1"
+   __asm__ __volatile__(".machine push;   \
+ .machine power6; \
+ lwzcix %0,0, %1; \
+ .machine pop;"
 : "=r" (ret) : "r" (paddr) : "memory");
return ret;
 }
@@ -413,7 +434,10 @@ static inline u32 __raw_rm_readl(

[PATCHv2 1/3] powerpc: lib: sstep: fix 'sthcx' instruction

2022-02-24 Thread Anders Roxell
Looks like there been a copy paste mistake when added the instruction
'stbcx' twice and one was probably meant to be 'sthcx'.
Changing to 'sthcx' from 'stbcx'.

Cc:  # v4.13+
Fixes: 350779a29f11 ("powerpc: Handle most loads and stores in instruction 
emulation code")
Reported-by: Arnd Bergmann 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/lib/sstep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index bd3734d5be89..d2d29243fa6d 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -3389,7 +3389,7 @@ int emulate_loadstore(struct pt_regs *regs, struct 
instruction_op *op)
__put_user_asmx(op->val, ea, err, "stbcx.", cr);
break;
case 2:
-   __put_user_asmx(op->val, ea, err, "stbcx.", cr);
+   __put_user_asmx(op->val, ea, err, "sthcx.", cr);
break;
 #endif
case 4:
-- 
2.34.1



[PATCHv2 3/3] powerpc: lib: sstep: fix build errors

2022-02-24 Thread Anders Roxell
Building tinyconfig with gcc (Debian 11.2.0-16) and assembler (Debian
2.37.90.20220207) the following build error shows up:

{standard input}: Assembler messages:
{standard input}:10576: Error: unrecognized opcode: `stbcx.'
{standard input}:10680: Error: unrecognized opcode: `lharx'
{standard input}:10694: Error: unrecognized opcode: `lbarx'

Rework to add assembler directives [1] around the instruction.  The
problem with this might be that we can trick a power6 into
single-stepping through an stbcx. for instance, and it will execute that
in kernel mode.

[1] 
https://sourceware.org/binutils/docs/as/PowerPC_002dPseudo.html#PowerPC_002dPseudo

Cc: 
Co-developed-by: Arnd Bergmann 
Signed-off-by: Arnd Bergmann 
Reviewed-by: Segher Boessenkool 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/lib/sstep.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index d2d29243fa6d..f3ed80513a90 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -1097,7 +1097,10 @@ NOKPROBE_SYMBOL(emulate_dcbz);
 
 #define __put_user_asmx(x, addr, err, op, cr)  \
__asm__ __volatile__(   \
+   ".machine push\n"   \
+   ".machine power8\n" \
"1: " op " %2,0,%3\n"   \
+   ".machine pop\n"\
"   mfcr%1\n"   \
"2:\n"  \
".section .fixup,\"ax\"\n"  \
@@ -1110,7 +1113,10 @@ NOKPROBE_SYMBOL(emulate_dcbz);
 
 #define __get_user_asmx(x, addr, err, op)  \
__asm__ __volatile__(   \
+   ".machine push\n"   \
+   ".machine power8\n" \
"1: "op" %1,0,%2\n" \
+   ".machine pop\n"\
"2:\n"  \
".section .fixup,\"ax\"\n"  \
"3: li  %0,%3\n"\
-- 
2.34.1



Re: [PATCH 2/3] powerpc: fix build errors

2022-02-24 Thread Anders Roxell
On Thu, 24 Feb 2022 at 13:39, Michael Ellerman  wrote:
>
> Hi Anders,

Hi Michael,

>
> Thanks for these, just a few comments below ...

I will resolve the comments below and resend a v2 shortly.

Cheers,
Anders

>
> Anders Roxell  writes:
> > Building tinyconfig with gcc (Debian 11.2.0-16) and assembler (Debian
> > 2.37.90.20220207) the following build error shows up:
> >
> >  {standard input}: Assembler messages:
> >  {standard input}:1190: Error: unrecognized opcode: `stbcix'
> >  {standard input}:1433: Error: unrecognized opcode: `lwzcix'
> >  {standard input}:1453: Error: unrecognized opcode: `stbcix'
> >  {standard input}:1460: Error: unrecognized opcode: `stwcix'
> >  {standard input}:1596: Error: unrecognized opcode: `stbcix'
> >  ...
> >
> > Rework to add assembler directives [1] around the instruction. Going
> > through the them one by one shows that the changes should be safe.  Like
> > __get_user_atomic_128_aligned() is only called in p9_hmi_special_emu(),
> > which according to the name is specific to power9.  And __raw_rm_read*()
> > are only called in things that are powernv or book3s_hv specific.
> >
> > [1] 
> > https://sourceware.org/binutils/docs/as/PowerPC_002dPseudo.html#PowerPC_002dPseudo
> >
> > Cc: 
> > Co-developed-by: Arnd Bergmann 
> > Signed-off-by: Arnd Bergmann 
> > Signed-off-by: Anders Roxell 
> > ---
> >  arch/powerpc/include/asm/io.h| 46 +++-
> >  arch/powerpc/include/asm/uaccess.h   |  3 ++
> >  arch/powerpc/platforms/powernv/rng.c |  6 +++-
> >  3 files changed, 46 insertions(+), 9 deletions(-)
> >
> > diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h
> > index beba4979bff9..5ff6dec489f8 100644
> > --- a/arch/powerpc/include/asm/io.h
> > +++ b/arch/powerpc/include/asm/io.h
> > @@ -359,25 +359,37 @@ static inline void __raw_writeq_be(unsigned long v, 
> > volatile void __iomem *addr)
> >   */
> >  static inline void __raw_rm_writeb(u8 val, volatile void __iomem *paddr)
> >  {
> > - __asm__ __volatile__("stbcix %0,0,%1"
> > + __asm__ __volatile__(".machine \"push\"\n"
> > +  ".machine \"power6\"\n"
> > +  "stbcix %0,0,%1\n"
> > +  ".machine \"pop\"\n"
> >   : : "r" (val), "r" (paddr) : "memory");
>
> As Segher said it'd be cleaner without the embedded quotes.
>
> > @@ -441,7 +465,10 @@ static inline unsigned int name(unsigned int port) 
> >   \
> >   unsigned int x; \
> >   __asm__ __volatile__(   \
> >   "sync\n"\
> > + ".machine \"push\"\n"   \
> > + ".machine \"power6\"\n" \
> >   "0:"op "%0,0,%1\n"  \
> > + ".machine \"pop\"\n"\
> >   "1: twi 0,%0,0\n"   \
> >   "2: isync\n"\
> >   "3: nop\n"  \
> > @@ -465,7 +492,10 @@ static inline void name(unsigned int val, unsigned int 
> > port) \
> >  {\
> >   __asm__ __volatile__(   \
> >   "sync\n"\
> > + ".machine \"push\"\n"   \
> > + ".machine \"power6\"\n" \
> >   "0:" op " %0,0,%1\n"\
> > + ".machine \"pop\"\n"\
> >   "1: sync\n" \
> >   "2:\n"  \
> >   EX_TABLE(0b, 2b)\
>
> It's not visible from the diff, but the above two are __do_in_asm and
> __do_out_asm and are inside an ifdef CONFIG_PPC32.
>
> AFAICS they're only used for:
>
> __do_in_asm(_rec_inb, "lbzx")
> __do_in_asm(_rec_inw, "lhbrx")
> __do_in_asm(_rec_inl, "lwbrx")
> __do_out_asm(_rec_outb, "stbx")
> __do_out_asm(_rec_outw, "sthbrx")
> __do_out_asm(_rec_outl, &

[PATCH 2/3] powerpc: fix build errors

2022-02-23 Thread Anders Roxell
Building tinyconfig with gcc (Debian 11.2.0-16) and assembler (Debian
2.37.90.20220207) the following build error shows up:

 {standard input}: Assembler messages:
 {standard input}:1190: Error: unrecognized opcode: `stbcix'
 {standard input}:1433: Error: unrecognized opcode: `lwzcix'
 {standard input}:1453: Error: unrecognized opcode: `stbcix'
 {standard input}:1460: Error: unrecognized opcode: `stwcix'
 {standard input}:1596: Error: unrecognized opcode: `stbcix'
 ...

Rework to add assembler directives [1] around the instruction. Going
through the them one by one shows that the changes should be safe.  Like
__get_user_atomic_128_aligned() is only called in p9_hmi_special_emu(),
which according to the name is specific to power9.  And __raw_rm_read*()
are only called in things that are powernv or book3s_hv specific.

[1] 
https://sourceware.org/binutils/docs/as/PowerPC_002dPseudo.html#PowerPC_002dPseudo

Cc: 
Co-developed-by: Arnd Bergmann 
Signed-off-by: Arnd Bergmann 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/include/asm/io.h| 46 +++-
 arch/powerpc/include/asm/uaccess.h   |  3 ++
 arch/powerpc/platforms/powernv/rng.c |  6 +++-
 3 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h
index beba4979bff9..5ff6dec489f8 100644
--- a/arch/powerpc/include/asm/io.h
+++ b/arch/powerpc/include/asm/io.h
@@ -359,25 +359,37 @@ static inline void __raw_writeq_be(unsigned long v, 
volatile void __iomem *addr)
  */
 static inline void __raw_rm_writeb(u8 val, volatile void __iomem *paddr)
 {
-   __asm__ __volatile__("stbcix %0,0,%1"
+   __asm__ __volatile__(".machine \"push\"\n"
+".machine \"power6\"\n"
+"stbcix %0,0,%1\n"
+".machine \"pop\"\n"
: : "r" (val), "r" (paddr) : "memory");
 }
 
 static inline void __raw_rm_writew(u16 val, volatile void __iomem *paddr)
 {
-   __asm__ __volatile__("sthcix %0,0,%1"
+   __asm__ __volatile__(".machine \"push\"\n"
+".machine \"power6\"\n"
+"sthcix %0,0,%1\n"
+".machine \"pop\"\n"
: : "r" (val), "r" (paddr) : "memory");
 }
 
 static inline void __raw_rm_writel(u32 val, volatile void __iomem *paddr)
 {
-   __asm__ __volatile__("stwcix %0,0,%1"
+   __asm__ __volatile__(".machine \"push\"\n"
+".machine \"power6\"\n"
+"stwcix %0,0,%1\n"
+".machine \"pop\"\n"
: : "r" (val), "r" (paddr) : "memory");
 }
 
 static inline void __raw_rm_writeq(u64 val, volatile void __iomem *paddr)
 {
-   __asm__ __volatile__("stdcix %0,0,%1"
+   __asm__ __volatile__(".machine \"push\"\n"
+".machine \"power6\"\n"
+"stdcix %0,0,%1\n"
+".machine \"pop\"\n"
: : "r" (val), "r" (paddr) : "memory");
 }
 
@@ -389,7 +401,10 @@ static inline void __raw_rm_writeq_be(u64 val, volatile 
void __iomem *paddr)
 static inline u8 __raw_rm_readb(volatile void __iomem *paddr)
 {
u8 ret;
-   __asm__ __volatile__("lbzcix %0,0, %1"
+   __asm__ __volatile__(".machine \"push\"\n"
+".machine \"power6\"\n"
+"lbzcix %0,0, %1\n"
+".machine \"pop\"\n"
 : "=r" (ret) : "r" (paddr) : "memory");
return ret;
 }
@@ -397,7 +412,10 @@ static inline u8 __raw_rm_readb(volatile void __iomem 
*paddr)
 static inline u16 __raw_rm_readw(volatile void __iomem *paddr)
 {
u16 ret;
-   __asm__ __volatile__("lhzcix %0,0, %1"
+   __asm__ __volatile__(".machine \"push\"\n"
+".machine \"power6\"\n"
+"lhzcix %0,0, %1\n"
+".machine \"pop\"\n"
 : "=r" (ret) : "r" (paddr) : "memory");
return ret;
 }
@@ -405,7 +423,10 @@ static inline u16 __raw_rm_readw(volatile void __iomem 
*paddr)
 static inline u32 __raw_rm_readl(volatile void __iomem *paddr)
 {
u32 ret;
-   __asm__ __volatile__("lwzcix %0,0,

[PATCH 1/3] powerpc: lib: sstep: fix 'sthcx' instruction

2022-02-23 Thread Anders Roxell
Looks like there been a copy paste mistake when added the instruction
'stbcx' twice and one was probably meant to be 'sthcx'.
Changing to 'sthcx' from 'stbcx'.

Cc:  # v4.13+
Fixes: 350779a29f11 ("powerpc: Handle most loads and stores in instruction 
emulation code")
Reported-by: Arnd Bergmann 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/lib/sstep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index bd3734d5be89..d2d29243fa6d 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -3389,7 +3389,7 @@ int emulate_loadstore(struct pt_regs *regs, struct 
instruction_op *op)
__put_user_asmx(op->val, ea, err, "stbcx.", cr);
break;
case 2:
-   __put_user_asmx(op->val, ea, err, "stbcx.", cr);
+   __put_user_asmx(op->val, ea, err, "sthcx.", cr);
break;
 #endif
case 4:
-- 
2.34.1



[PATCH 3/3] powerpc: lib: sstep: fix build errors

2022-02-23 Thread Anders Roxell
Building tinyconfig with gcc (Debian 11.2.0-16) and assembler (Debian
2.37.90.20220207) the following build error shows up:

{standard input}: Assembler messages:
{standard input}:10576: Error: unrecognized opcode: `stbcx.'
{standard input}:10680: Error: unrecognized opcode: `lharx'
{standard input}:10694: Error: unrecognized opcode: `lbarx'

Rework to add assembler directives [1] around the instruction.  The
problem with this might be that we can trick a power6 into
single-stepping through an stbcx. for instance, and it will execute that
in kernel mode.

[1] 
https://sourceware.org/binutils/docs/as/PowerPC_002dPseudo.html#PowerPC_002dPseudo

Cc: 
Co-developed-by: Arnd Bergmann 
Signed-off-by: Arnd Bergmann 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/lib/sstep.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index d2d29243fa6d..b9f43bbdd55a 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -1097,7 +1097,10 @@ NOKPROBE_SYMBOL(emulate_dcbz);
 
 #define __put_user_asmx(x, addr, err, op, cr)  \
__asm__ __volatile__(   \
+   ".machine \"push\"\n"   \
+   ".machine \"power8\"\n" \
"1: " op " %2,0,%3\n"   \
+   ".machine \"pop\"\n"\
"   mfcr%1\n"   \
"2:\n"  \
".section .fixup,\"ax\"\n"  \
@@ -1110,7 +1113,10 @@ NOKPROBE_SYMBOL(emulate_dcbz);
 
 #define __get_user_asmx(x, addr, err, op)  \
__asm__ __volatile__(   \
+   ".machine \"push\"\n"   \
+   ".machine \"power8\"\n" \
"1: "op" %1,0,%2\n" \
+   ".machine \"pop\"\n"\
"2:\n"  \
".section .fixup,\"ax\"\n"  \
"3: li  %0,%3\n"\
-- 
2.34.1



[PATCHv2] powerpc/lib/sstep: fix 'ptesync' build error

2022-02-10 Thread Anders Roxell
Building tinyconfig with gcc (Debian 11.2.0-16) and assembler (Debian
2.37.90.20220207) the following build error shows up:

{standard input}: Assembler messages:
{standard input}:2088: Error: unrecognized opcode: `ptesync'
make[3]: *** [/builds/linux/scripts/Makefile.build:287: 
arch/powerpc/lib/sstep.o] Error 1

Add the 'ifdef CONFIG_PPC64' around the 'ptesync' in function
'emulate_update_regs()' to like it is in 'analyse_instr()'. Since it looks like
it got dropped inadvertently by commit 3cdfcbfd32b9 ("powerpc: Change
analyse_instr so it doesn't modify *regs").

Cc: sta...@vger.kernel.org # v4.14+
Fixes: 3cdfcbfd32b9 ("powerpc: Change analyse_instr so it doesn't modify *regs")
Suggested-by: Arnd Bergmann 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/lib/sstep.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index a94b0cd0bdc5..bd3734d5be89 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -3264,12 +3264,14 @@ void emulate_update_regs(struct pt_regs *regs, struct 
instruction_op *op)
case BARRIER_EIEIO:
eieio();
break;
+#ifdef CONFIG_PPC64
case BARRIER_LWSYNC:
asm volatile("lwsync" : : : "memory");
break;
case BARRIER_PTESYNC:
asm volatile("ptesync" : : : "memory");
break;
+#endif
}
break;
 
-- 
2.34.1



[PATCH] powerpc/lib/sstep: fix 'ptesync' build error

2022-02-10 Thread Anders Roxell
Building tinyconfig with gcc (Debian 11.2.0-16) and assembler (Debian
2.37.90.20220207) the following build error shows up:

{standard input}: Assembler messages:
{standard input}:2088: Error: unrecognized opcode: `ptesync'
make[3]: *** [/builds/linux/scripts/Makefile.build:287: 
arch/powerpc/lib/sstep.o] Error 1

Re-add the ifdef __powerpc64__ around the 'ptesync' in function
'emulate_update_regs()' to like it is in 'analyse_instr()'. Since it looks like
it got dropped inadvertently by commit 3cdfcbfd32b9 ("powerpc: Change
analyse_instr so it doesn't modify *regs").

Cc: sta...@vger.kernel.org # v4.14+
Fixes: 3cdfcbfd32b9 ("powerpc: Change analyse_instr so it doesn't modify *regs")
Suggested-by: Arnd Bergmann 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/lib/sstep.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index a94b0cd0bdc5..d23772f91a36 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -3264,12 +3264,14 @@ void emulate_update_regs(struct pt_regs *regs, struct 
instruction_op *op)
case BARRIER_EIEIO:
eieio();
break;
+#ifdef __powerpc64__
case BARRIER_LWSYNC:
asm volatile("lwsync" : : : "memory");
break;
case BARRIER_PTESYNC:
asm volatile("ptesync" : : : "memory");
break;
+#endif
}
break;
 
-- 
2.34.1



[PATCHv3] powerpc: mm: radix_tlb: rearrange the if-else block

2022-01-28 Thread Anders Roxell
Clang warns:

arch/powerpc/mm/book3s64/radix_tlb.c:1191:23: error: variable 'hstart' is 
uninitialized when used here [-Werror,-Wuninitialized]
__tlbiel_va_range(hstart, hend, pid,
  ^~
arch/powerpc/mm/book3s64/radix_tlb.c:1175:23: note: initialize the variable 
'hstart' to silence this warning
unsigned long hstart, hend;
^
 = 0
arch/powerpc/mm/book3s64/radix_tlb.c:1191:31: error: variable 'hend' is 
uninitialized when used here [-Werror,-Wuninitialized]
__tlbiel_va_range(hstart, hend, pid,
  ^~~~
arch/powerpc/mm/book3s64/radix_tlb.c:1175:29: note: initialize the variable 
'hend' to silence this warning
unsigned long hstart, hend;
  ^
   = 0
2 errors generated.

Rework the 'if (IS_ENABLE(CONFIG_TRANSPARENT_HUGEPAGE))' so hstart/hend
always gets initialized, this will silence the warnings. That will also
simplify the 'else' path. Clang is getting confused with these warnings,
but the warnings is a false-positive.

Suggested-by: Arnd Bergmann 
Suggested-by: Nathan Chancellor 
Reviewed-by: Christophe Leroy 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/mm/book3s64/radix_tlb.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/radix_tlb.c 
b/arch/powerpc/mm/book3s64/radix_tlb.c
index 7724af19ed7e..5172d5cec2c0 100644
--- a/arch/powerpc/mm/book3s64/radix_tlb.c
+++ b/arch/powerpc/mm/book3s64/radix_tlb.c
@@ -1171,15 +1171,12 @@ static inline void __radix__flush_tlb_range(struct 
mm_struct *mm,
}
}
} else {
-   bool hflush = false;
+   bool hflush;
unsigned long hstart, hend;
 
-   if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
-   hstart = (start + PMD_SIZE - 1) & PMD_MASK;
-   hend = end & PMD_MASK;
-   if (hstart < hend)
-   hflush = true;
-   }
+   hstart = (start + PMD_SIZE - 1) & PMD_MASK;
+   hend = end & PMD_MASK;
+   hflush = IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && hstart < 
hend;
 
if (type == FLUSH_TYPE_LOCAL) {
asm volatile("ptesync": : :"memory");
-- 
2.34.1



Re: [PATCHv2] powerpc: mm: radix_tlb: rearrange the if-else block

2022-01-28 Thread Anders Roxell
On Fri, 28 Jan 2022 at 11:14, Christophe Leroy
 wrote:
>
>
>
> Le 28/01/2022 à 11:08, Anders Roxell a écrit :
> > Clang warns:
> >
> > arch/powerpc/mm/book3s64/radix_tlb.c:1191:23: error: variable 'hstart' is 
> > uninitialized when used here [-Werror,-Wuninitialized]
> >  __tlbiel_va_range(hstart, hend, pid,
> >^~
> > arch/powerpc/mm/book3s64/radix_tlb.c:1175:23: note: initialize the variable 
> > 'hstart' to silence this warning
> >  unsigned long hstart, hend;
> >  ^
> >   = 0
> > arch/powerpc/mm/book3s64/radix_tlb.c:1191:31: error: variable 'hend' is 
> > uninitialized when used here [-Werror,-Wuninitialized]
> >  __tlbiel_va_range(hstart, hend, pid,
> >^~~~
> > arch/powerpc/mm/book3s64/radix_tlb.c:1175:29: note: initialize the variable 
> > 'hend' to silence this warning
> >  unsigned long hstart, hend;
> >^
> > = 0
> > 2 errors generated.
> >
> > Rework the 'if (IS_ENABLE(CONFIG_TRANSPARENT_HUGEPAGE))' so hstart/hend
> > always gets initialized, this will silence the warnings. That will also
> > simplify the 'else' path. Clang is getting confused with these warnings,
> > but the warnings is a false-positive.
> >
> > Suggested-by: Arnd Bergmann 
> > Suggested-by: Nathan Chancellor 
> > Signed-off-by: Anders Roxell 
> > ---
> >   arch/powerpc/mm/book3s64/radix_tlb.c | 9 +++--
> >   1 file changed, 3 insertions(+), 6 deletions(-)
> >
> > diff --git a/arch/powerpc/mm/book3s64/radix_tlb.c 
> > b/arch/powerpc/mm/book3s64/radix_tlb.c
> > index 7724af19ed7e..7d65965a0688 100644
> > --- a/arch/powerpc/mm/book3s64/radix_tlb.c
> > +++ b/arch/powerpc/mm/book3s64/radix_tlb.c
> > @@ -1174,12 +1174,9 @@ static inline void __radix__flush_tlb_range(struct 
> > mm_struct *mm,
> >   bool hflush = false;
>
> You should then remove the default initialisation of hflush to false
> which has become pointless.
>
> With that fixed,
>
> Reviewed-by: Christophe Leroy 

Thank you for the review.
I will send a v3 shortly with that fixed.

Cheers,
Anders


[PATCHv2] powerpc: mm: radix_tlb: rearrange the if-else block

2022-01-28 Thread Anders Roxell
Clang warns:

arch/powerpc/mm/book3s64/radix_tlb.c:1191:23: error: variable 'hstart' is 
uninitialized when used here [-Werror,-Wuninitialized]
__tlbiel_va_range(hstart, hend, pid,
  ^~
arch/powerpc/mm/book3s64/radix_tlb.c:1175:23: note: initialize the variable 
'hstart' to silence this warning
unsigned long hstart, hend;
^
 = 0
arch/powerpc/mm/book3s64/radix_tlb.c:1191:31: error: variable 'hend' is 
uninitialized when used here [-Werror,-Wuninitialized]
__tlbiel_va_range(hstart, hend, pid,
  ^~~~
arch/powerpc/mm/book3s64/radix_tlb.c:1175:29: note: initialize the variable 
'hend' to silence this warning
unsigned long hstart, hend;
  ^
   = 0
2 errors generated.

Rework the 'if (IS_ENABLE(CONFIG_TRANSPARENT_HUGEPAGE))' so hstart/hend
always gets initialized, this will silence the warnings. That will also
simplify the 'else' path. Clang is getting confused with these warnings,
but the warnings is a false-positive.

Suggested-by: Arnd Bergmann 
Suggested-by: Nathan Chancellor 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/mm/book3s64/radix_tlb.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/radix_tlb.c 
b/arch/powerpc/mm/book3s64/radix_tlb.c
index 7724af19ed7e..7d65965a0688 100644
--- a/arch/powerpc/mm/book3s64/radix_tlb.c
+++ b/arch/powerpc/mm/book3s64/radix_tlb.c
@@ -1174,12 +1174,9 @@ static inline void __radix__flush_tlb_range(struct 
mm_struct *mm,
bool hflush = false;
unsigned long hstart, hend;
 
-   if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
-   hstart = (start + PMD_SIZE - 1) & PMD_MASK;
-   hend = end & PMD_MASK;
-   if (hstart < hend)
-   hflush = true;
-   }
+   hstart = (start + PMD_SIZE - 1) & PMD_MASK;
+   hend = end & PMD_MASK;
+   hflush = IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && hstart < 
hend;
 
if (type == FLUSH_TYPE_LOCAL) {
asm volatile("ptesync": : :"memory");
-- 
2.34.1



[PATCH] powerpc: platforms: cell: pervasive: fix clang -Wimplicit-fallthrough

2021-12-07 Thread Anders Roxell
Clang warns:

arch/powerpc/platforms/cell/pervasive.c:81:2: error: unannotated fall-through 
between switch labels [-Werror,-Wimplicit-fallthrough]
case SRR1_WAKEEE:
^
arch/powerpc/platforms/cell/pervasive.c:81:2: note: insert 'break;' to avoid 
fall-through
case SRR1_WAKEEE:
^
break;
1 error generated.

Clang is more pedantic than GCC, which does not warn when failing
through to a case that is just break or return. Clang's version
is more in line with the kernel's own stance in deprecated.rst.
Add athe missing break to silence the warning.

Fixes: 6e83985b0f6e ("powerpc/cbe: Do not process external or decremeter 
interrupts from sreset")
Reported-by: Naresh Kamboju 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/platforms/cell/pervasive.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/platforms/cell/pervasive.c 
b/arch/powerpc/platforms/cell/pervasive.c
index 5b9a7e9f144b..dff8d5e7ab82 100644
--- a/arch/powerpc/platforms/cell/pervasive.c
+++ b/arch/powerpc/platforms/cell/pervasive.c
@@ -78,6 +78,7 @@ static int cbe_system_reset_exception(struct pt_regs *regs)
switch (regs->msr & SRR1_WAKEMASK) {
case SRR1_WAKEDEC:
set_dec(1);
+   break;
case SRR1_WAKEEE:
/*
 * Handle these when interrupts get re-enabled and we take
-- 
2.33.0



[PATCH] powerpc: mm: radix_tlb: rearrange the if-else block

2021-11-25 Thread Anders Roxell
Clang warns:

arch/powerpc/mm/book3s64/radix_tlb.c:1191:23: error: variable 'hstart' is 
uninitialized when used here [-Werror,-Wuninitialized]
__tlbiel_va_range(hstart, hend, pid,
  ^~
arch/powerpc/mm/book3s64/radix_tlb.c:1175:23: note: initialize the variable 
'hstart' to silence this warning
unsigned long hstart, hend;
^
 = 0
arch/powerpc/mm/book3s64/radix_tlb.c:1191:31: error: variable 'hend' is 
uninitialized when used here [-Werror,-Wuninitialized]
__tlbiel_va_range(hstart, hend, pid,
  ^~~~
arch/powerpc/mm/book3s64/radix_tlb.c:1175:29: note: initialize the variable 
'hend' to silence this warning
unsigned long hstart, hend;
  ^
   = 0
2 errors generated.

Rework the if-else to pull the 'IS_ENABLE(CONFIG_TRANSPARENT_HUGEPAGE)'
check one level up, this will silent the warnings. That will also
simplify the 'else' path. Clang is getting confused with these warnings,
but the warnings is a false-positive.

Suggested-by: Arnd Bergmann 
Signed-off-by: Anders Roxell 
---
 arch/powerpc/mm/book3s64/radix_tlb.c | 31 +---
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/radix_tlb.c 
b/arch/powerpc/mm/book3s64/radix_tlb.c
index 7724af19ed7e..e494a45ce1b4 100644
--- a/arch/powerpc/mm/book3s64/radix_tlb.c
+++ b/arch/powerpc/mm/book3s64/radix_tlb.c
@@ -1170,16 +1170,14 @@ static inline void __radix__flush_tlb_range(struct 
mm_struct *mm,
_tlbiel_pid_multicast(mm, pid, RIC_FLUSH_ALL);
}
}
-   } else {
+   } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
bool hflush = false;
unsigned long hstart, hend;
 
-   if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
-   hstart = (start + PMD_SIZE - 1) & PMD_MASK;
-   hend = end & PMD_MASK;
-   if (hstart < hend)
-   hflush = true;
-   }
+   hstart = (start + PMD_SIZE - 1) & PMD_MASK;
+   hend = end & PMD_MASK;
+   if (hstart < hend)
+   hflush = true;
 
if (type == FLUSH_TYPE_LOCAL) {
asm volatile("ptesync": : :"memory");
@@ -1207,6 +1205,25 @@ static inline void __radix__flush_tlb_range(struct 
mm_struct *mm,
_tlbiel_va_range_multicast(mm,
hstart, hend, pid, PMD_SIZE, 
MMU_PAGE_2M, flush_pwc);
}
+   } else {
+
+   if (type == FLUSH_TYPE_LOCAL) {
+   asm volatile("ptesync" : : : "memory");
+   if (flush_pwc)
+   /* For PWC, only one flush is needed */
+   __tlbiel_pid(pid, 0, RIC_FLUSH_PWC);
+   __tlbiel_va_range(start, end, pid, page_size, 
mmu_virtual_psize);
+   ppc_after_tlbiel_barrier();
+   } else if (cputlb_use_tlbie()) {
+   asm volatile("ptesync" : : : "memory");
+   if (flush_pwc)
+   __tlbie_pid(pid, RIC_FLUSH_PWC);
+   __tlbie_va_range(start, end, pid, page_size, 
mmu_virtual_psize);
+   asm volatile("eieio; tlbsync; ptesync" : : : "memory");
+   } else {
+   _tlbiel_va_range_multicast(mm,
+   start, end, pid, page_size, 
mmu_virtual_psize, flush_pwc);
+   }
}
 out:
preempt_enable();
-- 
2.33.0



[PATCH] arm64: defconfig: enable modern virtio pci device

2021-02-10 Thread Anders Roxell
Since patch ("virtio-pci: introduce modern device module") got added it
is not possible to boot a defconfig kernel in qemu with a virtio pci
device.  Add CONFIG_VIRTIO_PCI_MODERN=y fragment makes the kernel able
to boot.

Signed-off-by: Anders Roxell 
---
 arch/arm/configs/multi_v7_defconfig | 1 +
 arch/arm64/configs/defconfig| 1 +
 arch/mips/configs/loongson3_defconfig   | 1 +
 arch/mips/configs/malta_kvm_guest_defconfig | 1 +
 arch/powerpc/configs/guest.config   | 1 +
 arch/riscv/configs/defconfig| 1 +
 arch/riscv/configs/rv32_defconfig   | 1 +
 arch/xtensa/configs/virt_defconfig  | 1 +
 kernel/configs/kvm_guest.config | 1 +
 9 files changed, 9 insertions(+)

diff --git a/arch/arm/configs/multi_v7_defconfig 
b/arch/arm/configs/multi_v7_defconfig
index 3823da605430..02297ed49b20 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -972,6 +972,7 @@ CONFIG_DW_DMAC=y
 CONFIG_RCAR_DMAC=y
 CONFIG_RENESAS_USB_DMAC=m
 CONFIG_VIRTIO_PCI=y
+CONFIG_VIRTIO_PCI_MODERN=y
 CONFIG_VIRTIO_MMIO=y
 CONFIG_STAGING=y
 CONFIG_MFD_NVEC=y
diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index 83c28da85834..8334e9cb4608 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -910,6 +910,7 @@ CONFIG_TI_K3_UDMA_GLUE_LAYER=y
 CONFIG_VFIO=y
 CONFIG_VFIO_PCI=y
 CONFIG_VIRTIO_PCI=y
+CONFIG_VIRTIO_PCI_MODERN=y
 CONFIG_VIRTIO_BALLOON=y
 CONFIG_VIRTIO_MMIO=y
 CONFIG_XEN_GNTDEV=y
diff --git a/arch/mips/configs/loongson3_defconfig 
b/arch/mips/configs/loongson3_defconfig
index 0e79f81217bc..ac5f2dcbffb1 100644
--- a/arch/mips/configs/loongson3_defconfig
+++ b/arch/mips/configs/loongson3_defconfig
@@ -324,6 +324,7 @@ CONFIG_RTC_DRV_CMOS=y
 CONFIG_RTC_DRV_GOLDFISH=y
 CONFIG_DMADEVICES=y
 CONFIG_VIRTIO_PCI=y
+CONFIG_VIRTIO_PCI_MODERN=y
 CONFIG_VIRTIO_BALLOON=m
 CONFIG_VIRTIO_INPUT=y
 CONFIG_VIRTIO_MMIO=y
diff --git a/arch/mips/configs/malta_kvm_guest_defconfig 
b/arch/mips/configs/malta_kvm_guest_defconfig
index 9185e0a0aa45..043633cdb406 100644
--- a/arch/mips/configs/malta_kvm_guest_defconfig
+++ b/arch/mips/configs/malta_kvm_guest_defconfig
@@ -332,6 +332,7 @@ CONFIG_RTC_DRV_CMOS=y
 CONFIG_UIO=m
 CONFIG_UIO_CIF=m
 CONFIG_VIRTIO_PCI=y
+CONFIG_VIRTIO_PCI_MODERN=y
 CONFIG_VIRTIO_BALLOON=y
 CONFIG_VIRTIO_MMIO=y
 CONFIG_EXT2_FS=y
diff --git a/arch/powerpc/configs/guest.config 
b/arch/powerpc/configs/guest.config
index 209f58515d88..fbff632c8633 100644
--- a/arch/powerpc/configs/guest.config
+++ b/arch/powerpc/configs/guest.config
@@ -5,6 +5,7 @@ CONFIG_NET_FAILOVER=y
 CONFIG_VIRTIO_CONSOLE=y
 CONFIG_VIRTIO=y
 CONFIG_VIRTIO_PCI=y
+CONFIG_VIRTIO_PCI_MODERN=y
 CONFIG_KVM_GUEST=y
 CONFIG_EPAPR_PARAVIRT=y
 CONFIG_VIRTIO_BALLOON=y
diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig
index 8c3d1e451703..b7fa7a1a0c6d 100644
--- a/arch/riscv/configs/defconfig
+++ b/arch/riscv/configs/defconfig
@@ -85,6 +85,7 @@ CONFIG_MMC=y
 CONFIG_MMC_SPI=y
 CONFIG_RTC_CLASS=y
 CONFIG_VIRTIO_PCI=y
+CONFIG_VIRTIO_PCI_MODERN=y
 CONFIG_VIRTIO_BALLOON=y
 CONFIG_VIRTIO_INPUT=y
 CONFIG_VIRTIO_MMIO=y
diff --git a/arch/riscv/configs/rv32_defconfig 
b/arch/riscv/configs/rv32_defconfig
index 2c2cda6cc1c5..68296101fa06 100644
--- a/arch/riscv/configs/rv32_defconfig
+++ b/arch/riscv/configs/rv32_defconfig
@@ -84,6 +84,7 @@ CONFIG_MMC=y
 CONFIG_MMC_SPI=y
 CONFIG_RTC_CLASS=y
 CONFIG_VIRTIO_PCI=y
+CONFIG_VIRTIO_PCI_MODERN=y
 CONFIG_VIRTIO_BALLOON=y
 CONFIG_VIRTIO_INPUT=y
 CONFIG_VIRTIO_MMIO=y
diff --git a/arch/xtensa/configs/virt_defconfig 
b/arch/xtensa/configs/virt_defconfig
index 6d1387dfa96f..7fad1c2454fd 100644
--- a/arch/xtensa/configs/virt_defconfig
+++ b/arch/xtensa/configs/virt_defconfig
@@ -74,6 +74,7 @@ CONFIG_FRAMEBUFFER_CONSOLE=y
 CONFIG_LOGO=y
 # CONFIG_USB_SUPPORT is not set
 CONFIG_VIRTIO_PCI=y
+CONFIG_VIRTIO_PCI_MODERN=y
 CONFIG_VIRTIO_INPUT=y
 # CONFIG_IOMMU_SUPPORT is not set
 CONFIG_EXT3_FS=y
diff --git a/kernel/configs/kvm_guest.config b/kernel/configs/kvm_guest.config
index 208481d91090..8dea6df20006 100644
--- a/kernel/configs/kvm_guest.config
+++ b/kernel/configs/kvm_guest.config
@@ -22,6 +22,7 @@ CONFIG_S390_GUEST=y
 CONFIG_VIRTIO=y
 CONFIG_VIRTIO_MENU=y
 CONFIG_VIRTIO_PCI=y
+CONFIG_VIRTIO_PCI_MODERN=y
 CONFIG_VIRTIO_BLK=y
 CONFIG_VIRTIO_CONSOLE=y
 CONFIG_VIRTIO_NET=y
-- 
2.30.0



Re: [PATCH v2 1/2] kbuild: introduce ccflags-remove-y and asflags-remove-y

2020-07-07 Thread Anders Roxell
On Tue, 7 Jul 2020 at 11:21, Masahiro Yamada  wrote:
>
> CFLAGS_REMOVE_.o filters out flags when compiling a particular
> object, but there is no convenient way to do that for every object in
> a directory.
>
> Add ccflags-remove-y and asflags-remove-y to make it easily.
>
> Use ccflags-remove-y to clean up some Makefiles.
>
> The add/remove order works as follows:
>
>  [1] KBUILD_CFLAGS specifies compiler flags used globally
>
>  [2] ccflags-y adds compiler flags for all objects in the
>  current Makefile
>
>  [3] ccflags-remove-y removes compiler flags for all objects in the
>  current Makefile (New feature)
>
>  [4] CFLAGS_ adds compiler flags per file.
>
>  [5] CFLAGS_REMOVE_ removes compiler flags per file.
>
> Having [3] before [4] allows us to remove flags from most (but not all)
> objects in the current Makefile.
>
> For example, kernel/trace/Makefile removes $(CC_FLAGS_FTRACE)
> from all objects in the directory, then adds it back to
> trace_selftest_dynamic.o and CFLAGS_trace_kprobe_selftest.o
>
> Please note ccflags-remove-y has no effect to the sub-directories.
> In contrast, the previous notation got rid of compiler flags also from
> all the sub-directories.
>
>   arch/arm/boot/compressed/
>   arch/powerpc/xmon/
>   arch/sh/
>   kernel/trace/
>
> ... have no sub-directories.
>
>   lib/
>
> ... has several sub-directories.
>
> To keep the behavior, I added ccflags-remove-y to all Makefiles
> in subdirectories of lib/, except:
>
>   lib/vdso/Makefile- Kbuild does not descend into this Makefile
>   lib/raid/test/Makefile   - This is not used for the kernel build
>
> I think commit 2464a609ded0 ("ftrace: do not trace library functions")
> excluded too much. In later commit, I will try to remove ccflags-remove-y
> from sub-directory Makefiles.
>
> Suggested-by: Sami Tolvanen 
> Signed-off-by: Masahiro Yamada 
> Acked-by: Steven Rostedt (VMware) 
> Acked-by: Michael Ellerman  (powerpc)

Tested-by: Anders Roxell 

> ---
>
> Changes in v2:
>   - Swap the order of [3] and [4] to keep the current behavior of
> kernel/trace/Makefile.
>   - Add ccflags-remove-y to subdir Makefiles of lib/
>
>  Documentation/kbuild/makefiles.rst | 14 ++
>  arch/arm/boot/compressed/Makefile  |  6 +-
>  arch/powerpc/xmon/Makefile |  3 +--
>  arch/sh/boot/compressed/Makefile   |  5 +
>  kernel/trace/Makefile  |  4 ++--
>  lib/842/Makefile   |  3 +++
>  lib/Makefile   |  5 +
>  lib/crypto/Makefile|  2 ++
>  lib/dim/Makefile   |  2 ++
>  lib/fonts/Makefile |  2 ++
>  lib/kunit/Makefile |  3 +++
>  lib/livepatch/Makefile |  2 ++
>  lib/lz4/Makefile   |  1 +
>  lib/lzo/Makefile   |  2 ++
>  lib/math/Makefile  |  2 ++
>  lib/mpi/Makefile   |  2 ++
>  lib/raid6/Makefile |  3 +++
>  lib/reed_solomon/Makefile  |  2 ++
>  lib/xz/Makefile|  3 +++
>  lib/zlib_deflate/Makefile  |  2 ++
>  lib/zlib_dfltcc/Makefile   |  2 ++
>  lib/zlib_inflate/Makefile  |  2 ++
>  lib/zstd/Makefile  |  1 +
>  scripts/Makefile.lib   | 14 --
>  24 files changed, 64 insertions(+), 23 deletions(-)
>
> diff --git a/Documentation/kbuild/makefiles.rst 
> b/Documentation/kbuild/makefiles.rst
> index 6515ebc12b6f..14d8e7d23c04 100644
> --- a/Documentation/kbuild/makefiles.rst
> +++ b/Documentation/kbuild/makefiles.rst
> @@ -368,6 +368,14 @@ more details, with real examples.
>
> subdir-ccflags-y := -Werror
>
> +ccflags-remove-y, asflags-remove-y
> +   These flags are used to remove particular flags for the compiler,
> +   assembler invocations.
> +
> +   Example::
> +
> +   ccflags-remove-$(CONFIG_MCOUNT) += -pg
> +
>  CFLAGS_$@, AFLAGS_$@
> CFLAGS_$@ and AFLAGS_$@ only apply to commands in current
> kbuild makefile.
> @@ -375,6 +383,9 @@ more details, with real examples.
> $(CFLAGS_$@) specifies per-file options for $(CC).  The $@
> part has a literal value which specifies the file that it is for.
>
> +   CFLAGS_$@ has the higher priority than ccflags-remove-y; CFLAGS_$@
> +   can re-add compiler flags that were removed by ccflags-remove-y.
> +
> Example::
>
> # drivers/scsi/Makefile
> @@ -387,6 +398,9 @@ more details, with real examples.
> $(AFLAGS_$@) is a similar feature for source files in assembly
> languages.
>

Re: [PATCH] kbuild: introduce ccflags-remove-y and asflags-remove-y

2020-07-06 Thread Anders Roxell
On Mon, 6 Jul 2020 at 13:24, Anders Roxell  wrote:
>
> Hi,
>
> When I built an allmodconfig kernel for arm64, and boot that in qemu
> guest I see the following issues:
>
> [...]
> [   10.451561][T1] Testing tracer function: PASSED
> [   33.087895][T1] Testing dynamic ftrace: .. filter did not
> filter .. FAILED!
> [   51.127094][T1] [ cut here ]
> [   51.132387][T1] WARNING: CPU: 0 PID: 1 at
> kernel/trace/trace.c:1814 run_tracer_selftest+0x314/0x40c
> [   51.140805][T1] Modules linked in:
> [   51.145398][T1] CPU: 0 PID: 1 Comm: swapper/0 Not tainted
> 5.8.0-rc3-next-20200703-4-g8cd4bc531754 #1
> [   51.154146][T1] Hardware name: linux,dummy-virt (DT)
> [   51.159536][T1] pstate: 8045 (Nzcv daif +PAN -UAO BTYPE=--)
> [   51.165711][T1] pc : run_tracer_selftest+0x314/0x40c
> [   51.171167][T1] lr : run_tracer_selftest+0x308/0x40c
> [   51.176475][T1] sp : 69c07c40
> [   51.180855][T1] x29: 69c07c40 x28: a00015e80320
> [   51.187187][T1] x27: a00013e074a0 x26: a000150f22ee
> [   51.193520][T1] x25: a000125b35a0 x24: a00013f6a000
> [   51.199868][T1] x23: a00013f6adc0 x22: 
> [   51.206225][T1] x21: a000150f2250 x20: a00015e801c0
> [   51.212582][T1] x19: a00015e7fa80 x18: 2750
> [   51.218887][T1] x17: 14c0 x16: 16f0
> [   51.225229][T1] x15: 14f8 x14: a0001000a3c8
> [   51.231584][T1] x13: a000124a5fb8 x12: 8d494822
> [   51.237935][T1] x11: 1fffed494821 x10: 8d494821
> [   51.244293][T1] x9 : a000101763b0 x8 : 69c077d7
> [   51.250704][T1] x7 : 0001 x6 : 69c077d0
> [   51.257060][T1] x5 : 6a7fc040 x4 : 
> [   51.263423][T1] x3 : a0001028 x2 : 8af050918b00
> [   51.269757][T1] x1 :  x0 : 0001
> [   51.276084][T1] Call trace:
> [   51.279934][T1]  run_tracer_selftest+0x314/0x40c
> [   51.285174][T1]  init_trace_selftests+0x110/0x31c
> [   51.290391][T1]  do_one_initcall+0x410/0x960
> [   51.295315][T1]  kernel_init_freeable+0x430/0x4f0
> [   51.300595][T1]  kernel_init+0x20/0x1d8
> [   51.305180][T1]  ret_from_fork+0x10/0x18
> [   51.309741][T1] irq event stamp: 1401832
> [   51.314399][T1] hardirqs last  enabled at (1401831):
> [] console_unlock+0xc04/0xd10
> [   51.322973][T1] hardirqs last disabled at (1401832):
> [] debug_exception_enter+0xbc/0x200
> [   51.331993][T1] softirqs last  enabled at (1401828):
> [] __do_softirq+0x95c/0x9f8
> [   51.340490][T1] softirqs last disabled at (1401821):
> [] irq_exit+0x118/0x198
> [   51.348717][T1] _warn_unseeded_randomness: 5 callbacks suppressed
> [   51.349263][T1] random: get_random_bytes called from
> print_oops_end_marker+0x48/0x80 with crng_init=0
> [   51.350502][T1] ---[ end trace c566e8a71c933d3c ]---
> [...]
> [40709.672335][C0] pool 2: cpus=0 flags=0x5 nice=0 hung=3s
> workers=3 manager: 1455
> [40739.960593][   T26] INFO: lockdep is turned off.
> [40775.312499][   T26] Kernel panic - not syncing: hung_task: blocked tasks
> [40775.341521][   T26] CPU: 0 PID: 26 Comm: khungtaskd Tainted: G
>   W 5.8.0-rc3-next-20200703-4-g8cd4bc531754 #1
> [40775.352848][   T26] Hardware name: linux,dummy-virt (DT)
> [40775.359304][   T26] Call trace:
> [40775.364148][   T26]  dump_backtrace+0x0/0x418
> [40775.369918][   T26]  show_stack+0x34/0x48
> [40775.375468][   T26]  dump_stack+0x1f4/0x2b0
> [40775.381136][   T26]  panic+0x2dc/0x6ec
> [40775.386430][   T26]  watchdog+0x1400/0x1460
> [40775.392103][   T26]  kthread+0x23c/0x250
> [40775.397548][   T26]  ret_from_fork+0x10/0x18
> [40775.407039][   T26] Kernel Offset: disabled
> [40775.412634][   T26] CPU features: 0x240002,20002004
> [40775.418751][   T26] Memory Limit: none
> [40775.425823][   T26] ---[ end Kernel panic - not syncing: hung_task:
> blocked tasks ]---
>
> The full log can be found here [1].
>
> Without this patch for  'trace_selftest_dynamic' for instance, CC_FLAGS_FTRACE
> was removed from kernel/trace/*, and then added back to
> kernel/trace/trace_selftest_dynamic.
> While with this patch it looks like we add the flag (even though it is
> already there), and then
> removes the flag for all files in kernel/trace/* .

Hi again,

I think the patch below solved the issue for trace_selftest_dynamic. However,
I think there is still differences in lib/* .

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index cc5e3c6aaa20..5632a711921f 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefi

Re: [PATCH] kbuild: introduce ccflags-remove-y and asflags-remove-y

2020-07-06 Thread Anders Roxell
Hi,

When I built an allmodconfig kernel for arm64, and boot that in qemu
guest I see the following issues:

[...]
[   10.451561][T1] Testing tracer function: PASSED
[   33.087895][T1] Testing dynamic ftrace: .. filter did not
filter .. FAILED!
[   51.127094][T1] [ cut here ]
[   51.132387][T1] WARNING: CPU: 0 PID: 1 at
kernel/trace/trace.c:1814 run_tracer_selftest+0x314/0x40c
[   51.140805][T1] Modules linked in:
[   51.145398][T1] CPU: 0 PID: 1 Comm: swapper/0 Not tainted
5.8.0-rc3-next-20200703-4-g8cd4bc531754 #1
[   51.154146][T1] Hardware name: linux,dummy-virt (DT)
[   51.159536][T1] pstate: 8045 (Nzcv daif +PAN -UAO BTYPE=--)
[   51.165711][T1] pc : run_tracer_selftest+0x314/0x40c
[   51.171167][T1] lr : run_tracer_selftest+0x308/0x40c
[   51.176475][T1] sp : 69c07c40
[   51.180855][T1] x29: 69c07c40 x28: a00015e80320
[   51.187187][T1] x27: a00013e074a0 x26: a000150f22ee
[   51.193520][T1] x25: a000125b35a0 x24: a00013f6a000
[   51.199868][T1] x23: a00013f6adc0 x22: 
[   51.206225][T1] x21: a000150f2250 x20: a00015e801c0
[   51.212582][T1] x19: a00015e7fa80 x18: 2750
[   51.218887][T1] x17: 14c0 x16: 16f0
[   51.225229][T1] x15: 14f8 x14: a0001000a3c8
[   51.231584][T1] x13: a000124a5fb8 x12: 8d494822
[   51.237935][T1] x11: 1fffed494821 x10: 8d494821
[   51.244293][T1] x9 : a000101763b0 x8 : 69c077d7
[   51.250704][T1] x7 : 0001 x6 : 69c077d0
[   51.257060][T1] x5 : 6a7fc040 x4 : 
[   51.263423][T1] x3 : a0001028 x2 : 8af050918b00
[   51.269757][T1] x1 :  x0 : 0001
[   51.276084][T1] Call trace:
[   51.279934][T1]  run_tracer_selftest+0x314/0x40c
[   51.285174][T1]  init_trace_selftests+0x110/0x31c
[   51.290391][T1]  do_one_initcall+0x410/0x960
[   51.295315][T1]  kernel_init_freeable+0x430/0x4f0
[   51.300595][T1]  kernel_init+0x20/0x1d8
[   51.305180][T1]  ret_from_fork+0x10/0x18
[   51.309741][T1] irq event stamp: 1401832
[   51.314399][T1] hardirqs last  enabled at (1401831):
[] console_unlock+0xc04/0xd10
[   51.322973][T1] hardirqs last disabled at (1401832):
[] debug_exception_enter+0xbc/0x200
[   51.331993][T1] softirqs last  enabled at (1401828):
[] __do_softirq+0x95c/0x9f8
[   51.340490][T1] softirqs last disabled at (1401821):
[] irq_exit+0x118/0x198
[   51.348717][T1] _warn_unseeded_randomness: 5 callbacks suppressed
[   51.349263][T1] random: get_random_bytes called from
print_oops_end_marker+0x48/0x80 with crng_init=0
[   51.350502][T1] ---[ end trace c566e8a71c933d3c ]---
[...]
[40709.672335][C0] pool 2: cpus=0 flags=0x5 nice=0 hung=3s
workers=3 manager: 1455
[40739.960593][   T26] INFO: lockdep is turned off.
[40775.312499][   T26] Kernel panic - not syncing: hung_task: blocked tasks
[40775.341521][   T26] CPU: 0 PID: 26 Comm: khungtaskd Tainted: G
  W 5.8.0-rc3-next-20200703-4-g8cd4bc531754 #1
[40775.352848][   T26] Hardware name: linux,dummy-virt (DT)
[40775.359304][   T26] Call trace:
[40775.364148][   T26]  dump_backtrace+0x0/0x418
[40775.369918][   T26]  show_stack+0x34/0x48
[40775.375468][   T26]  dump_stack+0x1f4/0x2b0
[40775.381136][   T26]  panic+0x2dc/0x6ec
[40775.386430][   T26]  watchdog+0x1400/0x1460
[40775.392103][   T26]  kthread+0x23c/0x250
[40775.397548][   T26]  ret_from_fork+0x10/0x18
[40775.407039][   T26] Kernel Offset: disabled
[40775.412634][   T26] CPU features: 0x240002,20002004
[40775.418751][   T26] Memory Limit: none
[40775.425823][   T26] ---[ end Kernel panic - not syncing: hung_task:
blocked tasks ]---

The full log can be found here [1].

Without this patch for  'trace_selftest_dynamic' for instance, CC_FLAGS_FTRACE
was removed from kernel/trace/*, and then added back to
kernel/trace/trace_selftest_dynamic.
While with this patch it looks like we add the flag (even though it is
already there), and then
removes the flag for all files in kernel/trace/* .

Cheers,
Anders
[1] https://people.linaro.org/~anders.roxell/output-next-20200703.log

On Tue, 30 Jun 2020 at 04:09, Masahiro Yamada  wrote:
>
> On Mon, Jun 29, 2020 at 2:55 PM Michael Ellerman  wrote:
> >
> > Masahiro Yamada  writes:
> > > CFLAGS_REMOVE_.o works per object, that is, there is no
> > > convenient way to filter out flags for every object in a directory.
> > >
> > > Add ccflags-remove-y and asflags-remove-y to make it easily.
> > >
> > > Use ccflags-remove-y to clean up some Makefiles.
> > >
> > > Suggested-by: Sami Tolvanen 
> > > Signed-off-by: Masahiro Yamada 
> > > ---
> > >
> > >  arch/arm/boot/compressed/Makefile | 6 +-
> > >  arch/powerpc/xmon/Makefile| 3 +--
> > >  arch/sh/boot/compressed/Makefile  | 5 +
> > >  

Re: [PATCH v3 0/4] Clean up hugetlb boot command line processing

2020-04-20 Thread Anders Roxell
On Mon, 20 Apr 2020 at 23:43, Mike Kravetz  wrote:
>
> On 4/20/20 1:29 PM, Anders Roxell wrote:
> > On Mon, 20 Apr 2020 at 20:23, Mike Kravetz  wrote:
> >> On 4/20/20 8:34 AM, Qian Cai wrote:
> >>>
> >>> Reverted this series fixed many undefined behaviors on arm64 with the 
> >>> config,
> >> While rearranging the code (patch 3 in series), I made the incorrect
> >> assumption that CONT_XXX_SIZE == (1UL << CONT_XXX_SHIFT).  However,
> >> this is not the case.  Does the following patch fix these issues?
> >>
> >> From b75cb4a0852e208bee8c4eb347dc076fcaa88859 Mon Sep 17 00:00:00 2001
> >> From: Mike Kravetz 
> >> Date: Mon, 20 Apr 2020 10:41:18 -0700
> >> Subject: [PATCH] arm64/hugetlb: fix hugetlb initialization
> >>
> >> When calling hugetlb_add_hstate() to initialize a new hugetlb size,
> >> be sure to use correct huge pages size order.
> >>
> >> Signed-off-by: Mike Kravetz 
> >> ---
> >>  arch/arm64/mm/hugetlbpage.c | 8 
> >>  1 file changed, 4 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
> >> index 9ca840527296..a02411a1f19a 100644
> >> --- a/arch/arm64/mm/hugetlbpage.c
> >> +++ b/arch/arm64/mm/hugetlbpage.c
> >> @@ -453,11 +453,11 @@ void huge_ptep_clear_flush(struct vm_area_struct 
> >> *vma,
> >>  static int __init hugetlbpage_init(void)
> >>  {
> >>  #ifdef CONFIG_ARM64_4K_PAGES
> >> -   hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
> >> +   hugetlb_add_hstate(ilog2(PUD_SIZE) - PAGE_SHIFT);
> >>  #endif
> >> -   hugetlb_add_hstate(CONT_PMD_SHIFT - PAGE_SHIFT);
> >> -   hugetlb_add_hstate(PMD_SHIFT - PAGE_SHIFT);
> >> -   hugetlb_add_hstate(CONT_PTE_SHIFT - PAGE_SHIFT);
> >> +   hugetlb_add_hstate(ilog2(CONT_PMD_SIZE) - PAGE_SHIFT);
> >> +   hugetlb_add_hstate(ilog2(PMD_SIZE) - PAGE_SHIFT);
> >> +   hugetlb_add_hstate(ilog2(CONT_PTE_SIZE) - PAGE_SHIFT);
> >>
> >> return 0;
> >>  }
> >
> > I build this for an arm64 kernel and ran it in qemu and it worked.
>
> Thanks for testing Anders!
>
> Will, here is an updated version of the patch based on your suggestion.
> I added the () for emphasis but that may just be noise for some.  Also,
> the naming differences and values for CONT_PTE may make some people
> look twice.  Not sure if being consistent here helps?
>
> I have only built this.  No testing.
>
> From daf833ab6b806ecc0816d84d45dcbacc052a7eec Mon Sep 17 00:00:00 2001
> From: Mike Kravetz 
> Date: Mon, 20 Apr 2020 13:56:15 -0700
> Subject: [PATCH] arm64/hugetlb: fix hugetlb initialization
>
> When calling hugetlb_add_hstate() to initialize a new hugetlb size,
> be sure to use correct huge pages size order.
>
> Signed-off-by: Mike Kravetz 

Tested-by: Anders Roxell 

I tested this patch on qemu-aarch64.

Cheers,
Anders

> ---
>  arch/arm64/mm/hugetlbpage.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
> index 9ca840527296..bed6dc7c4276 100644
> --- a/arch/arm64/mm/hugetlbpage.c
> +++ b/arch/arm64/mm/hugetlbpage.c
> @@ -455,9 +455,9 @@ static int __init hugetlbpage_init(void)
>  #ifdef CONFIG_ARM64_4K_PAGES
> hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
>  #endif
> -   hugetlb_add_hstate(CONT_PMD_SHIFT - PAGE_SHIFT);
> +   hugetlb_add_hstate((CONT_PMD_SHIFT + PMD_SHIFT) - PAGE_SHIFT);
> hugetlb_add_hstate(PMD_SHIFT - PAGE_SHIFT);
> -   hugetlb_add_hstate(CONT_PTE_SHIFT - PAGE_SHIFT);
> +   hugetlb_add_hstate((CONT_PTE_SHIFT + PAGE_SHIFT) - PAGE_SHIFT);
>
> return 0;
>  }
> --
> 2.25.2
>


Re: [PATCH v3 0/4] Clean up hugetlb boot command line processing

2020-04-20 Thread Anders Roxell
On Mon, 20 Apr 2020 at 20:23, Mike Kravetz  wrote:
>
> On 4/20/20 8:34 AM, Qian Cai wrote:
> >
> >
> >> On Apr 17, 2020, at 2:50 PM, Mike Kravetz  wrote:
> >>
> >> Longpeng(Mike) reported a weird message from hugetlb command line 
> >> processing
> >> and proposed a solution [1].  While the proposed patch does address the
> >> specific issue, there are other related issues in command line processing.
> >> As hugetlbfs evolved, updates to command line processing have been made to
> >> meet immediate needs and not necessarily in a coordinated manner.  The 
> >> result
> >> is that some processing is done in arch specific code, some is done in arch
> >> independent code and coordination is problematic.  Semantics can vary 
> >> between
> >> architectures.
> >>
> >> The patch series does the following:
> >> - Define arch specific arch_hugetlb_valid_size routine used to validate
> >>  passed huge page sizes.
> >> - Move hugepagesz= command line parsing out of arch specific code and into
> >>  an arch independent routine.
> >> - Clean up command line processing to follow desired semantics and
> >>  document those semantics.
> >>
> >> [1] 
> >> https://lore.kernel.org/linux-mm/20200305033014.1152-1-longpe...@huawei.com
> >>
> >> Mike Kravetz (4):
> >>  hugetlbfs: add arch_hugetlb_valid_size
> >>  hugetlbfs: move hugepagesz= parsing to arch independent code
> >>  hugetlbfs: remove hugetlb_add_hstate() warning for existing hstate
> >>  hugetlbfs: clean up command line processing
> >
> > Reverted this series fixed many undefined behaviors on arm64 with the 
> > config,
> >
> > https://raw.githubusercontent.com/cailca/linux-mm/master/arm64.config
> >
> > [   54.172683][T1] UBSAN: shift-out-of-bounds in 
> > ./include/linux/hugetlb.h:555:34
> > [   54.180411][T1] shift exponent 4294967285 is too large for 64-bit 
> > type 'unsigned long'
> > [   54.15][T1] CPU: 130 PID: 1 Comm: swapper/0 Not tainted 
> > 5.7.0-rc2-next-20200420 #1
> > [   54.197284][T1] Hardware name: HPE Apollo 70 
> > /C01_APACHE_MB , BIOS L50_5.13_1.11 06/18/2019
> > [   54.207888][T1] Call trace:
> > [   54.211100][T1]  dump_backtrace+0x0/0x224
> > [   54.215565][T1]  show_stack+0x20/0x2c
> > [   54.219651][T1]  dump_stack+0xfc/0x184
> > [   54.223829][T1]  __ubsan_handle_shift_out_of_bounds+0x304/0x344
> > [   54.230204][T1]  hugetlb_add_hstate+0x3ec/0x414
> > huge_page_size at include/linux/hugetlb.h:555
> > (inlined by) hugetlb_add_hstate at mm/hugetlb.c:3301
> > [   54.235191][T1]  hugetlbpage_init+0x14/0x30
> > [   54.239824][T1]  do_one_initcall+0x6c/0x144
> > [   54.26][T1]  do_initcall_level+0x158/0x1c4
> > [   54.249336][T1]  do_initcalls+0x68/0xb0
> > [   54.253597][T1]  do_basic_setup+0x28/0x30
> > [   54.258049][T1]  kernel_init_freeable+0x19c/0x228
> > [   54.263188][T1]  kernel_init+0x14/0x208
> > [   54.267473][T1]  ret_from_fork+0x10/0x18
>
> While rearranging the code (patch 3 in series), I made the incorrect
> assumption that CONT_XXX_SIZE == (1UL << CONT_XXX_SHIFT).  However,
> this is not the case.  Does the following patch fix these issues?
>
> From b75cb4a0852e208bee8c4eb347dc076fcaa88859 Mon Sep 17 00:00:00 2001
> From: Mike Kravetz 
> Date: Mon, 20 Apr 2020 10:41:18 -0700
> Subject: [PATCH] arm64/hugetlb: fix hugetlb initialization
>
> When calling hugetlb_add_hstate() to initialize a new hugetlb size,
> be sure to use correct huge pages size order.
>
> Signed-off-by: Mike Kravetz 
> ---
>  arch/arm64/mm/hugetlbpage.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
> index 9ca840527296..a02411a1f19a 100644
> --- a/arch/arm64/mm/hugetlbpage.c
> +++ b/arch/arm64/mm/hugetlbpage.c
> @@ -453,11 +453,11 @@ void huge_ptep_clear_flush(struct vm_area_struct *vma,
>  static int __init hugetlbpage_init(void)
>  {
>  #ifdef CONFIG_ARM64_4K_PAGES
> -   hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
> +   hugetlb_add_hstate(ilog2(PUD_SIZE) - PAGE_SHIFT);
>  #endif
> -   hugetlb_add_hstate(CONT_PMD_SHIFT - PAGE_SHIFT);
> -   hugetlb_add_hstate(PMD_SHIFT - PAGE_SHIFT);
> -   hugetlb_add_hstate(CONT_PTE_SHIFT - PAGE_SHIFT);
> +   hugetlb_add_hstate(ilog2(CONT_PMD_SIZE) - PAGE_SHIFT);
> +   hugetlb_add_hstate(ilog2(PMD_SIZE) - PAGE_SHIFT);
> +   hugetlb_add_hstate(ilog2(CONT_PTE_SIZE) - PAGE_SHIFT);
>
> return 0;
>  }

I build this for an arm64 kernel and ran it in qemu and it worked.

Cheers,
Anders


Re: [PATCH v3 3/4] hugetlbfs: remove hugetlb_add_hstate() warning for existing hstate

2020-04-20 Thread Anders Roxell
On Fri, 17 Apr 2020 at 20:52, Mike Kravetz  wrote:
>
> The routine hugetlb_add_hstate prints a warning if the hstate already
> exists.  This was originally done as part of kernel command line
> parsing.  If 'hugepagesz=' was specified more than once, the warning
> pr_warn("hugepagesz= specified twice, ignoring\n");
> would be printed.
>
> Some architectures want to enable all huge page sizes.  They would
> call hugetlb_add_hstate for all supported sizes.  However, this was
> done after command line processing and as a result hstates could have
> already been created for some sizes.  To make sure no warning were
> printed, there would often be code like:
> if (!size_to_hstate(size)
> hugetlb_add_hstate(ilog2(size) - PAGE_SHIFT)
>
> The only time we want to print the warning is as the result of command
> line processing.  So, remove the warning from hugetlb_add_hstate and
> add it to the single arch independent routine processing "hugepagesz=".
> After this, calls to size_to_hstate() in arch specific code can be
> removed and hugetlb_add_hstate can be called without worrying about
> warning messages.
>
> Signed-off-by: Mike Kravetz 
> Acked-by: Mina Almasry 

When I build an arm64 kernel on today's next-20200420 and ran that in
qemu I got the following output [1]:

...
[  311.326817][T1] kobject: 'drivers' ((ptrval)):
kobject_add_internal: parent: 'coresight', set: ''
[  311.331513][T1] kobject: 'drivers' ((ptrval)): kobject_uevent_env
[  311.334514][T1] kobject: 'drivers' ((ptrval)):
kobject_uevent_env: filter function caused the event to drop!
[  311.340127][T1] bus: 'coresight': registered
[  311.342228][T1] initcall coresight_init+0x0/0x64 returned 0
after 27343 usecs
[  311.349740][T1] calling  debug_traps_init+0x0/0xa4 @ 1
[  311.352138][T1] initcall debug_traps_init+0x0/0xa4 returned 0
after 0 usecs
[  311.30][T1] calling  reserve_memblock_reserved_regions+0x0/0x374 @ 1
[  311.364913][T1] initcall
reserve_memblock_reserved_regions+0x0/0x374 returned 0 after 7812
usecs
[  311.368937][T1] calling  aarch32_alloc_vdso_pages+0x0/0x1d0 @ 1
[  311.371819][T1] initcall aarch32_alloc_vdso_pages+0x0/0x1d0
returned 0 after 0 usecs
[  311.375608][T1] calling  vdso_init+0x0/0x52c @ 1
[  311.378092][T1] initcall vdso_init+0x0/0x52c returned 0 after 0 usecs
[  311.381386][T1] calling  arch_hw_breakpoint_init+0x0/0x178 @ 1
[  311.384007][T1] hw-breakpoint: found 6 breakpoint and 4
watchpoint registers.
[  311.388120][T1] initcall arch_hw_breakpoint_init+0x0/0x178
returned 0 after 3906 usecs
[  311.391924][T1] calling  asids_update_limit+0x0/0x110 @ 1
[  311.394390][T1] ASID allocator initialised with 65536 entries
[  311.397427][T1] initcall asids_update_limit+0x0/0x110 returned
0 after 3906 usecs
[  311.400749][T1] calling  hugetlbpage_init+0x0/0x7c @ 1
[  311.403581][T1] Unexpected kernel BRK exception at EL1
[  311.405771][T1] Internal error: ptrace BRK handler: f20003e8
[#1] PREEMPT SMP
[  311.408759][T1] Modules linked in:
[  311.410514][T1] CPU: 0 PID: 1 Comm: swapper/0 Tainted: G
T 5.7.0-rc2-next-20200420-03722-ge4ba9b47e4ed #1
[  311.415175][T1] Hardware name: linux,dummy-virt (DT)
[  311.417466][T1] pstate: 8045 (Nzcv daif +PAN -UAO)
[  311.419887][T1] pc : hugetlb_add_hstate+0x68/0x4f0
[  311.422171][T1] lr : hugetlb_add_hstate+0x68/0x4f0
[  311.424354][T1] sp : 69c07c60
[  311.426124][T1] x29: 69c07c60 x28: 6a7f8058
[  311.428754][T1] x27:  x26: a00013f56950
[  311.431376][T1] x25: a000141b8000 x24: 6a7f8040
[  311.433987][T1] x23: 1fffed380fae x22: fff8
[  311.436574][T1] x21: 0001 x20: a000141b8000
[  311.439167][T1] x19: ec632d51be3d2507 x18: 1a68
[  311.441763][T1] x17: 13e0 x16: 1a94
[  311.444386][T1] x15: 1a68 x14: 6573752036303933
[  311.447034][T1] x13: 2072657466612030 x12: 25b0
[  311.449639][T1] x11: f1f1f1f1 x10: 41b58ab3
[  311.452238][T1] x9 : a000139a833c x8 : 140002bf2c23
[  311.454849][T1] x7 : 940002bf2c23 x6 : a00015f9611b
[  311.457480][T1] x5 : 6a7f8040 x4 : 
[  311.460124][T1] x3 : a000139fd98c x2 : fff8
[  311.462737][T1] x1 : 6a7f8040 x0 : 
[  311.465322][T1] Call trace:
[  311.466818][T1]  hugetlb_add_hstate+0x68/0x4f0
[  311.468934][T1]  hugetlbpage_init+0x34/0x7c
[  311.470934][T1]  do_one_initcall+0x480/0xa40
[  311.472996][T1]  kernel_init_freeable+0x7a0/0x968
[  311.475224][T1]  kernel_init+0x20/0x1f8
[  311.477078][T1]  ret_from_fork+0x10/0x18
[  311.479053][T1] Code: 972762be 7100fedf 5469 97276197 (d4207d00)
[  311.482106][T1] 

Re: [PATCH] selftests/powerpc: Fix Makefiles for headers_install change

2018-09-28 Thread Anders Roxell
On Fri, 28 Sep 2018 at 07:43, Michael Ellerman  wrote:
>
> Commit b2d35fa5fc80 ("selftests: add headers_install to lib.mk")
> introduced a requirement that Makefiles more than one level below the
> selftests directory need to define top_srcdir, but it didn't update
> any of the powerpc Makefiles.
>
> This broke building all the powerpc selftests with eg:
>
>   make[1]: Entering directory '/src/linux/tools/testing/selftests/powerpc'
>   BUILD_TARGET=/src/linux/tools/testing/selftests/powerpc/alignment; mkdir -p 
> $BUILD_TARGET; make OUTPUT=$BUILD_TARGET -k -C alignment all
>   make[2]: Entering directory 
> '/src/linux/tools/testing/selftests/powerpc/alignment'
>   ../../lib.mk:20: ../../../../scripts/subarch.include: No such file or 
> directory
>   make[2]: *** No rule to make target '../../../../scripts/subarch.include'.
>   make[2]: Failed to remake makefile '../../../../scripts/subarch.include'.
>   Makefile:38: recipe for target 'alignment' failed
>
> Fix it by setting top_srcdir in the affected Makefiles.
>
> Fixes: b2d35fa5fc80 ("selftests: add headers_install to lib.mk")
> Signed-off-by: Michael Ellerman 

oops, I'm sorry =/

Reviewed-by: Anders Roxell 

> ---
>  tools/testing/selftests/powerpc/alignment/Makefile | 1 +
>  tools/testing/selftests/powerpc/benchmarks/Makefile| 1 +
>  tools/testing/selftests/powerpc/cache_shape/Makefile   | 1 +
>  tools/testing/selftests/powerpc/copyloops/Makefile | 1 +
>  tools/testing/selftests/powerpc/dscr/Makefile  | 1 +
>  tools/testing/selftests/powerpc/math/Makefile  | 1 +
>  tools/testing/selftests/powerpc/mm/Makefile| 1 +
>  tools/testing/selftests/powerpc/pmu/Makefile   | 1 +
>  tools/testing/selftests/powerpc/pmu/ebb/Makefile   | 1 +
>  tools/testing/selftests/powerpc/primitives/Makefile| 1 +
>  tools/testing/selftests/powerpc/ptrace/Makefile| 1 +
>  tools/testing/selftests/powerpc/signal/Makefile| 1 +
>  tools/testing/selftests/powerpc/stringloops/Makefile   | 1 +
>  tools/testing/selftests/powerpc/switch_endian/Makefile | 1 +
>  tools/testing/selftests/powerpc/syscalls/Makefile  | 1 +
>  tools/testing/selftests/powerpc/tm/Makefile| 1 +
>  tools/testing/selftests/powerpc/vphn/Makefile  | 1 +
>  17 files changed, 17 insertions(+)
>
> diff --git a/tools/testing/selftests/powerpc/alignment/Makefile 
> b/tools/testing/selftests/powerpc/alignment/Makefile
> index 93baacab7693..d056486f49de 100644
> --- a/tools/testing/selftests/powerpc/alignment/Makefile
> +++ b/tools/testing/selftests/powerpc/alignment/Makefile
> @@ -1,5 +1,6 @@
>  TEST_GEN_PROGS := copy_first_unaligned alignment_handler
>
> +top_srcdir = ../../../../..
>  include ../../lib.mk
>
>  $(TEST_GEN_PROGS): ../harness.c ../utils.c
> diff --git a/tools/testing/selftests/powerpc/benchmarks/Makefile 
> b/tools/testing/selftests/powerpc/benchmarks/Makefile
> index b4d7432a0ecd..d40300a65b42 100644
> --- a/tools/testing/selftests/powerpc/benchmarks/Makefile
> +++ b/tools/testing/selftests/powerpc/benchmarks/Makefile
> @@ -4,6 +4,7 @@ TEST_GEN_FILES := exec_target
>
>  CFLAGS += -O2
>
> +top_srcdir = ../../../../..
>  include ../../lib.mk
>
>  $(TEST_GEN_PROGS): ../harness.c
> diff --git a/tools/testing/selftests/powerpc/cache_shape/Makefile 
> b/tools/testing/selftests/powerpc/cache_shape/Makefile
> index 1be547434a49..ede4d3dae750 100644
> --- a/tools/testing/selftests/powerpc/cache_shape/Makefile
> +++ b/tools/testing/selftests/powerpc/cache_shape/Makefile
> @@ -5,6 +5,7 @@ all: $(TEST_PROGS)
>
>  $(TEST_PROGS): ../harness.c ../utils.c
>
> +top_srcdir = ../../../../..
>  include ../../lib.mk
>
>  clean:
> diff --git a/tools/testing/selftests/powerpc/copyloops/Makefile 
> b/tools/testing/selftests/powerpc/copyloops/Makefile
> index 1cf89a34d97c..44574f3818b3 100644
> --- a/tools/testing/selftests/powerpc/copyloops/Makefile
> +++ b/tools/testing/selftests/powerpc/copyloops/Makefile
> @@ -17,6 +17,7 @@ TEST_GEN_PROGS := copyuser_64_t0 copyuser_64_t1 
> copyuser_64_t2 \
>
>  EXTRA_SOURCES := validate.c ../harness.c stubs.S
>
> +top_srcdir = ../../../../..
>  include ../../lib.mk
>
>  $(OUTPUT)/copyuser_64_t%:  copyuser_64.S $(EXTRA_SOURCES)
> diff --git a/tools/testing/selftests/powerpc/dscr/Makefile 
> b/tools/testing/selftests/powerpc/dscr/Makefile
> index 55d7db7a616b..5df476364b4d 100644
> --- a/tools/testing/selftests/powerpc/dscr/Makefile
> +++ b/tools/testing/selftests/powerpc/dscr/Makefile
> @@ -3,6 +3,7 @@ TEST_GEN_PROGS := dscr_default_test dscr_explicit_test 
> dscr_user_test   \
>   dscr_inherit_test dscr_inherit_exec_test dscr_sysfs_test  \
>