Re: [PATCH v2 17/24] x86/cpu: Make sure play_dead() doesn't return

2023-02-14 Thread Philippe Mathieu-Daudé

On 14/2/23 08:05, Josh Poimboeuf wrote:

After commit 076cbf5d2163 ("x86/xen: don't let xen_pv_play_dead()
return"), play_dead() never returns.  Make that more explicit with a
BUG().

BUG() is preferable to unreachable() because BUG() is a more explicit
failure mode and avoids undefined behavior like falling off the edge of
the function into whatever code happens to be next.

Signed-off-by: Josh Poimboeuf 
---
  arch/x86/include/asm/smp.h | 1 +
  1 file changed, 1 insertion(+)

diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index b4dbb20dab1a..8f628e08b25a 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -96,6 +96,7 @@ static inline void __cpu_die(unsigned int cpu)
  static inline void play_dead(void)
  {
smp_ops.play_dead();
+   BUG();
  }


Similarly, smp_ops::play_dead() should be decorated noreturn first.


Re: [PATCH v2 08/24] loongarch/cpu: Mark play_dead() __noreturn

2023-02-14 Thread Philippe Mathieu-Daudé

On 14/2/23 08:05, Josh Poimboeuf wrote:

play_dead() doesn't return.  Annotate it as such.  By extension this
also makes arch_cpu_idle_dead() noreturn.

Signed-off-by: Josh Poimboeuf 
---
  arch/loongarch/include/asm/smp.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)


Reviewed-by: Philippe Mathieu-Daudé 




Re: [PATCH v2 06/24] ia64/cpu: Mark play_dead() __noreturn

2023-02-14 Thread Philippe Mathieu-Daudé

On 14/2/23 08:05, Josh Poimboeuf wrote:

play_dead() doesn't return.  Annotate it as such.  By extension this
also makes arch_cpu_idle_dead() noreturn.

Signed-off-by: Josh Poimboeuf 
---
  arch/ia64/kernel/process.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)


Reviewed-by: Philippe Mathieu-Daudé 



Re: [PATCH v2 04/24] arm64/cpu: Mark cpu_die() __noreturn

2023-02-14 Thread Philippe Mathieu-Daudé

On 14/2/23 08:05, Josh Poimboeuf wrote:

cpu_die() doesn't return.  Annotate it as such.  By extension this also
makes arch_cpu_idle_dead() noreturn.

Signed-off-by: Josh Poimboeuf 
---
  arch/arm64/include/asm/smp.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h
index fc55f5a57a06..5733a31bab08 100644
--- a/arch/arm64/include/asm/smp.h
+++ b/arch/arm64/include/asm/smp.h
@@ -100,7 +100,7 @@ static inline void arch_send_wakeup_ipi_mask(const struct 
cpumask *mask)
  extern int __cpu_disable(void);
  
  extern void __cpu_die(unsigned int cpu);

-extern void cpu_die(void);
+extern void __noreturn cpu_die(void);
  extern void cpu_die_early(void);


Shouldn't cpu_operations::cpu_die() be declared noreturn first?



Re: [PATCH v3 24/24] s390: Remove empty

2023-02-14 Thread Heiko Carstens
On Tue, Feb 14, 2023 at 08:49:25AM +0100, Alexandre Ghiti wrote:
> From: Palmer Dabbelt 
> 
> Signed-off-by: Palmer Dabbelt 
> ---
>  arch/s390/include/asm/setup.h  | 1 -
>  arch/s390/include/uapi/asm/setup.h | 1 -
>  2 files changed, 2 deletions(-)
>  delete mode 100644 arch/s390/include/uapi/asm/setup.h

Acked-by: Heiko Carstens 


Re: [PATCH v3 00/24] Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Heiko Carstens
On Tue, Feb 14, 2023 at 08:49:01AM +0100, Alexandre Ghiti wrote:
> This all came up in the context of increasing COMMAND_LINE_SIZE in the
> RISC-V port.  In theory that's a UABI break, as COMMAND_LINE_SIZE is the
> maximum length of /proc/cmdline and userspace could staticly rely on
> that to be correct.
> 
> Usually I wouldn't mess around with changing this sort of thing, but
> PowerPC increased it with a5980d064fe2 ("powerpc: Bump COMMAND_LINE_SIZE
> to 2048").  There are also a handful of examples of COMMAND_LINE_SIZE
> increasing, but they're from before the UAPI split so I'm not quite sure
> what that means: e5a6a1c90948 ("powerpc: derive COMMAND_LINE_SIZE from
> asm-generic"), 684d2fd48e71 ("[S390] kernel: Append scpdata to kernel
> boot command line"), 22242681cff5 ("MIPS: Extend COMMAND_LINE_SIZE"),
> and 2b74b85693c7 ("sh: Derive COMMAND_LINE_SIZE from
> asm-generic/setup.h.").
> 
> It seems to me like COMMAND_LINE_SIZE really just shouldn't have been
> part of the uapi to begin with, and userspace should be able to handle
> /proc/cmdline of whatever length it turns out to be.  I don't see any
> references to COMMAND_LINE_SIZE anywhere but Linux via a quick Google
> search, but that's not really enough to consider it unused on my end.
> 
> The feedback on the v1 seemed to indicate that COMMAND_LINE_SIZE really
> shouldn't be part of uapi, so this now touches all the ports.  I've
> tried to split this all out and leave it bisectable, but I haven't
> tested it all that aggressively.

Just to confirm this assumption a bit more: that's actually the same
conclusion that we ended up with when commit 3da0243f906a ("s390: make
command line configurable") went upstream.


Re: [PATCH v3 00/24] Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Geert Uytterhoeven
Hi Heiko,

On Tue, Feb 14, 2023 at 9:39 AM Heiko Carstens  wrote:
> On Tue, Feb 14, 2023 at 08:49:01AM +0100, Alexandre Ghiti wrote:
> > This all came up in the context of increasing COMMAND_LINE_SIZE in the
> > RISC-V port.  In theory that's a UABI break, as COMMAND_LINE_SIZE is the
> > maximum length of /proc/cmdline and userspace could staticly rely on
> > that to be correct.
> >
> > Usually I wouldn't mess around with changing this sort of thing, but
> > PowerPC increased it with a5980d064fe2 ("powerpc: Bump COMMAND_LINE_SIZE
> > to 2048").  There are also a handful of examples of COMMAND_LINE_SIZE
> > increasing, but they're from before the UAPI split so I'm not quite sure
> > what that means: e5a6a1c90948 ("powerpc: derive COMMAND_LINE_SIZE from
> > asm-generic"), 684d2fd48e71 ("[S390] kernel: Append scpdata to kernel
> > boot command line"), 22242681cff5 ("MIPS: Extend COMMAND_LINE_SIZE"),
> > and 2b74b85693c7 ("sh: Derive COMMAND_LINE_SIZE from
> > asm-generic/setup.h.").
> >
> > It seems to me like COMMAND_LINE_SIZE really just shouldn't have been
> > part of the uapi to begin with, and userspace should be able to handle
> > /proc/cmdline of whatever length it turns out to be.  I don't see any
> > references to COMMAND_LINE_SIZE anywhere but Linux via a quick Google
> > search, but that's not really enough to consider it unused on my end.
> >
> > The feedback on the v1 seemed to indicate that COMMAND_LINE_SIZE really
> > shouldn't be part of uapi, so this now touches all the ports.  I've
> > tried to split this all out and leave it bisectable, but I haven't
> > tested it all that aggressively.
>
> Just to confirm this assumption a bit more: that's actually the same
> conclusion that we ended up with when commit 3da0243f906a ("s390: make
> command line configurable") went upstream.

Commit 622021cd6c560ce7 ("s390: make command line configurable"),
I assume?

Gr{oetje,eeting}s,

Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH v3 15/24] m68k: Remove empty

2023-02-14 Thread Geert Uytterhoeven
On Tue, Feb 14, 2023 at 9:05 AM Alexandre Ghiti  wrote:
> From: Palmer Dabbelt 
>
> Signed-off-by: Palmer Dabbelt 

Acked-by: Geert Uytterhoeven 

Gr{oetje,eeting}s,

Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH v3 20/24] x86: Remove empty

2023-02-14 Thread Philippe Mathieu-Daudé

On 14/2/23 08:49, Alexandre Ghiti wrote:

From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
  arch/x86/include/asm/setup.h  | 2 --
  arch/x86/include/uapi/asm/setup.h | 1 -
  2 files changed, 3 deletions(-)
  delete mode 100644 arch/x86/include/uapi/asm/setup.h


Reviewed-by: Philippe Mathieu-Daudé 



Re: [PATCH v3 24/24] s390: Remove empty

2023-02-14 Thread Philippe Mathieu-Daudé

On 14/2/23 08:49, Alexandre Ghiti wrote:

From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
  arch/s390/include/asm/setup.h  | 1 -
  arch/s390/include/uapi/asm/setup.h | 1 -
  2 files changed, 2 deletions(-)
  delete mode 100644 arch/s390/include/uapi/asm/setup.h


Reviewed-by: Philippe Mathieu-Daudé 



Re: [PATCH v3 10/24] sparc: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Sergey Shtylyov
On 2/14/23 10:49 AM, Alexandre Ghiti wrote:

> From: Palmer Dabbelt 
> 
> As far as I can tell this is not used by userspace and thus should not
> be part of the user-visible API.
> 
> Signed-off-by: Palmer Dabbelt 
> ---
>  arch/sparc/include/asm/setup.h  | 6 +-
>  arch/sparc/include/uapi/asm/setup.h | 7 ---
>  2 files changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
> index 72205684e51e..d1384ed92547 100644
> --- a/arch/sparc/include/asm/setup.h
> +++ b/arch/sparc/include/asm/setup.h
> @@ -7,7 +7,11 @@
>  
>  #include 
>  
> -#include 
> +#if defined(__sparc__) && defined(__arch64__)

   Mhm, I don't think these two can be #define'd simulaneously...

> +# define COMMAND_LINE_SIZE 2048
> +#else
> +# define COMMAND_LINE_SIZE 256
> +#endif
>  
>  extern char reboot_command[];
>  
> diff --git a/arch/sparc/include/uapi/asm/setup.h 
> b/arch/sparc/include/uapi/asm/setup.h
> index 3c208a4dd464..c3cf1b0d30b3 100644
> --- a/arch/sparc/include/uapi/asm/setup.h
> +++ b/arch/sparc/include/uapi/asm/setup.h
> @@ -6,11 +6,4 @@
>  #ifndef _UAPI_SPARC_SETUP_H
>  #define _UAPI_SPARC_SETUP_H
>  
> -#if defined(__sparc__) && defined(__arch64__)
> -# define COMMAND_LINE_SIZE 2048
> -#else
> -# define COMMAND_LINE_SIZE 256
> -#endif
> -
> -
>  #endif /* _UAPI_SPARC_SETUP_H */

MBR, Sergey


Re: [PATCH v3 14/24] arc: Remove empty

2023-02-14 Thread Philippe Mathieu-Daudé

On 14/2/23 08:49, Alexandre Ghiti wrote:

From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
  arch/arc/include/asm/setup.h  | 1 -
  arch/arc/include/uapi/asm/setup.h | 6 --
  2 files changed, 7 deletions(-)
  delete mode 100644 arch/arc/include/uapi/asm/setup.h


Reviewed-by: Philippe Mathieu-Daudé 



Re: [PATCH v3 07/24] mips: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Philippe Mathieu-Daudé

On 14/2/23 08:49, Alexandre Ghiti wrote:

From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
  arch/mips/include/asm/setup.h  | 3 ++-
  arch/mips/include/uapi/asm/setup.h | 3 ---
  2 files changed, 2 insertions(+), 4 deletions(-)


Reviewed-by: Philippe Mathieu-Daudé 



Re: [PATCH v3 05/24] m68k: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Geert Uytterhoeven
On Tue, Feb 14, 2023 at 8:55 AM Alexandre Ghiti  wrote:
> From: Palmer Dabbelt 
>
> As far as I can tell this is not used by userspace and thus should not
> be part of the user-visible API.
>
> Signed-off-by: Palmer Dabbelt 

Acked-by: Geert Uytterhoeven 

Gr{oetje,eeting}s,

Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH v3 01/24] alpha: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Philippe Mathieu-Daudé

On 14/2/23 08:49, Alexandre Ghiti wrote:

From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
  arch/alpha/include/asm/setup.h  | 4 ++--
  arch/alpha/include/uapi/asm/setup.h | 2 --
  2 files changed, 2 insertions(+), 4 deletions(-)


Reviewed-by: Philippe Mathieu-Daudé 



Re: [PATCH v3 10/24] sparc: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread WANG Xuerui

On 2023/2/14 16:50, Sergey Shtylyov wrote:

On 2/14/23 10:49 AM, Alexandre Ghiti wrote:


From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
  arch/sparc/include/asm/setup.h  | 6 +-
  arch/sparc/include/uapi/asm/setup.h | 7 ---
  2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
index 72205684e51e..d1384ed92547 100644
--- a/arch/sparc/include/asm/setup.h
+++ b/arch/sparc/include/asm/setup.h
@@ -7,7 +7,11 @@
  
  #include 
  
-#include 

+#if defined(__sparc__) && defined(__arch64__)


Mhm, I don't think these two can be #define'd simulaneously...


I believe it's just a SPARC-ism [1] [2] that may look strange and be 
easily confused for __aarch64__ (notice the extra 'a')...


[1]: 
https://github.com/gcc-mirror/gcc/blob/basepoints/gcc-12/gcc/config/sparc/sparc.h#L301
[2]: 
https://github.com/llvm/llvm-project/blob/llvmorg-17-init/clang/lib/Basic/Targets/Sparc.cpp#L241


--
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/



Re: [PATCH v3 08/24] parisc: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Philippe Mathieu-Daudé

On 14/2/23 08:49, Alexandre Ghiti wrote:

From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
  arch/parisc/include/asm/setup.h  | 7 +++
  arch/parisc/include/uapi/asm/setup.h | 2 --
  2 files changed, 7 insertions(+), 2 deletions(-)
  create mode 100644 arch/parisc/include/asm/setup.h


Reviewed-by: Philippe Mathieu-Daudé 



Re: [PATCH v3 19/24] parisc: Remove empty

2023-02-14 Thread Philippe Mathieu-Daudé

On 14/2/23 08:49, Alexandre Ghiti wrote:

From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
  arch/parisc/include/uapi/asm/setup.h | 5 -
  1 file changed, 5 deletions(-)
  delete mode 100644 arch/parisc/include/uapi/asm/setup.h


Reviewed-by: Philippe Mathieu-Daudé 



Re: [PATCH v3 10/24] sparc: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Sergey Shtylyov
On 2/14/23 11:59 AM, WANG Xuerui wrote:
[...]

>>> From: Palmer Dabbelt 
>>>
>>> As far as I can tell this is not used by userspace and thus should not
>>> be part of the user-visible API.
>>>
>>> Signed-off-by: Palmer Dabbelt 
>>> ---
>>>   arch/sparc/include/asm/setup.h  | 6 +-
>>>   arch/sparc/include/uapi/asm/setup.h | 7 ---
>>>   2 files changed, 5 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
>>> index 72205684e51e..d1384ed92547 100644
>>> --- a/arch/sparc/include/asm/setup.h
>>> +++ b/arch/sparc/include/asm/setup.h
>>> @@ -7,7 +7,11 @@
>>>     #include 
>>>   -#include 
>>> +#if defined(__sparc__) && defined(__arch64__)
>>
>>     Mhm, I don't think these two can be #define'd simulaneously...
> 
> I believe it's just a SPARC-ism [1] [2] that may look strange and be easily 
> confused for __aarch64__ (notice the extra 'a')...

  Yeah, sorry, I did confuse it with AArgh64. :-)

[...]

MNR, Sergey


Re: [PATCH v3 00/24] Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Heiko Carstens
On Tue, Feb 14, 2023 at 09:58:17AM +0100, Geert Uytterhoeven wrote:
> Hi Heiko,
> 
> On Tue, Feb 14, 2023 at 9:39 AM Heiko Carstens  wrote:
> > On Tue, Feb 14, 2023 at 08:49:01AM +0100, Alexandre Ghiti wrote:
> > > This all came up in the context of increasing COMMAND_LINE_SIZE in the
> > > RISC-V port.  In theory that's a UABI break, as COMMAND_LINE_SIZE is the
> > > maximum length of /proc/cmdline and userspace could staticly rely on
> > > that to be correct.
> > >
> > > Usually I wouldn't mess around with changing this sort of thing, but
> > > PowerPC increased it with a5980d064fe2 ("powerpc: Bump COMMAND_LINE_SIZE
> > > to 2048").  There are also a handful of examples of COMMAND_LINE_SIZE
> > > increasing, but they're from before the UAPI split so I'm not quite sure
> > > what that means: e5a6a1c90948 ("powerpc: derive COMMAND_LINE_SIZE from
> > > asm-generic"), 684d2fd48e71 ("[S390] kernel: Append scpdata to kernel
> > > boot command line"), 22242681cff5 ("MIPS: Extend COMMAND_LINE_SIZE"),
> > > and 2b74b85693c7 ("sh: Derive COMMAND_LINE_SIZE from
> > > asm-generic/setup.h.").
> > >
> > > It seems to me like COMMAND_LINE_SIZE really just shouldn't have been
> > > part of the uapi to begin with, and userspace should be able to handle
> > > /proc/cmdline of whatever length it turns out to be.  I don't see any
> > > references to COMMAND_LINE_SIZE anywhere but Linux via a quick Google
> > > search, but that's not really enough to consider it unused on my end.
> > >
> > > The feedback on the v1 seemed to indicate that COMMAND_LINE_SIZE really
> > > shouldn't be part of uapi, so this now touches all the ports.  I've
> > > tried to split this all out and leave it bisectable, but I haven't
> > > tested it all that aggressively.
> >
> > Just to confirm this assumption a bit more: that's actually the same
> > conclusion that we ended up with when commit 3da0243f906a ("s390: make
> > command line configurable") went upstream.
> 
> Commit 622021cd6c560ce7 ("s390: make command line configurable"),
> I assume?

Yes, sorry for that. I got distracted while writing and used the wrong
branch to look this up.


Re: [PATCH v2 00/24] cpu,sched: Mark arch_cpu_idle_dead() __noreturn

2023-02-14 Thread Philippe Mathieu-Daudé

On 14/2/23 08:05, Josh Poimboeuf wrote:

v2:
- make arch_call_rest_init() and rest_init() __noreturn
- make objtool 'global_returns' work for weak functions
- rebase on tip/objtool/core with dependencies merged in (mingo)
- add acks

v1.1:
- add __noreturn to all arch_cpu_idle_dead() implementations (mpe)


Possible similar candidates: panic_smp_self_stop, nmi_panic_self_stop
and kexec.



Re: [PATCH v3 08/24] parisc: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Helge Deller

On 2/14/23 10:08, Philippe Mathieu-Daudé wrote:

On 14/2/23 08:49, Alexandre Ghiti wrote:

From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
  arch/parisc/include/asm/setup.h  | 7 +++
  arch/parisc/include/uapi/asm/setup.h | 2 --
  2 files changed, 7 insertions(+), 2 deletions(-)
  create mode 100644 arch/parisc/include/asm/setup.h


Reviewed-by: Philippe Mathieu-Daudé 


Acked-by: Helge Deller 





Re: [PATCH v3 19/24] parisc: Remove empty

2023-02-14 Thread Helge Deller

On 2/14/23 10:08, Philippe Mathieu-Daudé wrote:

On 14/2/23 08:49, Alexandre Ghiti wrote:

From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
  arch/parisc/include/uapi/asm/setup.h | 5 -
  1 file changed, 5 deletions(-)
  delete mode 100644 arch/parisc/include/uapi/asm/setup.h


Reviewed-by: Philippe Mathieu-Daudé 


Acked-by: Helge Deller 




Re: API for setting multiple PTEs at once

2023-02-14 Thread Alexandre Ghiti

Hi Matthew,

On 2/7/23 21:27, Matthew Wilcox wrote:

On Thu, Feb 02, 2023 at 09:14:23PM +, Matthew Wilcox wrote:

For those of you not subscribed, linux-mm is currently discussing
how best to handle page faults on large folios.  I simply made it work
when adding large folio support.  Now Yin Fengwei is working on
making it fast.

OK, here's an actual implementation:

https://lore.kernel.org/linux-mm/20230207194937.122543-3-wi...@infradead.org/

It survives a run of xfstests.  If your architecture doesn't store its
PFNs at PAGE_SHIFT, you're going to want to implement your own set_ptes(),
or you'll see entirely the wrong pages mapped into userspace.  You may
also wish to implement set_ptes() if it can be done more efficiently
than __pte(pteval(pte) + PAGE_SIZE).

Architectures that implement things like flush_icache_page() and
update_mmu_cache() may want to propose batched versions of those.
That's alpha, csky, m68k, mips, nios2, parisc, sh,
arm, loongarch, openrisc, powerpc, riscv, sparc and xtensa.
Maintainers BCC'd, mailing lists CC'd.

I'm happy to collect implementations and submit them as part of a v6.



Please find below the riscv implementation for set_ptes:

diff --git a/arch/riscv/include/asm/pgtable.h 
b/arch/riscv/include/asm/pgtable.h

index ebee56d47003..10bf812776a4 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -463,6 +463,20 @@ static inline void set_pte_at(struct mm_struct *mm,
    __set_pte_at(mm, addr, ptep, pteval);
 }

+#define set_ptes set_ptes
+static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
+   pte_t *ptep, pte_t pte, unsigned int nr)
+{
+   for (;;) {
+   set_pte_at(mm, addr, ptep, pte);
+   if (--nr == 0)
+   break;
+   ptep++;
+   addr += PAGE_SIZE;
+   pte = __pte(pte_val(pte) + (1 << _PAGE_PFN_SHIFT));
+   }
+}
+
 static inline void pte_clear(struct mm_struct *mm,
    unsigned long addr, pte_t *ptep)
 {


Thanks,

Alex



[PATCH v3 00/24] Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
This all came up in the context of increasing COMMAND_LINE_SIZE in the
RISC-V port.  In theory that's a UABI break, as COMMAND_LINE_SIZE is the
maximum length of /proc/cmdline and userspace could staticly rely on
that to be correct.

Usually I wouldn't mess around with changing this sort of thing, but
PowerPC increased it with a5980d064fe2 ("powerpc: Bump COMMAND_LINE_SIZE
to 2048").  There are also a handful of examples of COMMAND_LINE_SIZE
increasing, but they're from before the UAPI split so I'm not quite sure
what that means: e5a6a1c90948 ("powerpc: derive COMMAND_LINE_SIZE from
asm-generic"), 684d2fd48e71 ("[S390] kernel: Append scpdata to kernel
boot command line"), 22242681cff5 ("MIPS: Extend COMMAND_LINE_SIZE"),
and 2b74b85693c7 ("sh: Derive COMMAND_LINE_SIZE from
asm-generic/setup.h.").

It seems to me like COMMAND_LINE_SIZE really just shouldn't have been
part of the uapi to begin with, and userspace should be able to handle
/proc/cmdline of whatever length it turns out to be.  I don't see any
references to COMMAND_LINE_SIZE anywhere but Linux via a quick Google
search, but that's not really enough to consider it unused on my end.

The feedback on the v1 seemed to indicate that COMMAND_LINE_SIZE really
shouldn't be part of uapi, so this now touches all the ports.  I've
tried to split this all out and leave it bisectable, but I haven't
tested it all that aggressively.

Changes since v2 
:
* Fix sh, csky and ia64 builds, as reported by kernel test robot

Changes since v1 
:
* Touches every arch.

base-commit-tag: next-20230207

Palmer Dabbelt (24):
  alpha: Remove COMMAND_LINE_SIZE from uapi
  arm64: Remove COMMAND_LINE_SIZE from uapi
  arm: Remove COMMAND_LINE_SIZE from uapi
  ia64: Remove COMMAND_LINE_SIZE from uapi
  m68k: Remove COMMAND_LINE_SIZE from uapi
  microblaze: Remove COMMAND_LINE_SIZE from uapi
  mips: Remove COMMAND_LINE_SIZE from uapi
  parisc: Remove COMMAND_LINE_SIZE from uapi
  powerpc: Remove COMMAND_LINE_SIZE from uapi
  sparc: Remove COMMAND_LINE_SIZE from uapi
  xtensa: Remove COMMAND_LINE_SIZE from uapi
  asm-generic: Remove COMMAND_LINE_SIZE from uapi
  alpha: Remove empty 
  arc: Remove empty 
  m68k: Remove empty 
  arm64: Remove empty 
  microblaze: Remove empty 
  sparc: Remove empty 
  parisc: Remove empty 
  x86: Remove empty 
  xtensa: Remove empty 
  powerpc: Remove empty 
  mips: Remove empty 
  s390: Remove empty 

 .../admin-guide/kernel-parameters.rst |  2 +-
 arch/alpha/include/asm/setup.h|  4 +--
 arch/alpha/include/uapi/asm/setup.h   |  7 -
 arch/arc/include/asm/setup.h  |  1 -
 arch/arc/include/uapi/asm/setup.h |  6 -
 arch/arm/include/asm/setup.h  |  1 +
 arch/arm/include/uapi/asm/setup.h |  2 --
 arch/arm64/include/asm/setup.h|  3 ++-
 arch/arm64/include/uapi/asm/setup.h   | 27 ---
 arch/ia64/include/asm/setup.h | 10 +++
 arch/ia64/include/uapi/asm/setup.h|  6 ++---
 arch/loongarch/include/asm/setup.h|  2 +-
 arch/m68k/include/asm/setup.h |  3 +--
 arch/m68k/include/uapi/asm/setup.h| 17 
 arch/microblaze/include/asm/setup.h   |  2 +-
 arch/microblaze/include/uapi/asm/setup.h  | 20 --
 arch/mips/include/asm/setup.h |  3 ++-
 arch/mips/include/uapi/asm/setup.h|  8 --
 arch/parisc/include/{uapi => }/asm/setup.h|  0
 arch/powerpc/include/asm/setup.h  |  2 +-
 arch/powerpc/include/uapi/asm/setup.h |  7 -
 arch/s390/include/asm/setup.h |  1 -
 arch/s390/include/uapi/asm/setup.h|  1 -
 arch/sh/include/asm/setup.h   |  2 +-
 arch/sparc/include/asm/setup.h|  6 -
 arch/sparc/include/uapi/asm/setup.h   | 16 ---
 arch/x86/include/asm/setup.h  |  2 --
 arch/x86/include/uapi/asm/setup.h |  1 -
 arch/xtensa/include/{uapi => }/asm/setup.h|  0
 include/asm-generic/Kbuild|  1 +
 include/{uapi => }/asm-generic/setup.h|  0
 include/uapi/asm-generic/Kbuild   |  1 -
 32 files changed, 31 insertions(+), 133 deletions(-)
 delete mode 100644 arch/alpha/include/uapi/asm/setup.h
 delete mode 100644 arch/arc/include/uapi/asm/setup.h
 delete mode 100644 arch/arm64/include/uapi/asm/setup.h
 create mode 100644 arch/ia64/include/asm/setup.h
 delete mode 100644 arch/m68k/include/uapi/asm/setup.h
 delete mode 100644 arch/microblaze/include/uapi/asm/setup.h
 delete mode 100644 arch/mips/include/uapi/asm/setup.h
 rename arch/parisc/include/{uapi => }/asm/setup.h (100%)
 delete mode 100644 arch/powerpc/include/uapi/asm/setup.h
 delete mode 100644 arch/s390/include/uapi/asm/setup.h
 delete mode 100644 a

[PATCH v3 01/24] alpha: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
 arch/alpha/include/asm/setup.h  | 4 ++--
 arch/alpha/include/uapi/asm/setup.h | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/alpha/include/asm/setup.h b/arch/alpha/include/asm/setup.h
index 262aab99e391..ea08ca45efa8 100644
--- a/arch/alpha/include/asm/setup.h
+++ b/arch/alpha/include/asm/setup.h
@@ -2,8 +2,6 @@
 #ifndef __ALPHA_SETUP_H
 #define __ALPHA_SETUP_H
 
-#include 
-
 /*
  * We leave one page for the initial stack page, and one page for
  * the initial process structure. Also, the console eats 3 MB for
@@ -14,6 +12,8 @@
 /* Remove when official MILO sources have ELF support: */
 #define BOOT_SIZE  (16*1024)
 
+#define COMMAND_LINE_SIZE  256
+
 #ifdef CONFIG_ALPHA_LEGACY_START_ADDRESS
 #define KERNEL_START_PHYS  0x30 /* Old bootloaders hardcoded this.  */
 #else
diff --git a/arch/alpha/include/uapi/asm/setup.h 
b/arch/alpha/include/uapi/asm/setup.h
index f881ea5947cb..9b3b5ba39b1d 100644
--- a/arch/alpha/include/uapi/asm/setup.h
+++ b/arch/alpha/include/uapi/asm/setup.h
@@ -2,6 +2,4 @@
 #ifndef _UAPI__ALPHA_SETUP_H
 #define _UAPI__ALPHA_SETUP_H
 
-#define COMMAND_LINE_SIZE  256
-
 #endif /* _UAPI__ALPHA_SETUP_H */
-- 
2.37.2



[PATCH v3 02/24] arm64: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
 arch/arm64/include/asm/setup.h  | 3 ++-
 arch/arm64/include/uapi/asm/setup.h | 2 --
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/setup.h b/arch/arm64/include/asm/setup.h
index f4af547ef54c..7ca70f883cee 100644
--- a/arch/arm64/include/asm/setup.h
+++ b/arch/arm64/include/asm/setup.h
@@ -4,8 +4,9 @@
 #define __ARM64_ASM_SETUP_H
 
 #include 
+#include 
 
-#include 
+#define COMMAND_LINE_SIZE  2048
 
 void *get_early_fdt_ptr(void);
 void early_fdt_map(u64 dt_phys);
diff --git a/arch/arm64/include/uapi/asm/setup.h 
b/arch/arm64/include/uapi/asm/setup.h
index 5d703888f351..f9f51e5925aa 100644
--- a/arch/arm64/include/uapi/asm/setup.h
+++ b/arch/arm64/include/uapi/asm/setup.h
@@ -22,6 +22,4 @@
 
 #include 
 
-#define COMMAND_LINE_SIZE  2048
-
 #endif
-- 
2.37.2



[PATCH v3 03/24] arm: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
 arch/arm/include/asm/setup.h  | 1 +
 arch/arm/include/uapi/asm/setup.h | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/setup.h b/arch/arm/include/asm/setup.h
index ba0872a8dcda..8a1e4f804d1b 100644
--- a/arch/arm/include/asm/setup.h
+++ b/arch/arm/include/asm/setup.h
@@ -13,6 +13,7 @@
 
 #include 
 
+#define COMMAND_LINE_SIZE 1024
 
 #define __tag __used __section(".taglist.init")
 #define __tagtable(tag, fn) \
diff --git a/arch/arm/include/uapi/asm/setup.h 
b/arch/arm/include/uapi/asm/setup.h
index 25ceda63b284..87a4f4af28e1 100644
--- a/arch/arm/include/uapi/asm/setup.h
+++ b/arch/arm/include/uapi/asm/setup.h
@@ -17,8 +17,6 @@
 
 #include 
 
-#define COMMAND_LINE_SIZE 1024
-
 /* The list ends with an ATAG_NONE node. */
 #define ATAG_NONE  0x
 
-- 
2.37.2



[PATCH v3 04/24] ia64: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
 arch/ia64/include/asm/setup.h  | 10 ++
 arch/ia64/include/uapi/asm/setup.h |  6 ++
 2 files changed, 12 insertions(+), 4 deletions(-)
 create mode 100644 arch/ia64/include/asm/setup.h

diff --git a/arch/ia64/include/asm/setup.h b/arch/ia64/include/asm/setup.h
new file mode 100644
index ..0b19338ea3ec
--- /dev/null
+++ b/arch/ia64/include/asm/setup.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+
+#ifndef __IA64_SETUP_H
+#define __IA64_SETUP_H
+
+#include 
+
+#define COMMAND_LINE_SIZE  2048
+
+#endif
diff --git a/arch/ia64/include/uapi/asm/setup.h 
b/arch/ia64/include/uapi/asm/setup.h
index 8d13ce8fb03a..bcbb2b242ded 100644
--- a/arch/ia64/include/uapi/asm/setup.h
+++ b/arch/ia64/include/uapi/asm/setup.h
@@ -1,8 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef __IA64_SETUP_H
-#define __IA64_SETUP_H
-
-#define COMMAND_LINE_SIZE  2048
+#ifndef __UAPI_IA64_SETUP_H
+#define __UAPI_IA64_SETUP_H
 
 extern struct ia64_boot_param {
__u64 command_line; /* physical address of command line 
arguments */
-- 
2.37.2



[PATCH v3 05/24] m68k: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
 arch/m68k/include/asm/setup.h  | 3 +--
 arch/m68k/include/uapi/asm/setup.h | 2 --
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/m68k/include/asm/setup.h b/arch/m68k/include/asm/setup.h
index 2c99477aaf89..9a256cc3931d 100644
--- a/arch/m68k/include/asm/setup.h
+++ b/arch/m68k/include/asm/setup.h
@@ -23,9 +23,8 @@
 #define _M68K_SETUP_H
 
 #include 
-#include 
-
 
+#define COMMAND_LINE_SIZE 256
 #define CL_SIZE COMMAND_LINE_SIZE
 
 #ifndef __ASSEMBLY__
diff --git a/arch/m68k/include/uapi/asm/setup.h 
b/arch/m68k/include/uapi/asm/setup.h
index 25fe26d5597c..005593acc7d8 100644
--- a/arch/m68k/include/uapi/asm/setup.h
+++ b/arch/m68k/include/uapi/asm/setup.h
@@ -12,6 +12,4 @@
 #ifndef _UAPI_M68K_SETUP_H
 #define _UAPI_M68K_SETUP_H
 
-#define COMMAND_LINE_SIZE 256
-
 #endif /* _UAPI_M68K_SETUP_H */
-- 
2.37.2



[PATCH v3 06/24] microblaze: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
 arch/microblaze/include/asm/setup.h  | 2 +-
 arch/microblaze/include/uapi/asm/setup.h | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/microblaze/include/asm/setup.h 
b/arch/microblaze/include/asm/setup.h
index a06cc1f97aa9..2becbf3b8baf 100644
--- a/arch/microblaze/include/asm/setup.h
+++ b/arch/microblaze/include/asm/setup.h
@@ -7,7 +7,7 @@
 #ifndef _ASM_MICROBLAZE_SETUP_H
 #define _ASM_MICROBLAZE_SETUP_H
 
-#include 
+#define COMMAND_LINE_SIZE  256
 
 # ifndef __ASSEMBLY__
 extern char cmd_line[COMMAND_LINE_SIZE];
diff --git a/arch/microblaze/include/uapi/asm/setup.h 
b/arch/microblaze/include/uapi/asm/setup.h
index 6831794e6f2c..51aed65880e7 100644
--- a/arch/microblaze/include/uapi/asm/setup.h
+++ b/arch/microblaze/include/uapi/asm/setup.h
@@ -12,8 +12,6 @@
 #ifndef _UAPI_ASM_MICROBLAZE_SETUP_H
 #define _UAPI_ASM_MICROBLAZE_SETUP_H
 
-#define COMMAND_LINE_SIZE  256
-
 # ifndef __ASSEMBLY__
 
 # endif /* __ASSEMBLY__ */
-- 
2.37.2



[PATCH v3 07/24] mips: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
 arch/mips/include/asm/setup.h  | 3 ++-
 arch/mips/include/uapi/asm/setup.h | 3 ---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/mips/include/asm/setup.h b/arch/mips/include/asm/setup.h
index 8c56b862fd9c..a13b9259b476 100644
--- a/arch/mips/include/asm/setup.h
+++ b/arch/mips/include/asm/setup.h
@@ -3,7 +3,8 @@
 #define _MIPS_SETUP_H
 
 #include 
-#include 
+
+#define COMMAND_LINE_SIZE  4096
 
 extern void prom_putchar(char);
 extern void setup_early_printk(void);
diff --git a/arch/mips/include/uapi/asm/setup.h 
b/arch/mips/include/uapi/asm/setup.h
index 7d48c433b0c2..157c3c392fb4 100644
--- a/arch/mips/include/uapi/asm/setup.h
+++ b/arch/mips/include/uapi/asm/setup.h
@@ -2,7 +2,4 @@
 #ifndef _UAPI_MIPS_SETUP_H
 #define _UAPI_MIPS_SETUP_H
 
-#define COMMAND_LINE_SIZE  4096
-
-
 #endif /* _UAPI_MIPS_SETUP_H */
-- 
2.37.2



[PATCH v3 08/24] parisc: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
 arch/parisc/include/asm/setup.h  | 7 +++
 arch/parisc/include/uapi/asm/setup.h | 2 --
 2 files changed, 7 insertions(+), 2 deletions(-)
 create mode 100644 arch/parisc/include/asm/setup.h

diff --git a/arch/parisc/include/asm/setup.h b/arch/parisc/include/asm/setup.h
new file mode 100644
index ..78b2f4ec7d65
--- /dev/null
+++ b/arch/parisc/include/asm/setup.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _PARISC_SETUP_H
+#define _PARISC_SETUP_H
+
+#define COMMAND_LINE_SIZE  1024
+
+#endif /* _PARISC_SETUP_H */
diff --git a/arch/parisc/include/uapi/asm/setup.h 
b/arch/parisc/include/uapi/asm/setup.h
index 78b2f4ec7d65..bfad89428e47 100644
--- a/arch/parisc/include/uapi/asm/setup.h
+++ b/arch/parisc/include/uapi/asm/setup.h
@@ -2,6 +2,4 @@
 #ifndef _PARISC_SETUP_H
 #define _PARISC_SETUP_H
 
-#define COMMAND_LINE_SIZE  1024
-
 #endif /* _PARISC_SETUP_H */
-- 
2.37.2



[PATCH v3 09/24] powerpc: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
 arch/powerpc/include/asm/setup.h  | 2 +-
 arch/powerpc/include/uapi/asm/setup.h | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/setup.h b/arch/powerpc/include/asm/setup.h
index e29e83f8a89c..31786d1db2ef 100644
--- a/arch/powerpc/include/asm/setup.h
+++ b/arch/powerpc/include/asm/setup.h
@@ -2,7 +2,7 @@
 #ifndef _ASM_POWERPC_SETUP_H
 #define _ASM_POWERPC_SETUP_H
 
-#include 
+#define COMMAND_LINE_SIZE  2048
 
 #ifndef __ASSEMBLY__
 extern void ppc_printk_progress(char *s, unsigned short hex);
diff --git a/arch/powerpc/include/uapi/asm/setup.h 
b/arch/powerpc/include/uapi/asm/setup.h
index c54940b09d06..f2ca747aa45b 100644
--- a/arch/powerpc/include/uapi/asm/setup.h
+++ b/arch/powerpc/include/uapi/asm/setup.h
@@ -2,6 +2,4 @@
 #ifndef _UAPI_ASM_POWERPC_SETUP_H
 #define _UAPI_ASM_POWERPC_SETUP_H
 
-#define COMMAND_LINE_SIZE  2048
-
 #endif /* _UAPI_ASM_POWERPC_SETUP_H */
-- 
2.37.2



[PATCH v3 10/24] sparc: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
 arch/sparc/include/asm/setup.h  | 6 +-
 arch/sparc/include/uapi/asm/setup.h | 7 ---
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
index 72205684e51e..d1384ed92547 100644
--- a/arch/sparc/include/asm/setup.h
+++ b/arch/sparc/include/asm/setup.h
@@ -7,7 +7,11 @@
 
 #include 
 
-#include 
+#if defined(__sparc__) && defined(__arch64__)
+# define COMMAND_LINE_SIZE 2048
+#else
+# define COMMAND_LINE_SIZE 256
+#endif
 
 extern char reboot_command[];
 
diff --git a/arch/sparc/include/uapi/asm/setup.h 
b/arch/sparc/include/uapi/asm/setup.h
index 3c208a4dd464..c3cf1b0d30b3 100644
--- a/arch/sparc/include/uapi/asm/setup.h
+++ b/arch/sparc/include/uapi/asm/setup.h
@@ -6,11 +6,4 @@
 #ifndef _UAPI_SPARC_SETUP_H
 #define _UAPI_SPARC_SETUP_H
 
-#if defined(__sparc__) && defined(__arch64__)
-# define COMMAND_LINE_SIZE 2048
-#else
-# define COMMAND_LINE_SIZE 256
-#endif
-
-
 #endif /* _UAPI_SPARC_SETUP_H */
-- 
2.37.2



[PATCH v3 11/24] xtensa: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.

Signed-off-by: Palmer Dabbelt 
---
 arch/xtensa/include/asm/setup.h  | 17 +
 arch/xtensa/include/uapi/asm/setup.h |  2 --
 2 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 arch/xtensa/include/asm/setup.h

diff --git a/arch/xtensa/include/asm/setup.h b/arch/xtensa/include/asm/setup.h
new file mode 100644
index ..5356a5fd4d17
--- /dev/null
+++ b/arch/xtensa/include/asm/setup.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * include/asm-xtensa/setup.h
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2001 - 2005 Tensilica Inc.
+ */
+
+#ifndef _XTENSA_SETUP_H
+#define _XTENSA_SETUP_H
+
+#define COMMAND_LINE_SIZE  256
+
+#endif
diff --git a/arch/xtensa/include/uapi/asm/setup.h 
b/arch/xtensa/include/uapi/asm/setup.h
index 5356a5fd4d17..6f982394684a 100644
--- a/arch/xtensa/include/uapi/asm/setup.h
+++ b/arch/xtensa/include/uapi/asm/setup.h
@@ -12,6 +12,4 @@
 #ifndef _XTENSA_SETUP_H
 #define _XTENSA_SETUP_H
 
-#define COMMAND_LINE_SIZE  256
-
 #endif
-- 
2.37.2



[PATCH v3 12/24] asm-generic: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

As far as I can tell this is not used by userspace and thus should not
be part of the user-visible API.  Since  only
contains COMMAND_LINE_SIZE we can just move it out of uapi to hide the
definition and fix up the only direct use in Loongarch.

Signed-off-by: Palmer Dabbelt 
Link: https://lore.kernel.org/r/20210423025545.313965-1-pal...@dabbelt.com
Signed-off-by: Palmer Dabbelt 
---
 Documentation/admin-guide/kernel-parameters.rst | 2 +-
 arch/loongarch/include/asm/setup.h  | 2 +-
 arch/sh/include/asm/setup.h | 2 +-
 include/asm-generic/Kbuild  | 1 +
 include/{uapi => }/asm-generic/setup.h  | 0
 include/uapi/asm-generic/Kbuild | 1 -
 6 files changed, 4 insertions(+), 4 deletions(-)
 rename include/{uapi => }/asm-generic/setup.h (100%)

diff --git a/Documentation/admin-guide/kernel-parameters.rst 
b/Documentation/admin-guide/kernel-parameters.rst
index 19600c50277b..2b94d5a42bd6 100644
--- a/Documentation/admin-guide/kernel-parameters.rst
+++ b/Documentation/admin-guide/kernel-parameters.rst
@@ -207,7 +207,7 @@ The number of kernel parameters is not limited, but the 
length of the
 complete command line (parameters including spaces etc.) is limited to
 a fixed number of characters. This limit depends on the architecture
 and is between 256 and 4096 characters. It is defined in the file
-./include/uapi/asm-generic/setup.h as COMMAND_LINE_SIZE.
+./include/asm-generic/setup.h as COMMAND_LINE_SIZE.
 
 Finally, the [KMG] suffix is commonly described after a number of kernel
 parameter values. These 'K', 'M', and 'G' letters represent the _binary_
diff --git a/arch/loongarch/include/asm/setup.h 
b/arch/loongarch/include/asm/setup.h
index 72ead58039f3..86c99b183ea0 100644
--- a/arch/loongarch/include/asm/setup.h
+++ b/arch/loongarch/include/asm/setup.h
@@ -7,7 +7,7 @@
 #define _LOONGARCH_SETUP_H
 
 #include 
-#include 
+#include 
 
 #define VECSIZE 0x200
 
diff --git a/arch/sh/include/asm/setup.h b/arch/sh/include/asm/setup.h
index fc807011187f..ae09b1c29fd1 100644
--- a/arch/sh/include/asm/setup.h
+++ b/arch/sh/include/asm/setup.h
@@ -2,7 +2,7 @@
 #ifndef _SH_SETUP_H
 #define _SH_SETUP_H
 
-#include 
+#include 
 
 /*
  * This is set up by the setup-routine at boot-time
diff --git a/include/asm-generic/Kbuild b/include/asm-generic/Kbuild
index 941be574bbe0..0fb55a119f54 100644
--- a/include/asm-generic/Kbuild
+++ b/include/asm-generic/Kbuild
@@ -49,6 +49,7 @@ mandatory-y += preempt.h
 mandatory-y += rwonce.h
 mandatory-y += sections.h
 mandatory-y += serial.h
+mandatory-y += setup.h
 mandatory-y += shmparam.h
 mandatory-y += simd.h
 mandatory-y += softirq_stack.h
diff --git a/include/uapi/asm-generic/setup.h b/include/asm-generic/setup.h
similarity index 100%
rename from include/uapi/asm-generic/setup.h
rename to include/asm-generic/setup.h
diff --git a/include/uapi/asm-generic/Kbuild b/include/uapi/asm-generic/Kbuild
index ebb180aac74e..0e7122339ee9 100644
--- a/include/uapi/asm-generic/Kbuild
+++ b/include/uapi/asm-generic/Kbuild
@@ -20,7 +20,6 @@ mandatory-y += posix_types.h
 mandatory-y += ptrace.h
 mandatory-y += resource.h
 mandatory-y += sembuf.h
-mandatory-y += setup.h
 mandatory-y += shmbuf.h
 mandatory-y += sigcontext.h
 mandatory-y += siginfo.h
-- 
2.37.2



[PATCH v3 13/24] alpha: Remove empty

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
 arch/alpha/include/uapi/asm/setup.h | 5 -
 1 file changed, 5 deletions(-)
 delete mode 100644 arch/alpha/include/uapi/asm/setup.h

diff --git a/arch/alpha/include/uapi/asm/setup.h 
b/arch/alpha/include/uapi/asm/setup.h
deleted file mode 100644
index 9b3b5ba39b1d..
--- a/arch/alpha/include/uapi/asm/setup.h
+++ /dev/null
@@ -1,5 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _UAPI__ALPHA_SETUP_H
-#define _UAPI__ALPHA_SETUP_H
-
-#endif /* _UAPI__ALPHA_SETUP_H */
-- 
2.37.2



[PATCH v3 14/24] arc: Remove empty

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
 arch/arc/include/asm/setup.h  | 1 -
 arch/arc/include/uapi/asm/setup.h | 6 --
 2 files changed, 7 deletions(-)
 delete mode 100644 arch/arc/include/uapi/asm/setup.h

diff --git a/arch/arc/include/asm/setup.h b/arch/arc/include/asm/setup.h
index 028a8cf76206..fe45ff4681bc 100644
--- a/arch/arc/include/asm/setup.h
+++ b/arch/arc/include/asm/setup.h
@@ -7,7 +7,6 @@
 
 
 #include 
-#include 
 
 #define COMMAND_LINE_SIZE 256
 
diff --git a/arch/arc/include/uapi/asm/setup.h 
b/arch/arc/include/uapi/asm/setup.h
deleted file mode 100644
index a6d4e44938be..
--- a/arch/arc/include/uapi/asm/setup.h
+++ /dev/null
@@ -1,6 +0,0 @@
-/*
- * setup.h is part of userspace header ABI so UAPI scripts have to generate it
- * even if there's nothing to export - causing empty 
- * However to prevent "patch" from discarding it we add this placeholder
- * comment
- */
-- 
2.37.2



[PATCH v3 15/24] m68k: Remove empty

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
 arch/m68k/include/uapi/asm/setup.h | 15 ---
 1 file changed, 15 deletions(-)
 delete mode 100644 arch/m68k/include/uapi/asm/setup.h

diff --git a/arch/m68k/include/uapi/asm/setup.h 
b/arch/m68k/include/uapi/asm/setup.h
deleted file mode 100644
index 005593acc7d8..
--- a/arch/m68k/include/uapi/asm/setup.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/*
-** asm/setup.h -- Definition of the Linux/m68k setup information
-**
-** Copyright 1992 by Greg Harp
-**
-** This file is subject to the terms and conditions of the GNU General Public
-** License.  See the file COPYING in the main directory of this archive
-** for more details.
-*/
-
-#ifndef _UAPI_M68K_SETUP_H
-#define _UAPI_M68K_SETUP_H
-
-#endif /* _UAPI_M68K_SETUP_H */
-- 
2.37.2



[PATCH v3 16/24] arm64: Remove empty

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
 arch/arm64/include/uapi/asm/setup.h | 25 -
 1 file changed, 25 deletions(-)
 delete mode 100644 arch/arm64/include/uapi/asm/setup.h

diff --git a/arch/arm64/include/uapi/asm/setup.h 
b/arch/arm64/include/uapi/asm/setup.h
deleted file mode 100644
index f9f51e5925aa..
--- a/arch/arm64/include/uapi/asm/setup.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/*
- * Based on arch/arm/include/asm/setup.h
- *
- * Copyright (C) 1997-1999 Russell King
- * Copyright (C) 2012 ARM Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see .
- */
-#ifndef __ASM_SETUP_H
-#define __ASM_SETUP_H
-
-#include 
-
-#endif
-- 
2.37.2



[PATCH v3 17/24] microblaze: Remove empty

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
 arch/microblaze/include/uapi/asm/setup.h | 18 --
 1 file changed, 18 deletions(-)
 delete mode 100644 arch/microblaze/include/uapi/asm/setup.h

diff --git a/arch/microblaze/include/uapi/asm/setup.h 
b/arch/microblaze/include/uapi/asm/setup.h
deleted file mode 100644
index 51aed65880e7..
--- a/arch/microblaze/include/uapi/asm/setup.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/*
- * Copyright (C) 2007-2009 Michal Simek 
- * Copyright (C) 2007-2009 PetaLogix
- * Copyright (C) 2006 Atmark Techno, Inc.
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License. See the file "COPYING" in the main directory of this archive
- * for more details.
- */
-
-#ifndef _UAPI_ASM_MICROBLAZE_SETUP_H
-#define _UAPI_ASM_MICROBLAZE_SETUP_H
-
-# ifndef __ASSEMBLY__
-
-# endif /* __ASSEMBLY__ */
-#endif /* _UAPI_ASM_MICROBLAZE_SETUP_H */
-- 
2.37.2



[PATCH v3 18/24] sparc: Remove empty

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
 arch/sparc/include/uapi/asm/setup.h | 9 -
 1 file changed, 9 deletions(-)
 delete mode 100644 arch/sparc/include/uapi/asm/setup.h

diff --git a/arch/sparc/include/uapi/asm/setup.h 
b/arch/sparc/include/uapi/asm/setup.h
deleted file mode 100644
index c3cf1b0d30b3..
--- a/arch/sparc/include/uapi/asm/setup.h
+++ /dev/null
@@ -1,9 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/*
- * Just a place holder. 
- */
-
-#ifndef _UAPI_SPARC_SETUP_H
-#define _UAPI_SPARC_SETUP_H
-
-#endif /* _UAPI_SPARC_SETUP_H */
-- 
2.37.2



[PATCH v3 19/24] parisc: Remove empty

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
 arch/parisc/include/uapi/asm/setup.h | 5 -
 1 file changed, 5 deletions(-)
 delete mode 100644 arch/parisc/include/uapi/asm/setup.h

diff --git a/arch/parisc/include/uapi/asm/setup.h 
b/arch/parisc/include/uapi/asm/setup.h
deleted file mode 100644
index bfad89428e47..
--- a/arch/parisc/include/uapi/asm/setup.h
+++ /dev/null
@@ -1,5 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _PARISC_SETUP_H
-#define _PARISC_SETUP_H
-
-#endif /* _PARISC_SETUP_H */
-- 
2.37.2



[PATCH v3 20/24] x86: Remove empty

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
 arch/x86/include/asm/setup.h  | 2 --
 arch/x86/include/uapi/asm/setup.h | 1 -
 2 files changed, 3 deletions(-)
 delete mode 100644 arch/x86/include/uapi/asm/setup.h

diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
index f37cbff7354c..449b50a2f390 100644
--- a/arch/x86/include/asm/setup.h
+++ b/arch/x86/include/asm/setup.h
@@ -2,8 +2,6 @@
 #ifndef _ASM_X86_SETUP_H
 #define _ASM_X86_SETUP_H
 
-#include 
-
 #define COMMAND_LINE_SIZE 2048
 
 #include 
diff --git a/arch/x86/include/uapi/asm/setup.h 
b/arch/x86/include/uapi/asm/setup.h
deleted file mode 100644
index 79a9626b5500..
--- a/arch/x86/include/uapi/asm/setup.h
+++ /dev/null
@@ -1 +0,0 @@
-/* */
-- 
2.37.2



[PATCH v3 21/24] xtensa: Remove empty

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
 arch/xtensa/include/uapi/asm/setup.h | 15 ---
 1 file changed, 15 deletions(-)
 delete mode 100644 arch/xtensa/include/uapi/asm/setup.h

diff --git a/arch/xtensa/include/uapi/asm/setup.h 
b/arch/xtensa/include/uapi/asm/setup.h
deleted file mode 100644
index 6f982394684a..
--- a/arch/xtensa/include/uapi/asm/setup.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-/*
- * include/asm-xtensa/setup.h
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file "COPYING" in the main directory of this archive
- * for more details.
- *
- * Copyright (C) 2001 - 2005 Tensilica Inc.
- */
-
-#ifndef _XTENSA_SETUP_H
-#define _XTENSA_SETUP_H
-
-#endif
-- 
2.37.2



[PATCH v3 22/24] powerpc: Remove empty

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
 arch/powerpc/include/uapi/asm/setup.h | 5 -
 1 file changed, 5 deletions(-)
 delete mode 100644 arch/powerpc/include/uapi/asm/setup.h

diff --git a/arch/powerpc/include/uapi/asm/setup.h 
b/arch/powerpc/include/uapi/asm/setup.h
deleted file mode 100644
index f2ca747aa45b..
--- a/arch/powerpc/include/uapi/asm/setup.h
+++ /dev/null
@@ -1,5 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _UAPI_ASM_POWERPC_SETUP_H
-#define _UAPI_ASM_POWERPC_SETUP_H
-
-#endif /* _UAPI_ASM_POWERPC_SETUP_H */
-- 
2.37.2



[PATCH v3 23/24] mips: Remove empty

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
 arch/mips/include/uapi/asm/setup.h | 5 -
 1 file changed, 5 deletions(-)
 delete mode 100644 arch/mips/include/uapi/asm/setup.h

diff --git a/arch/mips/include/uapi/asm/setup.h 
b/arch/mips/include/uapi/asm/setup.h
deleted file mode 100644
index 157c3c392fb4..
--- a/arch/mips/include/uapi/asm/setup.h
+++ /dev/null
@@ -1,5 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _UAPI_MIPS_SETUP_H
-#define _UAPI_MIPS_SETUP_H
-
-#endif /* _UAPI_MIPS_SETUP_H */
-- 
2.37.2



[PATCH v3 24/24] s390: Remove empty

2023-02-14 Thread Alexandre Ghiti
From: Palmer Dabbelt 

Signed-off-by: Palmer Dabbelt 
---
 arch/s390/include/asm/setup.h  | 1 -
 arch/s390/include/uapi/asm/setup.h | 1 -
 2 files changed, 2 deletions(-)
 delete mode 100644 arch/s390/include/uapi/asm/setup.h

diff --git a/arch/s390/include/asm/setup.h b/arch/s390/include/asm/setup.h
index 177bf6deaa27..99c1cc97350a 100644
--- a/arch/s390/include/asm/setup.h
+++ b/arch/s390/include/asm/setup.h
@@ -7,7 +7,6 @@
 #define _ASM_S390_SETUP_H
 
 #include 
-#include 
 #include 
 
 #define PARMAREA   0x10400
diff --git a/arch/s390/include/uapi/asm/setup.h 
b/arch/s390/include/uapi/asm/setup.h
deleted file mode 100644
index 598d769e76df..
--- a/arch/s390/include/uapi/asm/setup.h
+++ /dev/null
@@ -1 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-- 
2.37.2



Re: [PATCH v3 10/24] sparc: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread John Paul Adrian Glaubitz
On Tue, 2023-02-14 at 16:59 +0800, WANG Xuerui wrote:
> On 2023/2/14 16:50, Sergey Shtylyov wrote:
> > On 2/14/23 10:49 AM, Alexandre Ghiti wrote:
> > 
> > > From: Palmer Dabbelt 
> > > 
> > > As far as I can tell this is not used by userspace and thus should not
> > > be part of the user-visible API.
> > > 
> > > Signed-off-by: Palmer Dabbelt 
> > > ---
> > >   arch/sparc/include/asm/setup.h  | 6 +-
> > >   arch/sparc/include/uapi/asm/setup.h | 7 ---
> > >   2 files changed, 5 insertions(+), 8 deletions(-)
> > > 
> > > diff --git a/arch/sparc/include/asm/setup.h 
> > > b/arch/sparc/include/asm/setup.h
> > > index 72205684e51e..d1384ed92547 100644
> > > --- a/arch/sparc/include/asm/setup.h
> > > +++ b/arch/sparc/include/asm/setup.h
> > > @@ -7,7 +7,11 @@
> > >   
> > >   #include 
> > >   
> > > -#include 
> > > +#if defined(__sparc__) && defined(__arch64__)
> > 
> > Mhm, I don't think these two can be #define'd simulaneously...
> 
> I believe it's just a SPARC-ism [1] [2] that may look strange and be 
> easily confused for __aarch64__ (notice the extra 'a')...

Yep, that's correct. On 64-bit Linux/SPARC, gcc/clang define __sparc__ AND 
__arch64__.

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913


[powerpc:next] BUILD SUCCESS 08273c9f619cb32fb041935724f576e607101f3b

2023-02-14 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git 
next
branch HEAD: 08273c9f619cb32fb041935724f576e607101f3b  powerpc/rtas: arch-wide 
function token lookup conversions

elapsed time: 1340m

configs tested: 42
configs skipped: 3

The following configs have been built successfully.
More configs may be tested in the coming days.

gcc tested configs:
alphaallyesconfig
alpha   defconfig
arc  allyesconfig
arc defconfig
arm  allmodconfig
arm  allyesconfig
arm defconfig
arm64allyesconfig
arm64   defconfig
cskydefconfig
i386 allyesconfig
i386  debian-10.3
i386defconfig
ia64 allmodconfig
ia64defconfig
loongarchallmodconfig
loongarch allnoconfig
loongarch   defconfig
m68k allmodconfig
m68kdefconfig
mips allmodconfig
mips allyesconfig
nios2   defconfig
parisc  defconfig
parisc64defconfig
powerpc  allmodconfig
powerpc   allnoconfig
riscvallmodconfig
riscv allnoconfig
riscv   defconfig
riscv  rv32_defconfig
s390 allmodconfig
s390 allyesconfig
s390defconfig
sh   allmodconfig
sparc   defconfig
um i386_defconfig
um   x86_64_defconfig
x86_64   allyesconfig
x86_64  defconfig
x86_64  kexec
x86_64   rhel-8.3

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests


Re: [PATCH v2 03/24] arm/cpu: Make sure arch_cpu_idle_dead() doesn't return

2023-02-14 Thread Russell King (Oracle)
On Mon, Feb 13, 2023 at 11:05:37PM -0800, Josh Poimboeuf wrote:
> arch_cpu_idle_dead() doesn't return.  Make that more explicit with a
> BUG().
> 
> BUG() is preferable to unreachable() because BUG() is a more explicit
> failure mode and avoids undefined behavior like falling off the edge of
> the function into whatever code happens to be next.

This is silly. Just mark the function __noreturn and be done with it.
If the CPU ever executes code past the "b" instruction, it's already
really broken that the extra instructions that BUG() gives will be
meaningless.

This patch does nothing except add yet more bloat the kernel.

Sorry, but NAK.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!


Re: [PATCH v2 20/24] xtensa/cpu: Mark cpu_die() __noreturn

2023-02-14 Thread Max Filippov
On Mon, Feb 13, 2023 at 11:07 PM Josh Poimboeuf  wrote:
>
> cpu_die() doesn't return.  Annotate it as such.  By extension this also
> makes arch_cpu_idle_dead() noreturn.
>
> Signed-off-by: Josh Poimboeuf 
> ---
>  arch/xtensa/include/asm/smp.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Max Filippov 

-- 
Thanks.
-- Max


Re: [PATCH v3 11/24] xtensa: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Max Filippov
On Tue, Feb 14, 2023 at 12:01 AM Alexandre Ghiti  wrote:
>
> From: Palmer Dabbelt 
>
> As far as I can tell this is not used by userspace and thus should not
> be part of the user-visible API.
>
> Signed-off-by: Palmer Dabbelt 
> ---
>  arch/xtensa/include/asm/setup.h  | 17 +
>  arch/xtensa/include/uapi/asm/setup.h |  2 --
>  2 files changed, 17 insertions(+), 2 deletions(-)
>  create mode 100644 arch/xtensa/include/asm/setup.h

Acked-by: Max Filippov 

-- 
Thanks.
-- Max


Re: [PATCH v3 21/24] xtensa: Remove empty

2023-02-14 Thread Max Filippov
On Tue, Feb 14, 2023 at 12:11 AM Alexandre Ghiti  wrote:
>
> From: Palmer Dabbelt 
>
> Signed-off-by: Palmer Dabbelt 
> ---
>  arch/xtensa/include/uapi/asm/setup.h | 15 ---
>  1 file changed, 15 deletions(-)
>  delete mode 100644 arch/xtensa/include/uapi/asm/setup.h

Acked-by: Max Filippov 

-- 
Thanks.
-- Max


Re: [PATCH v4 0/7] Generic IPI sending tracepoint

2023-02-14 Thread Valentin Schneider


Hey folks,

On 19/01/23 14:36, Valentin Schneider wrote:
> Patches
> ===
>
> o Patches 1-5 spread out the tracepoint across relevant sites.
>   Patch 5 ends up sprinkling lots of #include  which I'm 
> not
>   the biggest fan of, but is the least horrible solution I've been able to 
> come
>   up with so far.
>
> o Patch 7 is trying to be smart about tracing the callback associated with the
>   IPI.
>
> This results in having IPI trace events for:
>
> o smp_call_function*()
> o smp_send_reschedule()
> o irq_work_queue*()
> o standalone uses of __smp_call_single_queue()
>

This still rebases cleanly on top of the latest tip/sched/core, any
objections to parking it there?



Re: [PATCH v3 02/24] arm64: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Catalin Marinas
On Tue, Feb 14, 2023 at 08:49:03AM +0100, Alexandre Ghiti wrote:
> From: Palmer Dabbelt 
> 
> As far as I can tell this is not used by userspace and thus should not
> be part of the user-visible API.
> 
> Signed-off-by: Palmer Dabbelt 

Acked-by: Catalin Marinas 


Re: [PATCH] powerpc/pseries/cpuhp: respect current SMT when adding new CPU

2023-02-14 Thread Laurent Dufour
On 13/02/2023 16:40:50, Nathan Lynch wrote:
> Michal Suchánek  writes:
>> On Mon, Feb 13, 2023 at 08:46:50AM -0600, Nathan Lynch wrote:
>>> Laurent Dufour  writes:
 When a new CPU is added, the kernel is activating all its threads. This
 leads to weird, but functional, result when adding CPU on a SMT 4 system
 for instance.

 Here the newly added CPU 1 has 8 threads while the other one has 4 threads
 active (system has been booted with the 'smt-enabled=4' kernel option):

 ltcden3-lp12:~ # ppc64_cpu --info
 Core   0:0*1*2*3*4 5 6 7
 Core   1:8*9*   10*   11*   12*   13*   14*   15*

 There is no SMT value in the kernel. It is possible to run unbalanced LPAR
 with 2 threads for a CPU, 4 for another one, and 5 on the latest.

 To work around this possibility, and assuming that the LPAR run with the
 same number of threads for each CPU, which is the common case,
>>>
>>> I am skeptical at best of baking that assumption into this code. Mixed
>>> SMT modes within a partition doesn't strike me as an unreasonable
>>> possibility for some use cases. And if that's wrong, then we should just
>>> add a global smt value instead of using heuristics.
>>>
 the number
 of active threads of the CPU doing the hot-plug operation is computed. Only
 that number of threads will be activated for the newly added CPU.

 This way on a LPAR running in SMT=4, newly added CPU will be running 4
 threads, which is what a end user would expect.
>>>
>>> I could see why most users would prefer this new behavior. But surely
>>> some users have come to expect the existing behavior, which has been in
>>> place for years, and developed workarounds that might be broken by this
>>> change?
>>>
>>> I would suggest that to handle this well, we need to give user space
>>> more ability to tell the kernel what actions to take on added cores, on
>>> an opt-in basis.
>>>
>>> This could take the form of extending the DLPAR sysfs command set:
>>>
>>> Option 1 - Add a flag that tells the kernel not to online any threads at
>>> all; user space will online the desired threads later.
>>>
>>> Option 2 - Add an option that tells the kernel which SMT mode to apply.
>>
>> powerpc-utils grew some drmgr hooks recently so maybe the policy can be
>> moved to userspace?
> 
> I'm not sure whether the hook mechanism would come into play, but yes, I
> am suggesting that user space be given the option of overriding the
> kernel's current behavior.

I agree, sounds doable using the new drmgr hook mechanism.


Re: [PATCH v2 00/33] Per-VMA locks

2023-02-14 Thread Suren Baghdasaryan
On Fri, Jan 27, 2023 at 4:00 PM Suren Baghdasaryan  wrote:
>
> On Fri, Jan 27, 2023 at 3:26 PM Matthew Wilcox  wrote:
> >
> > On Fri, Jan 27, 2023 at 02:51:38PM -0800, Andrew Morton wrote:
> > > On Fri, 27 Jan 2023 11:40:37 -0800 Suren Baghdasaryan  
> > > wrote:
> > >
> > > > Per-vma locks idea that was discussed during SPF [1] discussion at 
> > > > LSF/MM
> > > > last year [2], which concluded with suggestion that “a reader/writer
> > > > semaphore could be put into the VMA itself; that would have the effect 
> > > > of
> > > > using the VMA as a sort of range lock. There would still be contention 
> > > > at
> > > > the VMA level, but it would be an improvement.” This patchset implements
> > > > this suggested approach.
> > >
> > > I think I'll await reviewer/tester input for a while.

Over the last two weeks I did not receive any feedback on the mailing
list but off-list a couple of people reported positive results in
their tests and Punit reported a regression on his NUMA machine when
running pft-threads workload. I found the source of that regression
and have two small fixes which were confirmed to improve the
performance (hopefully Punit will share the results here).
I'm planning to post v3 sometime this week. If anyone has additional
feedback, please let me know soon so that I can address it in the v3.
Thanks,
Suren.


>
> Sure, I don't expect the review to be very quick considering the
> complexity, however I would appreciate any testing that can be done.
>
> > >
> > > > The patchset implements per-VMA locking only for anonymous pages which
> > > > are not in swap and avoids userfaultfs as their implementation is more
> > > > complex. Additional support for file-back page faults, swapped and user
> > > > pages can be added incrementally.
> > >
> > > This is a significant risk.  How can we be confident that these as yet
> > > unimplemented parts are implementable and that the result will be good?
> >
> > They don't need to be implementable for this patchset to be evaluated
> > on its own terms.  This patchset improves scalability for anon pages
> > without making file/swap/uffd pages worse (or if it does, I haven't
> > seen the benchmarks to prove it).
>
> Making it work for all kinds of page faults would require much more
> time. So, this incremental approach, when we tackle the mmap_lock
> scalability problem part-by-part seems more doable. Even with
> anonymous-only support, the patch shows considerable improvements.
> Therefore I would argue that the patch is viable even if it does not
> support the above-mentioned cases.
>
> >
> > That said, I'm confident that I have a good handle on how to make
> > file-backed page faults work under RCU.
>
> Looking forward to collaborating on that!
> Thanks,
> Suren.


RE: [PATCH 1/1] PCI: layerscape: Set 64-bit DMA mask

2023-02-14 Thread Frank Li
> -Original Message-
> From: Frank Li
> Subject: RE: [PATCH 1/1] PCI: layerscape: Set 64-bit DMA mask
> 
> 
> > Subject: [PATCH 1/1] PCI: layerscape: Set 64-bit DMA mask
> >
> > From: Guanhua Gao 
> >
> > Set DMA mask and coherent DMA mask to enable 64-bit addressing.
> >
> > Signed-off-by: Guanhua Gao 
> > Signed-off-by: Hou Zhiqiang 
> > Signed-off-by: Frank Li 
> > ---
> 
> Ping

Ping again

> 
> >  drivers/pci/controller/dwc/pci-layerscape-ep.c | 4 
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/pci/controller/dwc/pci-layerscape-ep.c


RE: [PATCH 1/1] PCI: layerscape: Add the workaround for A-010305

2023-02-14 Thread Frank Li
> -Original Message-
> From: Frank Li
> Subject: RE: [PATCH 1/1] PCI: layerscape: Add the workaround for A-010305
> 
> > Subject: [PATCH 1/1] PCI: layerscape: Add the workaround for A-010305
> >
> > From: Xiaowei Bao 
> >
> > When a link down or hot reset event occurs, the PCI Express EP
> > controller's Link Capabilities Register should retain the values of
> > the Maximum Link Width and Supported Link Speed configured by RCW.
> >
> > Signed-off-by: Xiaowei Bao 
> > Signed-off-by: Hou Zhiqiang 
> > Signed-off-by: Frank Li 
> > ---
> 
> Ping

Friendly ping. 

> 
>
> >  static struct platform_driver ls_pcie_ep_driver = {
> > --
> > 2.34.1



Re: [PATCH 1/1] PCI: layerscape: Set 64-bit DMA mask

2023-02-14 Thread Sean Anderson
On 1/12/23 14:36, Frank Li wrote:
> From: Guanhua Gao 
> 
> Set DMA mask and coherent DMA mask to enable 64-bit addressing.
> 
> Signed-off-by: Guanhua Gao 
> Signed-off-by: Hou Zhiqiang 
> Signed-off-by: Frank Li 
> ---
>  drivers/pci/controller/dwc/pci-layerscape-ep.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/pci/controller/dwc/pci-layerscape-ep.c 
> b/drivers/pci/controller/dwc/pci-layerscape-ep.c
> index 1b884854c18e..c19e7ec58b05 100644
> --- a/drivers/pci/controller/dwc/pci-layerscape-ep.c
> +++ b/drivers/pci/controller/dwc/pci-layerscape-ep.c
> @@ -261,6 +261,10 @@ static int __init ls_pcie_ep_probe(struct 
> platform_device *pdev)
>   pcie->max_width = (dw_pcie_readw_dbi(pci, PCIE_LINK_CAP) >>
> MAX_LINK_W_SHIFT) & MAX_LINK_W_MASK;
>  
> + /* set 64-bit DMA mask and coherent DMA mask */
> + if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)))
> + dev_warn(dev, "Failed to set 64-bit DMA mask.\n");

Isn't this mandatory? Why not dev_err_probe and return the error?

--Sean

>   platform_set_drvdata(pdev, pcie);
>  
>   ret = dw_pcie_ep_init(&pci->ep);



Re: [PATCH] ASoC: imx-pcm-rpmsg: Remove unused variable

2023-02-14 Thread Mark Brown
On Mon, 13 Feb 2023 23:43:03 +0530, Deepak R Varma wrote:
> Variable ret is initialed but is never modified or used except for
> returning the initial value 0. The value can be directly returned
> instead and the variable definition can be dropped.
> Issue identified using returnvar.cocci Coccinelle semantic patch.
> 
> 

Applied to

   broonie/sound.git for-next

Thanks!

[1/1] ASoC: imx-pcm-rpmsg: Remove unused variable
  commit: 88541443497d47313ec4de1ecc1946288ae0ed16

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark



Re: [PATCH v2 09/24] mips/cpu: Expose play_dead()'s prototype definition

2023-02-14 Thread Josh Poimboeuf
On Tue, Feb 14, 2023 at 08:46:41AM +0100, Philippe Mathieu-Daudé wrote:
> Hi Josh,
> 
> On 14/2/23 08:05, Josh Poimboeuf wrote:
> > Include  to make sure play_dead() matches its prototype going
> > forward.
> > 
> > Acked-by: Florian Fainelli 
> > Signed-off-by: Josh Poimboeuf 
> > ---
> >   arch/mips/kernel/smp-bmips.c | 1 +
> >   1 file changed, 1 insertion(+)
> > 
> > diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
> > index f5d7bfa3472a..df9158e8329d 100644
> > --- a/arch/mips/kernel/smp-bmips.c
> > +++ b/arch/mips/kernel/smp-bmips.c
> > @@ -38,6 +38,7 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> 
> What about the other implementations?
> 
> $ git grep -L asm/smp.h $(git grep -wlF 'play_dead(void)' arch/mips)
> arch/mips/cavium-octeon/smp.c
> arch/mips/kernel/smp-bmips.c
> arch/mips/kernel/smp-cps.c
> arch/mips/loongson64/smp.c

Indeed.  I really wish we had -Wmissing-prototypes.

I'll squash this in:

diff --git a/arch/mips/cavium-octeon/smp.c b/arch/mips/cavium-octeon/smp.c
index 89954f5f87fb..4212584e6efa 100644
--- a/arch/mips/cavium-octeon/smp.c
+++ b/arch/mips/cavium-octeon/smp.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
diff --git a/arch/mips/kernel/smp-cps.c b/arch/mips/kernel/smp-cps.c
index bcd6a944b839..6d69a9ba8167 100644
--- a/arch/mips/kernel/smp-cps.c
+++ b/arch/mips/kernel/smp-cps.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/mips/loongson64/smp.c b/arch/mips/loongson64/smp.c
index c81c2bd07c62..df8d789ede3c 100644
--- a/arch/mips/loongson64/smp.c
+++ b/arch/mips/loongson64/smp.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 


Re: [PATCH v2 19/24] xtensa/cpu: Make sure cpu_die() doesn't return

2023-02-14 Thread Josh Poimboeuf
On Tue, Feb 14, 2023 at 08:55:32AM +0100, Philippe Mathieu-Daudé wrote:
> Hi Josh,
> 
> On 14/2/23 08:05, Josh Poimboeuf wrote:
> > cpu_die() doesn't return.  Make that more explicit with a BUG().
> > 
> > BUG() is preferable to unreachable() because BUG() is a more explicit
> > failure mode and avoids undefined behavior like falling off the edge of
> > the function into whatever code happens to be next.
> > 
> > Signed-off-by: Josh Poimboeuf 
> > ---
> >   arch/xtensa/kernel/smp.c | 2 ++
> >   1 file changed, 2 insertions(+)
> > 
> > diff --git a/arch/xtensa/kernel/smp.c b/arch/xtensa/kernel/smp.c
> > index 4dc109dd6214..7bad78495536 100644
> > --- a/arch/xtensa/kernel/smp.c
> > +++ b/arch/xtensa/kernel/smp.c
> 
> Can you update the documentation along? Currently we have:
> 
>   /*
>* Called from the idle thread for the CPU which has been shutdown.
>*
>* Note that we disable IRQs here, but do not re-enable them
>* before returning to the caller. This is also the behaviour
>* of the other hotplug-cpu capable cores, so presumably coming
>* out of idle fixes this.
>*/

void __ref cpu_die(void)
{
idle_task_exit();
local_irq_disable();
__asm__ __volatile__(
"   movia2, cpu_restart\n"
"   jx  a2\n");

BUG();
}

Hm, not only is the comment wrong, but it seems to be branching to
cpu_restart?  That doesn't seem right at all.

Max/Chris?

-- 
Josh


Re: [PATCH v2 13/24] sh/cpu: Make sure play_dead() doesn't return

2023-02-14 Thread Josh Poimboeuf
On Tue, Feb 14, 2023 at 08:57:39AM +0100, Philippe Mathieu-Daudé wrote:
> On 14/2/23 08:05, Josh Poimboeuf wrote:
> > play_dead() doesn't return.  Make that more explicit with a BUG().
> > 
> > BUG() is preferable to unreachable() because BUG() is a more explicit
> > failure mode and avoids undefined behavior like falling off the edge of
> > the function into whatever code happens to be next.
> > 
> > Signed-off-by: Josh Poimboeuf 
> > ---
> >   arch/sh/include/asm/smp-ops.h | 1 +
> >   1 file changed, 1 insertion(+)
> > 
> > diff --git a/arch/sh/include/asm/smp-ops.h b/arch/sh/include/asm/smp-ops.h
> > index e27702130eb6..63866b1595a0 100644
> > --- a/arch/sh/include/asm/smp-ops.h
> > +++ b/arch/sh/include/asm/smp-ops.h
> > @@ -27,6 +27,7 @@ static inline void plat_smp_setup(void)
> >   static inline void play_dead(void)
> >   {
> > mp_ops->play_dead();
> > +   BUG();
> >   }
> 
> Shouldn't we decorate plat_smp_ops::play_dead() as noreturn first?

I guess it really depends on how far we want to go down the __noreturn
rabbit hole.  To keep the patch set constrained yet still useful I
stopped when I got to a function pointer, as I think it still needs a
BUG() afterwards either way.

That said, there would still be benefits of adding __noreturn to
function pointers, I just wanted to keep the patch set down to a
manageable size ;-)

-- 
Josh


Re: [PATCH v2 00/24] cpu,sched: Mark arch_cpu_idle_dead() __noreturn

2023-02-14 Thread Josh Poimboeuf
On Tue, Feb 14, 2023 at 10:25:50AM +0100, Philippe Mathieu-Daudé wrote:
> On 14/2/23 08:05, Josh Poimboeuf wrote:
> > v2:
> > - make arch_call_rest_init() and rest_init() __noreturn
> > - make objtool 'global_returns' work for weak functions
> > - rebase on tip/objtool/core with dependencies merged in (mingo)
> > - add acks
> > 
> > v1.1:
> > - add __noreturn to all arch_cpu_idle_dead() implementations (mpe)
> 
> Possible similar candidates: panic_smp_self_stop, nmi_panic_self_stop
> and kexec.

Agreed.  Any volunteers?

-- 
Josh


Re: [PATCH v2 03/24] arm/cpu: Make sure arch_cpu_idle_dead() doesn't return

2023-02-14 Thread Josh Poimboeuf
On Tue, Feb 14, 2023 at 11:15:23AM +, Russell King (Oracle) wrote:
> On Mon, Feb 13, 2023 at 11:05:37PM -0800, Josh Poimboeuf wrote:
> > arch_cpu_idle_dead() doesn't return.  Make that more explicit with a
> > BUG().
> > 
> > BUG() is preferable to unreachable() because BUG() is a more explicit
> > failure mode and avoids undefined behavior like falling off the edge of
> > the function into whatever code happens to be next.
> 
> This is silly. Just mark the function __noreturn and be done with it.
> If the CPU ever executes code past the "b" instruction, it's already
> really broken that the extra instructions that BUG() gives will be
> meaningless.
> 
> This patch does nothing except add yet more bloat the kernel.
> 
> Sorry, but NAK.

Problem is, the compiler can't read inline asm.  So you'd get a 
"'noreturn' function does return" warning.

We can do an unreachable() instead of a BUG() here if you prefer
undefined behavior.

-- 
Josh


Re: [PATCH v2 19/24] xtensa/cpu: Make sure cpu_die() doesn't return

2023-02-14 Thread Steven Rostedt
On Tue, 14 Feb 2023 10:23:22 -0800
Josh Poimboeuf  wrote:


> void __ref cpu_die(void)
> {
>   idle_task_exit();
>   local_irq_disable();
>   __asm__ __volatile__(
>   "   movia2, cpu_restart\n"
>   "   jx  a2\n");
> 
>   BUG();
> }
> 
> Hm, not only is the comment wrong, but it seems to be branching to
> cpu_restart?  That doesn't seem right at all.

Agreed, that does not look right at all.

-- Steve

> 
> Max/Chris?
> 



Re: [PATCH v2 19/24] xtensa/cpu: Make sure cpu_die() doesn't return

2023-02-14 Thread Max Filippov
On Tue, Feb 14, 2023 at 10:23 AM Josh Poimboeuf  wrote:
> On Tue, Feb 14, 2023 at 08:55:32AM +0100, Philippe Mathieu-Daudé wrote:
> > Can you update the documentation along? Currently we have:
> >
> >   /*
> >* Called from the idle thread for the CPU which has been shutdown.
> >*
> >* Note that we disable IRQs here, but do not re-enable them
> >* before returning to the caller. This is also the behaviour
> >* of the other hotplug-cpu capable cores, so presumably coming
> >* out of idle fixes this.
> >*/
>
> void __ref cpu_die(void)
> {
> idle_task_exit();
> local_irq_disable();
> __asm__ __volatile__(
> "   movia2, cpu_restart\n"
> "   jx  a2\n");
>
> BUG();
> }
>
> Hm, not only is the comment wrong, but it seems to be branching to
> cpu_restart?  That doesn't seem right at all.

Perhaps the name is a bit misleading. The CPU that enters 'cpu_restart'
loops there until a call to 'boot_secondary' releases it, after which it goes
to '_startup'. So it is a restart, but not immediate.

-- 
Thanks.
-- Max


Re: [PATCH v2 19/24] xtensa/cpu: Make sure cpu_die() doesn't return

2023-02-14 Thread Josh Poimboeuf
On Tue, Feb 14, 2023 at 11:48:41AM -0800, Max Filippov wrote:
> On Tue, Feb 14, 2023 at 10:23 AM Josh Poimboeuf  wrote:
> > On Tue, Feb 14, 2023 at 08:55:32AM +0100, Philippe Mathieu-Daudé wrote:
> > > Can you update the documentation along? Currently we have:
> > >
> > >   /*
> > >* Called from the idle thread for the CPU which has been shutdown.
> > >*
> > >* Note that we disable IRQs here, but do not re-enable them
> > >* before returning to the caller. This is also the behaviour
> > >* of the other hotplug-cpu capable cores, so presumably coming
> > >* out of idle fixes this.
> > >*/
> >
> > void __ref cpu_die(void)
> > {
> > idle_task_exit();
> > local_irq_disable();
> > __asm__ __volatile__(
> > "   movia2, cpu_restart\n"
> > "   jx  a2\n");
> >
> > BUG();
> > }
> >
> > Hm, not only is the comment wrong, but it seems to be branching to
> > cpu_restart?  That doesn't seem right at all.
> 
> Perhaps the name is a bit misleading. The CPU that enters 'cpu_restart'
> loops there until a call to 'boot_secondary' releases it, after which it goes
> to '_startup'. So it is a restart, but not immediate.

Ah, I see.  That sounds similar to what Xen does.

-- 
Josh


RE: [EXT] Re: [PATCH 1/1] PCI: layerscape: Set 64-bit DMA mask

2023-02-14 Thread Frank Li
> >
> > + /* set 64-bit DMA mask and coherent DMA mask */
> > + if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)))
> > + dev_warn(dev, "Failed to set 64-bit DMA mask.\n");
> 
> Isn't this mandatory? Why not dev_err_probe and return the error?

I don't think it is mandatory. If failure, dma will use swiotlb. 
Just an additional memcpy involved. 

Frank Li

> 
> --Sean
> 
> >   platform_set_drvdata(pdev, pcie);
> >
> >   ret = dw_pcie_ep_init(&pci->ep);



Re: [PATCH v2 03/24] arm/cpu: Make sure arch_cpu_idle_dead() doesn't return

2023-02-14 Thread Russell King (Oracle)
On Tue, Feb 14, 2023 at 10:39:26AM -0800, Josh Poimboeuf wrote:
> On Tue, Feb 14, 2023 at 11:15:23AM +, Russell King (Oracle) wrote:
> > On Mon, Feb 13, 2023 at 11:05:37PM -0800, Josh Poimboeuf wrote:
> > > arch_cpu_idle_dead() doesn't return.  Make that more explicit with a
> > > BUG().
> > > 
> > > BUG() is preferable to unreachable() because BUG() is a more explicit
> > > failure mode and avoids undefined behavior like falling off the edge of
> > > the function into whatever code happens to be next.
> > 
> > This is silly. Just mark the function __noreturn and be done with it.
> > If the CPU ever executes code past the "b" instruction, it's already
> > really broken that the extra instructions that BUG() gives will be
> > meaningless.
> > 
> > This patch does nothing except add yet more bloat the kernel.
> > 
> > Sorry, but NAK.
> 
> Problem is, the compiler can't read inline asm.  So you'd get a 
> "'noreturn' function does return" warning.
> 
> We can do an unreachable() instead of a BUG() here if you prefer
> undefined behavior.

That's fine.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!


Re: (subset) [PATCH 00/35] Documentation: correct lots of spelling errors (series 1)

2023-02-14 Thread Martin K. Petersen
On Thu, 26 Jan 2023 22:39:30 -0800, Randy Dunlap wrote:

> Correct many spelling errors in Documentation/ as reported by codespell.
> 
> Maintainers of specific kernel subsystems are only Cc-ed on their
> respective patches, not the entire series. [if all goes well]
> 
> These patches are based on linux-next-20230125.
> 
> [...]

Applied to 6.3/scsi-queue, thanks!

[28/35] Documentation: target: correct spelling
https://git.kernel.org/mkp/scsi/c/c57ac5748be5

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH] tools/perf/tests: Add system wide check for perf bench workload in all metric test

2023-02-14 Thread Ian Rogers
On Tue, Feb 7, 2023 at 7:45 PM kajoljain  wrote:
>
>
>
> On 2/6/23 10:10, Athira Rajeev wrote:
> >
> >
> >> On 02-Feb-2023, at 10:14 PM, Kajol Jain  wrote:
> >>
> >> Testcase stat_all_metrics.sh fails in powerpc:
> >>
> >> 92: perf all metrics test : FAILED!
> >>
> >> Logs with verbose:
> >>
> >> [command]# ./perf test 92 -vv
> >> 92: perf all metrics test   :
> >> --- start ---
> >> test child forked, pid 13262
> >> Testing BRU_STALL_CPI
> >> Testing COMPLETION_STALL_CPI
> >> 
> >> Testing TOTAL_LOCAL_NODE_PUMPS_P23
> >> Metric 'TOTAL_LOCAL_NODE_PUMPS_P23' not printed in:
> >> Error:
> >> Invalid event (hv_24x7/PM_PB_LNS_PUMP23,chip=3/) in per-thread mode, 
> >> enable system wide with '-a'.
> >> Testing TOTAL_LOCAL_NODE_PUMPS_RETRIES_P01
> >> Metric 'TOTAL_LOCAL_NODE_PUMPS_RETRIES_P01' not printed in:
> >> Error:
> >> Invalid event (hv_24x7/PM_PB_RTY_LNS_PUMP01,chip=3/) in per-thread mode, 
> >> enable system wide with '-a'.
> >> 
> >>
> >> Based on above logs, we could see some of the hv-24x7 metric events fails,
> >> and logs suggest to run the metric event with -a option.
> >> This change happened after the commit a4b8cfcabb1d ("perf stat: Delay 
> >> metric
> >> parsing"), which delayed the metric parsing phase and now before metric 
> >> parsing
> >> phase perf tool identifies, whether target is system-wide or not. With this
> >> change, perf_event_open will fails with workload monitoring for uncore 
> >> events
> >> as expected.
> >>
> >> The perf all metric test case fails as some of the hv-24x7 metric events
> >> may need bigger workload to get the data. And the added perf bench
> >> workload in 'perf all metric test case' will not run for hv-24x7 without
> >> -a option.
> >>
> >> Fix this issue by adding system wide check for perf bench workload.
> >>
> >> Result with the patch changes in powerpc:
> >>
> >> 92: perf all metrics test : Ok
> >>
> >> Signed-off-by: Kajol Jain 
> >
> > Looks good to me
> >
> > Reviewed-by: Athira Rajeev 
>
> Hi Arnaldo,
>Let me know if patch looks fine to you.
>
> Thanks,
> Kajol Jain

I ran into a similar issue but worked around it with:

```
--- a/tools/perf/tests/shell/stat_all_metrics.sh
+++ b/tools/perf/tests/shell/stat_all_metrics.sh
@@ -11,7 +11,7 @@ for m in $(perf list --raw-dump metrics); do
continue
  fi
  # Failed so try system wide.
-  result=$(perf stat -M "$m" -a true 2>&1)
+  result=$(perf stat -M "$m" -a sleep 0.01 2>&1)
  if [[ "$result" =~ "${m:0:50}" ]]
  then
continue
```

Running the synthesize benchmark is potentially slow, wdyt of the change above?

Thanks,
Ian


> >
> >> ---
> >> tools/perf/tests/shell/stat_all_metrics.sh | 7 +++
> >> 1 file changed, 7 insertions(+)
> >>
> >> diff --git a/tools/perf/tests/shell/stat_all_metrics.sh 
> >> b/tools/perf/tests/shell/stat_all_metrics.sh
> >> index 6e79349e42be..d49832a316d9 100755
> >> --- a/tools/perf/tests/shell/stat_all_metrics.sh
> >> +++ b/tools/perf/tests/shell/stat_all_metrics.sh
> >> @@ -23,6 +23,13 @@ for m in $(perf list --raw-dump metrics); do
> >>   then
> >> continue
> >>   fi
> >> +  # Failed again, possibly the event is uncore pmu event which will need
> >> +  # system wide monitoring with workload, so retry with -a option
> >> +  result=$(perf stat -M "$m" -a perf bench internals synthesize 2>&1)
> >> +  if [[ "$result" =~ "${m:0:50}" ]]
> >> +  then
> >> +continue
> >> +  fi
> >>   echo "Metric '$m' not printed in:"
> >>   echo "$result"
> >>   if [[ "$err" != "1" ]]
> >> --
> >> 2.39.0
> >>
> >


Re: [PATCH RFC] PCI/AER: Enable internal AER errors by default

2023-02-14 Thread Ira Weiny
Bjorn Helgaas wrote:
> On Fri, Feb 10, 2023 at 02:33:23PM -0800, Ira Weiny wrote:
> > The CXL driver expects internal error reporting to be enabled via
> > pci_enable_pcie_error_reporting().  It is likely other drivers expect the 
> > same.
> > Dave submitted a patch to enable the CXL side[1] but the PCI AER registers
> > still mask errors.
> > 
> > PCIe v6.0 Uncorrectable Mask Register (7.8.4.3) and Correctable Mask
> > Register (7.8.4.6) default to masking internal errors.  The
> > Uncorrectable Error Severity Register (7.8.4.4) defaults internal errors
> > as fatal.
> > 
> > Enable internal errors to be reported via the standard
> > pci_enable_pcie_error_reporting() call.  Ensure uncorrectable errors are set
> > non-fatal to limit any impact to other drivers.
> 
> Do you have any background on why the spec makes these errors masked
> by default?  I'm sympathetic to wanting to learn about all the errors
> we can, but I'm a little wary if the spec authors thought it was
> important to mask these by default.
> 

I don't have any idea of the history.

To me 'internal errors' is a pretty wide net and was likely a catch all
that the authors felt was mostly unneeded.

CXL is different because it further divides the errors.

I've enlisted some help internal to Intel to hopefully find some answers.
But in the event no one knows it would be safe to to with my alternate
suggestion and add a new PCIe call to enable this specifically for the
drivers who need it.

Ira


Re: [PATCH v6 2/7] powerpc/64s: mm: Introduce __pmdp_collapse_flush with mm_struct argument

2023-02-14 Thread Rohan McLure
> On 14 Feb 2023, at 5:02 pm, Christophe Leroy  
> wrote:
> 
> 
> 
> Le 14/02/2023 à 02:59, Rohan McLure a écrit :
>> pmdp_collapse_flush has references in generic code with just three
>> parameters, due to the choice of mm context being implied by the vm_area
>> context parameter.
>> 
>> Define __pmdp_collapse_flush to accept an additional mm_struct *
>> parameter, with pmdp_collapse_flush a macro that unpacks the vma and
>> calls __pmdp_collapse_flush. The mm_struct * parameter is needed in a
>> future patch providing Page Table Check support, which is defined in
>> terms of mm context objects.
>> 
>> Signed-off-by: Rohan McLure 
>> ---
>> v6: New patch
>> ---
>>  arch/powerpc/include/asm/book3s/64/pgtable.h | 14 +++---
>>  1 file changed, 11 insertions(+), 3 deletions(-)
>> 
>> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
>> b/arch/powerpc/include/asm/book3s/64/pgtable.h
>> index cb4c67bf45d7..9d8b4e25f5ed 100644
>> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
>> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
>> @@ -1244,14 +1244,22 @@ static inline pmd_t pmdp_huge_get_and_clear(struct 
>> mm_struct *mm,
>>   return hash__pmdp_huge_get_and_clear(mm, addr, pmdp);
>>  }
>> 
>> -static inline pmd_t pmdp_collapse_flush(struct vm_area_struct *vma,
>> - unsigned long address, pmd_t *pmdp)
>> +static inline pmd_t __pmdp_collapse_flush(struct vm_area_struct *vma, 
>> struct mm_struct *mm,
>> +  unsigned long address, pmd_t *pmdp)
>>  {
>>   if (radix_enabled())
>>   return radix__pmdp_collapse_flush(vma, address, pmdp);
>>   return hash__pmdp_collapse_flush(vma, address, pmdp);
>>  }
>> -#define pmdp_collapse_flush pmdp_collapse_flush
>> +#define pmdp_collapse_flush(vma, addr, pmdp) \
>> +({ \
>> + struct vm_area_struct *_vma = (vma); \
>> + pmd_t _r; \
>> + \
>> + _r = __pmdp_collapse_flush(_vma, _vma->vm_mm, (addr), (pmdp)); \
>> + \
>> + _r; \
>> +})
> 
> Can you make it a static inline function instead of a ugly macro ?

Due to some header hell, it’s looking like this location only has access to
a prototype for struct vm_area_struct. Might have to remain a macro then.

Probably don’t need to expliclty declare a variable for the macro ‘return’
though.

> 
>> 
>>  #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR_FULL
>>  pmd_t pmdp_huge_get_and_clear_full(struct vm_area_struct *vma,



Re: [PATCH v6 2/7] powerpc/64s: mm: Introduce __pmdp_collapse_flush with mm_struct argument

2023-02-14 Thread Rohan McLure
> On 15 Feb 2023, at 11:17 am, Rohan McLure  wrote:
> 
>> On 14 Feb 2023, at 5:02 pm, Christophe Leroy  
>> wrote:
>> 
>> 
>> 
>> Le 14/02/2023 à 02:59, Rohan McLure a écrit :
>>> pmdp_collapse_flush has references in generic code with just three
>>> parameters, due to the choice of mm context being implied by the vm_area
>>> context parameter.
>>> 
>>> Define __pmdp_collapse_flush to accept an additional mm_struct *
>>> parameter, with pmdp_collapse_flush a macro that unpacks the vma and
>>> calls __pmdp_collapse_flush. The mm_struct * parameter is needed in a
>>> future patch providing Page Table Check support, which is defined in
>>> terms of mm context objects.
>>> 
>>> Signed-off-by: Rohan McLure 
>>> ---
>>> v6: New patch
>>> ---
>>> arch/powerpc/include/asm/book3s/64/pgtable.h | 14 +++---
>>> 1 file changed, 11 insertions(+), 3 deletions(-)
>>> 
>>> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
>>> b/arch/powerpc/include/asm/book3s/64/pgtable.h
>>> index cb4c67bf45d7..9d8b4e25f5ed 100644
>>> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
>>> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
>>> @@ -1244,14 +1244,22 @@ static inline pmd_t pmdp_huge_get_and_clear(struct 
>>> mm_struct *mm,
>>>  return hash__pmdp_huge_get_and_clear(mm, addr, pmdp);
>>> }
>>> 
>>> -static inline pmd_t pmdp_collapse_flush(struct vm_area_struct *vma,
>>> - unsigned long address, pmd_t *pmdp)
>>> +static inline pmd_t __pmdp_collapse_flush(struct vm_area_struct *vma, 
>>> struct mm_struct *mm,
>>> +  unsigned long address, pmd_t *pmdp)
>>> {
>>>  if (radix_enabled())
>>>  return radix__pmdp_collapse_flush(vma, address, pmdp);
>>>  return hash__pmdp_collapse_flush(vma, address, pmdp);
>>> }
>>> -#define pmdp_collapse_flush pmdp_collapse_flush
>>> +#define pmdp_collapse_flush(vma, addr, pmdp) \
>>> +({ \
>>> + struct vm_area_struct *_vma = (vma); \
>>> + pmd_t _r; \
>>> + \
>>> + _r = __pmdp_collapse_flush(_vma, _vma->vm_mm, (addr), (pmdp)); \
>>> + \
>>> + _r; \
>>> +})
>> 
>> Can you make it a static inline function instead of a ugly macro ?
> 
> Due to some header hell, it’s looking like this location only has access to
> a prototype for struct vm_area_struct. Might have to remain a macro then.
> 
> Probably don’t need to expliclty declare a variable for the macro ‘return’
> though.

It’s the same solution opted for by ptep_test_and_clear_young.

#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
#define ptep_test_and_clear_young(__vma, __addr, __ptep)\
({  \
__ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep); \
})

> 
>> 
>>> 
>>> #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR_FULL
>>> pmd_t pmdp_huge_get_and_clear_full(struct vm_area_struct *vma,




[PATCH v7 3/7] powerpc: mm: Replace p{u,m,4}d_is_leaf with p{u,m,4}_leaf

2023-02-14 Thread Rohan McLure
Replace occurrences of p{u,m,4}d_is_leaf with p{u,m,4}_leaf, as the
latter is the name given to checking that a higher-level entry in
multi-level paging contains a page translation entry (pte) throughout
all other archs.

A future patch will implement p{u,m,4}_leaf stubs on all platforms so
that they may be referenced in generic code.

Signed-off-by: Rohan McLure 
---
V4: New patch
V5: Previously replaced stub definition for *_is_leaf with *_leaf. Do
that in a later patch
---
 arch/powerpc/kvm/book3s_64_mmu_radix.c   | 12 ++--
 arch/powerpc/mm/book3s64/radix_pgtable.c | 14 +++---
 arch/powerpc/mm/pgtable.c|  6 +++---
 arch/powerpc/mm/pgtable_64.c |  6 +++---
 arch/powerpc/xmon/xmon.c |  6 +++---
 5 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c 
b/arch/powerpc/kvm/book3s_64_mmu_radix.c
index 9d3743ca16d5..0d24fd984d16 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_radix.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c
@@ -497,7 +497,7 @@ static void kvmppc_unmap_free_pmd(struct kvm *kvm, pmd_t 
*pmd, bool full,
for (im = 0; im < PTRS_PER_PMD; ++im, ++p) {
if (!pmd_present(*p))
continue;
-   if (pmd_is_leaf(*p)) {
+   if (pmd_leaf(*p)) {
if (full) {
pmd_clear(p);
} else {
@@ -526,7 +526,7 @@ static void kvmppc_unmap_free_pud(struct kvm *kvm, pud_t 
*pud,
for (iu = 0; iu < PTRS_PER_PUD; ++iu, ++p) {
if (!pud_present(*p))
continue;
-   if (pud_is_leaf(*p)) {
+   if (pud_leaf(*p)) {
pud_clear(p);
} else {
pmd_t *pmd;
@@ -629,12 +629,12 @@ int kvmppc_create_pte(struct kvm *kvm, pgd_t *pgtable, 
pte_t pte,
new_pud = pud_alloc_one(kvm->mm, gpa);
 
pmd = NULL;
-   if (pud && pud_present(*pud) && !pud_is_leaf(*pud))
+   if (pud && pud_present(*pud) && !pud_leaf(*pud))
pmd = pmd_offset(pud, gpa);
else if (level <= 1)
new_pmd = kvmppc_pmd_alloc();
 
-   if (level == 0 && !(pmd && pmd_present(*pmd) && !pmd_is_leaf(*pmd)))
+   if (level == 0 && !(pmd && pmd_present(*pmd) && !pmd_leaf(*pmd)))
new_ptep = kvmppc_pte_alloc();
 
/* Check if we might have been invalidated; let the guest retry if so */
@@ -652,7 +652,7 @@ int kvmppc_create_pte(struct kvm *kvm, pgd_t *pgtable, 
pte_t pte,
new_pud = NULL;
}
pud = pud_offset(p4d, gpa);
-   if (pud_is_leaf(*pud)) {
+   if (pud_leaf(*pud)) {
unsigned long hgpa = gpa & PUD_MASK;
 
/* Check if we raced and someone else has set the same thing */
@@ -703,7 +703,7 @@ int kvmppc_create_pte(struct kvm *kvm, pgd_t *pgtable, 
pte_t pte,
new_pmd = NULL;
}
pmd = pmd_offset(pud, gpa);
-   if (pmd_is_leaf(*pmd)) {
+   if (pmd_leaf(*pmd)) {
unsigned long lgpa = gpa & PMD_MASK;
 
/* Check if we raced and someone else has set the same thing */
diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c 
b/arch/powerpc/mm/book3s64/radix_pgtable.c
index 26245aaf12b8..4e46e001c3c3 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -205,14 +205,14 @@ static void radix__change_memory_range(unsigned long 
start, unsigned long end,
pudp = pud_alloc(&init_mm, p4dp, idx);
if (!pudp)
continue;
-   if (pud_is_leaf(*pudp)) {
+   if (pud_leaf(*pudp)) {
ptep = (pte_t *)pudp;
goto update_the_pte;
}
pmdp = pmd_alloc(&init_mm, pudp, idx);
if (!pmdp)
continue;
-   if (pmd_is_leaf(*pmdp)) {
+   if (pmd_leaf(*pmdp)) {
ptep = pmdp_ptep(pmdp);
goto update_the_pte;
}
@@ -786,7 +786,7 @@ static void __meminit remove_pmd_table(pmd_t *pmd_start, 
unsigned long addr,
if (!pmd_present(*pmd))
continue;
 
-   if (pmd_is_leaf(*pmd)) {
+   if (pmd_leaf(*pmd)) {
if (!IS_ALIGNED(addr, PMD_SIZE) ||
!IS_ALIGNED(next, PMD_SIZE)) {
WARN_ONCE(1, "%s: unaligned range\n", __func__);
@@ -816,7 +816,7 @@ static void __meminit remove_pud_table(pud_t *pud_start, 
unsigned long addr,
if (!pud_present(*pud))
continue;
 
-   if (pud_is_leaf(*pud)) {
+   if (pud_leaf(*pud)) {
if (!IS_ALIGNED(addr, PUD_SIZE) ||
!IS_ALIGNED(n

[PATCH v7 1/7] powerpc: mm: Separate set_pte, set_pte_at for internal, external use

2023-02-14 Thread Rohan McLure
Produce separate symbols for set_pte, which is to be used in
arch/powerpc for reassignment of pte's, and set_pte_at, used in generic
code.

The reason for this distinction is to support the Page Table Check
sanitiser. Having this distinction allows for set_pte_at to
instrumented, but set_pte not to be, permitting for uninstrumented
internal mappings. This distinction in names is also present in x86.

Signed-off-by: Rohan McLure 
---
v6: new patch
v7: Remove extern, move set_pte args to be in a single line.
---
 arch/powerpc/include/asm/book3s/pgtable.h | 3 +--
 arch/powerpc/include/asm/nohash/pgtable.h | 3 +--
 arch/powerpc/include/asm/pgtable.h| 1 +
 arch/powerpc/mm/pgtable.c | 3 +--
 4 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/pgtable.h 
b/arch/powerpc/include/asm/book3s/pgtable.h
index d18b748ea3ae..1386ed705e66 100644
--- a/arch/powerpc/include/asm/book3s/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/pgtable.h
@@ -12,8 +12,7 @@
 /* Insert a PTE, top-level function is out of line. It uses an inline
  * low level function in the respective pgtable-* files
  */
-extern void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
-  pte_t pte);
+void set_pte(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
 
 
 #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
diff --git a/arch/powerpc/include/asm/nohash/pgtable.h 
b/arch/powerpc/include/asm/nohash/pgtable.h
index 69c3a050a3d8..f36dd2e2d591 100644
--- a/arch/powerpc/include/asm/nohash/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/pgtable.h
@@ -154,8 +154,7 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 /* Insert a PTE, top-level function is out of line. It uses an inline
  * low level function in the respective pgtable-* files
  */
-extern void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
-  pte_t pte);
+void set_pte(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte);
 
 /* This low level function performs the actual PTE insertion
  * Setting the PTE depends on the MMU type and other factors. It's
diff --git a/arch/powerpc/include/asm/pgtable.h 
b/arch/powerpc/include/asm/pgtable.h
index 9972626ddaf6..17d30359d1f4 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -48,6 +48,7 @@ struct mm_struct;
 /* Keep these as a macros to avoid include dependency mess */
 #define pte_page(x)pfn_to_page(pte_pfn(x))
 #define mk_pte(page, pgprot)   pfn_pte(page_to_pfn(page), (pgprot))
+#define set_pte_at set_pte
 /*
  * Select all bits except the pfn
  */
diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c
index cb2dcdb18f8e..d7cce317cef8 100644
--- a/arch/powerpc/mm/pgtable.c
+++ b/arch/powerpc/mm/pgtable.c
@@ -187,8 +187,7 @@ static pte_t set_access_flags_filter(pte_t pte, struct 
vm_area_struct *vma,
 /*
  * set_pte stores a linux PTE into the linux page table.
  */
-void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
-   pte_t pte)
+void set_pte(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte)
 {
/*
 * Make sure hardware valid bit is not set. We don't do
-- 
2.37.2



[PATCH v7 2/7] powerpc/64s: mm: Introduce __pmdp_collapse_flush with mm_struct argument

2023-02-14 Thread Rohan McLure
pmdp_collapse_flush has references in generic code with just three
parameters, due to the choice of mm context being implied by the vm_area
context parameter.

Define __pmdp_collapse_flush to accept an additional mm_struct *
parameter, with pmdp_collapse_flush an inline function that unpacks
the vma and calls __pmdp_collapse_flush. The mm_struct * parameter
is needed in a future patch providing Page Table Check support,
which is defined in terms of mm context objects.

Signed-off-by: Rohan McLure 
---
v6: New patch
v7: Remove explicit `return' in macro. Prefix macro args with __,
as done with ptep_test_and_clear_young.
---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
b/arch/powerpc/include/asm/book3s/64/pgtable.h
index cb4c67bf45d7..7e0d546f4b3c 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -1244,14 +1244,19 @@ static inline pmd_t pmdp_huge_get_and_clear(struct 
mm_struct *mm,
return hash__pmdp_huge_get_and_clear(mm, addr, pmdp);
 }
 
-static inline pmd_t pmdp_collapse_flush(struct vm_area_struct *vma,
-   unsigned long address, pmd_t *pmdp)
+static inline pmd_t __pmdp_collapse_flush(struct vm_area_struct *vma, struct 
mm_struct *mm,
+ unsigned long address, pmd_t *pmdp)
 {
if (radix_enabled())
return radix__pmdp_collapse_flush(vma, address, pmdp);
return hash__pmdp_collapse_flush(vma, address, pmdp);
 }
-#define pmdp_collapse_flush pmdp_collapse_flush
+#define pmdp_collapse_flush(__vma, __addr, __pmdp) \
+({ \
+   struct vm_area_struct *_vma = (__vma);  \
+   \
+   __pmdp_collapse_flush(_vma, _vma->vm_mm, (__addr), (__pmdp));   \
+})
 
 #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR_FULL
 pmd_t pmdp_huge_get_and_clear_full(struct vm_area_struct *vma,
-- 
2.37.2



[PATCH v7 4/7] powerpc: mm: Implement p{m,u,4}d_leaf on all platforms

2023-02-14 Thread Rohan McLure
The check that a higher-level entry in multi-level pages contains a page
translation entry (pte) is performed by p{m,u,4}d_leaf stubs, which may
be specialised for each choice of mmu. In a prior commit, we replace
uses to the catch-all stubs, p{m,u,4}d_is_leaf with p{m,u,4}d_leaf.

Replace the catch-all stub definitions for p{m,u,4}d_is_leaf with
definitions for p{m,u,4}d_leaf. A future patch will assume that
p{m,u,4}d_leaf is defined on all platforms.

In particular, implement pud_leaf for Book3E-64, pmd_leaf for all Book3E
and Book3S-64 platforms, with a catch-all definition for p4d_leaf.

Signed-off-by: Rohan McLure 
---
v5: Split patch that replaces p{m,u,4}d_is_leaf into two patches, first
replacing callsites and afterward providing generic definition.
Remove ifndef-defines implementing p{m,u}d_leaf in favour of
implementing stubs in headers belonging to the particular platforms
needing them.
---
 arch/powerpc/include/asm/book3s/32/pgtable.h |  5 +
 arch/powerpc/include/asm/book3s/64/pgtable.h | 10 -
 arch/powerpc/include/asm/nohash/64/pgtable.h |  6 ++
 arch/powerpc/include/asm/nohash/pgtable.h|  6 ++
 arch/powerpc/include/asm/pgtable.h   | 22 ++--
 5 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h 
b/arch/powerpc/include/asm/book3s/32/pgtable.h
index 75823f39e042..a090cb13a4a0 100644
--- a/arch/powerpc/include/asm/book3s/32/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
@@ -242,6 +242,11 @@ static inline void pmd_clear(pmd_t *pmdp)
*pmdp = __pmd(0);
 }
 
+#define pmd_leaf pmd_leaf
+static inline bool pmd_leaf(pmd_t pmd)
+{
+   return false;
+}
 
 /*
  * When flushing the tlb entry for a page, we also need to flush the hash
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 7e0d546f4b3c..589d2dbe3873 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -1359,16 +1359,14 @@ static inline bool is_pte_rw_upgrade(unsigned long 
old_val, unsigned long new_va
 /*
  * Like pmd_huge() and pmd_large(), but works regardless of config options
  */
-#define pmd_is_leaf pmd_is_leaf
-#define pmd_leaf pmd_is_leaf
-static inline bool pmd_is_leaf(pmd_t pmd)
+#define pmd_leaf pmd_leaf
+static inline bool pmd_leaf(pmd_t pmd)
 {
return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE));
 }
 
-#define pud_is_leaf pud_is_leaf
-#define pud_leaf pud_is_leaf
-static inline bool pud_is_leaf(pud_t pud)
+#define pud_leaf pud_leaf
+static inline bool pud_leaf(pud_t pud)
 {
return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE));
 }
diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h 
b/arch/powerpc/include/asm/nohash/64/pgtable.h
index 879e9a6e5a87..d391a45e0f11 100644
--- a/arch/powerpc/include/asm/nohash/64/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
@@ -141,6 +141,12 @@ static inline void pud_clear(pud_t *pudp)
*pudp = __pud(0);
 }
 
+#define pud_leaf pud_leaf
+static inline bool pud_leaf(pud_t pud)
+{
+   return false;
+}
+
 #define pud_none(pud)  (!pud_val(pud))
 #definepud_bad(pud)(!is_kernel_addr(pud_val(pud)) \
 || (pud_val(pud) & PUD_BAD_BITS))
diff --git a/arch/powerpc/include/asm/nohash/pgtable.h 
b/arch/powerpc/include/asm/nohash/pgtable.h
index f36dd2e2d591..43b50fd8d236 100644
--- a/arch/powerpc/include/asm/nohash/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/pgtable.h
@@ -60,6 +60,12 @@ static inline bool pte_hw_valid(pte_t pte)
return pte_val(pte) & _PAGE_PRESENT;
 }
 
+#define pmd_leaf pmd_leaf
+static inline bool pmd_leaf(pmd_t pmd)
+{
+   return false;
+}
+
 /*
  * Don't just check for any non zero bits in __PAGE_USER, since for book3e
  * and PTE_64BIT, PAGE_KERNEL_X contains _PAGE_BAP_SR which is also in
diff --git a/arch/powerpc/include/asm/pgtable.h 
b/arch/powerpc/include/asm/pgtable.h
index 17d30359d1f4..284408829fa3 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -128,29 +128,11 @@ static inline void pte_frag_set(mm_context_t *ctx, void 
*p)
 }
 #endif
 
-#ifndef pmd_is_leaf
-#define pmd_is_leaf pmd_is_leaf
-static inline bool pmd_is_leaf(pmd_t pmd)
+#define p4d_leaf p4d_leaf
+static inline bool p4d_leaf(p4d_t p4d)
 {
return false;
 }
-#endif
-
-#ifndef pud_is_leaf
-#define pud_is_leaf pud_is_leaf
-static inline bool pud_is_leaf(pud_t pud)
-{
-   return false;
-}
-#endif
-
-#ifndef p4d_is_leaf
-#define p4d_is_leaf p4d_is_leaf
-static inline bool p4d_is_leaf(p4d_t p4d)
-{
-   return false;
-}
-#endif
 
 #define pmd_pgtable pmd_pgtable
 static inline pgtable_t pmd_pgtable(pmd_t pmd)
-- 
2.37.2



[PATCH v7 0/7] Support page table check

2023-02-14 Thread Rohan McLure
Support the page table check sanitiser on all PowerPC platforms. This
sanitiser works by serialising assignments, reassignments and clears of
page table entries at each level in order to ensure that anonymous
mappings have at most one writable consumer, and likewise that
file-backed mappings are not simultaneously also anonymous mappings.

In order to support this infrastructure, a number of stubs must be
defined for all powerpc platforms. Additionally, seperate set_pte_at
and set_pte, to allow for internal, uninstrumented mappings.

v7:
 * Remove use of extern in set_pte prototypes
 * Clean up pmdp_collapse_flush macro
 * Replace set_pte_at with static inline function
 * Fix commit message for patch 7

v6:
 * Support huge pages and p{m,u}d accounting.
 * Remove instrumentation from set_pte from kernel internal pages.
 * 64s: Implement pmdp_collapse_flush in terms of __pmdp_collapse_flush
   as access to the mm_struct * is required.
Link: 
https://lore.kernel.org/linuxppc-dev/20230214015939.1853438-1-rmcl...@linux.ibm.com/

v5:
Link: 
https://lore.kernel.org/linuxppc-dev/20221118002146.25979-1-rmcl...@linux.ibm.com/

Rohan McLure (7):
  powerpc: mm: Separate set_pte, set_pte_at for internal, external use
  powerpc/64s: mm: Introduce __pmdp_collapse_flush with mm_struct
argument
  powerpc: mm: Replace p{u,m,4}d_is_leaf with p{u,m,4}_leaf
  powerpc: mm: Implement p{m,u,4}d_leaf on all platforms
  powerpc: mm: Add common pud_pfn stub for all platforms
  powerpc: mm: Add p{te,md,ud}_user_accessible_page helpers
  powerpc: mm: Support page table check

 arch/powerpc/Kconfig |  1 +
 arch/powerpc/include/asm/book3s/32/pgtable.h | 17 +++-
 arch/powerpc/include/asm/book3s/64/pgtable.h | 85 +---
 arch/powerpc/include/asm/book3s/pgtable.h|  3 +-
 arch/powerpc/include/asm/nohash/32/pgtable.h | 12 ++-
 arch/powerpc/include/asm/nohash/64/pgtable.h | 24 +-
 arch/powerpc/include/asm/nohash/pgtable.h|  9 ++-
 arch/powerpc/include/asm/pgtable.h   | 60 +-
 arch/powerpc/kvm/book3s_64_mmu_radix.c   | 12 +--
 arch/powerpc/mm/book3s64/hash_pgtable.c  |  2 +-
 arch/powerpc/mm/book3s64/pgtable.c   | 16 ++--
 arch/powerpc/mm/book3s64/radix_pgtable.c | 24 +++---
 arch/powerpc/mm/nohash/book3e_pgtable.c  |  2 +-
 arch/powerpc/mm/pgtable.c|  9 +--
 arch/powerpc/mm/pgtable_32.c |  2 +-
 arch/powerpc/mm/pgtable_64.c |  6 +-
 arch/powerpc/xmon/xmon.c |  6 +-
 17 files changed, 197 insertions(+), 93 deletions(-)

-- 
2.37.2



[PATCH v7 5/7] powerpc: mm: Add common pud_pfn stub for all platforms

2023-02-14 Thread Rohan McLure
Prior to this commit, pud_pfn was implemented with BUILD_BUG as the inline
function for 64-bit Book3S systems but is never included, as its
invocations in generic code are guarded by calls to pud_devmap which return
zero on such systems. A future patch will provide support for page table
checks, the generic code for which depends on a pud_pfn stub being
implemented, even while the patch will not interact with puds directly.

Remove the 64-bit Book3S stub and define pud_pfn to warn on all
platforms. pud_pfn may be defined properly on a per-platform basis
should it grow real usages in future.

Signed-off-by: Rohan McLure 
---
V2: Remove conditional BUILD_BUG and BUG. Instead warn on usage.
V3: Replace WARN with WARN_ONCE, which should suffice to demonstrate
misuse of puds.
---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 10 --
 arch/powerpc/include/asm/pgtable.h   | 14 ++
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 589d2dbe3873..df5ee856444d 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -1327,16 +1327,6 @@ static inline int pgd_devmap(pgd_t pgd)
 }
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
-static inline int pud_pfn(pud_t pud)
-{
-   /*
-* Currently all calls to pud_pfn() are gated around a pud_devmap()
-* check so this should never be used. If it grows another user we
-* want to know about it.
-*/
-   BUILD_BUG();
-   return 0;
-}
 #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
 pte_t ptep_modify_prot_start(struct vm_area_struct *, unsigned long, pte_t *);
 void ptep_modify_prot_commit(struct vm_area_struct *, unsigned long,
diff --git a/arch/powerpc/include/asm/pgtable.h 
b/arch/powerpc/include/asm/pgtable.h
index 284408829fa3..ad0829f816e9 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -153,6 +153,20 @@ struct seq_file;
 void arch_report_meminfo(struct seq_file *m);
 #endif /* CONFIG_PPC64 */
 
+/*
+ * Currently only consumed by page_table_check_pud_{set,clear}. Since clears
+ * and sets to page table entries at any level are done through
+ * page_table_check_pte_{set,clear}, provide stub implementation.
+ */
+#ifndef pud_pfn
+#define pud_pfn pud_pfn
+static inline int pud_pfn(pud_t pud)
+{
+   WARN_ONCE(1, "pud: platform does not use pud entries directly");
+   return 0;
+}
+#endif
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_PGTABLE_H */
-- 
2.37.2



[PATCH v7 7/7] powerpc: mm: Support page table check

2023-02-14 Thread Rohan McLure
On creation and clearing of a page table mapping, instrument such calls
by invoking page_table_check_pte_set and page_table_check_pte_clear
respectively. These calls serve as a sanity check against illegal
mappings.

Enable ARCH_SUPPORTS_PAGE_TABLE_CHECK for all platforms.

Use set_pte internally, and cause this function to reassign a page table
entry without instrumentation. Generic code will be instrumented, as it
references set_pte_at.

See also:

riscv support in commit 3fee229a8eb9 ("riscv/mm: enable
ARCH_SUPPORTS_PAGE_TABLE_CHECK")
arm64 in commit 42b2547137f5 ("arm64/mm: enable
ARCH_SUPPORTS_PAGE_TABLE_CHECK")
x86_64 in commit d283d422c6c4 ("x86: mm: add x86_64 support for page table
check")

Signed-off-by: Rohan McLure 
---
V2: Update spacing and types assigned to pte_update calls.
V3: Update one last pte_update call to remove __pte invocation.
V5: Fix 32-bit nohash double set
V6: Omit __set_pte_at instrumentation - should be instrumented by
set_pte_at, with set_pte in between, performing all prior checks.
Instrument pmds. Use set_pte where needed.
V7: Make set_pte_at an inline function. Fix commit message.
Detail changes of internal references to set_pte_at, and its semantics.
---
 arch/powerpc/Kconfig |  1 +
 arch/powerpc/include/asm/book3s/32/pgtable.h |  8 +++-
 arch/powerpc/include/asm/book3s/64/pgtable.h | 44 
 arch/powerpc/include/asm/nohash/32/pgtable.h |  7 +++-
 arch/powerpc/include/asm/nohash/64/pgtable.h |  8 +++-
 arch/powerpc/include/asm/pgtable.h   | 10 -
 arch/powerpc/mm/book3s64/hash_pgtable.c  |  2 +-
 arch/powerpc/mm/book3s64/pgtable.c   | 16 ---
 arch/powerpc/mm/book3s64/radix_pgtable.c | 10 ++---
 arch/powerpc/mm/nohash/book3e_pgtable.c  |  2 +-
 arch/powerpc/mm/pgtable_32.c |  2 +-
 11 files changed, 83 insertions(+), 27 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 2c9cdf1d8761..2474e2699037 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -154,6 +154,7 @@ config PPC
select ARCH_STACKWALK
select ARCH_SUPPORTS_ATOMIC_RMW
select ARCH_SUPPORTS_DEBUG_PAGEALLOCif PPC_BOOK3S || PPC_8xx || 40x
+   select ARCH_SUPPORTS_PAGE_TABLE_CHECK
select ARCH_USE_BUILTIN_BSWAP
select ARCH_USE_CMPXCHG_LOCKREF if PPC64
select ARCH_USE_MEMTEST
diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h 
b/arch/powerpc/include/asm/book3s/32/pgtable.h
index afd672e84791..8850b4fb22a4 100644
--- a/arch/powerpc/include/asm/book3s/32/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
@@ -53,6 +53,8 @@
 
 #ifndef __ASSEMBLY__
 
+#include 
+
 static inline bool pte_user(pte_t pte)
 {
return pte_val(pte) & _PAGE_USER;
@@ -338,7 +340,11 @@ static inline int __ptep_test_and_clear_young(struct 
mm_struct *mm,
 static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long 
addr,
   pte_t *ptep)
 {
-   return __pte(pte_update(mm, addr, ptep, ~_PAGE_HASHPTE, 0, 0));
+   pte_t old_pte = __pte(pte_update(mm, addr, ptep, ~_PAGE_HASHPTE, 0, 0));
+
+   page_table_check_pte_clear(mm, addr, old_pte);
+
+   return old_pte;
 }
 
 #define __HAVE_ARCH_PTEP_SET_WRPROTECT
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
b/arch/powerpc/include/asm/book3s/64/pgtable.h
index a6ed93d01da1..0c6838875720 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -162,6 +162,8 @@
 #define PAGE_KERNEL_ROX__pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX)
 
 #ifndef __ASSEMBLY__
+#include 
+
 /*
  * page table defines
  */
@@ -431,8 +433,11 @@ static inline void huge_ptep_set_wrprotect(struct 
mm_struct *mm,
 static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
   unsigned long addr, pte_t *ptep)
 {
-   unsigned long old = pte_update(mm, addr, ptep, ~0UL, 0, 0);
-   return __pte(old);
+   pte_t old_pte = __pte(pte_update(mm, addr, ptep, ~0UL, 0, 0));
+
+   page_table_check_pte_clear(mm, addr, old_pte);
+
+   return old_pte;
 }
 
 #define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
@@ -441,11 +446,16 @@ static inline pte_t ptep_get_and_clear_full(struct 
mm_struct *mm,
pte_t *ptep, int full)
 {
if (full && radix_enabled()) {
+   pte_t old_pte;
+
/*
 * We know that this is a full mm pte clear and
 * hence can be sure there is no parallel set_pte.
 */
-   return radix__ptep_get_and_clear_full(mm, addr, ptep, full);
+   old_pte = radix__ptep_get_and_clear_full(mm, addr, ptep, full);
+   page_table_check_pte_clear(mm, addr, old_pte);
+
+   return old_pte;
}
return ptep_get_and_clear(mm, addr, ptep);
 }
@@ -1249,17 +1259,33 @@ extern int pmdp_test_and_clea

[PATCH v7 6/7] powerpc: mm: Add p{te,md,ud}_user_accessible_page helpers

2023-02-14 Thread Rohan McLure
Add the following helpers for detecting whether a page table entry
is a leaf and is accessible to user space.

 * pte_user_accessible_page
 * pmd_user_accessible_page
 * pud_user_accessible_page

Also implement missing pud_user definitions for both Book3S/nohash 64-bit
systems, and pmd_user for Book3S/nohash 32-bit systems.

Signed-off-by: Rohan McLure 
---
V2: Provide missing pud_user implementations, use p{u,m}d_is_leaf.
V3: Provide missing pmd_user implementations as stubs in 32-bit.
V4: Use pmd_leaf, pud_leaf, and define pmd_user for 32 Book3E with
static inline method rather than macro.
---
 arch/powerpc/include/asm/book3s/32/pgtable.h |  4 
 arch/powerpc/include/asm/book3s/64/pgtable.h | 10 ++
 arch/powerpc/include/asm/nohash/32/pgtable.h |  5 +
 arch/powerpc/include/asm/nohash/64/pgtable.h | 10 ++
 arch/powerpc/include/asm/pgtable.h   | 15 +++
 5 files changed, 44 insertions(+)

diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h 
b/arch/powerpc/include/asm/book3s/32/pgtable.h
index a090cb13a4a0..afd672e84791 100644
--- a/arch/powerpc/include/asm/book3s/32/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
@@ -516,6 +516,10 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
 }
 
+static inline bool pmd_user(pmd_t pmd)
+{
+   return 0;
+}
 
 
 /* This low level function performs the actual PTE insertion
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
b/arch/powerpc/include/asm/book3s/64/pgtable.h
index df5ee856444d..a6ed93d01da1 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -538,6 +538,16 @@ static inline bool pte_user(pte_t pte)
return !(pte_raw(pte) & cpu_to_be64(_PAGE_PRIVILEGED));
 }
 
+static inline bool pmd_user(pmd_t pmd)
+{
+   return !(pmd_raw(pmd) & cpu_to_be64(_PAGE_PRIVILEGED));
+}
+
+static inline bool pud_user(pud_t pud)
+{
+   return !(pud_raw(pud) & cpu_to_be64(_PAGE_PRIVILEGED));
+}
+
 #define pte_access_permitted pte_access_permitted
 static inline bool pte_access_permitted(pte_t pte, bool write)
 {
diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h 
b/arch/powerpc/include/asm/nohash/32/pgtable.h
index 70edad44dff6..d953533c56ff 100644
--- a/arch/powerpc/include/asm/nohash/32/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/32/pgtable.h
@@ -209,6 +209,11 @@ static inline void pmd_clear(pmd_t *pmdp)
*pmdp = __pmd(0);
 }
 
+static inline bool pmd_user(pmd_t pmd)
+{
+   return false;
+}
+
 /*
  * PTE updates. This function is called whenever an existing
  * valid PTE is updated. This does -not- include set_pte_at()
diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h 
b/arch/powerpc/include/asm/nohash/64/pgtable.h
index d391a45e0f11..14e69ebad31f 100644
--- a/arch/powerpc/include/asm/nohash/64/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
@@ -123,6 +123,11 @@ static inline pte_t pmd_pte(pmd_t pmd)
return __pte(pmd_val(pmd));
 }
 
+static inline bool pmd_user(pmd_t pmd)
+{
+   return (pmd_val(pmd) & _PAGE_USER) == _PAGE_USER;
+}
+
 #define pmd_none(pmd)  (!pmd_val(pmd))
 #definepmd_bad(pmd)(!is_kernel_addr(pmd_val(pmd)) \
 || (pmd_val(pmd) & PMD_BAD_BITS))
@@ -164,6 +169,11 @@ static inline pte_t pud_pte(pud_t pud)
return __pte(pud_val(pud));
 }
 
+static inline bool pud_user(pud_t pud)
+{
+   return (pud_val(pud) & _PAGE_USER) == _PAGE_USER;
+}
+
 static inline pud_t pte_pud(pte_t pte)
 {
return __pud(pte_val(pte));
diff --git a/arch/powerpc/include/asm/pgtable.h 
b/arch/powerpc/include/asm/pgtable.h
index ad0829f816e9..b76fdb80b6c9 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -167,6 +167,21 @@ static inline int pud_pfn(pud_t pud)
 }
 #endif
 
+static inline bool pte_user_accessible_page(pte_t pte)
+{
+   return pte_present(pte) && pte_user(pte);
+}
+
+static inline bool pmd_user_accessible_page(pmd_t pmd)
+{
+   return pmd_leaf(pmd) && pmd_present(pmd) && pmd_user(pmd);
+}
+
+static inline bool pud_user_accessible_page(pud_t pud)
+{
+   return pud_leaf(pud) && pud_present(pud) && pud_user(pud);
+}
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_PGTABLE_H */
-- 
2.37.2



Re: [PATCH] mm: remove zap_page_range and create zap_vma_pages

2023-02-14 Thread Palmer Dabbelt

On Tue, 03 Jan 2023 16:27:32 PST (-0800), mike.krav...@oracle.com wrote:

zap_page_range was originally designed to unmap pages within an address
range that could span multiple vmas.  While working on [1], it was
discovered that all callers of zap_page_range pass a range entirely within
a single vma.  In addition, the mmu notification call within zap_page
range does not correctly handle ranges that span multiple vmas.  When
crossing a vma boundary, a new mmu_notifier_range_init/end call pair
with the new vma should be made.

Instead of fixing zap_page_range, do the following:
- Create a new routine zap_vma_pages() that will remove all pages within
  the passed vma.  Most users of zap_page_range pass the entire vma and
  can use this new routine.
- For callers of zap_page_range not passing the entire vma, instead call
  zap_page_range_single().
- Remove zap_page_range.

[1] 
https://lore.kernel.org/linux-mm/20221114235507.294320-2-mike.krav...@oracle.com/
Suggested-by: Peter Xu 
Signed-off-by: Mike Kravetz 


[...]


diff --git a/arch/riscv/kernel/vdso.c b/arch/riscv/kernel/vdso.c
index e410275918ac..5c30212d8d1c 100644
--- a/arch/riscv/kernel/vdso.c
+++ b/arch/riscv/kernel/vdso.c
@@ -124,13 +124,11 @@ int vdso_join_timens(struct task_struct *task, struct 
time_namespace *ns)
mmap_read_lock(mm);

for_each_vma(vmi, vma) {
-   unsigned long size = vma->vm_end - vma->vm_start;
-
if (vma_is_special_mapping(vma, vdso_info.dm))
-   zap_page_range(vma, vma->vm_start, size);
+   zap_vma_pages(vma);
 #ifdef CONFIG_COMPAT
if (vma_is_special_mapping(vma, compat_vdso_info.dm))
-   zap_page_range(vma, vma->vm_start, size);
+   zap_vma_pages(vma);
 #endif
}


Acked-by: Palmer Dabbelt  # RISC-V

Thanks!


Re: [PATCH 13/19] arch/riscv: rename internal name __xchg to __arch_xchg

2023-02-14 Thread Palmer Dabbelt

On Thu, 22 Dec 2022 03:46:29 PST (-0800), andrzej.ha...@intel.com wrote:

__xchg will be used for non-atomic xchg macro.

Signed-off-by: Andrzej Hajda 
---
 arch/riscv/include/asm/atomic.h  | 2 +-
 arch/riscv/include/asm/cmpxchg.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/include/asm/atomic.h b/arch/riscv/include/asm/atomic.h
index 0dfe9d857a762b..bba472928b5393 100644
--- a/arch/riscv/include/asm/atomic.h
+++ b/arch/riscv/include/asm/atomic.h
@@ -261,7 +261,7 @@ c_t arch_atomic##prefix##_xchg_release(atomic##prefix##_t 
*v, c_t n)\
 static __always_inline \
 c_t arch_atomic##prefix##_xchg(atomic##prefix##_t *v, c_t n)   \
 {  \
-   return __xchg(&(v->counter), n, size);   \
+   return __arch_xchg(&(v->counter), n, size);  \
 }  \
 static __always_inline \
 c_t arch_atomic##prefix##_cmpxchg_relaxed(atomic##prefix##_t *v,   \
diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h
index 12debce235e52d..2f4726d3cfcc25 100644
--- a/arch/riscv/include/asm/cmpxchg.h
+++ b/arch/riscv/include/asm/cmpxchg.h
@@ -114,7 +114,7 @@
_x_, sizeof(*(ptr)));   \
 })

-#define __xchg(ptr, new, size) \
+#define __arch_xchg(ptr, new, size)\
 ({ \
__typeof__(ptr) __ptr = (ptr);  \
__typeof__(new) __new = (new);  \
@@ -143,7 +143,7 @@
 #define arch_xchg(ptr, x)  \
 ({ \
__typeof__(*(ptr)) _x_ = (x);   \
-   (__typeof__(*(ptr))) __xchg((ptr), _x_, sizeof(*(ptr)));\
+   (__typeof__(*(ptr))) __arch_xchg((ptr), _x_, sizeof(*(ptr)));   \
 })

 #define xchg32(ptr, x) \


Acked-by: Palmer Dabbelt 


Re: [PATCH v3 09/24] powerpc: Remove COMMAND_LINE_SIZE from uapi

2023-02-14 Thread Michael Ellerman
Alexandre Ghiti  writes:
> From: Palmer Dabbelt 
>
> As far as I can tell this is not used by userspace and thus should not
> be part of the user-visible API.
>
> Signed-off-by: Palmer Dabbelt 
> ---
>  arch/powerpc/include/asm/setup.h  | 2 +-
>  arch/powerpc/include/uapi/asm/setup.h | 2 --
>  2 files changed, 1 insertion(+), 3 deletions(-)

Acked-by: Michael Ellerman  (powerpc)

cheers


Re: [PATCH v7 1/7] powerpc: mm: Separate set_pte, set_pte_at for internal, external use

2023-02-14 Thread Christophe Leroy


Le 15/02/2023 à 03:01, Rohan McLure a écrit :
> Produce separate symbols for set_pte, which is to be used in
> arch/powerpc for reassignment of pte's, and set_pte_at, used in generic
> code.
> 
> The reason for this distinction is to support the Page Table Check
> sanitiser. Having this distinction allows for set_pte_at to
> instrumented, but set_pte not to be, permitting for uninstrumented
> internal mappings. This distinction in names is also present in x86.
> 
> Signed-off-by: Rohan McLure 

Reviewed-by: Christophe Leroy 

> ---
> v6: new patch
> v7: Remove extern, move set_pte args to be in a single line.
> ---
>   arch/powerpc/include/asm/book3s/pgtable.h | 3 +--
>   arch/powerpc/include/asm/nohash/pgtable.h | 3 +--
>   arch/powerpc/include/asm/pgtable.h| 1 +
>   arch/powerpc/mm/pgtable.c | 3 +--
>   4 files changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/book3s/pgtable.h 
> b/arch/powerpc/include/asm/book3s/pgtable.h
> index d18b748ea3ae..1386ed705e66 100644
> --- a/arch/powerpc/include/asm/book3s/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/pgtable.h
> @@ -12,8 +12,7 @@
>   /* Insert a PTE, top-level function is out of line. It uses an inline
>* low level function in the respective pgtable-* files
>*/
> -extern void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
> -pte_t pte);
> +void set_pte(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t 
> pte);
>   
>   
>   #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
> diff --git a/arch/powerpc/include/asm/nohash/pgtable.h 
> b/arch/powerpc/include/asm/nohash/pgtable.h
> index 69c3a050a3d8..f36dd2e2d591 100644
> --- a/arch/powerpc/include/asm/nohash/pgtable.h
> +++ b/arch/powerpc/include/asm/nohash/pgtable.h
> @@ -154,8 +154,7 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t 
> newprot)
>   /* Insert a PTE, top-level function is out of line. It uses an inline
>* low level function in the respective pgtable-* files
>*/
> -extern void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
> -pte_t pte);
> +void set_pte(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t 
> pte);
>   
>   /* This low level function performs the actual PTE insertion
>* Setting the PTE depends on the MMU type and other factors. It's
> diff --git a/arch/powerpc/include/asm/pgtable.h 
> b/arch/powerpc/include/asm/pgtable.h
> index 9972626ddaf6..17d30359d1f4 100644
> --- a/arch/powerpc/include/asm/pgtable.h
> +++ b/arch/powerpc/include/asm/pgtable.h
> @@ -48,6 +48,7 @@ struct mm_struct;
>   /* Keep these as a macros to avoid include dependency mess */
>   #define pte_page(x) pfn_to_page(pte_pfn(x))
>   #define mk_pte(page, pgprot)pfn_pte(page_to_pfn(page), (pgprot))
> +#define set_pte_at   set_pte
>   /*
>* Select all bits except the pfn
>*/
> diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c
> index cb2dcdb18f8e..d7cce317cef8 100644
> --- a/arch/powerpc/mm/pgtable.c
> +++ b/arch/powerpc/mm/pgtable.c
> @@ -187,8 +187,7 @@ static pte_t set_access_flags_filter(pte_t pte, struct 
> vm_area_struct *vma,
>   /*
>* set_pte stores a linux PTE into the linux page table.
>*/
> -void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
> - pte_t pte)
> +void set_pte(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t 
> pte)
>   {
>   /*
>* Make sure hardware valid bit is not set. We don't do


Re: [PATCH v7 3/7] powerpc: mm: Replace p{u,m,4}d_is_leaf with p{u,m,4}_leaf

2023-02-14 Thread Christophe Leroy


Le 15/02/2023 à 03:01, Rohan McLure a écrit :
> Replace occurrences of p{u,m,4}d_is_leaf with p{u,m,4}_leaf, as the
> latter is the name given to checking that a higher-level entry in
> multi-level paging contains a page translation entry (pte) throughout
> all other archs.
> 
> A future patch will implement p{u,m,4}_leaf stubs on all platforms so
> that they may be referenced in generic code.
> 
> Signed-off-by: Rohan McLure 

Reviewed-by: Christophe Leroy 

> ---
> V4: New patch
> V5: Previously replaced stub definition for *_is_leaf with *_leaf. Do
> that in a later patch
> ---
>   arch/powerpc/kvm/book3s_64_mmu_radix.c   | 12 ++--
>   arch/powerpc/mm/book3s64/radix_pgtable.c | 14 +++---
>   arch/powerpc/mm/pgtable.c|  6 +++---
>   arch/powerpc/mm/pgtable_64.c |  6 +++---
>   arch/powerpc/xmon/xmon.c |  6 +++---
>   5 files changed, 22 insertions(+), 22 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c 
> b/arch/powerpc/kvm/book3s_64_mmu_radix.c
> index 9d3743ca16d5..0d24fd984d16 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_radix.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c
> @@ -497,7 +497,7 @@ static void kvmppc_unmap_free_pmd(struct kvm *kvm, pmd_t 
> *pmd, bool full,
>   for (im = 0; im < PTRS_PER_PMD; ++im, ++p) {
>   if (!pmd_present(*p))
>   continue;
> - if (pmd_is_leaf(*p)) {
> + if (pmd_leaf(*p)) {
>   if (full) {
>   pmd_clear(p);
>   } else {
> @@ -526,7 +526,7 @@ static void kvmppc_unmap_free_pud(struct kvm *kvm, pud_t 
> *pud,
>   for (iu = 0; iu < PTRS_PER_PUD; ++iu, ++p) {
>   if (!pud_present(*p))
>   continue;
> - if (pud_is_leaf(*p)) {
> + if (pud_leaf(*p)) {
>   pud_clear(p);
>   } else {
>   pmd_t *pmd;
> @@ -629,12 +629,12 @@ int kvmppc_create_pte(struct kvm *kvm, pgd_t *pgtable, 
> pte_t pte,
>   new_pud = pud_alloc_one(kvm->mm, gpa);
>   
>   pmd = NULL;
> - if (pud && pud_present(*pud) && !pud_is_leaf(*pud))
> + if (pud && pud_present(*pud) && !pud_leaf(*pud))
>   pmd = pmd_offset(pud, gpa);
>   else if (level <= 1)
>   new_pmd = kvmppc_pmd_alloc();
>   
> - if (level == 0 && !(pmd && pmd_present(*pmd) && !pmd_is_leaf(*pmd)))
> + if (level == 0 && !(pmd && pmd_present(*pmd) && !pmd_leaf(*pmd)))
>   new_ptep = kvmppc_pte_alloc();
>   
>   /* Check if we might have been invalidated; let the guest retry if so */
> @@ -652,7 +652,7 @@ int kvmppc_create_pte(struct kvm *kvm, pgd_t *pgtable, 
> pte_t pte,
>   new_pud = NULL;
>   }
>   pud = pud_offset(p4d, gpa);
> - if (pud_is_leaf(*pud)) {
> + if (pud_leaf(*pud)) {
>   unsigned long hgpa = gpa & PUD_MASK;
>   
>   /* Check if we raced and someone else has set the same thing */
> @@ -703,7 +703,7 @@ int kvmppc_create_pte(struct kvm *kvm, pgd_t *pgtable, 
> pte_t pte,
>   new_pmd = NULL;
>   }
>   pmd = pmd_offset(pud, gpa);
> - if (pmd_is_leaf(*pmd)) {
> + if (pmd_leaf(*pmd)) {
>   unsigned long lgpa = gpa & PMD_MASK;
>   
>   /* Check if we raced and someone else has set the same thing */
> diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c 
> b/arch/powerpc/mm/book3s64/radix_pgtable.c
> index 26245aaf12b8..4e46e001c3c3 100644
> --- a/arch/powerpc/mm/book3s64/radix_pgtable.c
> +++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
> @@ -205,14 +205,14 @@ static void radix__change_memory_range(unsigned long 
> start, unsigned long end,
>   pudp = pud_alloc(&init_mm, p4dp, idx);
>   if (!pudp)
>   continue;
> - if (pud_is_leaf(*pudp)) {
> + if (pud_leaf(*pudp)) {
>   ptep = (pte_t *)pudp;
>   goto update_the_pte;
>   }
>   pmdp = pmd_alloc(&init_mm, pudp, idx);
>   if (!pmdp)
>   continue;
> - if (pmd_is_leaf(*pmdp)) {
> + if (pmd_leaf(*pmdp)) {
>   ptep = pmdp_ptep(pmdp);
>   goto update_the_pte;
>   }
> @@ -786,7 +786,7 @@ static void __meminit remove_pmd_table(pmd_t *pmd_start, 
> unsigned long addr,
>   if (!pmd_present(*pmd))
>   continue;
>   
> - if (pmd_is_leaf(*pmd)) {
> + if (pmd_leaf(*pmd)) {
>   if (!IS_ALIGNED(addr, PMD_SIZE) ||
>   !IS_ALIGNED(next, PMD_SIZE)) {
>   WARN_ONCE(1, "%s: unaligned range\n", __func__);
> @@ -816,7 +816,7 @@ static void __meminit remove_pud_table(pud_t *pud_start, 
> unsigned long addr,
>   if (!pud_present(*pud))
>   

Re: [PATCH v7 4/7] powerpc: mm: Implement p{m,u,4}d_leaf on all platforms

2023-02-14 Thread Christophe Leroy


Le 15/02/2023 à 03:01, Rohan McLure a écrit :
> The check that a higher-level entry in multi-level pages contains a page
> translation entry (pte) is performed by p{m,u,4}d_leaf stubs, which may
> be specialised for each choice of mmu. In a prior commit, we replace
> uses to the catch-all stubs, p{m,u,4}d_is_leaf with p{m,u,4}d_leaf.
> 
> Replace the catch-all stub definitions for p{m,u,4}d_is_leaf with
> definitions for p{m,u,4}d_leaf. A future patch will assume that
> p{m,u,4}d_leaf is defined on all platforms.
> 
> In particular, implement pud_leaf for Book3E-64, pmd_leaf for all Book3E
> and Book3S-64 platforms, with a catch-all definition for p4d_leaf.
> 
> Signed-off-by: Rohan McLure 

Reviewed-by: Christophe Leroy 

> ---
> v5: Split patch that replaces p{m,u,4}d_is_leaf into two patches, first
> replacing callsites and afterward providing generic definition.
> Remove ifndef-defines implementing p{m,u}d_leaf in favour of
> implementing stubs in headers belonging to the particular platforms
> needing them.
> ---
>   arch/powerpc/include/asm/book3s/32/pgtable.h |  5 +
>   arch/powerpc/include/asm/book3s/64/pgtable.h | 10 -
>   arch/powerpc/include/asm/nohash/64/pgtable.h |  6 ++
>   arch/powerpc/include/asm/nohash/pgtable.h|  6 ++
>   arch/powerpc/include/asm/pgtable.h   | 22 ++--
>   5 files changed, 23 insertions(+), 26 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h 
> b/arch/powerpc/include/asm/book3s/32/pgtable.h
> index 75823f39e042..a090cb13a4a0 100644
> --- a/arch/powerpc/include/asm/book3s/32/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
> @@ -242,6 +242,11 @@ static inline void pmd_clear(pmd_t *pmdp)
>   *pmdp = __pmd(0);
>   }
>   
> +#define pmd_leaf pmd_leaf
> +static inline bool pmd_leaf(pmd_t pmd)
> +{
> + return false;
> +}
>   
>   /*
>* When flushing the tlb entry for a page, we also need to flush the hash
> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
> b/arch/powerpc/include/asm/book3s/64/pgtable.h
> index 7e0d546f4b3c..589d2dbe3873 100644
> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
> @@ -1359,16 +1359,14 @@ static inline bool is_pte_rw_upgrade(unsigned long 
> old_val, unsigned long new_va
>   /*
>* Like pmd_huge() and pmd_large(), but works regardless of config options
>*/
> -#define pmd_is_leaf pmd_is_leaf
> -#define pmd_leaf pmd_is_leaf
> -static inline bool pmd_is_leaf(pmd_t pmd)
> +#define pmd_leaf pmd_leaf
> +static inline bool pmd_leaf(pmd_t pmd)
>   {
>   return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE));
>   }
>   
> -#define pud_is_leaf pud_is_leaf
> -#define pud_leaf pud_is_leaf
> -static inline bool pud_is_leaf(pud_t pud)
> +#define pud_leaf pud_leaf
> +static inline bool pud_leaf(pud_t pud)
>   {
>   return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE));
>   }
> diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h 
> b/arch/powerpc/include/asm/nohash/64/pgtable.h
> index 879e9a6e5a87..d391a45e0f11 100644
> --- a/arch/powerpc/include/asm/nohash/64/pgtable.h
> +++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
> @@ -141,6 +141,12 @@ static inline void pud_clear(pud_t *pudp)
>   *pudp = __pud(0);
>   }
>   
> +#define pud_leaf pud_leaf
> +static inline bool pud_leaf(pud_t pud)
> +{
> + return false;
> +}
> +
>   #define pud_none(pud)   (!pud_val(pud))
>   #define pud_bad(pud)(!is_kernel_addr(pud_val(pud)) \
>|| (pud_val(pud) & PUD_BAD_BITS))
> diff --git a/arch/powerpc/include/asm/nohash/pgtable.h 
> b/arch/powerpc/include/asm/nohash/pgtable.h
> index f36dd2e2d591..43b50fd8d236 100644
> --- a/arch/powerpc/include/asm/nohash/pgtable.h
> +++ b/arch/powerpc/include/asm/nohash/pgtable.h
> @@ -60,6 +60,12 @@ static inline bool pte_hw_valid(pte_t pte)
>   return pte_val(pte) & _PAGE_PRESENT;
>   }
>   
> +#define pmd_leaf pmd_leaf
> +static inline bool pmd_leaf(pmd_t pmd)
> +{
> + return false;
> +}
> +
>   /*
>* Don't just check for any non zero bits in __PAGE_USER, since for book3e
>* and PTE_64BIT, PAGE_KERNEL_X contains _PAGE_BAP_SR which is also in
> diff --git a/arch/powerpc/include/asm/pgtable.h 
> b/arch/powerpc/include/asm/pgtable.h
> index 17d30359d1f4..284408829fa3 100644
> --- a/arch/powerpc/include/asm/pgtable.h
> +++ b/arch/powerpc/include/asm/pgtable.h
> @@ -128,29 +128,11 @@ static inline void pte_frag_set(mm_context_t *ctx, void 
> *p)
>   }
>   #endif
>   
> -#ifndef pmd_is_leaf
> -#define pmd_is_leaf pmd_is_leaf
> -static inline bool pmd_is_leaf(pmd_t pmd)
> +#define p4d_leaf p4d_leaf
> +static inline bool p4d_leaf(p4d_t p4d)
>   {
>   return false;
>   }
> -#endif
> -
> -#ifndef pud_is_leaf
> -#define pud_is_leaf pud_is_leaf
> -static inline bool pud_is_leaf(pud_t pud)
> -{
> - return false;
> -}
> -#endif
> -
> -#ifndef p4d_is_leaf
> -#define p4d_is_leaf p4d_is_leaf
> -st

Re: [PATCH v7 6/7] powerpc: mm: Add p{te,md,ud}_user_accessible_page helpers

2023-02-14 Thread Christophe Leroy


Le 15/02/2023 à 03:01, Rohan McLure a écrit :
> Add the following helpers for detecting whether a page table entry
> is a leaf and is accessible to user space.
> 
>   * pte_user_accessible_page
>   * pmd_user_accessible_page
>   * pud_user_accessible_page
> 
> Also implement missing pud_user definitions for both Book3S/nohash 64-bit
> systems, and pmd_user for Book3S/nohash 32-bit systems.
> 
> Signed-off-by: Rohan McLure 

Reviewed-by: Christophe Leroy 

> ---
> V2: Provide missing pud_user implementations, use p{u,m}d_is_leaf.
> V3: Provide missing pmd_user implementations as stubs in 32-bit.
> V4: Use pmd_leaf, pud_leaf, and define pmd_user for 32 Book3E with
> static inline method rather than macro.
> ---
>   arch/powerpc/include/asm/book3s/32/pgtable.h |  4 
>   arch/powerpc/include/asm/book3s/64/pgtable.h | 10 ++
>   arch/powerpc/include/asm/nohash/32/pgtable.h |  5 +
>   arch/powerpc/include/asm/nohash/64/pgtable.h | 10 ++
>   arch/powerpc/include/asm/pgtable.h   | 15 +++
>   5 files changed, 44 insertions(+)
> 
> diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h 
> b/arch/powerpc/include/asm/book3s/32/pgtable.h
> index a090cb13a4a0..afd672e84791 100644
> --- a/arch/powerpc/include/asm/book3s/32/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
> @@ -516,6 +516,10 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t 
> newprot)
>   return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
>   }
>   
> +static inline bool pmd_user(pmd_t pmd)
> +{
> + return 0;
> +}
>   
>   
>   /* This low level function performs the actual PTE insertion
> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
> b/arch/powerpc/include/asm/book3s/64/pgtable.h
> index df5ee856444d..a6ed93d01da1 100644
> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
> @@ -538,6 +538,16 @@ static inline bool pte_user(pte_t pte)
>   return !(pte_raw(pte) & cpu_to_be64(_PAGE_PRIVILEGED));
>   }
>   
> +static inline bool pmd_user(pmd_t pmd)
> +{
> + return !(pmd_raw(pmd) & cpu_to_be64(_PAGE_PRIVILEGED));
> +}
> +
> +static inline bool pud_user(pud_t pud)
> +{
> + return !(pud_raw(pud) & cpu_to_be64(_PAGE_PRIVILEGED));
> +}
> +
>   #define pte_access_permitted pte_access_permitted
>   static inline bool pte_access_permitted(pte_t pte, bool write)
>   {
> diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h 
> b/arch/powerpc/include/asm/nohash/32/pgtable.h
> index 70edad44dff6..d953533c56ff 100644
> --- a/arch/powerpc/include/asm/nohash/32/pgtable.h
> +++ b/arch/powerpc/include/asm/nohash/32/pgtable.h
> @@ -209,6 +209,11 @@ static inline void pmd_clear(pmd_t *pmdp)
>   *pmdp = __pmd(0);
>   }
>   
> +static inline bool pmd_user(pmd_t pmd)
> +{
> + return false;
> +}
> +
>   /*
>* PTE updates. This function is called whenever an existing
>* valid PTE is updated. This does -not- include set_pte_at()
> diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h 
> b/arch/powerpc/include/asm/nohash/64/pgtable.h
> index d391a45e0f11..14e69ebad31f 100644
> --- a/arch/powerpc/include/asm/nohash/64/pgtable.h
> +++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
> @@ -123,6 +123,11 @@ static inline pte_t pmd_pte(pmd_t pmd)
>   return __pte(pmd_val(pmd));
>   }
>   
> +static inline bool pmd_user(pmd_t pmd)
> +{
> + return (pmd_val(pmd) & _PAGE_USER) == _PAGE_USER;
> +}
> +
>   #define pmd_none(pmd)   (!pmd_val(pmd))
>   #define pmd_bad(pmd)(!is_kernel_addr(pmd_val(pmd)) \
>|| (pmd_val(pmd) & PMD_BAD_BITS))
> @@ -164,6 +169,11 @@ static inline pte_t pud_pte(pud_t pud)
>   return __pte(pud_val(pud));
>   }
>   
> +static inline bool pud_user(pud_t pud)
> +{
> + return (pud_val(pud) & _PAGE_USER) == _PAGE_USER;
> +}
> +
>   static inline pud_t pte_pud(pte_t pte)
>   {
>   return __pud(pte_val(pte));
> diff --git a/arch/powerpc/include/asm/pgtable.h 
> b/arch/powerpc/include/asm/pgtable.h
> index ad0829f816e9..b76fdb80b6c9 100644
> --- a/arch/powerpc/include/asm/pgtable.h
> +++ b/arch/powerpc/include/asm/pgtable.h
> @@ -167,6 +167,21 @@ static inline int pud_pfn(pud_t pud)
>   }
>   #endif
>   
> +static inline bool pte_user_accessible_page(pte_t pte)
> +{
> + return pte_present(pte) && pte_user(pte);
> +}
> +
> +static inline bool pmd_user_accessible_page(pmd_t pmd)
> +{
> + return pmd_leaf(pmd) && pmd_present(pmd) && pmd_user(pmd);
> +}
> +
> +static inline bool pud_user_accessible_page(pud_t pud)
> +{
> + return pud_leaf(pud) && pud_present(pud) && pud_user(pud);
> +}
> +
>   #endif /* __ASSEMBLY__ */
>   
>   #endif /* _ASM_POWERPC_PGTABLE_H */


Re: [PATCH v7 7/7] powerpc: mm: Support page table check

2023-02-14 Thread Christophe Leroy


Le 15/02/2023 à 03:01, Rohan McLure a écrit :
> On creation and clearing of a page table mapping, instrument such calls
> by invoking page_table_check_pte_set and page_table_check_pte_clear
> respectively. These calls serve as a sanity check against illegal
> mappings.
> 
> Enable ARCH_SUPPORTS_PAGE_TABLE_CHECK for all platforms.
> 
> Use set_pte internally, and cause this function to reassign a page table
> entry without instrumentation. Generic code will be instrumented, as it
> references set_pte_at.
> 
> See also:
> 
> riscv support in commit 3fee229a8eb9 ("riscv/mm: enable
> ARCH_SUPPORTS_PAGE_TABLE_CHECK")
> arm64 in commit 42b2547137f5 ("arm64/mm: enable
> ARCH_SUPPORTS_PAGE_TABLE_CHECK")
> x86_64 in commit d283d422c6c4 ("x86: mm: add x86_64 support for page table
> check")
> 
> Signed-off-by: Rohan McLure 

Reviewed-by: Christophe Leroy 

> ---
> V2: Update spacing and types assigned to pte_update calls.
> V3: Update one last pte_update call to remove __pte invocation.
> V5: Fix 32-bit nohash double set
> V6: Omit __set_pte_at instrumentation - should be instrumented by
> set_pte_at, with set_pte in between, performing all prior checks.
> Instrument pmds. Use set_pte where needed.
> V7: Make set_pte_at an inline function. Fix commit message.
> Detail changes of internal references to set_pte_at, and its semantics.
> ---
>   arch/powerpc/Kconfig |  1 +
>   arch/powerpc/include/asm/book3s/32/pgtable.h |  8 +++-
>   arch/powerpc/include/asm/book3s/64/pgtable.h | 44 
>   arch/powerpc/include/asm/nohash/32/pgtable.h |  7 +++-
>   arch/powerpc/include/asm/nohash/64/pgtable.h |  8 +++-
>   arch/powerpc/include/asm/pgtable.h   | 10 -
>   arch/powerpc/mm/book3s64/hash_pgtable.c  |  2 +-
>   arch/powerpc/mm/book3s64/pgtable.c   | 16 ---
>   arch/powerpc/mm/book3s64/radix_pgtable.c | 10 ++---
>   arch/powerpc/mm/nohash/book3e_pgtable.c  |  2 +-
>   arch/powerpc/mm/pgtable_32.c |  2 +-
>   11 files changed, 83 insertions(+), 27 deletions(-)
> 
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 2c9cdf1d8761..2474e2699037 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -154,6 +154,7 @@ config PPC
>   select ARCH_STACKWALK
>   select ARCH_SUPPORTS_ATOMIC_RMW
>   select ARCH_SUPPORTS_DEBUG_PAGEALLOCif PPC_BOOK3S || PPC_8xx || 40x
> + select ARCH_SUPPORTS_PAGE_TABLE_CHECK
>   select ARCH_USE_BUILTIN_BSWAP
>   select ARCH_USE_CMPXCHG_LOCKREF if PPC64
>   select ARCH_USE_MEMTEST
> diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h 
> b/arch/powerpc/include/asm/book3s/32/pgtable.h
> index afd672e84791..8850b4fb22a4 100644
> --- a/arch/powerpc/include/asm/book3s/32/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
> @@ -53,6 +53,8 @@
>   
>   #ifndef __ASSEMBLY__
>   
> +#include 
> +
>   static inline bool pte_user(pte_t pte)
>   {
>   return pte_val(pte) & _PAGE_USER;
> @@ -338,7 +340,11 @@ static inline int __ptep_test_and_clear_young(struct 
> mm_struct *mm,
>   static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long 
> addr,
>  pte_t *ptep)
>   {
> - return __pte(pte_update(mm, addr, ptep, ~_PAGE_HASHPTE, 0, 0));
> + pte_t old_pte = __pte(pte_update(mm, addr, ptep, ~_PAGE_HASHPTE, 0, 0));
> +
> + page_table_check_pte_clear(mm, addr, old_pte);
> +
> + return old_pte;
>   }
>   
>   #define __HAVE_ARCH_PTEP_SET_WRPROTECT
> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
> b/arch/powerpc/include/asm/book3s/64/pgtable.h
> index a6ed93d01da1..0c6838875720 100644
> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
> @@ -162,6 +162,8 @@
>   #define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX)
>   
>   #ifndef __ASSEMBLY__
> +#include 
> +
>   /*
>* page table defines
>*/
> @@ -431,8 +433,11 @@ static inline void huge_ptep_set_wrprotect(struct 
> mm_struct *mm,
>   static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
>  unsigned long addr, pte_t *ptep)
>   {
> - unsigned long old = pte_update(mm, addr, ptep, ~0UL, 0, 0);
> - return __pte(old);
> + pte_t old_pte = __pte(pte_update(mm, addr, ptep, ~0UL, 0, 0));
> +
> + page_table_check_pte_clear(mm, addr, old_pte);
> +
> + return old_pte;
>   }
>   
>   #define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
> @@ -441,11 +446,16 @@ static inline pte_t ptep_get_and_clear_full(struct 
> mm_struct *mm,
>   pte_t *ptep, int full)
>   {
>   if (full && radix_enabled()) {
> + pte_t old_pte;
> +
>   /*
>* We know that this is a full mm pte clear and
>* hence can be sure there is no parallel set_pte.
>*/
> - return radix__ptep_get_and_clear_full(mm, add