Re: [PATCH v2] tty: hvc: Fix the RISC-V SBI driver for a refactoring

2024-01-19 Thread Palmer Dabbelt

On Fri, 19 Jan 2024 19:59:11 PST (-0800), a...@brainfault.org wrote:

On Sat, Jan 20, 2024 at 4:15 AM Palmer Dabbelt  wrote:


From: Palmer Dabbelt 

I missed the int->size_t refactoring in f32fcbedbe92 ("tty: hvc: convert
to u8 and size_t"), which causes the newly used ops in 88ead68e764c
("tty: Add SBI debug console support to HVC SBI driver") to fail to
build due to a

linux/drivers/tty/hvc/hvc_riscv_sbi.c:59:15: error: incompatible function 
pointer types initializing 'ssize_t (*)(uint32_t, const u8 *, size_t)' (aka 
'long (*)(unsigned int, const unsigned char *, unsigned long)') with an 
expression of type 'int (uint32_t, const char *, int)' (aka 'int (unsigned int, 
const char *, int)') [-Wincompatible-function-pointer-types]
.put_chars = hvc_sbi_dbcn_tty_put,

Fixes: f32fcbedbe92 ("tty: hvc: convert to u8 and size_t")
Fixes: 88ead68e764c ("tty: Add SBI debug console support to HVC SBI driver")
Link: https://lore.kernel.org/r/20240119215612.20529-2-pal...@rivosinc.com
Signed-off-by: Palmer Dabbelt 
---
Changes since v1 <20240119215612.20529-2-pal...@rivosinc.com>:
* Fix the return and arguments correctly.
* Also fix the hvc_sbi_dbcn_tty_{get,put}().
---
 drivers/tty/hvc/hvc_riscv_sbi.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c
index 2f3571f17ecd..f8cd3310ef35 100644
--- a/drivers/tty/hvc/hvc_riscv_sbi.c
+++ b/drivers/tty/hvc/hvc_riscv_sbi.c
@@ -15,7 +15,7 @@

 #include "hvc_console.h"

-static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
+static ssize_t hvc_sbi_tty_put(uint32_t vtermno, const u8 *buf, size_t count)
 {
int i;

@@ -25,7 +25,7 @@ static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, 
int count)
return i;
 }

-static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
+static ssize_t hvc_sbi_tty_get(uint32_t vtermno, u8 *buf, size_t count)


The hvc_sbi_tty_put() and hvc_sbi_tty_get() functions are already
updated in Linus's tree. We only need to fix hvc_sbi_dbcn_tty_put()
and hvc_sbi_dbcn_tty_get()

Please rebase this fix upon Linux-6.8-rc1 whenever that is available.


Ya, it's kind of clunky: we added functions at the same time as the 
refactoring, so there's no good clean tree to apply a patch to.  Right 
now I've actually got this bundled up into a merge, that's usually the 
worst option but it's about as good as I could come up with -- Linus 
still hasn't merged my part 2, so I'm going to send a part 3 once I get 
through the tests on my end.


So we'll see, likely tomorrow, and then I'll deal with the fallout after 
rc1...





 {
int i, c;

@@ -44,12 +44,12 @@ static const struct hv_ops hvc_sbi_v01_ops = {
.put_chars = hvc_sbi_tty_put,
 };

-static int hvc_sbi_dbcn_tty_put(uint32_t vtermno, const char *buf, int count)
+static ssize_t hvc_sbi_dbcn_tty_put(uint32_t vtermno, const u8 *buf, size_t 
count)
 {
return sbi_debug_console_write(buf, count);
 }

-static int hvc_sbi_dbcn_tty_get(uint32_t vtermno, char *buf, int count)
+static ssize_t hvc_sbi_dbcn_tty_get(uint32_t vtermno, u8 *buf, size_t count)
 {
return sbi_debug_console_read(buf, count);
 }
--
2.43.0




Reviewed-by: Anup Patel 

Thanks,
Anup


Re: [PATCH v5 0/5] RISC-V SBI debug console extension support

2024-01-19 Thread Anup Patel
On Sat, Jan 20, 2024 at 3:29 AM Palmer Dabbelt  wrote:
>
> On Fri, 19 Jan 2024 02:09:18 PST (-0800), apa...@ventanamicro.com wrote:
> > On Sat, Jan 13, 2024 at 12:00 AM Palmer Dabbelt  wrote:
> >>
> >> On Thu, 11 Jan 2024 06:50:37 PST (-0800), 
> >> patchwork-bot+linux-ri...@kernel.org wrote:
> >> > Hello:
> >> >
> >> > This series was applied to riscv/linux.git (for-next)
> >> > by Palmer Dabbelt :
> >> >
> >> > On Fri, 24 Nov 2023 12:39:00 +0530 you wrote:
> >> >> The SBI v2.0 specification is now frozen. The SBI v2.0 specification 
> >> >> defines
> >> >> SBI debug console (DBCN) extension which replaces the legacy SBI v0.1
> >> >> functions sbi_console_putchar() and sbi_console_getchar().
> >> >> (Refer v2.0-rc5 at 
> >> >> https://github.com/riscv-non-isa/riscv-sbi-doc/releases)
> >> >>
> >> >> This series adds support for SBI debug console (DBCN) extension in
> >> >> Linux RISC-V.
> >> >>
> >> >> [...]
> >> >
> >> > Here is the summary with links:
> >> >   - [v5,1/5] RISC-V: Add stubs for sbi_console_putchar/getchar()
> >> > https://git.kernel.org/riscv/c/f503b167b660
> >> >   - [v5,2/5] RISC-V: Add SBI debug console helper routines
> >> > https://git.kernel.org/riscv/c/f43fabf444ca
> >> >   - [v5,3/5] tty/serial: Add RISC-V SBI debug console based earlycon
> >> > https://git.kernel.org/riscv/c/c77bf3607a0f
> >> >   - [v5,4/5] tty: Add SBI debug console support to HVC SBI driver
> >> > https://git.kernel.org/riscv/c/88ead68e764c
> >> >   - [v5,5/5] RISC-V: Enable SBI based earlycon support
> >> > https://git.kernel.org/riscv/c/50942ad6ddb5
> >> >
> >> > You are awesome, thank you!
> >>
> >> Nathan points out that this has some semantic conflicts with a patch in
> >> Greg's TTY tree: 
> >> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?id=f32fcbedbe9290565e4eac3fd7c4c451d5478787
> >>
> >> So I think the best bet is to wait on Greg's patch to land in Linus'
> >> tree, and then base a v6 of this patch set on that merged patch.  I'm
> >> going to drop this one from for-next.
> >
> > Greg's patch is now available in upstream Linux so I will rebase and
> > send out v6.
>
> Sorry, I forgot about this one and merged it.  I just sent up a fixup:
> https://lore.kernel.org/all/20240119215612.20529-2-pal...@rivosinc.com/

No issues. Apart from a minor comment, your fixup looks good to me.

Thanks,
Anup

> .
>
> >
> > Thanks,
> > Anup
>


Re: [PATCH v2] tty: hvc: Fix the RISC-V SBI driver for a refactoring

2024-01-19 Thread Anup Patel
On Sat, Jan 20, 2024 at 4:15 AM Palmer Dabbelt  wrote:
>
> From: Palmer Dabbelt 
>
> I missed the int->size_t refactoring in f32fcbedbe92 ("tty: hvc: convert
> to u8 and size_t"), which causes the newly used ops in 88ead68e764c
> ("tty: Add SBI debug console support to HVC SBI driver") to fail to
> build due to a
>
> linux/drivers/tty/hvc/hvc_riscv_sbi.c:59:15: error: incompatible function 
> pointer types initializing 'ssize_t (*)(uint32_t, const u8 *, size_t)' (aka 
> 'long (*)(unsigned int, const unsigned char *, unsigned long)') with an 
> expression of type 'int (uint32_t, const char *, int)' (aka 'int (unsigned 
> int, const char *, int)') [-Wincompatible-function-pointer-types]
> .put_chars = hvc_sbi_dbcn_tty_put,
>
> Fixes: f32fcbedbe92 ("tty: hvc: convert to u8 and size_t")
> Fixes: 88ead68e764c ("tty: Add SBI debug console support to HVC SBI driver")
> Link: https://lore.kernel.org/r/20240119215612.20529-2-pal...@rivosinc.com
> Signed-off-by: Palmer Dabbelt 
> ---
> Changes since v1 <20240119215612.20529-2-pal...@rivosinc.com>:
> * Fix the return and arguments correctly.
> * Also fix the hvc_sbi_dbcn_tty_{get,put}().
> ---
>  drivers/tty/hvc/hvc_riscv_sbi.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c
> index 2f3571f17ecd..f8cd3310ef35 100644
> --- a/drivers/tty/hvc/hvc_riscv_sbi.c
> +++ b/drivers/tty/hvc/hvc_riscv_sbi.c
> @@ -15,7 +15,7 @@
>
>  #include "hvc_console.h"
>
> -static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
> +static ssize_t hvc_sbi_tty_put(uint32_t vtermno, const u8 *buf, size_t count)
>  {
> int i;
>
> @@ -25,7 +25,7 @@ static int hvc_sbi_tty_put(uint32_t vtermno, const char 
> *buf, int count)
> return i;
>  }
>
> -static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
> +static ssize_t hvc_sbi_tty_get(uint32_t vtermno, u8 *buf, size_t count)

The hvc_sbi_tty_put() and hvc_sbi_tty_get() functions are already
updated in Linus's tree. We only need to fix hvc_sbi_dbcn_tty_put()
and hvc_sbi_dbcn_tty_get()

Please rebase this fix upon Linux-6.8-rc1 whenever that is available.

>  {
> int i, c;
>
> @@ -44,12 +44,12 @@ static const struct hv_ops hvc_sbi_v01_ops = {
> .put_chars = hvc_sbi_tty_put,
>  };
>
> -static int hvc_sbi_dbcn_tty_put(uint32_t vtermno, const char *buf, int count)
> +static ssize_t hvc_sbi_dbcn_tty_put(uint32_t vtermno, const u8 *buf, size_t 
> count)
>  {
> return sbi_debug_console_write(buf, count);
>  }
>
> -static int hvc_sbi_dbcn_tty_get(uint32_t vtermno, char *buf, int count)
> +static ssize_t hvc_sbi_dbcn_tty_get(uint32_t vtermno, u8 *buf, size_t count)
>  {
> return sbi_debug_console_read(buf, count);
>  }
> --
> 2.43.0
>
>

Reviewed-by: Anup Patel 

Thanks,
Anup


Re: [PATCH 1/1] PCI/DPC: Fix TLP Prefix register reading offset

2024-01-19 Thread Bjorn Helgaas
On Thu, Jan 18, 2024 at 01:08:15PM +0200, Ilpo Järvinen wrote:
> The TLP Prefix Log Register consists of multiple DWORDs (PCIe r6.1 sec
> 7.9.14.13) but the loop in dpc_process_rp_pio_error() keeps reading
> from the first DWORD. Add the iteration count based offset calculation
> into the config read.

So IIUC the user-visible bug is that we print only the first PIO TLP
Prefix (duplicated several times), and we never print the second,
third, etc Prefixes, right?

I wish we could print them all in a single pci_err(), as we do for the
TLP Header Log, instead of dribbling them out one by one.

> Fixes: f20c4ea49ec4 ("PCI/DPC: Add eDPC support")
> Signed-off-by: Ilpo Järvinen 
> ---
>  drivers/pci/pcie/dpc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c
> index 94111e438241..e5d7c12854fa 100644
> --- a/drivers/pci/pcie/dpc.c
> +++ b/drivers/pci/pcie/dpc.c
> @@ -234,7 +234,7 @@ static void dpc_process_rp_pio_error(struct pci_dev *pdev)
>  
>   for (i = 0; i < pdev->dpc_rp_log_size - 5; i++) {
>   pci_read_config_dword(pdev,
> - cap + PCI_EXP_DPC_RP_PIO_TLPPREFIX_LOG, );
> + cap + PCI_EXP_DPC_RP_PIO_TLPPREFIX_LOG + i * 4, 
> );
>   pci_err(pdev, "TLP Prefix Header: dw%d, %#010x\n", i, prefix);
>   }
>   clear_status:
> -- 
> 2.39.2
> 


[PATCH v2] tty: hvc: Fix the RISC-V SBI driver for a refactoring

2024-01-19 Thread Palmer Dabbelt
From: Palmer Dabbelt 

I missed the int->size_t refactoring in f32fcbedbe92 ("tty: hvc: convert
to u8 and size_t"), which causes the newly used ops in 88ead68e764c
("tty: Add SBI debug console support to HVC SBI driver") to fail to
build due to a

linux/drivers/tty/hvc/hvc_riscv_sbi.c:59:15: error: incompatible function 
pointer types initializing 'ssize_t (*)(uint32_t, const u8 *, size_t)' (aka 
'long (*)(unsigned int, const unsigned char *, unsigned long)') with an 
expression of type 'int (uint32_t, const char *, int)' (aka 'int (unsigned int, 
const char *, int)') [-Wincompatible-function-pointer-types]
.put_chars = hvc_sbi_dbcn_tty_put,

Fixes: f32fcbedbe92 ("tty: hvc: convert to u8 and size_t")
Fixes: 88ead68e764c ("tty: Add SBI debug console support to HVC SBI driver")
Link: https://lore.kernel.org/r/20240119215612.20529-2-pal...@rivosinc.com
Signed-off-by: Palmer Dabbelt 
---
Changes since v1 <20240119215612.20529-2-pal...@rivosinc.com>:
* Fix the return and arguments correctly.
* Also fix the hvc_sbi_dbcn_tty_{get,put}().
---
 drivers/tty/hvc/hvc_riscv_sbi.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c
index 2f3571f17ecd..f8cd3310ef35 100644
--- a/drivers/tty/hvc/hvc_riscv_sbi.c
+++ b/drivers/tty/hvc/hvc_riscv_sbi.c
@@ -15,7 +15,7 @@
 
 #include "hvc_console.h"
 
-static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
+static ssize_t hvc_sbi_tty_put(uint32_t vtermno, const u8 *buf, size_t count)
 {
int i;
 
@@ -25,7 +25,7 @@ static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, 
int count)
return i;
 }
 
-static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
+static ssize_t hvc_sbi_tty_get(uint32_t vtermno, u8 *buf, size_t count)
 {
int i, c;
 
@@ -44,12 +44,12 @@ static const struct hv_ops hvc_sbi_v01_ops = {
.put_chars = hvc_sbi_tty_put,
 };
 
-static int hvc_sbi_dbcn_tty_put(uint32_t vtermno, const char *buf, int count)
+static ssize_t hvc_sbi_dbcn_tty_put(uint32_t vtermno, const u8 *buf, size_t 
count)
 {
return sbi_debug_console_write(buf, count);
 }
 
-static int hvc_sbi_dbcn_tty_get(uint32_t vtermno, char *buf, int count)
+static ssize_t hvc_sbi_dbcn_tty_get(uint32_t vtermno, u8 *buf, size_t count)
 {
return sbi_debug_console_read(buf, count);
 }
-- 
2.43.0



Re: [PATCH] tty: hvc: Fix the RISC-V SBI driver for a refactoring

2024-01-19 Thread Palmer Dabbelt

On Fri, 19 Jan 2024 13:56:13 PST (-0800), Palmer Dabbelt wrote:

From: Palmer Dabbelt 

I missed the int->size_t refactoring in f32fcbedbe92 ("tty: hvc: convert
to u8 and size_t"), which causes the newly used ops in 88ead68e764c
("tty: Add SBI debug console support to HVC SBI driver") to fail to
build due to a

linux/drivers/tty/hvc/hvc_riscv_sbi.c:59:15: error: incompatible function 
pointer types initializing 'ssize_t (*)(uint32_t, const u8 *, size_t)' (aka 
'long (*)(unsigned int, const unsigned char *, unsigned long)') with an 
expression of type 'int (uint32_t, const char *, int)' (aka 'int (unsigned int, 
const char *, int)') [-Wincompatible-function-pointer-types]
.put_chars = hvc_sbi_dbcn_tty_put,

Fixes: f32fcbedbe92 ("tty: hvc: convert to u8 and size_t")
Fixes: 88ead68e764c ("tty: Add SBI debug console support to HVC SBI driver")
Signed-off-by: Palmer Dabbelt 
---
I now remember Anup pointing this one out, but looks like I forgot about
it.
---
 drivers/tty/hvc/hvc_riscv_sbi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c
index 2f3571f17ecd..c08718be8e73 100644
--- a/drivers/tty/hvc/hvc_riscv_sbi.c
+++ b/drivers/tty/hvc/hvc_riscv_sbi.c
@@ -15,7 +15,7 @@

 #include "hvc_console.h"

-static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
+static size_t hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)


I got a little lost in my branches here, that should be "ssize_t".  I'll 
send a v2 when I figure out why my tester is acting oddly...



 {
int i;

@@ -25,7 +25,7 @@ static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, 
int count)
return i;
 }

-static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
+static size_t hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
 {
int i, c;


Re: [PATCH v5 0/5] RISC-V SBI debug console extension support

2024-01-19 Thread Palmer Dabbelt

On Fri, 19 Jan 2024 02:09:18 PST (-0800), apa...@ventanamicro.com wrote:

On Sat, Jan 13, 2024 at 12:00 AM Palmer Dabbelt  wrote:


On Thu, 11 Jan 2024 06:50:37 PST (-0800), patchwork-bot+linux-ri...@kernel.org 
wrote:
> Hello:
>
> This series was applied to riscv/linux.git (for-next)
> by Palmer Dabbelt :
>
> On Fri, 24 Nov 2023 12:39:00 +0530 you wrote:
>> The SBI v2.0 specification is now frozen. The SBI v2.0 specification defines
>> SBI debug console (DBCN) extension which replaces the legacy SBI v0.1
>> functions sbi_console_putchar() and sbi_console_getchar().
>> (Refer v2.0-rc5 at https://github.com/riscv-non-isa/riscv-sbi-doc/releases)
>>
>> This series adds support for SBI debug console (DBCN) extension in
>> Linux RISC-V.
>>
>> [...]
>
> Here is the summary with links:
>   - [v5,1/5] RISC-V: Add stubs for sbi_console_putchar/getchar()
> https://git.kernel.org/riscv/c/f503b167b660
>   - [v5,2/5] RISC-V: Add SBI debug console helper routines
> https://git.kernel.org/riscv/c/f43fabf444ca
>   - [v5,3/5] tty/serial: Add RISC-V SBI debug console based earlycon
> https://git.kernel.org/riscv/c/c77bf3607a0f
>   - [v5,4/5] tty: Add SBI debug console support to HVC SBI driver
> https://git.kernel.org/riscv/c/88ead68e764c
>   - [v5,5/5] RISC-V: Enable SBI based earlycon support
> https://git.kernel.org/riscv/c/50942ad6ddb5
>
> You are awesome, thank you!

Nathan points out that this has some semantic conflicts with a patch in
Greg's TTY tree: 
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?id=f32fcbedbe9290565e4eac3fd7c4c451d5478787

So I think the best bet is to wait on Greg's patch to land in Linus'
tree, and then base a v6 of this patch set on that merged patch.  I'm
going to drop this one from for-next.


Greg's patch is now available in upstream Linux so I will rebase and
send out v6.


Sorry, I forgot about this one and merged it.  I just sent up a fixup: 
https://lore.kernel.org/all/20240119215612.20529-2-pal...@rivosinc.com/ 
.




Thanks,
Anup


[PATCH] tty: hvc: Fix the RISC-V SBI driver for a refactoring

2024-01-19 Thread Palmer Dabbelt
From: Palmer Dabbelt 

I missed the int->size_t refactoring in f32fcbedbe92 ("tty: hvc: convert
to u8 and size_t"), which causes the newly used ops in 88ead68e764c
("tty: Add SBI debug console support to HVC SBI driver") to fail to
build due to a

linux/drivers/tty/hvc/hvc_riscv_sbi.c:59:15: error: incompatible function 
pointer types initializing 'ssize_t (*)(uint32_t, const u8 *, size_t)' (aka 
'long (*)(unsigned int, const unsigned char *, unsigned long)') with an 
expression of type 'int (uint32_t, const char *, int)' (aka 'int (unsigned int, 
const char *, int)') [-Wincompatible-function-pointer-types]
.put_chars = hvc_sbi_dbcn_tty_put,

Fixes: f32fcbedbe92 ("tty: hvc: convert to u8 and size_t")
Fixes: 88ead68e764c ("tty: Add SBI debug console support to HVC SBI driver")
Signed-off-by: Palmer Dabbelt 
---
I now remember Anup pointing this one out, but looks like I forgot about
it.
---
 drivers/tty/hvc/hvc_riscv_sbi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c
index 2f3571f17ecd..c08718be8e73 100644
--- a/drivers/tty/hvc/hvc_riscv_sbi.c
+++ b/drivers/tty/hvc/hvc_riscv_sbi.c
@@ -15,7 +15,7 @@
 
 #include "hvc_console.h"
 
-static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
+static size_t hvc_sbi_tty_put(uint32_t vtermno, const char *buf, int count)
 {
int i;
 
@@ -25,7 +25,7 @@ static int hvc_sbi_tty_put(uint32_t vtermno, const char *buf, 
int count)
return i;
 }
 
-static int hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
+static size_t hvc_sbi_tty_get(uint32_t vtermno, char *buf, int count)
 {
int i, c;
 
-- 
2.43.0



[PATCH 4/4] powerpc: dts: fsl: rename ifc node name to be memory-controller

2024-01-19 Thread Frank Li
From: Li Yang 

Update the node name to be align with binding document.

Signed-off-by: Li Yang 
Signed-off-by: Frank Li 
---
 arch/powerpc/boot/dts/fsl/bsc9131rdb.dts| 2 +-
 arch/powerpc/boot/dts/fsl/bsc9132qds.dts| 2 +-
 arch/powerpc/boot/dts/fsl/c293pcie.dts  | 2 +-
 arch/powerpc/boot/dts/fsl/p1010rdb_32b.dtsi | 2 +-
 arch/powerpc/boot/dts/fsl/p1010rdb_36b.dtsi | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/boot/dts/fsl/bsc9131rdb.dts 
b/arch/powerpc/boot/dts/fsl/bsc9131rdb.dts
index 8da984251abc8..0ba86a6dce1b6 100644
--- a/arch/powerpc/boot/dts/fsl/bsc9131rdb.dts
+++ b/arch/powerpc/boot/dts/fsl/bsc9131rdb.dts
@@ -15,7 +15,7 @@ memory {
device_type = "memory";
};
 
-   board_ifc: ifc: ifc@ff71e000 {
+   board_ifc: ifc: memory-controller@ff71e000 {
/* NAND Flash on board */
ranges = <0x0 0x0 0x0 0xff80 0x4000>;
reg = <0x0 0xff71e000 0x0 0x2000>;
diff --git a/arch/powerpc/boot/dts/fsl/bsc9132qds.dts 
b/arch/powerpc/boot/dts/fsl/bsc9132qds.dts
index 7cb2158dfe583..ce642e879a1b8 100644
--- a/arch/powerpc/boot/dts/fsl/bsc9132qds.dts
+++ b/arch/powerpc/boot/dts/fsl/bsc9132qds.dts
@@ -15,7 +15,7 @@ memory {
device_type = "memory";
};
 
-   ifc: ifc@ff71e000 {
+   ifc: memory-controller@ff71e000 {
/* NOR, NAND Flash on board */
ranges = <0x0 0x0 0x0 0x8800 0x0800
  0x1 0x0 0x0 0xff80 0x0001>;
diff --git a/arch/powerpc/boot/dts/fsl/c293pcie.dts 
b/arch/powerpc/boot/dts/fsl/c293pcie.dts
index 5e905e0857cf9..e2fdac2ed4205 100644
--- a/arch/powerpc/boot/dts/fsl/c293pcie.dts
+++ b/arch/powerpc/boot/dts/fsl/c293pcie.dts
@@ -42,7 +42,7 @@ memory {
device_type = "memory";
};
 
-   ifc: ifc@fffe1e000 {
+   ifc: memory-controller@fffe1e000 {
reg = <0xf 0xffe1e000 0 0x2000>;
ranges = <0x0 0x0 0xf 0xec00 0x0400
  0x1 0x0 0xf 0xff80 0x0001
diff --git a/arch/powerpc/boot/dts/fsl/p1010rdb_32b.dtsi 
b/arch/powerpc/boot/dts/fsl/p1010rdb_32b.dtsi
index fdc19aab2f706..583a6cd050793 100644
--- a/arch/powerpc/boot/dts/fsl/p1010rdb_32b.dtsi
+++ b/arch/powerpc/boot/dts/fsl/p1010rdb_32b.dtsi
@@ -36,7 +36,7 @@ memory {
device_type = "memory";
 };
 
-board_ifc: ifc: ifc@ffe1e000 {
+board_ifc: ifc: memory-controller@ffe1e000 {
/* NOR, NAND Flashes and CPLD on board */
ranges = <0x0 0x0 0x0 0xee00 0x0200
  0x1 0x0 0x0 0xff80 0x0001
diff --git a/arch/powerpc/boot/dts/fsl/p1010rdb_36b.dtsi 
b/arch/powerpc/boot/dts/fsl/p1010rdb_36b.dtsi
index de2fceed4f799..4d41efe0038f2 100644
--- a/arch/powerpc/boot/dts/fsl/p1010rdb_36b.dtsi
+++ b/arch/powerpc/boot/dts/fsl/p1010rdb_36b.dtsi
@@ -36,7 +36,7 @@ memory {
device_type = "memory";
 };
 
-board_ifc: ifc: ifc@fffe1e000 {
+board_ifc: ifc: memory-controller@fffe1e000 {
/* NOR, NAND Flashes and CPLD on board */
ranges = <0x0 0x0 0xf 0xee00 0x0200
  0x1 0x0 0xf 0xff80 0x0001
-- 
2.34.1



[PATCH 3/4] powerpc: dts: mpc85xx: remove "simple-bus" compatible from ifc node

2024-01-19 Thread Frank Li
From: Li Yang 

Update dts to match dts binding document.

Signed-off-by: Li Yang 
Signed-off-by: Frank Li 
---
 arch/powerpc/boot/dts/fsl/b4si-post.dtsi  | 2 +-
 arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi | 2 +-
 arch/powerpc/boot/dts/fsl/bsc9132si-post.dtsi | 2 +-
 arch/powerpc/boot/dts/fsl/c293si-post.dtsi| 2 +-
 arch/powerpc/boot/dts/fsl/p1010si-post.dtsi   | 2 +-
 arch/powerpc/boot/dts/fsl/t1023si-post.dtsi   | 2 +-
 arch/powerpc/boot/dts/fsl/t1040si-post.dtsi   | 2 +-
 arch/powerpc/boot/dts/fsl/t2081si-post.dtsi   | 2 +-
 arch/powerpc/boot/dts/fsl/t4240si-post.dtsi   | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/boot/dts/fsl/b4si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/b4si-post.dtsi
index 4f044b41a776b..fb3200b006ade 100644
--- a/arch/powerpc/boot/dts/fsl/b4si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/b4si-post.dtsi
@@ -50,7 +50,7 @@ _pfdr {
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <25 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi
index 2a677fd323ebe..5c53cee8755f9 100644
--- a/arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/bsc9131si-post.dtsi
@@ -35,7 +35,7 @@
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <16 2 0 0 20 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/bsc9132si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/bsc9132si-post.dtsi
index b8e0edd1ac69a..4da451e000d90 100644
--- a/arch/powerpc/boot/dts/fsl/bsc9132si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/bsc9132si-post.dtsi
@@ -35,7 +35,7 @@
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
/* FIXME: Test whether interrupts are split */
interrupts = <16 2 0 0 20 2 0 0>;
 };
diff --git a/arch/powerpc/boot/dts/fsl/c293si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/c293si-post.dtsi
index f208fb8f64b37..2d443d5192749 100644
--- a/arch/powerpc/boot/dts/fsl/c293si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/c293si-post.dtsi
@@ -35,7 +35,7 @@
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <19 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/p1010si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/p1010si-post.dtsi
index b540e58ff79e7..2d2550729dcc2 100644
--- a/arch/powerpc/boot/dts/fsl/p1010si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/p1010si-post.dtsi
@@ -35,7 +35,7 @@
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <16 2 0 0 19 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/t1023si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/t1023si-post.dtsi
index aa5152ca81201..8ef0c020206b9 100644
--- a/arch/powerpc/boot/dts/fsl/t1023si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/t1023si-post.dtsi
@@ -52,7 +52,7 @@ _pfdr {
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <25 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/t1040si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/t1040si-post.dtsi
index 7767886232040..c9542b73bd7f1 100644
--- a/arch/powerpc/boot/dts/fsl/t1040si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/t1040si-post.dtsi
@@ -52,7 +52,7 @@ _pfdr {
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <25 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/t2081si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/t2081si-post.dtsi
index 27714dc2f04a5..6bb95878d39d3 100644
--- a/arch/powerpc/boot/dts/fsl/t2081si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/t2081si-post.dtsi
@@ -50,7 +50,7 @@ _pfdr {
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <25 2 0 0>;
 };
 
diff --git a/arch/powerpc/boot/dts/fsl/t4240si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/t4240si-post.dtsi
index fcac73486d487..65f3e17c0d413 100644
--- a/arch/powerpc/boot/dts/fsl/t4240si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/t4240si-post.dtsi
@@ -50,7 +50,7 @@ _pfdr {
  {
#address-cells = <2>;
#size-cells = <1>;
-   compatible = "fsl,ifc", "simple-bus";
+   compatible = "fsl,ifc";
interrupts = <25 2 0 0>;
 };
 
-- 
2.34.1



[PATCH 2/4] powerpc: dts: p1010rdb: fix INTx interrupt issue on P1010RDB-PB

2024-01-19 Thread Frank Li
From: Xiaowei Bao 

Due to the INTA is shared with the active-low PHY2 interrupt on
P1010RDB-PA board, so configure P1010RDB-PA's INTA with polarity as
active-low, the P1010RDB-PB board is used separately, so configure
P1010RDB-PB's INTA with polarity as active-high.  The INTX in
P1010RDB-PB do not work because of the pcie@0 node fixup will be
overwrited by p1010si-post.dtsi file, so we move the pcie@0 node fixup
to p1010rdb-pb.dts and p1010rdb-pb_36b.dts.

Signed-off-by: Xiaowei Bao 
Signed-off-by: Li Yang 
Signed-off-by: Frank Li 
---
 arch/powerpc/boot/dts/fsl/p1010rdb-pb.dts | 16 
 arch/powerpc/boot/dts/fsl/p1010rdb-pb_36b.dts | 16 
 arch/powerpc/boot/dts/fsl/p1010rdb.dtsi   | 16 
 3 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/boot/dts/fsl/p1010rdb-pb.dts 
b/arch/powerpc/boot/dts/fsl/p1010rdb-pb.dts
index 3a94acbb3c033..ce3346d77858f 100644
--- a/arch/powerpc/boot/dts/fsl/p1010rdb-pb.dts
+++ b/arch/powerpc/boot/dts/fsl/p1010rdb-pb.dts
@@ -29,3 +29,19 @@  {
 };
 
 /include/ "p1010si-post.dtsi"
+
+ {
+   pcie@0 {
+   interrupt-map = <
+   /* IDSEL 0x0 */
+   /*
+*irq[4:5] are active-high
+*irq[6:7] are active-low
+*/
+    0x0 0x0 0x1  0x4 0x2 0x0 0x0
+    0x0 0x0 0x2  0x5 0x2 0x0 0x0
+    0x0 0x0 0x3  0x6 0x1 0x0 0x0
+    0x0 0x0 0x4  0x7 0x1 0x0 0x0
+   >;
+   };
+};
diff --git a/arch/powerpc/boot/dts/fsl/p1010rdb-pb_36b.dts 
b/arch/powerpc/boot/dts/fsl/p1010rdb-pb_36b.dts
index 4cf255fedc96e..83590354f9a09 100644
--- a/arch/powerpc/boot/dts/fsl/p1010rdb-pb_36b.dts
+++ b/arch/powerpc/boot/dts/fsl/p1010rdb-pb_36b.dts
@@ -56,3 +56,19 @@  {
 };
 
 /include/ "p1010si-post.dtsi"
+
+ {
+   pcie@0 {
+   interrupt-map = <
+   /* IDSEL 0x0 */
+   /*
+*irq[4:5] are active-high
+*irq[6:7] are active-low
+*/
+    0x0 0x0 0x1  0x4 0x2 0x0 0x0
+    0x0 0x0 0x2  0x5 0x2 0x0 0x0
+    0x0 0x0 0x3  0x6 0x1 0x0 0x0
+    0x0 0x0 0x4  0x7 0x1 0x0 0x0
+   >;
+   };
+};
diff --git a/arch/powerpc/boot/dts/fsl/p1010rdb.dtsi 
b/arch/powerpc/boot/dts/fsl/p1010rdb.dtsi
index 2ca9cee2ddeb2..ef49a7d6c69dd 100644
--- a/arch/powerpc/boot/dts/fsl/p1010rdb.dtsi
+++ b/arch/powerpc/boot/dts/fsl/p1010rdb.dtsi
@@ -215,19 +215,3 @@ enet2: ethernet@b2000 {
phy-connection-type = "sgmii";
};
 };
-
- {
-   pcie@0 {
-   interrupt-map = <
-   /* IDSEL 0x0 */
-   /*
-*irq[4:5] are active-high
-*irq[6:7] are active-low
-*/
-    0x0 0x0 0x1  0x4 0x2 0x0 0x0
-    0x0 0x0 0x2  0x5 0x2 0x0 0x0
-    0x0 0x0 0x3  0x6 0x1 0x0 0x0
-    0x0 0x0 0x4  0x7 0x1 0x0 0x0
-   >;
-   };
-};
-- 
2.34.1



[PATCH 1/4] powerpc: dts: add power management nodes to FSL chips

2024-01-19 Thread Frank Li
From: Ran Wang 

Enable Power Management feature on device tree, including MPC8536,
MPC8544, MPC8548, MPC8572, P1010, P1020, P1021, P1022, P2020, P2041,
P3041, T104X, T1024.

Signed-off-by: Zhao Chenhui 
Signed-off-by: Ran Wang 
Signed-off-by: Frank Li 
---
 arch/powerpc/boot/dts/fsl/mpc8536si-post.dtsi | 14 --
 arch/powerpc/boot/dts/fsl/mpc8544si-post.dtsi |  2 ++
 arch/powerpc/boot/dts/fsl/mpc8548si-post.dtsi |  2 ++
 arch/powerpc/boot/dts/fsl/mpc8572si-post.dtsi |  2 ++
 arch/powerpc/boot/dts/fsl/p1010si-post.dtsi   | 14 ++
 arch/powerpc/boot/dts/fsl/p1020si-post.dtsi   |  5 +
 arch/powerpc/boot/dts/fsl/p1021si-post.dtsi   |  5 +
 arch/powerpc/boot/dts/fsl/p1022si-post.dtsi   |  7 +--
 arch/powerpc/boot/dts/fsl/p2020si-post.dtsi   | 17 +
 arch/powerpc/boot/dts/fsl/pq3-power.dtsi  | 19 +++
 arch/powerpc/boot/dts/fsl/t1024rdb.dts|  2 +-
 arch/powerpc/boot/dts/fsl/t1040rdb.dts|  2 +-
 arch/powerpc/boot/dts/fsl/t1042rdb.dts|  2 +-
 arch/powerpc/boot/dts/fsl/t1042rdb_pi.dts |  2 +-
 14 files changed, 83 insertions(+), 12 deletions(-)
 create mode 100644 arch/powerpc/boot/dts/fsl/pq3-power.dtsi

diff --git a/arch/powerpc/boot/dts/fsl/mpc8536si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/mpc8536si-post.dtsi
index 41935709ebe87..fba40a1bccc04 100644
--- a/arch/powerpc/boot/dts/fsl/mpc8536si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/mpc8536si-post.dtsi
@@ -199,6 +199,10 @@ L2: l2-cache-controller@2 {
 
 /include/ "pq3-dma-0.dtsi"
 /include/ "pq3-etsec1-0.dtsi"
+   enet0: ethernet@24000 {
+   fsl,wake-on-filer;
+   fsl,pmc-handle = <_clk>;
+   };
 /include/ "pq3-etsec1-timer-0.dtsi"
 
usb@22000 {
@@ -222,9 +226,10 @@ ptp_clock@24e00 {
};
 
 /include/ "pq3-etsec1-2.dtsi"
-
-   ethernet@26000 {
+   enet2: ethernet@26000 {
cell-index = <1>;
+   fsl,wake-on-filer;
+   fsl,pmc-handle = <_clk>;
};
 
usb@2b000 {
@@ -249,4 +254,9 @@ global-utilities@e {
reg = <0xe 0x1000>;
fsl,has-rstcr;
};
+
+/include/ "pq3-power.dtsi"
+   power@e0070 {
+   compatible = "fsl,mpc8536-pmc", "fsl,mpc8548-pmc";
+   };
 };
diff --git a/arch/powerpc/boot/dts/fsl/mpc8544si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/mpc8544si-post.dtsi
index b68eb119faef3..ea7416af7ee3e 100644
--- a/arch/powerpc/boot/dts/fsl/mpc8544si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/mpc8544si-post.dtsi
@@ -188,4 +188,6 @@ global-utilities@e {
reg = <0xe 0x1000>;
fsl,has-rstcr;
};
+
+/include/ "pq3-power.dtsi"
 };
diff --git a/arch/powerpc/boot/dts/fsl/mpc8548si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/mpc8548si-post.dtsi
index 579d76cb8e329..dddb7374508d6 100644
--- a/arch/powerpc/boot/dts/fsl/mpc8548si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/mpc8548si-post.dtsi
@@ -156,4 +156,6 @@ global-utilities@e {
reg = <0xe 0x1000>;
fsl,has-rstcr;
};
+
+/include/ "pq3-power.dtsi"
 };
diff --git a/arch/powerpc/boot/dts/fsl/mpc8572si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/mpc8572si-post.dtsi
index 49294cf36b4e6..40a6cff770327 100644
--- a/arch/powerpc/boot/dts/fsl/mpc8572si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/mpc8572si-post.dtsi
@@ -193,4 +193,6 @@ global-utilities@e {
reg = <0xe 0x1000>;
fsl,has-rstcr;
};
+
+/include/ "pq3-power.dtsi"
 };
diff --git a/arch/powerpc/boot/dts/fsl/p1010si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/p1010si-post.dtsi
index ccda0a91abf00..b540e58ff79e7 100644
--- a/arch/powerpc/boot/dts/fsl/p1010si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/p1010si-post.dtsi
@@ -183,9 +183,23 @@ sdhc@2e000 {
 /include/ "pq3-etsec2-1.dtsi"
 /include/ "pq3-etsec2-2.dtsi"
 
+   enet0: ethernet@b {
+   fsl,pmc-handle = <_clk>;
+   };
+
+   enet1: ethernet@b1000 {
+   fsl,pmc-handle = <_clk>;
+   };
+
+   enet2: ethernet@b2000 {
+   fsl,pmc-handle = <_clk>;
+   };
+
global-utilities@e {
compatible = "fsl,p1010-guts";
reg = <0xe 0x1000>;
fsl,has-rstcr;
};
+
+/include/ "pq3-power.dtsi"
 };
diff --git a/arch/powerpc/boot/dts/fsl/p1020si-post.dtsi 
b/arch/powerpc/boot/dts/fsl/p1020si-post.dtsi
index 642dc3a83d0e3..cc4c7461003bb 100644
--- a/arch/powerpc/boot/dts/fsl/p1020si-post.dtsi
+++ b/arch/powerpc/boot/dts/fsl/p1020si-post.dtsi
@@ -163,14 +163,17 @@ sdhc@2e000 {
 
 /include/ "pq3-etsec2-0.dtsi"
enet0: enet0_grp2: ethernet@b {
+   fsl,pmc-handle = <_clk>;
};
 
 /include/ "pq3-etsec2-1.dtsi"
enet1: enet1_grp2: ethernet@b1000 {
+   fsl,pmc-handle = <_clk>;
};
 
 /include/ "pq3-etsec2-2.dtsi"
enet2: enet2_grp2: ethernet@b2000 {
+   fsl,pmc-handle = 

Re: [PATCH] NUMA: Early use of cpu_to_node() returns 0 instead of the correct node id

2024-01-19 Thread Yury Norov
On Fri, Jan 19, 2024 at 04:50:53PM +0800, Shijie Huang wrote:
> 
> 在 2024/1/19 16:42, Mike Rapoport 写道:
> > On Fri, Jan 19, 2024 at 02:46:16PM +0800, Shijie Huang wrote:
> > > 在 2024/1/19 12:42, Yury Norov 写道:
> > > > This adds another level of indirection, I think. Currently cpu_to_node
> > > > is a simple inliner. After the patch it would be a real function with
> > > > all the associate overhead. Can you share a bloat-o-meter output here?
> > > #./scripts/bloat-o-meter vmlinux vmlinux.new
> > > add/remove: 6/1 grow/shrink: 61/51 up/down: 1168/-588 (580)
> > > Function old new   delta
> > > numa_update_cpu  148 244 +96
> > > 
> > >   
> > > ...(to
> > >  many to skip)
> > > 
> > > Total: Before=32990130, After=32990710, chg +0.00%
> > It's not only about text size, the indirect call also hurts performance
> 
> The cpu_to_node() is called at very low frequency, most of the times is in
> the kernel booting time.
 
That doesn't matter. This function is a simple inliner that dereferences
a pointer, and I believe all of us want to keep it simple. 
 
> > > > Regardless, I don't think that the approach is correct. As per your
> > > > description, some initialization functions erroneously call
> > > > cpu_to_node() instead of early_cpu_to_node() which exists specifically
> > > > for that case.
> > > > 
> > > > If the above correct, it's clearly a caller problem, and the fix is to
> > > > simply switch all those callers to use early version.
> > > It is easy to change to early_cpu_to_node() for sched_init(),
> > > init_sched_fair_class()
> > > 
> > > and workqueue_init_early(). These three places call the cpu_to_node() in 
> > > the
> > > __init function.
> > > 
> > > 
> > > But it is a little hard to change the early_trace_init(), since it calls
> > > cpu_to_node in the deep
> > > 
> > > function stack:
> > > 
> > >    early_trace_init() --> ring_buffer_alloc() -->rb_allocate_cpu_buffer()
> > > 
> > > 
> > > For early_trace_init(), we need to change more code.
> > > 
> > > 
> > > Anyway, If we think it is not a good idea to change the common code, I am
> > > oaky too.
> > Is there a fundamental reason to have early_cpu_to_node() at all?
> 
> The early_cpu_to_node does not work on some ARCHs (which support the NUMA),
> such
> 
> as  SPARC, MIPS and S390.

So, your approach wouldn't work either, right? I think you've got a
testing bot report on it already...

You can make it like this:

  #ifdef CONFIG_ARCH_NO_EARLY_CPU_TO_NODE
  #define early_cpu_to_node cpu_to_node
  #endif
 
> > It seems that all the mappings are known by the end of setup_arch() and the
> > initialization of numa_node can be moved earlier.
> > > > I would also initialize the numa_node with NUMA_NO_NODE at declaration,
> > > > so that if someone calls cpu_to_node() before the variable is properly
> > > > initialized at runtime, he'll get NO_NODE, which is obviously an error.
> > > Even we set the numa_node with NUMA_NO_NODE, it does not always produce
> > > error.

You can print this error yourself:

  #ifndef cpu_to_node
  static inline int cpu_to_node(int cpu)
  {
int node = per_cpu(numa_node, cpu);

  #ifdef CONFIG_DEBUG_PER_CPU_MAPS
if (node == NUMA_NO_NODE)
pr_err(...);
  #endif

  return node;
  }
  #endif



Re: [PATCH] NUMA: Early use of cpu_to_node() returns 0 instead of the correct node id

2024-01-19 Thread kernel test robot
Hi Huang,

kernel test robot noticed the following build errors:

[auto build test ERROR on driver-core/driver-core-testing]
[also build test ERROR on driver-core/driver-core-next 
driver-core/driver-core-linus akpm-mm/mm-everything linus/master v6.7 
next-20240119]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Huang-Shijie/NUMA-Early-use-of-cpu_to_node-returns-0-instead-of-the-correct-node-id/20240119-113623
base:   driver-core/driver-core-testing
patch link:
https://lore.kernel.org/r/20240119033227.14113-1-shijie%40os.amperecomputing.com
patch subject: [PATCH] NUMA: Early use of cpu_to_node() returns 0 instead of 
the correct node id
config: x86_64-defconfig 
(https://download.01.org/0day-ci/archive/20240120/20240126.womn1ygh-...@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20240120/20240126.womn1ygh-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/20240126.womn1ygh-...@intel.com/

All errors (new ones prefixed by >>):

   ld: vmlinux.o: in function `rapl_cpu_online':
>> rapl.c:(.text+0x75ec): undefined reference to `cpu_to_node'
   ld: vmlinux.o: in function `amd_pmu_cpu_prepare':
>> core.c:(.text+0x8580): undefined reference to `cpu_to_node'
>> ld: core.c:(.text+0x85d6): undefined reference to `cpu_to_node'
   ld: vmlinux.o: in function `amd_uncore_ctx_init.part.0':
>> uncore.c:(.text+0xc3bd): undefined reference to `cpu_to_node'
   ld: vmlinux.o: in function `intel_cpuc_prepare':
>> (.text+0x129ee): undefined reference to `cpu_to_node'
   ld: vmlinux.o:(.text+0x12a71): more undefined references to `cpu_to_node' 
follow
   ld: vmlinux.o: in function `kernel_init_freeable':
>> main.c:(.init.text+0x1240): undefined reference to `_cpu_to_node'
   ld: vmlinux.o: in function `check_timer':
>> io_apic.c:(.init.text+0x1ec1d): undefined reference to `cpu_to_node'
   ld: vmlinux.o: in function `kvm_alloc_cpumask':
>> kvm.c:(.init.text+0x21678): undefined reference to `cpu_to_node'
   ld: vmlinux.o: in function `fork_idle':
>> (.init.text+0x28fe2): undefined reference to `cpu_to_node'
   ld: vmlinux.o: in function `cpus_share_numa':
>> workqueue.c:(.init.text+0x2a4c8): undefined reference to `cpu_to_node'
>> ld: workqueue.c:(.init.text+0x2a4d8): undefined reference to `cpu_to_node'
   ld: vmlinux.o:workqueue.c:(.init.text+0x2a7bc): more undefined references to 
`cpu_to_node' follow

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


[PATCH v2 14/14] loongarch, crash: wrap crash dumping code into crash related ifdefs

2024-01-19 Thread Baoquan He
Now crash codes under kernel/ folder has been split out from kexec
code, crash dumping can be separated from kexec reboot in config
items on loongarch with some adjustments.

Here wrap up crash dumping codes with CONFIG_CRASH_DUMP ifdeffery, and
use IS_ENABLED(CONFIG_CRASH_RESERVE) check to decide if compiling
in the crashkernel reservation code.

Signed-off-by: Baoquan He 
---
 arch/loongarch/kernel/setup.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
index d183a745fb85..61f88dd97947 100644
--- a/arch/loongarch/kernel/setup.c
+++ b/arch/loongarch/kernel/setup.c
@@ -258,11 +258,13 @@ static void __init arch_reserve_vmcore(void)
 
 static void __init arch_parse_crashkernel(void)
 {
-#ifdef CONFIG_KEXEC
int ret;
unsigned long long total_mem;
unsigned long long crash_base, crash_size;
 
+   if (!IS_ENABLED(CONFIG_CRASH_RESERVE))
+   return;
+
total_mem = memblock_phys_mem_size();
ret = parse_crashkernel(boot_command_line, total_mem,
_size, _base,
@@ -283,7 +285,6 @@ static void __init arch_parse_crashkernel(void)
 
crashk_res.start = crash_base;
crashk_res.end   = crash_base + crash_size - 1;
-#endif
 }
 
 static void __init fdt_setup(void)
@@ -468,7 +469,7 @@ static void __init resource_init(void)
request_resource(res, _resource);
}
 
-#ifdef CONFIG_KEXEC
+#ifdef CONFIG_CRASH_RESERVE
if (crashk_res.start < crashk_res.end) {
insert_resource(_resource, _res);
pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
-- 
2.41.0



[PATCH v2 13/14] riscv, crash: wrap crash dumping code into crash related ifdefs

2024-01-19 Thread Baoquan He
Now crash codes under kernel/ folder has been split out from kexec
code, crash dumping can be separated from kexec reboot in config
items on risc-v with some adjustments.

Here wrap up crash dumping codes with CONFIG_CRASH_DUMP ifdeffery, and
use IS_ENABLED(CONFIG_CRASH_RESERVE) check to decide if compiling
in the crashkernel reservation code.

Signed-off-by: Baoquan He 
---
 arch/riscv/kernel/elf_kexec.c | 9 +++--
 arch/riscv/mm/init.c  | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c
index 5bd1ec3341fe..54260c16f991 100644
--- a/arch/riscv/kernel/elf_kexec.c
+++ b/arch/riscv/kernel/elf_kexec.c
@@ -117,6 +117,7 @@ static int elf_find_pbase(struct kimage *image, unsigned 
long kernel_len,
return ret;
 }
 
+#ifdef CONFIG_CRASH_DUMP
 static int get_nr_ram_ranges_callback(struct resource *res, void *arg)
 {
unsigned int *nr_ranges = arg;
@@ -189,6 +190,7 @@ static char *setup_kdump_cmdline(struct kimage *image, char 
*cmdline,
cmdline_ptr[COMMAND_LINE_SIZE - 1] = '\0';
return cmdline_ptr;
 }
+#endif
 
 static void *elf_kexec_load(struct kimage *image, char *kernel_buf,
unsigned long kernel_len, char *initrd,
@@ -196,12 +198,11 @@ static void *elf_kexec_load(struct kimage *image, char 
*kernel_buf,
unsigned long cmdline_len)
 {
int ret;
+   void *fdt;
unsigned long old_kernel_pbase = ULONG_MAX;
unsigned long new_kernel_pbase = 0UL;
unsigned long initrd_pbase = 0UL;
-   unsigned long headers_sz;
unsigned long kernel_start;
-   void *fdt, *headers;
struct elfhdr ehdr;
struct kexec_buf kbuf;
struct kexec_elf_info elf_info;
@@ -227,8 +228,11 @@ static void *elf_kexec_load(struct kimage *image, char 
*kernel_buf,
kbuf.buf_min = new_kernel_pbase + kernel_len;
kbuf.buf_max = ULONG_MAX;
 
+#ifdef CONFIG_CRASH_DUMP
/* Add elfcorehdr */
if (image->type == KEXEC_TYPE_CRASH) {
+   void *headers;
+   unsigned long headers_sz;
ret = prepare_elf_headers(, _sz);
if (ret) {
pr_err("Preparing elf core header failed\n");
@@ -264,6 +268,7 @@ static void *elf_kexec_load(struct kimage *image, char 
*kernel_buf,
}
cmdline = modified_cmdline;
}
+#endif
 
 #ifdef CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY
/* Add purgatory to the image */
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index a65937336cdc..f580d1f6ee13 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -1354,7 +1354,7 @@ static void __init arch_reserve_crashkernel(void)
bool high = false;
int ret;
 
-   if (!IS_ENABLED(CONFIG_KEXEC_CORE))
+   if (!IS_ENABLED(CONFIG_CRASH_RESERVE))
return;
 
ret = parse_crashkernel(cmdline, memblock_phys_mem_size(),
-- 
2.41.0



[PATCH v2 12/14] mips, crash: wrap crash dumping code into crash related ifdefs

2024-01-19 Thread Baoquan He
Now crash codes under kernel/ folder has been split out from kexec
code, crash dumping can be separated from kexec reboot in config
items on mips with some adjustments.

Here use IS_ENABLED(CONFIG_CRASH_RESERVE) check to decide if compiling
in the crashkernel reservation code.

Signed-off-by: Baoquan He 
---
 arch/mips/kernel/setup.c | 17 ++---
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 9c30de151597..12a1a4ffb602 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -442,8 +442,6 @@ static void __init mips_reserve_vmcore(void)
 #endif
 }
 
-#ifdef CONFIG_KEXEC
-
 /* 64M alignment for crash kernel regions */
 #define CRASH_ALIGNSZ_64M
 #define CRASH_ADDR_MAX SZ_512M
@@ -454,6 +452,9 @@ static void __init mips_parse_crashkernel(void)
unsigned long long crash_size, crash_base;
int ret;
 
+   if (!IS_ENABLED(CONFIG_CRASH_RESERVE))
+   return;
+
total_mem = memblock_phys_mem_size();
ret = parse_crashkernel(boot_command_line, total_mem,
_size, _base,
@@ -489,6 +490,9 @@ static void __init request_crashkernel(struct resource *res)
 {
int ret;
 
+   if (!IS_ENABLED(CONFIG_CRASH_RESERVE))
+   return;
+
if (crashk_res.start == crashk_res.end)
return;
 
@@ -498,15 +502,6 @@ static void __init request_crashkernel(struct resource 
*res)
(unsigned long)(resource_size(_res) >> 20),
(unsigned long)(crashk_res.start  >> 20));
 }
-#else /* !defined(CONFIG_KEXEC)*/
-static void __init mips_parse_crashkernel(void)
-{
-}
-
-static void __init request_crashkernel(struct resource *res)
-{
-}
-#endif /* !defined(CONFIG_KEXEC)  */
 
 static void __init check_kernel_sections_mem(void)
 {
-- 
2.41.0



[PATCH v2 11/14] arm, crash: wrap crash dumping code into crash related ifdefs

2024-01-19 Thread Baoquan He
Now crash codes under kernel/ folder has been split out from kexec
code, crash dumping can be separated from kexec reboot in config
items on arm with some adjustments.

Here use IS_ENABLED(CONFIG_CRASH_RESERVE) check to decide if compiling
in the crashkernel reservation code.

Signed-off-by: Baoquan He 
---
 arch/arm/kernel/setup.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index ff2299ce1ad7..cf0b3798179f 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -979,7 +979,6 @@ static int __init init_machine_late(void)
 }
 late_initcall(init_machine_late);
 
-#ifdef CONFIG_KEXEC
 /*
  * The crash region must be aligned to 128MB to avoid
  * zImage relocating below the reserved region.
@@ -1007,6 +1006,9 @@ static void __init reserve_crashkernel(void)
unsigned long long total_mem;
int ret;
 
+   if (!IS_ENABLED(CONFIG_CRASH_RESERVE))
+   return;
+
total_mem = get_total_mem();
ret = parse_crashkernel(boot_command_line, total_mem,
_size, _base,
@@ -1064,9 +1066,6 @@ static void __init reserve_crashkernel(void)
insert_resource(_resource, _boot_res);
}
 }
-#else
-static inline void reserve_crashkernel(void) {}
-#endif /* CONFIG_KEXEC */
 
 void __init hyp_mode_check(void)
 {
-- 
2.41.0



[PATCH v2 10/14] sh, crash: wrap crash dumping code into crash related ifdefs

2024-01-19 Thread Baoquan He
Now crash codes under kernel/ folder has been split out from kexec
code, crash dumping can be separated from kexec reboot in config
items on SuperH with some adjustments.

Here wrap up crashkernel reservation code inside CONFIG_CRASH_RESERVE
ifdeffery scope.

Signed-off-by: Baoquan He 
---
 arch/sh/kernel/machine_kexec.c | 3 +++
 arch/sh/kernel/setup.c | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/sh/kernel/machine_kexec.c b/arch/sh/kernel/machine_kexec.c
index fa3a7b36190a..8daa8a6e6fa6 100644
--- a/arch/sh/kernel/machine_kexec.c
+++ b/arch/sh/kernel/machine_kexec.c
@@ -153,6 +153,9 @@ void __init reserve_crashkernel(void)
unsigned long long crash_size, crash_base;
int ret;
 
+   if (!IS_ENABLED(CONFIG_CRASH_RESERVE))
+   return;
+
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
_size, _base, NULL, NULL);
if (ret == 0 && crash_size > 0) {
diff --git a/arch/sh/kernel/setup.c b/arch/sh/kernel/setup.c
index d3175f09b3aa..620e5cf8ae1e 100644
--- a/arch/sh/kernel/setup.c
+++ b/arch/sh/kernel/setup.c
@@ -220,7 +220,7 @@ void __init __add_active_range(unsigned int nid, unsigned 
long start_pfn,
request_resource(res, _resource);
request_resource(res, _resource);
request_resource(res, _resource);
-#ifdef CONFIG_KEXEC_CORE
+#ifdef CONFIG_CRASH_RESERVE
request_resource(res, _res);
 #endif
 
-- 
2.41.0



[PATCH v2 08/14] ppc, crash: enforce KEXEC and KEXEC_FILE to select CRASH_DUMP

2024-01-19 Thread Baoquan He
In PowerPC, the crash dumping and kexec reboot share code in
arch_kexec_locate_mem_hole(), in which struct crash_mem is used.

Here enfoce enforce KEXEC and KEXEC_FILE to select CRASH_DUMP for now.

Signed-off-by: Baoquan He 
---
 arch/powerpc/Kconfig | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 1cdb8fdd3735..fc3cd7f4bb73 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -608,6 +608,10 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
 config ARCH_SUPPORTS_KEXEC
def_bool PPC_BOOK3S || PPC_E500 || (44x && !SMP)
 
+config ARCH_SELECTS_KEXEC
+   def_bool y
+   select CRASH_DUMP
+
 config ARCH_SUPPORTS_KEXEC_FILE
def_bool PPC64
 
@@ -618,6 +622,7 @@ config ARCH_SELECTS_KEXEC_FILE
def_bool y
depends on KEXEC_FILE
select KEXEC_ELF
+   select CRASH_DUMP
select HAVE_IMA_KEXEC if IMA
 
 config PPC64_BIG_ENDIAN_ELF_ABI_V2
-- 
2.41.0



[PATCH v2 09/14] s390, crash: wrap crash dumping code into crash related ifdefs

2024-01-19 Thread Baoquan He
Now crash codes under kernel/ folder has been split out from kexec
code, crash dumping can be separated from kexec reboot in config
items on s390 with some adjustments.

Here wrap up crash dumping codes with CONFIG_CRASH_DUMP ifdeffery.

Signed-off-by: Baoquan He 
---
 arch/s390/kernel/kexec_elf.c  |  2 ++
 arch/s390/kernel/kexec_image.c|  2 ++
 arch/s390/kernel/machine_kexec_file.c | 10 ++
 3 files changed, 14 insertions(+)

diff --git a/arch/s390/kernel/kexec_elf.c b/arch/s390/kernel/kexec_elf.c
index 9da6fa30c447..4d364de43799 100644
--- a/arch/s390/kernel/kexec_elf.c
+++ b/arch/s390/kernel/kexec_elf.c
@@ -40,8 +40,10 @@ static int kexec_file_add_kernel_elf(struct kimage *image,
buf.bufsz = phdr->p_filesz;
 
buf.mem = ALIGN(phdr->p_paddr, phdr->p_align);
+#ifdef CONFIG_CRASH_DUMP
if (image->type == KEXEC_TYPE_CRASH)
buf.mem += crashk_res.start;
+#endif
buf.memsz = phdr->p_memsz;
data->memsz = ALIGN(data->memsz, phdr->p_align) + buf.memsz;
 
diff --git a/arch/s390/kernel/kexec_image.c b/arch/s390/kernel/kexec_image.c
index af23eff5774d..a32ce8bea745 100644
--- a/arch/s390/kernel/kexec_image.c
+++ b/arch/s390/kernel/kexec_image.c
@@ -24,8 +24,10 @@ static int kexec_file_add_kernel_image(struct kimage *image,
buf.bufsz = image->kernel_buf_len;
 
buf.mem = 0;
+#ifdef CONFIG_CRASH_DUMP
if (image->type == KEXEC_TYPE_CRASH)
buf.mem += crashk_res.start;
+#endif
buf.memsz = buf.bufsz;
 
data->kernel_buf = image->kernel_buf;
diff --git a/arch/s390/kernel/machine_kexec_file.c 
b/arch/s390/kernel/machine_kexec_file.c
index 8d207b82d9fe..c2bac14dd668 100644
--- a/arch/s390/kernel/machine_kexec_file.c
+++ b/arch/s390/kernel/machine_kexec_file.c
@@ -105,6 +105,7 @@ static int kexec_file_update_purgatory(struct kimage *image,
if (ret)
return ret;
 
+#ifdef CONFIG_CRASH_DUMP
if (image->type == KEXEC_TYPE_CRASH) {
u64 crash_size;
 
@@ -121,6 +122,7 @@ static int kexec_file_update_purgatory(struct kimage *image,
 sizeof(crash_size),
 false);
}
+#endif
return ret;
 }
 
@@ -134,8 +136,10 @@ static int kexec_file_add_purgatory(struct kimage *image,
 
data->memsz = ALIGN(data->memsz, PAGE_SIZE);
buf.mem = data->memsz;
+#ifdef CONFIG_CRASH_DUMP
if (image->type == KEXEC_TYPE_CRASH)
buf.mem += crashk_res.start;
+#endif
 
ret = kexec_load_purgatory(image, );
if (ret)
@@ -158,8 +162,10 @@ static int kexec_file_add_initrd(struct kimage *image,
 
data->memsz = ALIGN(data->memsz, PAGE_SIZE);
buf.mem = data->memsz;
+#ifdef CONFIG_CRASH_DUMP
if (image->type == KEXEC_TYPE_CRASH)
buf.mem += crashk_res.start;
+#endif
buf.memsz = buf.bufsz;
 
data->parm->initrd_start = data->memsz;
@@ -223,8 +229,10 @@ static int kexec_file_add_ipl_report(struct kimage *image,
data->kernel_buf + offsetof(struct lowcore, ipl_parmblock_ptr);
*lc_ipl_parmblock_ptr = (__u32)buf.mem;
 
+#ifdef CONFIG_CRASH_DUMP
if (image->type == KEXEC_TYPE_CRASH)
buf.mem += crashk_res.start;
+#endif
 
ret = kexec_add_buffer();
 out:
@@ -268,10 +276,12 @@ void *kexec_file_add_components(struct kimage *image,
memcpy(data.parm->command_line, image->cmdline_buf,
   image->cmdline_buf_len);
 
+#ifdef CONFIG_CRASH_DUMP
if (image->type == KEXEC_TYPE_CRASH) {
data.parm->oldmem_base = crashk_res.start;
data.parm->oldmem_size = crashk_res.end - crashk_res.start + 1;
}
+#endif
 
if (image->initrd_buf) {
ret = kexec_file_add_initrd(image, );
-- 
2.41.0



[PATCH v2 07/14] arm64, crash: wrap crash dumping code into crash related ifdefs

2024-01-19 Thread Baoquan He
Now crash codes under kernel/ folder has been split out from kexec
code, crash dumping can be separated from kexec reboot in config
items on arm64 with some adjustments.

Here wrap up crash dumping codes with CONFIG_CRASH_DUMP ifdeffery.

Signed-off-by: Baoquan He 
---
 arch/arm64/include/asm/kexec.h |  2 +-
 arch/arm64/kernel/machine_kexec.c  |  2 +-
 arch/arm64/kernel/machine_kexec_file.c | 10 --
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
index 9ac9572a3bbe..4d9cc7a76d9c 100644
--- a/arch/arm64/include/asm/kexec.h
+++ b/arch/arm64/include/asm/kexec.h
@@ -80,7 +80,7 @@ static inline void crash_setup_regs(struct pt_regs *newregs,
}
 }
 
-#if defined(CONFIG_KEXEC_CORE) && defined(CONFIG_HIBERNATION)
+#if defined(CONFIG_CRASH_DUMP) && defined(CONFIG_HIBERNATION)
 extern bool crash_is_nosave(unsigned long pfn);
 extern void crash_prepare_suspend(void);
 extern void crash_post_resume(void);
diff --git a/arch/arm64/kernel/machine_kexec.c 
b/arch/arm64/kernel/machine_kexec.c
index b38aae5b488d..82e2203d86a3 100644
--- a/arch/arm64/kernel/machine_kexec.c
+++ b/arch/arm64/kernel/machine_kexec.c
@@ -255,7 +255,7 @@ void machine_crash_shutdown(struct pt_regs *regs)
pr_info("Starting crashdump kernel...\n");
 }
 
-#ifdef CONFIG_HIBERNATION
+#if defined(CONFIG_CRASH_DUMP) && defined(CONFIG_HIBERNATION)
 /*
  * To preserve the crash dump kernel image, the relevant memory segments
  * should be mapped again around the hibernation.
diff --git a/arch/arm64/kernel/machine_kexec_file.c 
b/arch/arm64/kernel/machine_kexec_file.c
index 0e017358f4ba..af1ca875c52c 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -39,6 +39,7 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
return kexec_image_post_load_cleanup_default(image);
 }
 
+#ifdef CONFIG_CRASH_DUMP
 static int prepare_elf_headers(void **addr, unsigned long *sz)
 {
struct crash_mem *cmem;
@@ -80,6 +81,7 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
kfree(cmem);
return ret;
 }
+#endif
 
 /*
  * Tries to add the initrd and DTB to the image. If it is not possible to find
@@ -93,8 +95,8 @@ int load_other_segments(struct kimage *image,
char *cmdline)
 {
struct kexec_buf kbuf;
-   void *headers, *dtb = NULL;
-   unsigned long headers_sz, initrd_load_addr = 0, dtb_len,
+   void *dtb = NULL;
+   unsigned long initrd_load_addr = 0, dtb_len,
  orig_segments = image->nr_segments;
int ret = 0;
 
@@ -102,7 +104,10 @@ int load_other_segments(struct kimage *image,
/* not allocate anything below the kernel */
kbuf.buf_min = kernel_load_addr + kernel_size;
 
+#ifdef CONFIG_CRASH_DUMP
/* load elf core header */
+   void *headers;
+   unsigned long headers_sz;
if (image->type == KEXEC_TYPE_CRASH) {
ret = prepare_elf_headers(, _sz);
if (ret) {
@@ -130,6 +135,7 @@ int load_other_segments(struct kimage *image,
kexec_dprintk("Loaded elf core header at 0x%lx bufsz=0x%lx 
memsz=0x%lx\n",
  image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
}
+#endif
 
/* load initrd */
if (initrd) {
-- 
2.41.0



[PATCH v2 06/14] x86, crash: wrap crash dumping code into crash related ifdefs

2024-01-19 Thread Baoquan He
Now crash codes under kernel/ folder has been split out from kexec
code, crash dumping can be separated from kexec reboot in config
items on x86 with some adjustments.

Here, also change some ifdefs or IS_ENABLED() check to more appropriate
ones, e,g
 - #ifdef CONFIG_KEXEC_CORE -> #ifdef CONFIG_CRASH_DUMP
 - (!IS_ENABLED(CONFIG_KEXEC_CORE)) - > (!IS_ENABLED(CONFIG_CRASH_RESERVE))

Signed-off-by: Baoquan He 
---
 arch/x86/kernel/Makefile   | 4 ++--
 arch/x86/kernel/cpu/mshyperv.c | 4 
 arch/x86/kernel/kexec-bzimage64.c  | 4 
 arch/x86/kernel/kvm.c  | 4 ++--
 arch/x86/kernel/machine_kexec_64.c | 3 +++
 arch/x86/kernel/reboot.c   | 2 +-
 arch/x86/kernel/setup.c| 2 +-
 arch/x86/kernel/smp.c  | 2 +-
 arch/x86/xen/enlighten_hvm.c   | 4 
 9 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 913d4022131e..3668b1edef2d 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -100,9 +100,9 @@ obj-$(CONFIG_TRACING)   += trace.o
 obj-$(CONFIG_RETHOOK)  += rethook.o
 obj-$(CONFIG_VMCORE_INFO)  += vmcore_info_$(BITS).o
 obj-$(CONFIG_KEXEC_CORE)   += machine_kexec_$(BITS).o
-obj-$(CONFIG_KEXEC_CORE)   += relocate_kernel_$(BITS).o crash.o
+obj-$(CONFIG_KEXEC_CORE)   += relocate_kernel_$(BITS).o
 obj-$(CONFIG_KEXEC_FILE)   += kexec-bzimage64.o
-obj-$(CONFIG_CRASH_DUMP)   += crash_dump_$(BITS).o
+obj-$(CONFIG_CRASH_DUMP)   += crash_dump_$(BITS).o crash.o
 obj-y  += kprobes/
 obj-$(CONFIG_MODULES)  += module.o
 obj-$(CONFIG_X86_32)   += doublefault_32.o
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 01fa06dd06b6..f8163a59026b 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -210,6 +210,7 @@ static void hv_machine_shutdown(void)
hyperv_cleanup();
 }
 
+#ifdef CONFIG_CRASH_DUMP
 static void hv_machine_crash_shutdown(struct pt_regs *regs)
 {
if (hv_crash_handler)
@@ -221,6 +222,7 @@ static void hv_machine_crash_shutdown(struct pt_regs *regs)
/* Disable the hypercall page when there is only 1 active CPU. */
hyperv_cleanup();
 }
+#endif
 #endif /* CONFIG_KEXEC_CORE */
 #endif /* CONFIG_HYPERV */
 
@@ -497,7 +499,9 @@ static void __init ms_hyperv_init_platform(void)
 
 #if IS_ENABLED(CONFIG_HYPERV) && defined(CONFIG_KEXEC_CORE)
machine_ops.shutdown = hv_machine_shutdown;
+#ifdef CONFIG_CRASH_DUMP
machine_ops.crash_shutdown = hv_machine_crash_shutdown;
+#endif
 #endif
if (ms_hyperv.features & HV_ACCESS_TSC_INVARIANT) {
/*
diff --git a/arch/x86/kernel/kexec-bzimage64.c 
b/arch/x86/kernel/kexec-bzimage64.c
index 2a422e00ed4b..b55737b83a84 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -263,11 +263,13 @@ setup_boot_parameters(struct kimage *image, struct 
boot_params *params,
memset(>hd0_info, 0, sizeof(params->hd0_info));
memset(>hd1_info, 0, sizeof(params->hd1_info));
 
+#ifdef CONFIG_CRASH_DUMP
if (image->type == KEXEC_TYPE_CRASH) {
ret = crash_setup_memmap_entries(image, params);
if (ret)
return ret;
} else
+#endif
setup_e820_entries(params);
 
nr_e820_entries = params->e820_entries;
@@ -433,12 +435,14 @@ static void *bzImage64_load(struct kimage *image, char 
*kernel,
return ERR_PTR(-EINVAL);
}
 
+#ifdef CONFIG_CRASH_DUMP
/* Allocate and load backup region */
if (image->type == KEXEC_TYPE_CRASH) {
ret = crash_load_segments(image);
if (ret)
return ERR_PTR(ret);
}
+#endif
 
/*
 * Load purgatory. For 64bit entry point, purgatory  code can be
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index dfe9945b9bec..acfc2d3183bc 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -769,7 +769,7 @@ static struct notifier_block kvm_pv_reboot_nb = {
  * won't be valid. In cases like kexec, in which you install a new kernel, this
  * means a random memory location will be kept being written.
  */
-#ifdef CONFIG_KEXEC_CORE
+#ifdef CONFIG_CRASH_DUMP
 static void kvm_crash_shutdown(struct pt_regs *regs)
 {
kvm_guest_cpu_offline(true);
@@ -852,7 +852,7 @@ static void __init kvm_guest_init(void)
kvm_guest_cpu_init();
 #endif
 
-#ifdef CONFIG_KEXEC_CORE
+#ifdef CONFIG_CRASH_DUMP
machine_ops.crash_shutdown = kvm_crash_shutdown;
 #endif
 
diff --git a/arch/x86/kernel/machine_kexec_64.c 
b/arch/x86/kernel/machine_kexec_64.c
index bc0a5348b4a6..b180d8e497c3 100644
--- a/arch/x86/kernel/machine_kexec_64.c
+++ b/arch/x86/kernel/machine_kexec_64.c
@@ -508,6 +508,8 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
 }
 #endif /* 

[PATCH v2 05/14] crash: clean up kdump related config items

2024-01-19 Thread Baoquan He
By splitting CRASH_RESERVE and VMCORE_INFO out from CRASH_CORE, cleaning
up the dependency of FA_DMUMP on CRASH_DUMP, and moving crash codes from
kexec_core.c to crash_core.c, now we can rearrange CRASH_DUMP to
depend on KEXEC_CORE, and make CRASH_DUMP select CRASH_RESERVE and
VMCORE_INFO.

KEXEC_CORE won't select CRASH_RESERVE and VMCORE_INFO any more because
KEXEC_CORE enables codes which allocate control pages, copy
kexec/kdump segments, and prepare for switching. These codes are shared
by both kexec reboot and crash dumping.

Doing this makes codes and the corresponding config items more
logical (the right item depends on or is selected by the left item).

PROC_KCORE ---> VMCORE_INFO

   |--> VMCORE_INFO
FA_DUMP|
   |--> CRASH_RESERVE

>VMCORE_INFO
   /
   |>CRASH_RESERVE
KEXEC  --|/|
 |--> KEXEC_CORE--> CRASH_DUMP-->/-|>PROC_VMCORE
KEXEC_FILE --|   \ |
   \>CRASH_HOTPLUG

KEXEC  --|
 |--> KEXEC_CORE--> kexec reboot
KEXEC_FILE --|

Signed-off-by: Baoquan He 
---
 kernel/Kconfig.kexec | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec
index 8faf27043432..6c34e63c88ff 100644
--- a/kernel/Kconfig.kexec
+++ b/kernel/Kconfig.kexec
@@ -9,8 +9,6 @@ config VMCORE_INFO
bool
 
 config KEXEC_CORE
-   select VMCORE_INFO
-   select CRASH_RESERVE
bool
 
 config KEXEC_ELF
@@ -99,8 +97,11 @@ config KEXEC_JUMP
 
 config CRASH_DUMP
bool "kernel crash dumps"
+   default y
depends on ARCH_SUPPORTS_CRASH_DUMP
-   select KEXEC_CORE
+   depends on KEXEC_CORE
+   select VMCORE_INFO
+   select CRASH_RESERVE
help
  Generate crash dump after being started by kexec.
  This should be normally only set in special crash dump kernels
-- 
2.41.0



[PATCH v2 04/14] crash: split crash dumping code out from kexec_core.c

2024-01-19 Thread Baoquan He
Currently, KEXEC_CORE select CRASH_CORE automatically because crash codes
need be built in to avoid compiling error when building kexec code even
though the crash dumping functionality is not enabled. E.g

CONFIG_CRASH_CORE=y
CONFIG_KEXEC_CORE=y
CONFIG_KEXEC=y
CONFIG_KEXEC_FILE=y
-

After splitting out crashkernel reservation code and vmcoreinfo exporting
code, there's only crash related code left in kernel/crash_core.c. Now
move crash related codes from kexec_core.c to crash_core.c and only build it
in when CONFIG_CRASH_DUMP=y.

And also wrap up crash codes inside CONFIG_CRASH_DUMP ifdeffery scope,
or replace inappropriate CONFIG_KEXEC_CORE ifdef with CONFIG_CRASH_DUMP
ifdef in generic kernel files.

With these changes, crash_core codes are abstracted from kexec codes and
can be disabled at all if only kexec reboot feature is wanted.

Signed-off-by: Baoquan He 
---
 drivers/base/cpu.c |   6 +-
 include/linux/crash_core.h |  61 +
 include/linux/kexec.h  |  45 +--
 init/initramfs.c   |   2 +-
 kernel/Makefile|   3 +-
 kernel/crash_core.c| 256 +
 kernel/kexec.c |  11 +-
 kernel/kexec_core.c| 250 ++--
 kernel/kexec_file.c|  13 +-
 kernel/ksysfs.c|   4 +
 10 files changed, 359 insertions(+), 292 deletions(-)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 47de0f140ba6..b621a0fc75e1 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -144,7 +144,7 @@ static DEVICE_ATTR(release, S_IWUSR, NULL, 
cpu_release_store);
 #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
 #endif /* CONFIG_HOTPLUG_CPU */
 
-#ifdef CONFIG_KEXEC_CORE
+#ifdef CONFIG_CRASH_DUMP
 #include 
 
 static ssize_t crash_notes_show(struct device *dev,
@@ -189,14 +189,14 @@ static const struct attribute_group 
crash_note_cpu_attr_group = {
 #endif
 
 static const struct attribute_group *common_cpu_attr_groups[] = {
-#ifdef CONFIG_KEXEC_CORE
+#ifdef CONFIG_CRASH_DUMP
_note_cpu_attr_group,
 #endif
NULL
 };
 
 static const struct attribute_group *hotplugable_cpu_attr_groups[] = {
-#ifdef CONFIG_KEXEC_CORE
+#ifdef CONFIG_CRASH_DUMP
_note_cpu_attr_group,
 #endif
NULL
diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
index 7f19f62018ef..23270b16e1db 100644
--- a/include/linux/crash_core.h
+++ b/include/linux/crash_core.h
@@ -6,6 +6,48 @@
 #include 
 #include 
 
+struct kimage;
+
+#ifdef CONFIG_CRASH_DUMP
+
+int crash_shrink_memory(unsigned long new_size);
+ssize_t crash_get_memory_size(void);
+
+#ifndef arch_kexec_protect_crashkres
+/*
+ * Protection mechanism for crashkernel reserved memory after
+ * the kdump kernel is loaded.
+ *
+ * Provide an empty default implementation here -- architecture
+ * code may override this
+ */
+static inline void arch_kexec_protect_crashkres(void) { }
+#endif
+
+#ifndef arch_kexec_unprotect_crashkres
+static inline void arch_kexec_unprotect_crashkres(void) { }
+#endif
+
+
+
+#ifndef arch_crash_handle_hotplug_event
+static inline void arch_crash_handle_hotplug_event(struct kimage *image) { }
+#endif
+
+int crash_check_update_elfcorehdr(void);
+
+#ifndef crash_hotplug_cpu_support
+static inline int crash_hotplug_cpu_support(void) { return 0; }
+#endif
+
+#ifndef crash_hotplug_memory_support
+static inline int crash_hotplug_memory_support(void) { return 0; }
+#endif
+
+#ifndef crash_get_elfcorehdr_size
+static inline unsigned int crash_get_elfcorehdr_size(void) { return 0; }
+#endif
+
 /* Alignment required for elf header segment */
 #define ELF_CORE_HEADER_ALIGN   4096
 
@@ -31,4 +73,23 @@ struct kexec_segment;
 #define KEXEC_CRASH_HP_REMOVE_MEMORY   4
 #define KEXEC_CRASH_HP_INVALID_CPU -1U
 
+extern void __crash_kexec(struct pt_regs *regs);
+extern void crash_kexec(struct pt_regs *regs);
+int kexec_should_crash(struct task_struct *p);
+int kexec_crash_loaded(void);
+void crash_save_cpu(struct pt_regs *regs, int cpu);
+extern int kimage_crash_copy_vmcoreinfo(struct kimage *image);
+
+#else /* !CONFIG_CRASH_DUMP*/
+struct pt_regs;
+struct task_struct;
+struct kimage;
+static inline void __crash_kexec(struct pt_regs *regs) { }
+static inline void crash_kexec(struct pt_regs *regs) { }
+static inline int kexec_should_crash(struct task_struct *p) { return 0; }
+static inline int kexec_crash_loaded(void) { return 0; }
+static inline void crash_save_cpu(struct pt_regs *regs, int cpu) {};
+static inline int kimage_crash_copy_vmcoreinfo(struct kimage *image) { return 
0; };
+#endif /* CONFIG_CRASH_DUMP*/
+
 #endif /* LINUX_CRASH_CORE_H */
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index 9c7bb8b56ed6..060835bb82d5 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -15,7 +15,6 @@
 
 #if !defined(__ASSEMBLY__)
 
-#include 
 #include 
 #include 
 #include 
@@ -33,6 +32,7 @@ extern note_buf_t __percpu *crash_notes;
 #include 
 

[PATCH v2 03/14] crash: remove dependency of FA_DUMP on CRASH_DUMP

2024-01-19 Thread Baoquan He
In kdump kernel, /proc/vmcore is an elf file mapping the crashed kernel's
old memory content. Its elf header is constructed in 1st kernel and passed
to kdump kernel via elfcorehdr_addr. Config CRASH_DUMP enables the code
of 1st kernel's old memory accessing in different architectures.

Currently, config FA_DUMP has dependency on CRASH_DUMP because fadump
needs access global variable 'elfcorehdr_addr' to judge if it's in
kdump kernel within function is_kdump_kernel(). In the current
kernel/crash_dump.c, variable 'elfcorehdr_addr' is defined, and function
setup_elfcorehdr() used to parse kernel parameter to fetch the passed
value of elfcorehdr_addr. Only for accessing elfcorehdr_addr, FA_DUMP
really doesn't have to depends on CRASH_DUMP.

To remove the dependency of FA_DUMP on CRASH_DUMP to avoid confusion,
rename kernel/crash_dump.c to kernel/elfcorehdr.c, and build it when
CONFIG_VMCORE_INFO is ebabled. With this, FA_DUMP doesn't need to depend
on CRASH_DUMP.

Signed-off-by: Baoquan He 
---
 arch/powerpc/Kconfig  | 1 -
 kernel/Makefile   | 3 +--
 kernel/{crash_dump.c => elfcorehdr.c} | 0
 kernel/kexec_internal.h   | 2 ++
 4 files changed, 3 insertions(+), 3 deletions(-)
 rename kernel/{crash_dump.c => elfcorehdr.c} (100%)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 1520146d7c2c..1cdb8fdd3735 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -692,7 +692,6 @@ config FA_DUMP
depends on PPC64 && (PPC_RTAS || PPC_POWERNV)
select VMCORE_INFO
select CRASH_RESERVE
-   select CRASH_DUMP
help
  A robust mechanism to get reliable kernel crash dump with
  assistance from firmware. This approach does not use kexec,
diff --git a/kernel/Makefile b/kernel/Makefile
index 649272a1d6b9..35abc65e1f1a 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -68,7 +68,7 @@ obj-$(CONFIG_MODULE_SIG_FORMAT) += module_signature.o
 obj-$(CONFIG_KALLSYMS) += kallsyms.o
 obj-$(CONFIG_KALLSYMS_SELFTEST) += kallsyms_selftest.o
 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
-obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o
+obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o elfcorehdr.o
 obj-$(CONFIG_CRASH_RESERVE) += crash_reserve.o
 obj-$(CONFIG_KEXEC_CORE) += kexec_core.o crash_core.o
 obj-$(CONFIG_KEXEC) += kexec.o
@@ -121,7 +121,6 @@ obj-$(CONFIG_PERF_EVENTS) += events/
 
 obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o
 obj-$(CONFIG_PADATA) += padata.o
-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
 obj-$(CONFIG_JUMP_LABEL) += jump_label.o
 obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o
 obj-$(CONFIG_TORTURE_TEST) += torture.o
diff --git a/kernel/crash_dump.c b/kernel/elfcorehdr.c
similarity index 100%
rename from kernel/crash_dump.c
rename to kernel/elfcorehdr.c
diff --git a/kernel/kexec_internal.h b/kernel/kexec_internal.h
index 74da1409cd14..2595defe8c0d 100644
--- a/kernel/kexec_internal.h
+++ b/kernel/kexec_internal.h
@@ -4,6 +4,8 @@
 
 #include 
 
+struct kexec_segment;
+
 struct kimage *do_kimage_alloc_init(void);
 int sanity_check_segment_list(struct kimage *image);
 void kimage_free_page_list(struct list_head *list);
-- 
2.41.0



[PATCH v2 02/14] crash: split vmcoreinfo exporting code out from crash_core.c

2024-01-19 Thread Baoquan He
Now move the relevant codes into separate files:
kernel/crash_reserve.c, include/linux/crash_reserve.h.

And add config item CRASH_RESERVE to control its enabling.

And also update the old ifdeffery of CONFIG_CRASH_CORE, including of
 and config item dependency on CRASH_CORE
accordingly.

And also do renaming as follows:
 - arch/xxx/kernel/{crash_core.c => vmcore_info.c}
because they are only related to vmcoreinfo exporting on x86, arm64,
riscv.

And also Remove config item CRASH_CORE, and rely on CONFIG_KEXEC_CORE to
decide if build in crash_core.c.

Signed-off-by: Baoquan He 
---
 arch/arm64/kernel/Makefile|   2 +-
 .../kernel/{crash_core.c => vmcore_info.c}|   2 +-
 arch/powerpc/Kconfig  |   2 +-
 arch/powerpc/kernel/setup-common.c|   2 +-
 arch/powerpc/platforms/powernv/opal-core.c|   2 +-
 arch/riscv/kernel/Makefile|   2 +-
 .../kernel/{crash_core.c => vmcore_info.c}|   2 +-
 arch/x86/kernel/Makefile  |   2 +-
 .../{crash_core_32.c => vmcore_info_32.c} |   2 +-
 .../{crash_core_64.c => vmcore_info_64.c} |   2 +-
 drivers/firmware/qemu_fw_cfg.c|  14 +-
 fs/proc/Kconfig   |   2 +-
 fs/proc/kcore.c   |   2 +-
 include/linux/buildid.h   |   2 +-
 include/linux/crash_core.h|  73 --
 include/linux/kexec.h |   1 +
 include/linux/vmcore_info.h   |  81 ++
 kernel/Kconfig.kexec  |   4 +-
 kernel/Makefile   |   4 +-
 kernel/crash_core.c   | 208 
 kernel/ksysfs.c   |   6 +-
 kernel/printk/printk.c|   4 +-
 kernel/vmcore_info.c  | 233 ++
 lib/buildid.c |   2 +-
 24 files changed, 345 insertions(+), 311 deletions(-)
 rename arch/arm64/kernel/{crash_core.c => vmcore_info.c} (97%)
 rename arch/riscv/kernel/{crash_core.c => vmcore_info.c} (96%)
 rename arch/x86/kernel/{crash_core_32.c => vmcore_info_32.c} (90%)
 rename arch/x86/kernel/{crash_core_64.c => vmcore_info_64.c} (94%)
 create mode 100644 include/linux/vmcore_info.h
 create mode 100644 kernel/vmcore_info.c

diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index d95b3d6b471a..bcf89587a549 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -66,7 +66,7 @@ obj-$(CONFIG_KEXEC_FILE)  += machine_kexec_file.o 
kexec_image.o
 obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o
 arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o
 obj-$(CONFIG_CRASH_DUMP)   += crash_dump.o
-obj-$(CONFIG_CRASH_CORE)   += crash_core.o
+obj-$(CONFIG_VMCORE_INFO)  += vmcore_info.o
 obj-$(CONFIG_ARM_SDE_INTERFACE)+= sdei.o
 obj-$(CONFIG_ARM64_PTR_AUTH)   += pointer_auth.o
 obj-$(CONFIG_ARM64_MTE)+= mte.o
diff --git a/arch/arm64/kernel/crash_core.c b/arch/arm64/kernel/vmcore_info.c
similarity index 97%
rename from arch/arm64/kernel/crash_core.c
rename to arch/arm64/kernel/vmcore_info.c
index 66cde752cd74..a5abf7186922 100644
--- a/arch/arm64/kernel/crash_core.c
+++ b/arch/arm64/kernel/vmcore_info.c
@@ -4,7 +4,7 @@
  * Copyright (C) Huawei Futurewei Technologies.
  */
 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 6aeab95f0edd..1520146d7c2c 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -690,7 +690,7 @@ config ARCH_SELECTS_CRASH_DUMP
 config FA_DUMP
bool "Firmware-assisted dump"
depends on PPC64 && (PPC_RTAS || PPC_POWERNV)
-   select CRASH_CORE
+   select VMCORE_INFO
select CRASH_RESERVE
select CRASH_DUMP
help
diff --git a/arch/powerpc/kernel/setup-common.c 
b/arch/powerpc/kernel/setup-common.c
index 9b142b9d5187..733f210ffda1 100644
--- a/arch/powerpc/kernel/setup-common.c
+++ b/arch/powerpc/kernel/setup-common.c
@@ -109,7 +109,7 @@ int ppc_do_canonicalize_irqs;
 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
 #endif
 
-#ifdef CONFIG_CRASH_CORE
+#ifdef CONFIG_VMCORE_INFO
 /* This keeps a track of which one is the crashing cpu. */
 int crashing_cpu = -1;
 #endif
diff --git a/arch/powerpc/platforms/powernv/opal-core.c 
b/arch/powerpc/platforms/powernv/opal-core.c
index bb7657115f1d..c9a9b759cc92 100644
--- a/arch/powerpc/platforms/powernv/opal-core.c
+++ b/arch/powerpc/platforms/powernv/opal-core.c
@@ -16,7 +16,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 #include 
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index c92c623b311e..63a36539ea1a 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -91,7 +91,7 @@ obj-$(CONFIG_KGDB)+= kgdb.o
 

[PATCH v2 01/14] kexec: split crashkernel reservation code out from crash_core.c

2024-01-19 Thread Baoquan He
Both kdump and fa_dump of ppc rely on crashkernel reservation. Move the
relevant codes into separate files:
crash_reserve.c, include/linux/crash_reserve.h.

And also add config item CRASH_RESERVE to control its enabling of the
codes. And update config items which has relationship with crashkernel
reservation.

And also change ifdeffery from CONFIG_CRASH_CORE to CONFIG_CRASH_RESERVE
when those scopes are only crashkernel reservation related.

And also rename arch/XXX/include/asm/{crash_core.h => crash_reserve.h}
on arm64, x86 and risc-v because those architectures' crash_core.h
is only related to crashkernel reservation.

Signed-off-by: Baoquan He 
---
 arch/arm64/Kconfig|   2 +-
 .../asm/{crash_core.h => crash_reserve.h} |   4 +-
 arch/powerpc/Kconfig  |   1 +
 arch/powerpc/mm/nohash/kaslr_booke.c  |   4 +-
 arch/riscv/Kconfig|   2 +-
 .../asm/{crash_core.h => crash_reserve.h} |   4 +-
 arch/x86/Kconfig  |   2 +-
 .../asm/{crash_core.h => crash_reserve.h} |   6 +-
 include/linux/crash_core.h|  40 --
 include/linux/crash_reserve.h |  48 ++
 include/linux/kexec.h |   1 +
 kernel/Kconfig.kexec  |   5 +-
 kernel/Makefile   |   1 +
 kernel/crash_core.c   | 438 -
 kernel/crash_reserve.c| 464 ++
 15 files changed, 531 insertions(+), 491 deletions(-)
 rename arch/arm64/include/asm/{crash_core.h => crash_reserve.h} (81%)
 rename arch/riscv/include/asm/{crash_core.h => crash_reserve.h} (78%)
 rename arch/x86/include/asm/{crash_core.h => crash_reserve.h} (92%)
 create mode 100644 include/linux/crash_reserve.h
 create mode 100644 kernel/crash_reserve.c

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index ea01a2c43efa..d96bc3c67ec6 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -1501,7 +1501,7 @@ config ARCH_SUPPORTS_CRASH_DUMP
def_bool y
 
 config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION
-   def_bool CRASH_CORE
+   def_bool CRASH_RESERVE
 
 config TRANS_TABLE
def_bool y
diff --git a/arch/arm64/include/asm/crash_core.h 
b/arch/arm64/include/asm/crash_reserve.h
similarity index 81%
rename from arch/arm64/include/asm/crash_core.h
rename to arch/arm64/include/asm/crash_reserve.h
index 9f5c8d339f44..4afe027a4e7b 100644
--- a/arch/arm64/include/asm/crash_core.h
+++ b/arch/arm64/include/asm/crash_reserve.h
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
-#ifndef _ARM64_CRASH_CORE_H
-#define _ARM64_CRASH_CORE_H
+#ifndef _ARM64_CRASH_RESERVE_H
+#define _ARM64_CRASH_RESERVE_H
 
 /* Current arm64 boot protocol requires 2MB alignment */
 #define CRASH_ALIGN SZ_2M
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 414b978b8010..6aeab95f0edd 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -691,6 +691,7 @@ config FA_DUMP
bool "Firmware-assisted dump"
depends on PPC64 && (PPC_RTAS || PPC_POWERNV)
select CRASH_CORE
+   select CRASH_RESERVE
select CRASH_DUMP
help
  A robust mechanism to get reliable kernel crash dump with
diff --git a/arch/powerpc/mm/nohash/kaslr_booke.c 
b/arch/powerpc/mm/nohash/kaslr_booke.c
index b4f2786a7d2b..cdff129abb14 100644
--- a/arch/powerpc/mm/nohash/kaslr_booke.c
+++ b/arch/powerpc/mm/nohash/kaslr_booke.c
@@ -13,7 +13,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -173,7 +173,7 @@ static __init bool overlaps_region(const void *fdt, u32 
start,
 
 static void __init get_crash_kernel(void *fdt, unsigned long size)
 {
-#ifdef CONFIG_CRASH_CORE
+#ifdef CONFIG_CRASH_RESERVE
unsigned long long crash_size, crash_base;
int ret;
 
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index b549499eb363..37a438c23deb 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -712,7 +712,7 @@ config ARCH_SUPPORTS_CRASH_DUMP
def_bool y
 
 config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION
-   def_bool CRASH_CORE
+   def_bool CRASH_RESERVE
 
 config COMPAT
bool "Kernel support for 32-bit U-mode"
diff --git a/arch/riscv/include/asm/crash_core.h 
b/arch/riscv/include/asm/crash_reserve.h
similarity index 78%
rename from arch/riscv/include/asm/crash_core.h
rename to arch/riscv/include/asm/crash_reserve.h
index e1874b23feaf..013962e63587 100644
--- a/arch/riscv/include/asm/crash_core.h
+++ b/arch/riscv/include/asm/crash_reserve.h
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
-#ifndef _RISCV_CRASH_CORE_H
-#define _RISCV_CRASH_CORE_H
+#ifndef _RISCV_CRASH_RESERVE_H
+#define _RISCV_CRASH_RESERVE_H
 
 #define CRASH_ALIGNPMD_SIZE
 
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 5edec175b9bf..71417c5b228c 100644
--- a/arch/x86/Kconfig

[PATCH v2 00/14] Split crash out from kexec and clean up related config items

2024-01-19 Thread Baoquan He
Motivation:
=
Previously, LKP reported a building error. When investigating, it can't
be resolved reasonablly with the present messy kdump config items.

 https://lore.kernel.org/oe-kbuild-all/202312182200.ka7mzifq-...@intel.com/

The kdump (crash dumping) related config items could causes confusions:

Firstly,
---
CRASH_CORE enables codes including
 - crashkernel reservation;
 - elfcorehdr updating;
 - vmcoreinfo exporting;
 - crash hotplug handling;

Now fadump of powerpc, kcore dynamic debugging and kdump all selects
CRASH_CORE, while fadump
 - fadump needs crashkernel parsing, vmcoreinfo exporting, and accessing
   global variable 'elfcorehdr_addr';
 - kcore only needs vmcoreinfo exporting;
 - kdump needs all of the current kernel/crash_core.c.

So only enabling PROC_CORE or FA_DUMP will enable CRASH_CORE, this
mislead people that we enable crash dumping, actual it's not.

Secondly,
---
It's not reasonable to allow KEXEC_CORE select CRASH_CORE.

Because KEXEC_CORE enables codes which allocate control pages, copy
kexec/kdump segments, and prepare for switching. These codes are
shared by both kexec reboot and kdump. We could want kexec reboot,
but disable kdump. In that case, CRASH_CORE should not be selected.

 
 CONFIG_CRASH_CORE=y
 CONFIG_KEXEC_CORE=y
 CONFIG_KEXEC=y
 CONFIG_KEXEC_FILE=y
-

Thirdly,
---
It's not reasonable to allow CRASH_DUMP select KEXEC_CORE.

That could make KEXEC_CORE, CRASH_DUMP are enabled independently from
KEXEC or KEXEC_FILE. However, w/o KEXEC or KEXEC_FILE, the KEXEC_CORE
code built in doesn't make any sense because no kernel loading or
switching will happen to utilize the KEXEC_CORE code.
 -
 CONFIG_CRASH_CORE=y 
 CONFIG_KEXEC_CORE=y 
 CONFIG_CRASH_DUMP=y
 -

In this case, what is worse, on arch sh and arm, KEXEC relies on MMU,
while CRASH_DUMP can still be enabled when !MMU, then compiling error is
seen as the lkp test robot reported in above link.

 --arch/sh/Kconfig--
 config ARCH_SUPPORTS_KEXEC
 def_bool MMU

 config ARCH_SUPPORTS_CRASH_DUMP
 def_bool BROKEN_ON_SMP
 ---

Changes:
===
1, split out crash_reserve.c from crash_core.c;
2, split out vmcore_infoc. from crash_core.c;
3, move crash related codes in kexec_core.c into crash_core.c;
4, remove dependency of FA_DUMP on CRASH_DUMP;
5, clean up kdump related config items;
6, wrap up crash codes in crash related ifdefs on all 9 arch-es
   which support crash dumping;

Achievement:
===
With above changes, I can rearrange the config item logic as below (the right
item depends on or is selected by the left item):

PROC_KCORE ---> VMCORE_INFO

   |--> VMCORE_INFO
FA_DUMP|
   |--> CRASH_RESERVE

>VMCORE_INFO
   /
   |>CRASH_RESERVE
KEXEC  --|/|
 |--> KEXEC_CORE--> CRASH_DUMP-->/-|>PROC_VMCORE
KEXEC_FILE --|   \ |
   \>CRASH_HOTPLUG


KEXEC  --|
 |--> KEXEC_CORE (for kexec reboot only)
KEXEC_FILE --|

Test

On all 8 architectures, including x86_64, arm64, s390x, sh, arm, mips,
riscv, loongarch, I did below three cases of config item setting and
building all passed. Let me take configs on x86_64 as exampmle here:

(1) Both CONFIG_KEXEC and KEXEC_FILE is unset, then all kexec/kdump
items are unset automatically:
# Kexec and crash features
# CONFIG_KEXEC is not set
# CONFIG_KEXEC_FILE is not set
# end of Kexec and crash features

(2) set CONFIG_KEXEC_FILE and 'make olddefconfig':
---
# Kexec and crash features
CONFIG_CRASH_RESERVE=y
CONFIG_VMCORE_INFO=y
CONFIG_KEXEC_CORE=y
CONFIG_KEXEC_FILE=y
CONFIG_CRASH_DUMP=y
CONFIG_CRASH_HOTPLUG=y
CONFIG_CRASH_MAX_MEMORY_RANGES=8192
# end of Kexec and crash features
---

(3) unset CONFIG_CRASH_DUMP in case 2 and execute 'make olddefconfig':

# Kexec and crash features
CONFIG_KEXEC_CORE=y
CONFIG_KEXEC_FILE=y
# end of Kexec and crash features


Note:
For ppc, it needs investigation to make clear how to split out crash
code in arch folder. Hope Hari and Pingfan can help have a look, see if
it's doable. Now, I make it either have both kexec and crash enabled, or
disable both of them altogether.

Baoquan He (14):
  kexec: split crashkernel reservation code out from crash_core.c
  crash: split vmcoreinfo exporting code out from crash_core.c
  crash: remove dependency of FA_DUMP on CRASH_DUMP
  crash: split crash dumping code out from kexec_core.c
  crash: clean up kdump related config items
  x86, crash: wrap crash dumping code into crash related ifdefs
  arm64, crash: wrap crash 

Re: [PATCH] powerpc/6xx: set High BAT Enable flag on G2 cores

2024-01-19 Thread Christophe Leroy


Le 19/01/2024 à 14:41, Matthias Schiffer a écrit :
>>
>> Thinking about it once more, can we do even more simple ?
>>
>> Why do we need that __setup_cpu_g2() at all ?
>>
>> You could just add the following into __set_cpu_603()
>>
>> diff --git a/arch/powerpc/kernel/cpu_setup_6xx.S
>> b/arch/powerpc/kernel/cpu_setup_6xx.S
>> index c67d32e04df9..7b41e3884866 100644
>> --- a/arch/powerpc/kernel/cpu_setup_6xx.S
>> +++ b/arch/powerpc/kernel/cpu_setup_6xx.S
>> @@ -21,6 +21,11 @@ BEGIN_MMU_FTR_SECTION
>>li  r10,0
>>mtspr   SPRN_SPRG_603_LRU,r10   /* init SW LRU tracking */
>>END_MMU_FTR_SECTION_IFSET(MMU_FTR_NEED_DTLB_SW_LRU)
>> +BEGIN_MMU_FTR_SECTION
>> + mfspr   r11,SPRN_HID2_G2
>> + orisr11,r11,HID2_HBE_G2@h
>> + mtspr   SPRN_HID2_G2,r11
>> +END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
>>
>>BEGIN_FTR_SECTION
>>bl  __init_fpu_registers
>> ---
>>
>> By the way, as your register is named SPRN_HID2_G2, the bit would better
>> be named HID2_G2_HBE instead of HID2_HBE_G2 I think.
> 
> My intention was to keep this consistent with the SPRN_HID2_GEKKO define.

I don't understand what you mean. I can't see any bits defined for 
HID2_GEKKO.

What I see which is simitar is the definition of TSC register for CELL CPU.

#define SPRN_TSC_CELL   0x399   /* Thread switch control on Cell */
#define   TSC_CELL_DEC_ENABLE_0 0x40 /* Decrementer Interrupt */
#define   TSC_CELL_DEC_ENABLE_1 0x20 /* Decrementer Interrupt */
#define   TSC_CELL_EE_ENABLE0x10 /* External Interrupt */
#define   TSC_CELL_EE_BOOST 0x08 /* External Interrupt Boost */


They don't call it TSC_EE_BOOST_CELL or TSC_EE_ENABLE_CELL


Christophe

> 
> Regards,
> Matthias
> 
> 
> 
> 
>>
>> Christophe
>>
>>>

> +
> +BEGIN_FTR_SECTION
> +   bl  __init_fpu_registers
> +END_FTR_SECTION_IFCLR(CPU_FTR_FPU_UNAVAILABLE)
> +   bl  setup_common_caches
> +   bl  setup_g2_hid2
> +   mtlrr5
> +   blr
>
> /* Enable caches for 603's, 604, 750 & 7400 */
> SYM_FUNC_START_LOCAL(setup_common_caches)
> @@ -115,6 +129,16 @@ SYM_FUNC_START_LOCAL(setup_604_hid0)
>blr
> SYM_FUNC_END(setup_604_hid0)
>
> +/* Enable high BATs for G2 (G2_LE, e300cX) */
> +SYM_FUNC_START_LOCAL(setup_g2_hid2)
> +   mfspr   r11,SPRN_HID2_G2
> +   orisr11,r11,HID2_HBE_G2@h
> +   mtspr   SPRN_HID2_G2,r11
> +   sync
> +   isync
> +   blr
> +SYM_FUNC_END(setup_g2_hid2)
> +
> /* 7400 <= rev 2.7 and 7410 rev = 1.0 suffer from some
>  * erratas we work around here.
>  * Moto MPC710CE.pdf describes them, those are errata
> @@ -495,4 +519,3 @@ _GLOBAL(__restore_cpu_setup)
>mtcrr7
>blr
> _ASM_NOKPROBE_SYMBOL(__restore_cpu_setup)
> -
> diff --git a/arch/powerpc/kernel/cpu_specs_book3s_32.h 
> b/arch/powerpc/kernel/cpu_specs_book3s_32.h
> index 3714634d194a1..83f054fcf837c 100644
> --- a/arch/powerpc/kernel/cpu_specs_book3s_32.h
> +++ b/arch/powerpc/kernel/cpu_specs_book3s_32.h
> @@ -69,7 +69,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
>.mmu_features   = MMU_FTR_USE_HIGH_BATS,
>.icache_bsize   = 32,
>.dcache_bsize   = 32,
> -   .cpu_setup  = __setup_cpu_603,
> +   .cpu_setup  = __setup_cpu_g2,
>.machine_check  = machine_check_generic,
>.platform   = "ppc603",
>},
> @@ -83,7 +83,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
>.mmu_features   = MMU_FTR_USE_HIGH_BATS,
>.icache_bsize   = 32,
>.dcache_bsize   = 32,
> -   .cpu_setup  = __setup_cpu_603,
> +   .cpu_setup  = __setup_cpu_g2,
>.machine_check  = machine_check_83xx,
>.platform   = "ppc603",
>},
> @@ -96,7 +96,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
>.mmu_features   = MMU_FTR_USE_HIGH_BATS | 
> MMU_FTR_NEED_DTLB_SW_LRU,
>.icache_bsize   = 32,
>.dcache_bsize   = 32,
> -   .cpu_setup  = __setup_cpu_603,
> +   .cpu_setup  = __setup_cpu_g2,
>.machine_check  = machine_check_83xx,
>.platform   = "ppc603",
>},
> @@ -109,7 +109,7 @@ static struct cpu_spec cpu_specs[] __initdata = {
>.mmu_features   = MMU_FTR_USE_HIGH_BATS 

Re: [PATCH] powerpc/6xx: set High BAT Enable flag on G2 cores

2024-01-19 Thread Matthias Schiffer
On Fri, 2023-12-22 at 18:41 +, Christophe Leroy wrote:
> Le 22/12/2023 à 09:48, Matthias Schiffer a écrit :
> > [Vous ne recevez pas souvent de courriers de 
> > matthias.schif...@ew.tq-group.com. Découvrez pourquoi ceci est important à 
> > https://aka.ms/LearnAboutSenderIdentification ]
> > 
> > On Thu, 2023-12-21 at 13:57 +, Christophe Leroy wrote:
> > > 
> > > 
> > > Le 21/12/2023 à 13:45, Matthias Schiffer a écrit :
> > > > MMU_FTR_USE_HIGH_BATS is set for G2-based cores (G2_LE, e300cX), but the
> > > > high BATs need to be enabled in HID2 to work. Add register definitions
> > > > and introduce a G2 variant of __setup_cpu_603.
> > > 
> > > Well spotted.
> > > 
> > > I have a mpc8321, hence e300c2. I never had the problem you had.
> > > 
> > > But ... looks like U-boot configuration has CONFIG_HID2_HBE so that's
> > > set by U-boot indeed, that's the reason why I never had that problem.
> > 
> > I'll extend the commit message to mention that U-Boot setting in v2.
> > 
> > 
> > > 
> > > > 
> > > > This fixes boot on CPUs like the MPC5200B with STRICT_KERNEL_RWX 
> > > > enabled.
> > > > 
> > > > Fixes: e4d6654ebe6e ("powerpc/mm/32s: rework mmu_mapin_ram()")
> > > > Signed-off-by: Matthias Schiffer 
> > > > ---
> > > >arch/powerpc/include/asm/cpu_setup.h  |  1 +
> > > >arch/powerpc/include/asm/reg.h|  2 ++
> > > >arch/powerpc/kernel/cpu_setup_6xx.S   | 25 
> > > > ++-
> > > >arch/powerpc/kernel/cpu_specs_book3s_32.h | 10 -
> > > >4 files changed, 32 insertions(+), 6 deletions(-)
> > > > 
> > > > 
> > > > I have only tested this on the MPC5200B (G2_LE), but according to the
> > > > e300 manual, e300cX cores should behave the same.
> > > > 
> > > > The Fixes tag is the best I could come up with - I believe that the
> > > > underlying issue of setting USE_HIGH_BATS without actually enabling them
> > > > is as old as Linux's PowerPC implementation, but the specific code
> > > > causing the boot failure was added in the mentioned commit.
> > > 
> > > Agreed, before that only BATs 0 to 3 were used anyway.
> > > There was also BAT 4 used by platforms/embedded6xx/wii.c  , but that's
> > > probably not a G2 ?
> > > 
> > > > 
> > > > Another issue I found in the code is that
> > > > arch/powerpc/platforms/52xx/lite5200_sleep.S uses the SPRN_HID2 
> > > > definition
> > > > which does not refer to HID2 on the 5200... but that will be for someone
> > > > else to fix, if there is still anyone left using that platform.
> > > 
> > > Maybe file an issue for it at https://github.com/linuxppc/issues/issues
> > > if you don't plan to fix it ?
> > > 
> > > By the way, it looks like the SPRN_HID2 definition we have is very
> > > specific to the IBM 750.
> > > 
> > 
> > IBM 750GX even - googling for IBM 750 came up with several other cores that 
> > either don't have HID2,
> > or have it at a different SPR.
> > 
> > 
> > > MPC 750 has SPRN_HID2 as 1011 == 0x3f3 like others.
> > 
> > > > 
> > > > 
> > > > diff --git a/arch/powerpc/include/asm/cpu_setup.h 
> > > > b/arch/powerpc/include/asm/cpu_setup.h
> > > > index 30e2fe3895024..68d804e74d221 100644
> > > > --- a/arch/powerpc/include/asm/cpu_setup.h
> > > > +++ b/arch/powerpc/include/asm/cpu_setup.h
> > > > @@ -35,6 +35,7 @@ void __setup_cpu_750fx(unsigned long offset, struct 
> > > > cpu_spec *spec);
> > > >void __setup_cpu_7400(unsigned long offset, struct cpu_spec *spec);
> > > >void __setup_cpu_7410(unsigned long offset, struct cpu_spec *spec);
> > > >void __setup_cpu_745x(unsigned long offset, struct cpu_spec *spec);
> > > > +void __setup_cpu_g2(unsigned long offset, struct cpu_spec *spec);
> > > > 
> > > >void __setup_cpu_ppc970(unsigned long offset, struct cpu_spec *spec);
> > > >void __setup_cpu_ppc970MP(unsigned long offset, struct cpu_spec 
> > > > *spec);
> > > > diff --git a/arch/powerpc/include/asm/reg.h 
> > > > b/arch/powerpc/include/asm/reg.h
> > > > index 4ae4ab9090a2d..f5641fcd1da85 100644
> > > > --- a/arch/powerpc/include/asm/reg.h
> > > > +++ b/arch/powerpc/include/asm/reg.h
> > > > @@ -617,6 +617,8 @@
> > > >#endif
> > > >#define SPRN_HID2  0x3F8   /* Hardware Implementation 
> > > > Register 2 */
> > > 
> > > Should that HID2 be renamed to SPRN_HID2_750 to avoid confusion ?
> > 
> > Makes sense (should the suffix be "750GX"?). I can also add a FIXME comment 
> > to lite5200_sleep.S as
> > part of the rename.
> > 
> > 
> > > 
> > > >#define SPRN_HID2_GEKKO0x398   /* Gekko HID2 
> > > > Register */
> > > > +#define SPRN_HID2_G2   0x3F3   /* G2 HID2 Register */
> > > > +#define  HID2_HBE_G2   (1<<18) /* High BAT Enable (G2) */
> > > >#define SPRN_IABR  0x3F2   /* Instruction Address Breakpoint 
> > > > Register */
> > > >#define SPRN_IABR2 0x3FA   /* 83xx */
> > > >#define SPRN_IBCR  0x135   /* 83xx Insn Breakpoint 
> > > > Control Reg */
> > > > diff --git 

[PATCH] powerpc/kasan: Fix addr error caused by page alignment

2024-01-19 Thread Jiangfeng Xiao
In kasan_init_region, when k_start is not page aligned,
at the begin of for loop, k_cur = k_start & PAGE_MASK
is less than k_start, and then va = block + k_cur - k_start
is less than block, the addr va is invalid, because the
memory address space from va to block is not alloced by
memblock_alloc, which will not be reserved
by memblock_reserve later, it will be used by other places.

As a result, memory overwriting occurs.

for example:
int __init __weak kasan_init_region(void *start, size_t size)
{
[...]
/* if say block(dcd97000) k_start(feef7400) k_end(feeff3fe) */
block = memblock_alloc(k_end - k_start, PAGE_SIZE);
[...]
for (k_cur = k_start & PAGE_MASK; k_cur < k_end; k_cur += PAGE_SIZE) {
/* at the begin of for loop
 * block(dcd97000) va(dcd96c00) k_cur(feef7000) 
k_start(feef7400)
 * va(dcd96c00) is less than block(dcd97000), va is invalid
 */
void *va = block + k_cur - k_start;
[...]
}
[...]
}

Therefore, page alignment is performed on k_start before
memblock_alloc to ensure the validity of the VA address.

Fixes: 663c0c9496a6 ("powerpc/kasan: Fix shadow area set up for modules.")

Signed-off-by: Jiangfeng Xiao 
---
 arch/powerpc/mm/kasan/init_32.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/mm/kasan/init_32.c b/arch/powerpc/mm/kasan/init_32.c
index a70828a..aa9aa11 100644
--- a/arch/powerpc/mm/kasan/init_32.c
+++ b/arch/powerpc/mm/kasan/init_32.c
@@ -64,6 +64,7 @@ int __init __weak kasan_init_region(void *start, size_t size)
if (ret)
return ret;
 
+   k_start = k_start & PAGE_MASK;
block = memblock_alloc(k_end - k_start, PAGE_SIZE);
if (!block)
return -ENOMEM;
-- 
1.8.5.6



[PATCH v6 5/5] RISC-V: Enable SBI based earlycon support

2024-01-19 Thread Anup Patel
Let us enable SBI based earlycon support in defconfig for both RV32
and RV64 so that "earlycon=sbi" can be used again.

Signed-off-by: Anup Patel 
Reviewed-by: Andrew Jones 
---
 arch/riscv/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig
index 905881282a7c..eaf34e871e30 100644
--- a/arch/riscv/configs/defconfig
+++ b/arch/riscv/configs/defconfig
@@ -149,6 +149,7 @@ CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_SERIAL_8250_DW=y
 CONFIG_SERIAL_OF_PLATFORM=y
 CONFIG_SERIAL_SH_SCI=y
+CONFIG_SERIAL_EARLYCON_RISCV_SBI=y
 CONFIG_VIRTIO_CONSOLE=y
 CONFIG_HW_RANDOM=y
 CONFIG_HW_RANDOM_VIRTIO=y
-- 
2.34.1



[PATCH v6 4/5] tty: Add SBI debug console support to HVC SBI driver

2024-01-19 Thread Anup Patel
From: Atish Patra 

RISC-V SBI specification supports advanced debug console
support via SBI DBCN extension.

Extend the HVC SBI driver to support it.

Signed-off-by: Atish Patra 
Signed-off-by: Anup Patel 
Reviewed-by: Andrew Jones 
Acked-by: Greg Kroah-Hartman 
---
 drivers/tty/hvc/Kconfig |  2 +-
 drivers/tty/hvc/hvc_riscv_sbi.c | 37 ++---
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/hvc/Kconfig b/drivers/tty/hvc/Kconfig
index 4f9264d005c0..6e05c5c7bca1 100644
--- a/drivers/tty/hvc/Kconfig
+++ b/drivers/tty/hvc/Kconfig
@@ -108,7 +108,7 @@ config HVC_DCC_SERIALIZE_SMP
 
 config HVC_RISCV_SBI
bool "RISC-V SBI console support"
-   depends on RISCV_SBI_V01
+   depends on RISCV_SBI
select HVC_DRIVER
help
  This enables support for console output via RISC-V SBI calls, which
diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c
index a72591279f86..cede8a572594 100644
--- a/drivers/tty/hvc/hvc_riscv_sbi.c
+++ b/drivers/tty/hvc/hvc_riscv_sbi.c
@@ -40,21 +40,44 @@ static ssize_t hvc_sbi_tty_get(uint32_t vtermno, u8 *buf, 
size_t count)
return i;
 }
 
-static const struct hv_ops hvc_sbi_ops = {
+static const struct hv_ops hvc_sbi_v01_ops = {
.get_chars = hvc_sbi_tty_get,
.put_chars = hvc_sbi_tty_put,
 };
 
-static int __init hvc_sbi_init(void)
+static ssize_t hvc_sbi_dbcn_tty_put(uint32_t vtermno, const u8 *buf, size_t 
count)
 {
-   return PTR_ERR_OR_ZERO(hvc_alloc(0, 0, _sbi_ops, 16));
+   return sbi_debug_console_write(buf, count);
 }
-device_initcall(hvc_sbi_init);
 
-static int __init hvc_sbi_console_init(void)
+static ssize_t hvc_sbi_dbcn_tty_get(uint32_t vtermno, u8 *buf, size_t count)
 {
-   hvc_instantiate(0, 0, _sbi_ops);
+   return sbi_debug_console_read(buf, count);
+}
+
+static const struct hv_ops hvc_sbi_dbcn_ops = {
+   .put_chars = hvc_sbi_dbcn_tty_put,
+   .get_chars = hvc_sbi_dbcn_tty_get,
+};
+
+static int __init hvc_sbi_init(void)
+{
+   int err;
+
+   if (sbi_debug_console_available) {
+   err = PTR_ERR_OR_ZERO(hvc_alloc(0, 0, _sbi_dbcn_ops, 256));
+   if (err)
+   return err;
+   hvc_instantiate(0, 0, _sbi_dbcn_ops);
+   } else if (IS_ENABLED(CONFIG_RISCV_SBI_V01)) {
+   err = PTR_ERR_OR_ZERO(hvc_alloc(0, 0, _sbi_v01_ops, 256));
+   if (err)
+   return err;
+   hvc_instantiate(0, 0, _sbi_v01_ops);
+   } else {
+   return -ENODEV;
+   }
 
return 0;
 }
-console_initcall(hvc_sbi_console_init);
+device_initcall(hvc_sbi_init);
-- 
2.34.1



[PATCH v6 3/5] tty/serial: Add RISC-V SBI debug console based earlycon

2024-01-19 Thread Anup Patel
We extend the existing RISC-V SBI earlycon support to use the new
RISC-V SBI debug console extension.

Signed-off-by: Anup Patel 
Reviewed-by: Andrew Jones 
Acked-by: Greg Kroah-Hartman 
---
 drivers/tty/serial/Kconfig  |  2 +-
 drivers/tty/serial/earlycon-riscv-sbi.c | 27 ++---
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 8b1f5756002f..ffcf4882b25f 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -87,7 +87,7 @@ config SERIAL_EARLYCON_SEMIHOST
 
 config SERIAL_EARLYCON_RISCV_SBI
bool "Early console using RISC-V SBI"
-   depends on RISCV_SBI_V01
+   depends on RISCV_SBI
select SERIAL_CORE
select SERIAL_CORE_CONSOLE
select SERIAL_EARLYCON
diff --git a/drivers/tty/serial/earlycon-riscv-sbi.c 
b/drivers/tty/serial/earlycon-riscv-sbi.c
index 27afb0b74ea7..0162155f0c83 100644
--- a/drivers/tty/serial/earlycon-riscv-sbi.c
+++ b/drivers/tty/serial/earlycon-riscv-sbi.c
@@ -15,17 +15,38 @@ static void sbi_putc(struct uart_port *port, unsigned char 
c)
sbi_console_putchar(c);
 }
 
-static void sbi_console_write(struct console *con,
- const char *s, unsigned n)
+static void sbi_0_1_console_write(struct console *con,
+ const char *s, unsigned int n)
 {
struct earlycon_device *dev = con->data;
uart_console_write(>port, s, n, sbi_putc);
 }
 
+static void sbi_dbcn_console_write(struct console *con,
+  const char *s, unsigned int n)
+{
+   int ret;
+
+   while (n) {
+   ret = sbi_debug_console_write(s, n);
+   if (ret < 0)
+   break;
+
+   s += ret;
+   n -= ret;
+   }
+}
+
 static int __init early_sbi_setup(struct earlycon_device *device,
  const char *opt)
 {
-   device->con->write = sbi_console_write;
+   if (sbi_debug_console_available)
+   device->con->write = sbi_dbcn_console_write;
+   else if (IS_ENABLED(CONFIG_RISCV_SBI_V01))
+   device->con->write = sbi_0_1_console_write;
+   else
+   return -ENODEV;
+
return 0;
 }
 EARLYCON_DECLARE(sbi, early_sbi_setup);
-- 
2.34.1



[PATCH v6 2/5] RISC-V: Add SBI debug console helper routines

2024-01-19 Thread Anup Patel
Let us provide SBI debug console helper routines which can be
shared by serial/earlycon-riscv-sbi.c and hvc/hvc_riscv_sbi.c.

Signed-off-by: Anup Patel 
Reviewed-by: Andrew Jones 
---
 arch/riscv/include/asm/sbi.h |  5 +++
 arch/riscv/kernel/sbi.c  | 66 
 2 files changed, 71 insertions(+)

diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
index e0a8eca32ba5..13594efb24bd 100644
--- a/arch/riscv/include/asm/sbi.h
+++ b/arch/riscv/include/asm/sbi.h
@@ -351,6 +351,11 @@ static inline unsigned long sbi_mk_version(unsigned long 
major,
 }
 
 int sbi_err_map_linux_errno(int err);
+
+extern bool sbi_debug_console_available;
+ssize_t sbi_debug_console_write(const u8 *bytes, size_t num_bytes);
+ssize_t sbi_debug_console_read(u8 *bytes, size_t num_bytes);
+
 #else /* CONFIG_RISCV_SBI */
 static inline int sbi_remote_fence_i(const struct cpumask *cpu_mask) { return 
-1; }
 static inline void sbi_init(void) {}
diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
index 5a62ed1da453..b06ad29f54b5 100644
--- a/arch/riscv/kernel/sbi.c
+++ b/arch/riscv/kernel/sbi.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -571,6 +572,66 @@ long sbi_get_mimpid(void)
 }
 EXPORT_SYMBOL_GPL(sbi_get_mimpid);
 
+bool sbi_debug_console_available;
+
+ssize_t sbi_debug_console_write(const u8 *bytes, size_t num_bytes)
+{
+   phys_addr_t base_addr;
+   struct sbiret ret;
+
+   if (!sbi_debug_console_available)
+   return -EOPNOTSUPP;
+
+   if (is_vmalloc_addr(bytes))
+   base_addr = page_to_phys(vmalloc_to_page(bytes)) +
+   offset_in_page(bytes);
+   else
+   base_addr = __pa(bytes);
+   if (PAGE_SIZE < (offset_in_page(bytes) + num_bytes))
+   num_bytes = PAGE_SIZE - offset_in_page(bytes);
+
+   if (IS_ENABLED(CONFIG_32BIT))
+   ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE,
+   num_bytes, lower_32_bits(base_addr),
+   upper_32_bits(base_addr), 0, 0, 0);
+   else
+   ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE,
+   num_bytes, base_addr, 0, 0, 0, 0);
+
+   if (ret.error == SBI_ERR_FAILURE)
+   return -EIO;
+   return ret.error ? sbi_err_map_linux_errno(ret.error) : ret.value;
+}
+
+ssize_t sbi_debug_console_read(u8 *bytes, size_t num_bytes)
+{
+   phys_addr_t base_addr;
+   struct sbiret ret;
+
+   if (!sbi_debug_console_available)
+   return -EOPNOTSUPP;
+
+   if (is_vmalloc_addr(bytes))
+   base_addr = page_to_phys(vmalloc_to_page(bytes)) +
+   offset_in_page(bytes);
+   else
+   base_addr = __pa(bytes);
+   if (PAGE_SIZE < (offset_in_page(bytes) + num_bytes))
+   num_bytes = PAGE_SIZE - offset_in_page(bytes);
+
+   if (IS_ENABLED(CONFIG_32BIT))
+   ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_READ,
+   num_bytes, lower_32_bits(base_addr),
+   upper_32_bits(base_addr), 0, 0, 0);
+   else
+   ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_READ,
+   num_bytes, base_addr, 0, 0, 0, 0);
+
+   if (ret.error == SBI_ERR_FAILURE)
+   return -EIO;
+   return ret.error ? sbi_err_map_linux_errno(ret.error) : ret.value;
+}
+
 void __init sbi_init(void)
 {
int ret;
@@ -612,6 +673,11 @@ void __init sbi_init(void)
sbi_srst_reboot_nb.priority = 192;
register_restart_handler(_srst_reboot_nb);
}
+   if ((sbi_spec_version >= sbi_mk_version(2, 0)) &&
+   (sbi_probe_extension(SBI_EXT_DBCN) > 0)) {
+   pr_info("SBI DBCN extension detected\n");
+   sbi_debug_console_available = true;
+   }
} else {
__sbi_set_timer = __sbi_set_timer_v01;
__sbi_send_ipi  = __sbi_send_ipi_v01;
-- 
2.34.1



[PATCH v6 1/5] RISC-V: Add stubs for sbi_console_putchar/getchar()

2024-01-19 Thread Anup Patel
The functions sbi_console_putchar() and sbi_console_getchar() are
not defined when CONFIG_RISCV_SBI_V01 is disabled so let us add
stub of these functions to avoid "#ifdef" on user side.

Signed-off-by: Anup Patel 
Reviewed-by: Andrew Jones 
---
 arch/riscv/include/asm/sbi.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
index b6f898c56940..e0a8eca32ba5 100644
--- a/arch/riscv/include/asm/sbi.h
+++ b/arch/riscv/include/asm/sbi.h
@@ -288,8 +288,13 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long 
arg0,
unsigned long arg3, unsigned long arg4,
unsigned long arg5);
 
+#ifdef CONFIG_RISCV_SBI_V01
 void sbi_console_putchar(int ch);
 int sbi_console_getchar(void);
+#else
+static inline void sbi_console_putchar(int ch) { }
+static inline int sbi_console_getchar(void) { return -ENOENT; }
+#endif
 long sbi_get_mvendorid(void);
 long sbi_get_marchid(void);
 long sbi_get_mimpid(void);
-- 
2.34.1



[PATCH v6 0/5] RISC-V SBI debug console extension support

2024-01-19 Thread Anup Patel
The SBI v2.0 specification is now frozen. The SBI v2.0 specification defines
SBI debug console (DBCN) extension which replaces the legacy SBI v0.1
functions sbi_console_putchar() and sbi_console_getchar().
(Refer v2.0-rc5 at https://github.com/riscv-non-isa/riscv-sbi-doc/releases)

This series adds support for SBI debug console (DBCN) extension in
Linux RISC-V.

To try these patches with KVM RISC-V, use KVMTOOL from the
riscv_zbx_zicntr_smstateen_condops_v1 branch at:
https://github.com/avpatel/kvmtool.git

These patches can also be found in the riscv_sbi_dbcn_v6 branch at:
https://github.com/avpatel/linux.git

Changes since v5:
 - Rebased on commit 9d1694dc91ce7b80bc96d6d8eaf1a1eca668d847
   ("Merge tag 'for-6.8/block-2024-01-18' of git://git.kernel.dk/linux")
 - Added Acked-by from GregKH in PATCH3 and PATCH4

Changes since v4:
 - Rebased on Linux-6.7-rc2
 - Addressed Drew's comments in PATCH2
 - Improved sbi_debug_console_write/read() to directly take virtual
   address of data so that virtual address to physical address
   conversion can be shared between tty/serial/earlycon-riscv-sbi.c
   and tty/hvc/hvc_riscv_sbi.c
 - Addressed Samuel's comments in PATCH3 and PATCH4

Changes since v3:
 - Rebased on Linux-6.7-rc1
 - Dropped PATCH1 to PATCH5 of v3 series since these were merged through
   KVM RISC-V tree for Linux-6.7
 - Used proper error code in PATCH1
 - Added new PATCH2 which add common SBI debug console helper functions
 - Updated PATCH3 and PATCH4 to use SBI debug console helper functions

Changes since v2:
 - Rebased on Linux-6.6-rc5
 - Handled page-crossing in PATCH7 of v2 series
 - Addressed Drew's comment in PATCH3 of v2 series
 - Added new PATCH5 to make get-reg-list test aware of SBI DBCN extension

Changes since v1:
 - Remove use of #ifdef from PATCH4 and PATCH5 of the v1 series
 - Improved commit description of PATCH3 in v1 series
 - Introduced new PATCH3 in this series to allow some SBI extensions
   (such as SBI DBCN) do to disabled by default so that older KVM user space
   work fine and newer KVM user space have to explicitly opt-in for emulating
   SBI DBCN.
 - Introduced new PATCH5 in this series which adds inline version of
   sbi_console_getchar() and sbi_console_putchar() for the case where
   CONFIG_RISCV_SBI_V01 is disabled.

Anup Patel (4):
  RISC-V: Add stubs for sbi_console_putchar/getchar()
  RISC-V: Add SBI debug console helper routines
  tty/serial: Add RISC-V SBI debug console based earlycon
  RISC-V: Enable SBI based earlycon support

Atish Patra (1):
  tty: Add SBI debug console support to HVC SBI driver

 arch/riscv/configs/defconfig|  1 +
 arch/riscv/include/asm/sbi.h| 10 
 arch/riscv/kernel/sbi.c | 66 +
 drivers/tty/hvc/Kconfig |  2 +-
 drivers/tty/hvc/hvc_riscv_sbi.c | 37 +++---
 drivers/tty/serial/Kconfig  |  2 +-
 drivers/tty/serial/earlycon-riscv-sbi.c | 27 --
 7 files changed, 133 insertions(+), 12 deletions(-)

-- 
2.34.1



[PATCH 3/4] powerpc/ps3: Make real stack frames for LV1 hcalls

2024-01-19 Thread Geoff Levand
The PS3 hcall assembly code makes ad-hoc stack frames that don't have
a back-chain pointer or meet other requirements like minimum frame size.
This probably confuses stack unwinders. Give all hcalls a real stack
frame.

Signed-off-by: Nicholas Piggin 
Signed-off-by: Geoff Levand 
---
 arch/powerpc/platforms/ps3/hvcall.S | 152 +---
 1 file changed, 94 insertions(+), 58 deletions(-)

diff --git a/arch/powerpc/platforms/ps3/hvcall.S 
b/arch/powerpc/platforms/ps3/hvcall.S
index b854675f6113..b6454d476962 100644
--- a/arch/powerpc/platforms/ps3/hvcall.S
+++ b/arch/powerpc/platforms/ps3/hvcall.S
@@ -9,6 +9,7 @@
 
 #include 
 #include 
+#include 
 
 #define lv1call .long 0x4422; extsw r3, r3
 
@@ -18,8 +19,10 @@ _GLOBAL(_##API_NAME) \
mflrr0; \
std r0, LRSAVE(r1); \
\
+   stdur1, -STACK_FRAME_MIN_SIZE(r1);  \
li  r11, API_NUMBER;\
lv1call;\
+   addir1, r1, STACK_FRAME_MIN_SIZE;   \
\
ld  r0, LRSAVE(r1); \
mtlrr0; \
@@ -40,12 +43,13 @@ _GLOBAL(_##API_NAME)\
mflrr0; \
std r0, LRSAVE(r1); \
\
-   stdur3, -8(r1); \
+   std r3, -8(r1); \
+   stdur1, -STACK_FRAME_MIN_SIZE-8(r1); \
\
li  r11, API_NUMBER;\
lv1call;\
\
-   addir1, r1, 8;  \
+   addir1, r1, STACK_FRAME_MIN_SIZE+8; \
ld  r11, -8(r1);\
std r4, 0(r11); \
\
@@ -60,12 +64,13 @@ _GLOBAL(_##API_NAME)\
std r0, LRSAVE(r1); \
\
std r3, -8(r1); \
-   stdur4, -16(r1);\
+   std r4, -16(r1);\
+   stdur1, -STACK_FRAME_MIN_SIZE-16(r1); \
\
li  r11, API_NUMBER;\
lv1call;\
\
-   addir1, r1, 16; \
+   addir1, r1, STACK_FRAME_MIN_SIZE+16; \
ld  r11, -8(r1);\
std r4, 0(r11); \
ld  r11, -16(r1);   \
@@ -83,12 +88,13 @@ _GLOBAL(_##API_NAME)\
\
std r3, -8(r1); \
std r4, -16(r1);\
-   stdur5, -24(r1);\
+   std r5, -24(r1);\
+   stdur1, -STACK_FRAME_MIN_SIZE-24(r1); \
\
li  r11, API_NUMBER;\
lv1call;\
\
-   addir1, r1, 24; \
+   addir1, r1, STACK_FRAME_MIN_SIZE+24; \
ld  r11, -8(r1);\
std r4, 0(r11); \
ld  r11, -16(r1);   \
@@ -112,12 +118,13 @@ _GLOBAL(_##API_NAME)  \
std r6, -32(r1);\
std r7, -40(r1);\
std r8, -48(r1);\
-   stdur9, -56(r1);\
+   std r9, -56(r1);\
+   stdur1, -STACK_FRAME_MIN_SIZE-56(r1); \
\
li  r11, API_NUMBER;\
lv1call;\
\
-   addir1, r1, 56; \
+   addir1, r1, STACK_FRAME_MIN_SIZE+56; \
ld  r11, -8(r1);\
std r4, 0(r11); \
ld  r11, -16(r1);   \
@@ -143,12 +150,13 @@ _GLOBAL(_##API_NAME)  \
mflrr0; \
std r0, LRSAVE(r1); \
\
-   stdur4, -8(r1); \
+   std r4, -8(r1); \
+   stdur1, -STACK_FRAME_MIN_SIZE-8(r1); \

[PATCH 4/4] Revert "powerpc/ps3_defconfig: Disable PPC64_BIG_ENDIAN_ELF_ABI_V2"

2024-01-19 Thread Geoff Levand
Patches provided by Nicholas Piggin enable PS3
support for ELFv2.

Signed-off-by: Geoff Levand 
---
 arch/powerpc/configs/ps3_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/powerpc/configs/ps3_defconfig 
b/arch/powerpc/configs/ps3_defconfig
index aa8bb0208bcc..2b175ddf82f0 100644
--- a/arch/powerpc/configs/ps3_defconfig
+++ b/arch/powerpc/configs/ps3_defconfig
@@ -24,7 +24,6 @@ CONFIG_PS3_VRAM=m
 CONFIG_PS3_LPM=m
 # CONFIG_PPC_OF_BOOT_TRAMPOLINE is not set
 CONFIG_KEXEC=y
-# CONFIG_PPC64_BIG_ENDIAN_ELF_ABI_V2 is not set
 CONFIG_PPC_4K_PAGES=y
 CONFIG_SCHED_SMT=y
 CONFIG_PM=y
-- 
2.34.1



[PATCH 1/4] powerpc/ps3: Fix lv1 hcall assembly for ELFv2 calling convention

2024-01-19 Thread Geoff Levand
Stack-passed parameters begin at a different offset in the caller's
stack in the ELFv2 ABI.

Reported-by: Geoff Levand 
Fixes: 8c5fa3b5c4df ("powerpc/64: Make ELFv2 the default for big-endian builds")
Signed-off-by: Nicholas Piggin 
Signed-off-by: Geoff Levand 
---
 arch/powerpc/include/asm/ppc_asm.h  |  6 --
 arch/powerpc/platforms/ps3/hvcall.S | 18 +-
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/include/asm/ppc_asm.h 
b/arch/powerpc/include/asm/ppc_asm.h
index e7792aa13510..041ee2595520 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -201,11 +201,13 @@
 
 #ifdef CONFIG_PPC64_ELF_ABI_V2
 #define STK_GOT24
-#define __STK_PARAM(i) (32 + ((i)-3)*8)
+#define STK_PARAM_AREA 32
 #else
 #define STK_GOT40
-#define __STK_PARAM(i) (48 + ((i)-3)*8)
+#define STK_PARAM_AREA 48
 #endif
+
+#define __STK_PARAM(i) (STK_PARAM_AREA + ((i)-3)*8)
 #define STK_PARAM(i)   __STK_PARAM(__REG_##i)
 
 #ifdef CONFIG_PPC64_ELF_ABI_V2
diff --git a/arch/powerpc/platforms/ps3/hvcall.S 
b/arch/powerpc/platforms/ps3/hvcall.S
index 509e30ad01bb..59ea569debf4 100644
--- a/arch/powerpc/platforms/ps3/hvcall.S
+++ b/arch/powerpc/platforms/ps3/hvcall.S
@@ -714,7 +714,7 @@ _GLOBAL(_##API_NAME)\
std r4, 0(r11); \
ld  r11, -16(r1);   \
std r5, 0(r11); \
-   ld  r11, 48+8*8(r1);\
+   ld  r11, STK_PARAM_AREA+8*8(r1);\
std r6, 0(r11); \
\
ld  r0, 16(r1); \
@@ -746,22 +746,22 @@ _GLOBAL(_##API_NAME)  \
mflrr0; \
std r0, 16(r1); \
\
-   std r10, 48+8*7(r1);\
+   std r10, STK_PARAM_AREA+8*7(r1);\
\
li  r11, API_NUMBER;\
lv1call;\
\
-   ld  r11, 48+8*7(r1);\
+   ld  r11, STK_PARAM_AREA+8*7(r1);\
std r4, 0(r11); \
-   ld  r11, 48+8*8(r1);\
+   ld  r11, STK_PARAM_AREA+8*8(r1);\
std r5, 0(r11); \
-   ld  r11, 48+8*9(r1);\
+   ld  r11, STK_PARAM_AREA+8*9(r1);\
std r6, 0(r11); \
-   ld  r11, 48+8*10(r1);   \
+   ld  r11, STK_PARAM_AREA+8*10(r1);   \
std r7, 0(r11); \
-   ld  r11, 48+8*11(r1);   \
+   ld  r11, STK_PARAM_AREA+8*11(r1);   \
std r8, 0(r11); \
-   ld  r11, 48+8*12(r1);   \
+   ld  r11, STK_PARAM_AREA+8*12(r1);   \
std r9, 0(r11); \
\
ld  r0, 16(r1); \
@@ -777,7 +777,7 @@ _GLOBAL(_##API_NAME)\
li  r11, API_NUMBER;\
lv1call;\
\
-   ld  r11, 48+8*8(r1);\
+   ld  r11, STK_PARAM_AREA+8*8(r1);\
std r4, 0(r11); \
\
ld  r0, 16(r1); \
-- 
2.34.1




[PATCH 2/4] powerpc/ps3: lv1 hcall code use symbolic constant for LR save offset

2024-01-19 Thread Geoff Levand
The LRSAVE constant is required for assembly compiled for both 32-bit
and 64-bit, because the value differs there. PS3 is 64-bit only so
this is a noop, but it is nice to abstract stack frame offsets.

Signed-off-by: Nicholas Piggin 
Signed-off-by: Geoff Levand 
---
 arch/powerpc/platforms/ps3/hvcall.S | 128 ++--
 1 file changed, 64 insertions(+), 64 deletions(-)

diff --git a/arch/powerpc/platforms/ps3/hvcall.S 
b/arch/powerpc/platforms/ps3/hvcall.S
index 59ea569debf4..b854675f6113 100644
--- a/arch/powerpc/platforms/ps3/hvcall.S
+++ b/arch/powerpc/platforms/ps3/hvcall.S
@@ -16,12 +16,12 @@
 _GLOBAL(_##API_NAME)   \
\
mflrr0; \
-   std r0, 16(r1); \
+   std r0, LRSAVE(r1); \
\
li  r11, API_NUMBER;\
lv1call;\
\
-   ld  r0, 16(r1); \
+   ld  r0, LRSAVE(r1); \
mtlrr0; \
blr
 
@@ -38,7 +38,7 @@ _GLOBAL(_##API_NAME)  \
 _GLOBAL(_##API_NAME)   \
\
mflrr0; \
-   std r0, 16(r1); \
+   std r0, LRSAVE(r1); \
\
stdur3, -8(r1); \
\
@@ -49,7 +49,7 @@ _GLOBAL(_##API_NAME)  \
ld  r11, -8(r1);\
std r4, 0(r11); \
\
-   ld  r0, 16(r1); \
+   ld  r0, LRSAVE(r1); \
mtlrr0; \
blr
 
@@ -57,7 +57,7 @@ _GLOBAL(_##API_NAME)  \
 _GLOBAL(_##API_NAME)   \
\
mflrr0; \
-   std r0, 16(r1); \
+   std r0, LRSAVE(r1); \
\
std r3, -8(r1); \
stdur4, -16(r1);\
@@ -71,7 +71,7 @@ _GLOBAL(_##API_NAME)  \
ld  r11, -16(r1);   \
std r5, 0(r11); \
\
-   ld  r0, 16(r1); \
+   ld  r0, LRSAVE(r1); \
mtlrr0; \
blr
 
@@ -79,7 +79,7 @@ _GLOBAL(_##API_NAME)  \
 _GLOBAL(_##API_NAME)   \
\
mflrr0; \
-   std r0, 16(r1); \
+   std r0, LRSAVE(r1); \
\
std r3, -8(r1); \
std r4, -16(r1);\
@@ -96,7 +96,7 @@ _GLOBAL(_##API_NAME)  \
ld  r11, -24(r1);   \
std r6, 0(r11); \
\
-   ld  r0, 16(r1); \
+   ld  r0, LRSAVE(r1); \
mtlrr0; \
blr
 
@@ -104,7 +104,7 @@ _GLOBAL(_##API_NAME)\
 _GLOBAL(_##API_NAME)   \
\
mflrr0; \
-   std r0, 16(r1); \
+   std r0, LRSAVE(r1); \
\
std r3, -8(r1); \
std r4, -16(r1);\
@@ -133,7 +133,7 @@ _GLOBAL(_##API_NAME)\
ld  r11, -56(r1);   \
std r10, 0(r11);\
\
-   ld  r0, 16(r1); \
+   ld  r0, LRSAVE(r1); \
mtlrr0; \
blr
 
@@ -141,7 +141,7 @@ _GLOBAL(_##API_NAME)\
 _GLOBAL(_##API_NAME)   \
\
mflrr0; \
-   std r0, 16(r1); \
+   std r0, LRSAVE(r1); \
  

[PATCH 0/4] powerpc/ps3 Add ELFv2 support

2024-01-19 Thread Geoff Levand
The following changes since commit 44a1aad2fe6c10bfe0589d8047057b10a4c18a19:

  Merge branch 'topic/ppc-kvm' into next (2023-12-29 15:30:45 +1100)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/geoff/ps3-linux.git 
for-merge-elfv2

for you to fetch changes up to 983836405df1b6001a2262972fb32d1aee97d6f5:

  Revert "powerpc/ps3_defconfig: Disable PPC64_BIG_ENDIAN_ELF_ABI_V2" 
(2024-01-19 17:53:48 +0900)


Geoff Levand (1):
  Revert "powerpc/ps3_defconfig: Disable PPC64_BIG_ENDIAN_ELF_ABI_V2"

Nicholas Piggin (3):
  powerpc/ps3: Fix lv1 hcall assembly for ELFv2 calling convention
  powerpc/ps3: lv1 hcall code use symbolic constant for LR save offset
  powerpc/ps3: Make real stack frames for LV1 hcalls

 arch/powerpc/configs/ps3_defconfig  |   1 -
 arch/powerpc/include/asm/ppc_asm.h  |   6 +-
 arch/powerpc/platforms/ps3/hvcall.S | 298 
 3 files changed, 171 insertions(+), 134 deletions(-)

-- 
2.34.1



Re: [PATCH v5 0/5] RISC-V SBI debug console extension support

2024-01-19 Thread Anup Patel
On Sat, Jan 13, 2024 at 12:00 AM Palmer Dabbelt  wrote:
>
> On Thu, 11 Jan 2024 06:50:37 PST (-0800), 
> patchwork-bot+linux-ri...@kernel.org wrote:
> > Hello:
> >
> > This series was applied to riscv/linux.git (for-next)
> > by Palmer Dabbelt :
> >
> > On Fri, 24 Nov 2023 12:39:00 +0530 you wrote:
> >> The SBI v2.0 specification is now frozen. The SBI v2.0 specification 
> >> defines
> >> SBI debug console (DBCN) extension which replaces the legacy SBI v0.1
> >> functions sbi_console_putchar() and sbi_console_getchar().
> >> (Refer v2.0-rc5 at https://github.com/riscv-non-isa/riscv-sbi-doc/releases)
> >>
> >> This series adds support for SBI debug console (DBCN) extension in
> >> Linux RISC-V.
> >>
> >> [...]
> >
> > Here is the summary with links:
> >   - [v5,1/5] RISC-V: Add stubs for sbi_console_putchar/getchar()
> > https://git.kernel.org/riscv/c/f503b167b660
> >   - [v5,2/5] RISC-V: Add SBI debug console helper routines
> > https://git.kernel.org/riscv/c/f43fabf444ca
> >   - [v5,3/5] tty/serial: Add RISC-V SBI debug console based earlycon
> > https://git.kernel.org/riscv/c/c77bf3607a0f
> >   - [v5,4/5] tty: Add SBI debug console support to HVC SBI driver
> > https://git.kernel.org/riscv/c/88ead68e764c
> >   - [v5,5/5] RISC-V: Enable SBI based earlycon support
> > https://git.kernel.org/riscv/c/50942ad6ddb5
> >
> > You are awesome, thank you!
>
> Nathan points out that this has some semantic conflicts with a patch in
> Greg's TTY tree: 
> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?id=f32fcbedbe9290565e4eac3fd7c4c451d5478787
>
> So I think the best bet is to wait on Greg's patch to land in Linus'
> tree, and then base a v6 of this patch set on that merged patch.  I'm
> going to drop this one from for-next.

Greg's patch is now available in upstream Linux so I will rebase and
send out v6.

Thanks,
Anup


Re: [PATCH] NUMA: Early use of cpu_to_node() returns 0 instead of the correct node id

2024-01-19 Thread Shijie Huang



在 2024/1/19 16:42, Mike Rapoport 写道:

On Fri, Jan 19, 2024 at 02:46:16PM +0800, Shijie Huang wrote:

在 2024/1/19 12:42, Yury Norov 写道:

This adds another level of indirection, I think. Currently cpu_to_node
is a simple inliner. After the patch it would be a real function with
all the associate overhead. Can you share a bloat-o-meter output here?

#./scripts/bloat-o-meter vmlinux vmlinux.new
add/remove: 6/1 grow/shrink: 61/51 up/down: 1168/-588 (580)
Function old new   delta
numa_update_cpu  148 244 +96

  
...(to
 many to skip)

Total: Before=32990130, After=32990710, chg +0.00%
  
It's not only about text size, the indirect call also hurts performance
  


The cpu_to_node() is called at very low frequency, most of the times is 
in the kernel booting time.





Regardless, I don't think that the approach is correct. As per your
description, some initialization functions erroneously call
cpu_to_node() instead of early_cpu_to_node() which exists specifically
for that case.

If the above correct, it's clearly a caller problem, and the fix is to
simply switch all those callers to use early version.

It is easy to change to early_cpu_to_node() for sched_init(),
init_sched_fair_class()

and workqueue_init_early(). These three places call the cpu_to_node() in the
__init function.


But it is a little hard to change the early_trace_init(), since it calls
cpu_to_node in the deep

function stack:

   early_trace_init() --> ring_buffer_alloc() -->rb_allocate_cpu_buffer()


For early_trace_init(), we need to change more code.


Anyway, If we think it is not a good idea to change the common code, I am
oaky too.
  
Is there a fundamental reason to have early_cpu_to_node() at all?


The early_cpu_to_node does not work on some ARCHs (which support the 
NUMA), such


as  SPARC, MIPS and S390.


Thanks

Huang Shijie


It seems that all the mappings are known by the end of setup_arch() and the
initialization of numa_node can be moved earlier.
  

I would also initialize the numa_node with NUMA_NO_NODE at declaration,
so that if someone calls cpu_to_node() before the variable is properly
initialized at runtime, he'll get NO_NODE, which is obviously an error.

Even we set the numa_node with NUMA_NO_NODE, it does not always produce
error.

Please see the alloc_pages_node().


Thanks

Huang Shijie



Re: [PATCH] NUMA: Early use of cpu_to_node() returns 0 instead of the correct node id

2024-01-19 Thread Mike Rapoport
On Fri, Jan 19, 2024 at 02:46:16PM +0800, Shijie Huang wrote:
> 
> 在 2024/1/19 12:42, Yury Norov 写道:
> > This adds another level of indirection, I think. Currently cpu_to_node
> > is a simple inliner. After the patch it would be a real function with
> > all the associate overhead. Can you share a bloat-o-meter output here?
> #./scripts/bloat-o-meter vmlinux vmlinux.new
> add/remove: 6/1 grow/shrink: 61/51 up/down: 1168/-588 (580)
> Function old new   delta
> numa_update_cpu  148 244 +96
> 
>  
> ...(to
>  many to skip)
> 
> Total: Before=32990130, After=32990710, chg +0.00%
 
It's not only about text size, the indirect call also hurts performance
 
> > 
> > Regardless, I don't think that the approach is correct. As per your
> > description, some initialization functions erroneously call
> > cpu_to_node() instead of early_cpu_to_node() which exists specifically
> > for that case.
> > 
> > If the above correct, it's clearly a caller problem, and the fix is to
> > simply switch all those callers to use early version.
> 
> It is easy to change to early_cpu_to_node() for sched_init(),
> init_sched_fair_class()
> 
> and workqueue_init_early(). These three places call the cpu_to_node() in the
> __init function.
> 
> 
> But it is a little hard to change the early_trace_init(), since it calls
> cpu_to_node in the deep
> 
> function stack:
> 
>   early_trace_init() --> ring_buffer_alloc() -->rb_allocate_cpu_buffer()
> 
> 
> For early_trace_init(), we need to change more code.
> 
> 
> Anyway, If we think it is not a good idea to change the common code, I am
> oaky too.
 
Is there a fundamental reason to have early_cpu_to_node() at all?
It seems that all the mappings are known by the end of setup_arch() and the
initialization of numa_node can be moved earlier. 
 
> > I would also initialize the numa_node with NUMA_NO_NODE at declaration,
> > so that if someone calls cpu_to_node() before the variable is properly
> > initialized at runtime, he'll get NO_NODE, which is obviously an error.
> 
> Even we set the numa_node with NUMA_NO_NODE, it does not always produce
> error.
> 
> Please see the alloc_pages_node().
> 
> 
> Thanks
> 
> Huang Shijie
> 

-- 
Sincerely yours,
Mike.