* [PATCH v14 14/17] crash: Use crash_exclude_core_ranges() on powerpc
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
The crash memory exclude of crashk_res and crashk_cma memory on powerpc
are almost identical to the generic crash_exclude_core_ranges().
By introducing the architecture-specific arch_crash_exclude_mem_range()
function with a default implementation of crash_exclude_mem_range(),
and using crash_exclude_mem_range_guarded as powerpc's separate
implementation, the generic crash_exclude_core_ranges() helper function
can be reused.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
Acked-by: Baoquan He <bhe@redhat.com>
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/powerpc/include/asm/kexec_ranges.h | 3 ---
arch/powerpc/kexec/crash.c | 2 +-
arch/powerpc/kexec/ranges.c | 16 ++++------------
include/linux/crash_core.h | 4 ++++
kernel/crash_core.c | 19 +++++++++++++------
5 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/arch/powerpc/include/asm/kexec_ranges.h b/arch/powerpc/include/asm/kexec_ranges.h
index ad95e3792d10..8489e844b447 100644
--- a/arch/powerpc/include/asm/kexec_ranges.h
+++ b/arch/powerpc/include/asm/kexec_ranges.h
@@ -7,9 +7,6 @@
void sort_memory_ranges(struct crash_mem *mrngs, bool merge);
struct crash_mem *realloc_mem_ranges(struct crash_mem **mem_ranges);
int add_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size);
-int crash_exclude_mem_range_guarded(struct crash_mem **mem_ranges,
- unsigned long long mstart,
- unsigned long long mend);
int get_exclude_memory_ranges(struct crash_mem **mem_ranges);
int get_reserved_memory_ranges(struct crash_mem **mem_ranges);
int get_crash_memory_ranges(struct crash_mem **mem_ranges);
diff --git a/arch/powerpc/kexec/crash.c b/arch/powerpc/kexec/crash.c
index d634db67becc..775895f31037 100644
--- a/arch/powerpc/kexec/crash.c
+++ b/arch/powerpc/kexec/crash.c
@@ -513,7 +513,7 @@ static void update_crash_elfcorehdr(struct kimage *image, struct memory_notify *
base_addr = PFN_PHYS(mn->start_pfn);
size = mn->nr_pages * PAGE_SIZE;
end = base_addr + size - 1;
- ret = crash_exclude_mem_range_guarded(&cmem, base_addr, end);
+ ret = arch_crash_exclude_mem_range(&cmem, base_addr, end);
if (ret) {
pr_err("Failed to remove hot-unplugged memory from crash memory ranges\n");
goto out;
diff --git a/arch/powerpc/kexec/ranges.c b/arch/powerpc/kexec/ranges.c
index 6c58bcc3e130..e5fea23b191b 100644
--- a/arch/powerpc/kexec/ranges.c
+++ b/arch/powerpc/kexec/ranges.c
@@ -553,9 +553,9 @@ int get_usable_memory_ranges(struct crash_mem **mem_ranges)
#endif /* CONFIG_KEXEC_FILE */
#ifdef CONFIG_CRASH_DUMP
-int crash_exclude_mem_range_guarded(struct crash_mem **mem_ranges,
- unsigned long long mstart,
- unsigned long long mend)
+int arch_crash_exclude_mem_range(struct crash_mem **mem_ranges,
+ unsigned long long mstart,
+ unsigned long long mend)
{
struct crash_mem *tmem = *mem_ranges;
@@ -604,18 +604,10 @@ int get_crash_memory_ranges(struct crash_mem **mem_ranges)
sort_memory_ranges(*mem_ranges, true);
}
- /* Exclude crashkernel region */
- ret = crash_exclude_mem_range_guarded(mem_ranges, crashk_res.start, crashk_res.end);
+ ret = crash_exclude_core_ranges(mem_ranges);
if (ret)
goto out;
- for (i = 0; i < crashk_cma_cnt; ++i) {
- ret = crash_exclude_mem_range_guarded(mem_ranges, crashk_cma_ranges[i].start,
- crashk_cma_ranges[i].end);
- if (ret)
- goto out;
- }
-
/*
* FIXME: For now, stay in parity with kexec-tools but if RTAS/OPAL
* regions are exported to save their context at the time of
diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
index d69c4c7c1f5e..0f4ea7ffd066 100644
--- a/include/linux/crash_core.h
+++ b/include/linux/crash_core.h
@@ -63,6 +63,7 @@ extern int crash_prepare_headers(int need_kernel_map, void **addr,
unsigned long *sz, unsigned long *nr_mem_ranges);
extern int crash_prepare_headers_locked(int need_kernel_map, void **addr,
unsigned long *sz, unsigned long *nr_mem_ranges);
+extern int crash_exclude_core_ranges(struct crash_mem **cmem);
struct kimage;
struct kexec_segment;
@@ -83,6 +84,9 @@ extern int kimage_crash_copy_vmcoreinfo(struct kimage *image);
extern unsigned int arch_get_system_nr_ranges(void);
extern int arch_crash_populate_cmem(struct crash_mem *cmem);
extern int arch_crash_exclude_ranges(struct crash_mem *cmem);
+extern int arch_crash_exclude_mem_range(struct crash_mem **mem,
+ unsigned long long mstart,
+ unsigned long long mend);
#else /* !CONFIG_CRASH_DUMP*/
struct pt_regs;
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index e84f3b63e79d..33e945da6776 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -286,24 +286,31 @@ unsigned int __weak arch_get_system_nr_ranges(void) { return 0; }
int __weak arch_crash_populate_cmem(struct crash_mem *cmem) { return -1; }
int __weak arch_crash_exclude_ranges(struct crash_mem *cmem) { return 0; }
-static int crash_exclude_core_ranges(struct crash_mem *cmem)
+int __weak arch_crash_exclude_mem_range(struct crash_mem **mem,
+ unsigned long long mstart,
+ unsigned long long mend)
+{
+ return crash_exclude_mem_range(*mem, mstart, mend);
+}
+
+int crash_exclude_core_ranges(struct crash_mem **cmem)
{
int ret, i;
/* Exclude crashkernel region */
- ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
+ ret = arch_crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
if (ret)
return ret;
if (crashk_low_res.end) {
- ret = crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end);
+ ret = arch_crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end);
if (ret)
return ret;
}
for (i = 0; i < crashk_cma_cnt; ++i) {
- ret = crash_exclude_mem_range(cmem, crashk_cma_ranges[i].start,
- crashk_cma_ranges[i].end);
+ ret = arch_crash_exclude_mem_range(cmem, crashk_cma_ranges[i].start,
+ crashk_cma_ranges[i].end);
if (ret)
return ret;
}
@@ -330,7 +337,7 @@ int crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz,
if (ret)
goto out;
- ret = crash_exclude_core_ranges(cmem);
+ ret = crash_exclude_core_ranges(&cmem);
if (ret)
goto out;
--
2.34.1
^ permalink raw reply related
* [PATCH v14 13/17] LoongArch: kexec: Use crash_prepare_headers() helper to simplify code
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
Use the newly introduced crash_prepare_headers() function to replace
the existing prepare_elf_headers(), allocate cmem and exclude crash kernel
memory in the crash core, which reduce code duplication.
Only the following two architecture functions need to be implemented:
- arch_get_system_nr_ranges(). Use for_each_mem_range to traverse
and pre-count the max number of memory ranges.
- arch_crash_populate_cmem(). Use for_each_mem_range to traverse
and collect the memory ranges and fills them into cmem.
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>
Cc: Youling Tang <tangyouling@kylinos.cn>
Cc: Baoquan He <bhe@redhat.com>
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Acked-by: Baoquan He <bhe@redhat.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/loongarch/kernel/machine_kexec_file.c | 50 ++++++----------------
1 file changed, 14 insertions(+), 36 deletions(-)
diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c
index 2a1a6124f043..a845fbe8883d 100644
--- a/arch/loongarch/kernel/machine_kexec_file.c
+++ b/arch/loongarch/kernel/machine_kexec_file.c
@@ -14,7 +14,6 @@
#include <linux/kernel.h>
#include <linux/kexec.h>
#include <linux/memblock.h>
-#include <linux/memory_hotplug.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/types.h>
@@ -57,51 +56,33 @@ static void cmdline_add_initrd(struct kimage *image, unsigned long *cmdline_tmpl
}
#ifdef CONFIG_CRASH_DUMP
-
-static int prepare_elf_headers(void **addr, unsigned long *sz)
+unsigned int arch_get_system_nr_ranges(void)
{
- int ret, nr_ranges;
- uint64_t i;
+ int nr_ranges = 2; /* for exclusion of crashkernel region */
phys_addr_t start, end;
- struct crash_mem *cmem;
+ uint64_t i;
- nr_ranges = 2; /* for exclusion of crashkernel region */
for_each_mem_range(i, &start, &end)
nr_ranges++;
- cmem = kmalloc_flex(*cmem, ranges, nr_ranges);
- if (!cmem)
- return -ENOMEM;
+ return nr_ranges;
+}
+
+int arch_crash_populate_cmem(struct crash_mem *cmem)
+{
+ phys_addr_t start, end;
+ uint64_t i;
- cmem->max_nr_ranges = nr_ranges;
- cmem->nr_ranges = 0;
for_each_mem_range(i, &start, &end) {
- if (WARN_ON_ONCE(cmem->nr_ranges >= cmem->max_nr_ranges)) {
- ret = -EAGAIN;
- goto out;
- }
+ if (WARN_ON_ONCE(cmem->nr_ranges >= cmem->max_nr_ranges))
+ return -EAGAIN;
cmem->ranges[cmem->nr_ranges].start = start;
cmem->ranges[cmem->nr_ranges].end = end - 1;
cmem->nr_ranges++;
}
- /* Exclude crashkernel region */
- ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
- if (ret < 0)
- goto out;
-
- if (crashk_low_res.end) {
- ret = crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end);
- if (ret < 0)
- goto out;
- }
-
- ret = crash_prepare_elf64_headers(cmem, true, addr, sz);
-
-out:
- kfree(cmem);
- return ret;
+ return 0;
}
/*
@@ -169,15 +150,12 @@ int load_other_segments(struct kimage *image,
void *headers;
unsigned long headers_sz;
- get_online_mems();
- ret = prepare_elf_headers(&headers, &headers_sz);
+ ret = crash_prepare_headers_locked(true, &headers, &headers_sz, NULL);
if (ret < 0) {
- put_online_mems();
pr_err("Preparing elf core header failed\n");
goto out_err;
}
- put_online_mems();
kbuf.buffer = headers;
kbuf.bufsz = headers_sz;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
--
2.34.1
^ permalink raw reply related
* [PATCH v14 12/17] riscv: kexec_file: Use crash_prepare_headers() helper to simplify code
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
Use the newly introduced crash_prepare_headers() function to replace
the existing prepare_elf_headers(), allocate cmem and exclude crash kernel
memory in the crash core, which reduce code duplication.
Only the following two architecture functions need to be implemented:
- arch_get_system_nr_ranges(). Call get_nr_ram_ranges_callback()
to pre-counts the max number of memory ranges.
- arch_crash_populate_cmem(). Use prepare_elf64_ram_headers_callback()
to collects the memory ranges and fills them into cmem.
Cc: Paul Walmsley <pjw@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Guo Ren <guoren@kernel.org>
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Acked-by: Baoquan He <bhe@redhat.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/riscv/kernel/machine_kexec_file.c | 51 ++++++--------------------
1 file changed, 12 insertions(+), 39 deletions(-)
diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
index a88362dfbd89..d2bb61a8b6b6 100644
--- a/arch/riscv/kernel/machine_kexec_file.c
+++ b/arch/riscv/kernel/machine_kexec_file.c
@@ -8,7 +8,6 @@
*/
#include <linux/kexec.h>
#include <linux/elf.h>
-#include <linux/memory_hotplug.h>
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/libfdt.h>
@@ -45,6 +44,15 @@ static int get_nr_ram_ranges_callback(struct resource *res, void *arg)
return 0;
}
+unsigned int arch_get_system_nr_ranges(void)
+{
+ unsigned int nr_ranges = 2; /* For exclusion of crashkernel region */
+
+ walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
+
+ return nr_ranges;
+}
+
static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg)
{
struct crash_mem *cmem = arg;
@@ -59,41 +67,9 @@ static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg)
return 0;
}
-static int prepare_elf_headers(void **addr, unsigned long *sz)
+int arch_crash_populate_cmem(struct crash_mem *cmem)
{
- struct crash_mem *cmem;
- unsigned int nr_ranges;
- int ret;
-
- nr_ranges = 2; /* For exclusion of crashkernel region */
- walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
-
- cmem = kmalloc_flex(*cmem, ranges, nr_ranges);
- if (!cmem)
- return -ENOMEM;
-
- cmem->max_nr_ranges = nr_ranges;
- cmem->nr_ranges = 0;
- ret = walk_system_ram_res(0, -1, cmem, prepare_elf64_ram_headers_callback);
- if (ret)
- goto out;
-
- /* Exclude crashkernel region */
- ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
- if (ret)
- goto out;
-
- if (crashk_low_res.end) {
- ret = crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end);
- if (ret)
- goto out;
- }
-
- ret = crash_prepare_elf64_headers(cmem, true, addr, sz);
-
-out:
- kfree(cmem);
- return ret;
+ return walk_system_ram_res(0, -1, cmem, prepare_elf64_ram_headers_callback);
}
static char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
@@ -285,15 +261,12 @@ int load_extra_segments(struct kimage *image, unsigned long kernel_start,
if (image->type == KEXEC_TYPE_CRASH) {
void *headers;
unsigned long headers_sz;
- get_online_mems();
- ret = prepare_elf_headers(&headers, &headers_sz);
+ ret = crash_prepare_headers_locked(true, &headers, &headers_sz, NULL);
if (ret) {
- put_online_mems();
pr_err("Preparing elf core header failed\n");
goto out;
}
- put_online_mems();
kbuf.buffer = headers;
kbuf.bufsz = headers_sz;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
--
2.34.1
^ permalink raw reply related
* [PATCH v14 11/17] x86/kexec: Use crash_prepare_headers() helper to simplify code
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
Use the newly introduced crash_prepare_headers() function to replace
the existing prepare_elf_headers(), allocate cmem and exclude crash kernel
memory in the crash core, which reduce code duplication.
Only the following three architecture functions need to be implemented:
- arch_get_system_nr_ranges(). Call get_nr_ram_ranges_callback()
to pre-count the max number of memory ranges.
- arch_crash_populate_cmem(). Use prepare_elf64_ram_headers_callback()
to collect the memory ranges and fills them into cmem.
- arch_crash_exclude_ranges(). Exclude the low 1M for x86.
By the way, remove the unused "nr_mem_ranges" in
arch_crash_handle_hotplug_event().
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Acked-by: Baoquan He <bhe@redhat.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/x86/kernel/crash.c | 96 ++++++-----------------------------------
1 file changed, 12 insertions(+), 84 deletions(-)
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index f319308b06ee..26f140dff348 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -25,7 +25,6 @@
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/memblock.h>
-#include <linux/memory_hotplug.h>
#include <asm/bootparam.h>
#include <asm/processor.h>
@@ -154,16 +153,8 @@ static int get_nr_ram_ranges_callback(struct resource *res, void *arg)
return 0;
}
-/* Gather all the required information to prepare elf headers for ram regions */
-static struct crash_mem *fill_up_crash_elf_data(void)
+unsigned int arch_get_system_nr_ranges(void)
{
- unsigned int nr_ranges = 0;
- struct crash_mem *cmem;
-
- walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
- if (!nr_ranges)
- return NULL;
-
/*
* Exclusion of crash region, crashk_low_res and/or crashk_cma_ranges
* may cause range splits. So add extra slots here.
@@ -178,49 +169,16 @@ static struct crash_mem *fill_up_crash_elf_data(void)
* But in order to lest the low 1M could be changed in the future,
* (e.g. [start, 1M]), add a extra slot.
*/
- nr_ranges += 3 + crashk_cma_cnt;
- cmem = vzalloc(struct_size(cmem, ranges, nr_ranges));
- if (!cmem)
- return NULL;
-
- cmem->max_nr_ranges = nr_ranges;
+ unsigned int nr_ranges = 3 + crashk_cma_cnt;
- return cmem;
+ walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
+ return nr_ranges;
}
-/*
- * Look for any unwanted ranges between mstart, mend and remove them. This
- * might lead to split and split ranges are put in cmem->ranges[] array
- */
-static int elf_header_exclude_ranges(struct crash_mem *cmem)
+int arch_crash_exclude_ranges(struct crash_mem *cmem)
{
- int ret = 0;
- int i;
-
/* Exclude the low 1M because it is always reserved */
- ret = crash_exclude_mem_range(cmem, 0, SZ_1M - 1);
- if (ret)
- return ret;
-
- /* Exclude crashkernel region */
- ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
- if (ret)
- return ret;
-
- if (crashk_low_res.end)
- ret = crash_exclude_mem_range(cmem, crashk_low_res.start,
- crashk_low_res.end);
- if (ret)
- return ret;
-
- for (i = 0; i < crashk_cma_cnt; ++i) {
- ret = crash_exclude_mem_range(cmem, crashk_cma_ranges[i].start,
- crashk_cma_ranges[i].end);
- if (ret)
- return ret;
- }
-
- return 0;
+ return crash_exclude_mem_range(cmem, 0, SZ_1M - 1);
}
static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg)
@@ -237,35 +195,9 @@ static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg)
return 0;
}
-/* Prepare elf headers. Return addr and size */
-static int prepare_elf_headers(void **addr, unsigned long *sz,
- unsigned long *nr_mem_ranges)
+int arch_crash_populate_cmem(struct crash_mem *cmem)
{
- struct crash_mem *cmem;
- int ret;
-
- cmem = fill_up_crash_elf_data();
- if (!cmem)
- return -ENOMEM;
-
- ret = walk_system_ram_res(0, -1, cmem, prepare_elf64_ram_headers_callback);
- if (ret)
- goto out;
-
- /* Exclude unwanted mem ranges */
- ret = elf_header_exclude_ranges(cmem);
- if (ret)
- goto out;
-
- /* Return the computed number of memory ranges, for hotplug usage */
- *nr_mem_ranges = cmem->nr_ranges;
-
- /* By default prepare 64bit headers */
- ret = crash_prepare_elf64_headers(cmem, IS_ENABLED(CONFIG_X86_64), addr, sz);
-
-out:
- vfree(cmem);
- return ret;
+ return walk_system_ram_res(0, -1, cmem, prepare_elf64_ram_headers_callback);
}
#endif
@@ -423,14 +355,11 @@ int crash_load_segments(struct kimage *image)
.buf_max = ULONG_MAX, .top_down = false };
/* Prepare elf headers and add a segment */
- get_online_mems();
- ret = prepare_elf_headers(&kbuf.buffer, &kbuf.bufsz, &pnum);
- if (ret) {
- put_online_mems();
+ ret = crash_prepare_headers_locked(IS_ENABLED(CONFIG_X86_64), &kbuf.buffer,
+ &kbuf.bufsz, &pnum);
+ if (ret)
return ret;
- }
- put_online_mems();
image->elf_headers = kbuf.buffer;
image->elf_headers_sz = kbuf.bufsz;
kbuf.memsz = kbuf.bufsz;
@@ -520,7 +449,6 @@ unsigned int arch_crash_get_elfcorehdr_size(void)
void arch_crash_handle_hotplug_event(struct kimage *image, void *arg)
{
void *elfbuf = NULL, *old_elfcorehdr;
- unsigned long nr_mem_ranges;
unsigned long mem, memsz;
unsigned long elfsz = 0;
@@ -538,7 +466,7 @@ void arch_crash_handle_hotplug_event(struct kimage *image, void *arg)
* Create the new elfcorehdr reflecting the changes to CPU and/or
* memory resources.
*/
- if (prepare_elf_headers(&elfbuf, &elfsz, &nr_mem_ranges)) {
+ if (crash_prepare_headers(IS_ENABLED(CONFIG_X86_64), &elfbuf, &elfsz, NULL)) {
pr_err("unable to create new elfcorehdr");
goto out;
}
--
2.34.1
^ permalink raw reply related
* [PATCH v14 10/17] arm64: kexec_file: Use crash_prepare_headers() helper to simplify code
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
Use the newly introduced crash_prepare_headers() function to replace
the existing prepare_elf_headers(), allocate cmem and exclude crash
kernel memory in the crash core, which reduce code duplication.
Only the following two architecture functions need to be implemented:
- arch_get_system_nr_ranges(). Use for_each_mem_range() to traverse
and pre-count the max number of memory ranges.
- arch_crash_populate_cmem(). Use for_each_mem_range to traverse
and collect the memory ranges and fills them into cmem.
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Acked-by: Baoquan He <bhe@redhat.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/arm64/kernel/kexec_image.c | 6 +---
arch/arm64/kernel/machine_kexec_file.c | 44 ++++++++------------------
2 files changed, 14 insertions(+), 36 deletions(-)
diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
index 884e446f08e3..770a4c7bf573 100644
--- a/arch/arm64/kernel/kexec_image.c
+++ b/arch/arm64/kernel/kexec_image.c
@@ -12,7 +12,6 @@
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/kexec.h>
-#include <linux/memory_hotplug.h>
#include <linux/pe.h>
#include <linux/string.h>
#include <asm/byteorder.h>
@@ -97,14 +96,11 @@ static void *image_load(struct kimage *image,
#ifdef CONFIG_CRASH_DUMP
if (image->type == KEXEC_TYPE_CRASH) {
- get_online_mems();
- ret = prepare_elf_headers(&headers, &headers_sz);
+ ret = crash_prepare_headers_locked(true, &headers, &headers_sz, NULL);
if (ret) {
pr_err("Preparing elf core header failed\n");
- put_online_mems();
return ERR_PTR(ret);
}
- put_online_mems();
image->elf_headers = headers;
image->elf_headers_sz = headers_sz;
}
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index c0ace89ded92..66fbfbaec1c6 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -40,51 +40,33 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
}
#ifdef CONFIG_CRASH_DUMP
-int prepare_elf_headers(void **addr, unsigned long *sz)
+unsigned int arch_get_system_nr_ranges(void)
{
- struct crash_mem *cmem;
- unsigned int nr_ranges;
- int ret;
- u64 i;
+ unsigned int nr_ranges = 2; /* for exclusion of crashkernel region */
phys_addr_t start, end;
+ u64 i;
- nr_ranges = 2; /* for exclusion of crashkernel region */
for_each_mem_range(i, &start, &end)
nr_ranges++;
- cmem = kmalloc_flex(*cmem, ranges, nr_ranges);
- if (!cmem)
- return -ENOMEM;
+ return nr_ranges;
+}
+
+int arch_crash_populate_cmem(struct crash_mem *cmem)
+{
+ phys_addr_t start, end;
+ u64 i;
- cmem->max_nr_ranges = nr_ranges;
- cmem->nr_ranges = 0;
for_each_mem_range(i, &start, &end) {
- if (WARN_ON_ONCE(cmem->nr_ranges >= cmem->max_nr_ranges)) {
- ret = -EAGAIN;
- goto out;
- }
+ if (WARN_ON_ONCE(cmem->nr_ranges >= cmem->max_nr_ranges))
+ return -EAGAIN;
cmem->ranges[cmem->nr_ranges].start = start;
cmem->ranges[cmem->nr_ranges].end = end - 1;
cmem->nr_ranges++;
}
- /* Exclude crashkernel region */
- ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
- if (ret)
- goto out;
-
- if (crashk_low_res.end) {
- ret = crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end);
- if (ret)
- goto out;
- }
-
- ret = crash_prepare_elf64_headers(cmem, true, addr, sz);
-
-out:
- kfree(cmem);
- return ret;
+ return 0;
}
#endif
--
2.34.1
^ permalink raw reply related
* [PATCH v14 09/17] crash: Add crash_prepare_headers() to exclude crash kernel memory
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
The crash memory alloc, and the exclude of crashk_res, crashk_low_res
and crashk_cma memory are almost identical across different architectures,
handling them in the crash core would eliminate a lot of duplication, so
add crash_prepare_headers() helper to handle them in the common code.
To achieve the above goal, three architecture-specific functions are
introduced:
- arch_get_system_nr_ranges(). Pre-counts the max number of memory ranges.
- arch_crash_populate_cmem(). Collects the memory ranges and fills them
into cmem.
- arch_crash_exclude_ranges(). Architecture's additional crash memory
ranges exclusion, defaulting to empty.
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Acked-by: Baoquan He <bhe@redhat.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
include/linux/crash_core.h | 7 +++
kernel/crash_core.c | 95 ++++++++++++++++++++++++++++++++++++--
2 files changed, 99 insertions(+), 3 deletions(-)
diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h
index c1dee3f971a9..d69c4c7c1f5e 100644
--- a/include/linux/crash_core.h
+++ b/include/linux/crash_core.h
@@ -59,6 +59,10 @@ extern int crash_exclude_mem_range(struct crash_mem *mem,
unsigned long long mend);
extern int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map,
void **addr, unsigned long *sz);
+extern int crash_prepare_headers(int need_kernel_map, void **addr,
+ unsigned long *sz, unsigned long *nr_mem_ranges);
+extern int crash_prepare_headers_locked(int need_kernel_map, void **addr,
+ unsigned long *sz, unsigned long *nr_mem_ranges);
struct kimage;
struct kexec_segment;
@@ -76,6 +80,9 @@ 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);
+extern unsigned int arch_get_system_nr_ranges(void);
+extern int arch_crash_populate_cmem(struct crash_mem *cmem);
+extern int arch_crash_exclude_ranges(struct crash_mem *cmem);
#else /* !CONFIG_CRASH_DUMP*/
struct pt_regs;
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index 4f21fc3b108b..e84f3b63e79d 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -13,6 +13,7 @@
#include <linux/sizes.h>
#include <linux/kexec.h>
#include <linux/memory.h>
+#include <linux/memory_hotplug.h>
#include <linux/mm.h>
#include <linux/cpuhotplug.h>
#include <linux/memblock.h>
@@ -168,9 +169,6 @@ static inline resource_size_t crash_resource_size(const struct resource *res)
return !res->end ? 0 : resource_size(res);
}
-
-
-
int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map,
void **addr, unsigned long *sz)
{
@@ -272,6 +270,97 @@ int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map,
return 0;
}
+static struct crash_mem *alloc_cmem(unsigned int nr_ranges)
+{
+ struct crash_mem *cmem;
+
+ cmem = kvzalloc_flex(*cmem, ranges, nr_ranges);
+ if (!cmem)
+ return NULL;
+
+ cmem->max_nr_ranges = nr_ranges;
+ return cmem;
+}
+
+unsigned int __weak arch_get_system_nr_ranges(void) { return 0; }
+int __weak arch_crash_populate_cmem(struct crash_mem *cmem) { return -1; }
+int __weak arch_crash_exclude_ranges(struct crash_mem *cmem) { return 0; }
+
+static int crash_exclude_core_ranges(struct crash_mem *cmem)
+{
+ int ret, i;
+
+ /* Exclude crashkernel region */
+ ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
+ if (ret)
+ return ret;
+
+ if (crashk_low_res.end) {
+ ret = crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end);
+ if (ret)
+ return ret;
+ }
+
+ for (i = 0; i < crashk_cma_cnt; ++i) {
+ ret = crash_exclude_mem_range(cmem, crashk_cma_ranges[i].start,
+ crashk_cma_ranges[i].end);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+int crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz,
+ unsigned long *nr_mem_ranges)
+{
+ unsigned int max_nr_ranges;
+ struct crash_mem *cmem;
+ int ret;
+
+ max_nr_ranges = arch_get_system_nr_ranges();
+ if (!max_nr_ranges)
+ return -ENOMEM;
+
+ cmem = alloc_cmem(max_nr_ranges);
+ if (!cmem)
+ return -ENOMEM;
+
+ ret = arch_crash_populate_cmem(cmem);
+ if (ret)
+ goto out;
+
+ ret = crash_exclude_core_ranges(cmem);
+ if (ret)
+ goto out;
+
+ ret = arch_crash_exclude_ranges(cmem);
+ if (ret)
+ goto out;
+
+ /* Return the computed number of memory ranges, for hotplug usage */
+ if (nr_mem_ranges)
+ *nr_mem_ranges = cmem->nr_ranges;
+
+ ret = crash_prepare_elf64_headers(cmem, need_kernel_map, addr, sz);
+
+out:
+ kvfree(cmem);
+ return ret;
+}
+
+int crash_prepare_headers_locked(int need_kernel_map, void **addr, unsigned long *sz,
+ unsigned long *nr_mem_ranges)
+{
+ int ret;
+
+ get_online_mems();
+ ret = crash_prepare_headers(need_kernel_map, addr, sz, nr_mem_ranges);
+ put_online_mems();
+
+ return ret;
+}
+
/**
* crash_exclude_mem_range - exclude a mem range for existing ranges
* @mem: mem->range contains an array of ranges sorted in ascending order
--
2.34.1
^ permalink raw reply related
* [PATCH v14 08/17] LoongArch: kexec: Fix potential buffer overflow in prepare_elf_headers()
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
Sashiko AI code review pointed out there is a TOCTOU (Time-of-Check to
Time-of-Use) race condition in prepare_elf_headers() between the initial
pass that counts System RAM ranges and the second pass that populates them.
If a memory hotplug event occurs between these two steps, the number of
memory regions may increase, causing an out-of-bounds write to
the cmem->ranges[] array.
Directly introducing get_online_mems() inside prepare_elf_headers() would
trigger an immediate recursive read-after-write deadlock when invoked by
the runtime hotplug notification path (which already holds the hotplug
write lock).
To eliminate the TOCTOU window safely without deadlock risks, move the
get_online_mems() read lock to the top-level architecture image loaders.
Since these top-level loaders are strictly executed on the initial system
call path and are never re-entered by the runtime hotplug notifier, this
approach physically isolates the locking contexts. The system memory ranges
are forced to be statically frozen during the entire layout generation,
eradicating the buffer overflow vulnerability.
Cc: Youling Tang <tangyouling@kylinos.cn>
Cc: Huacai Chen <chenhuacai@loongson.cn>
Cc: WANG Xuerui <kernel@xen0n.name>
Cc: stable@vger.kernel.org
Fixes: 1bcca8620a91 ("LoongArch: Add crash dump support for kexec_file")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/loongarch/kernel/machine_kexec_file.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c
index 5584b798ba46..2a1a6124f043 100644
--- a/arch/loongarch/kernel/machine_kexec_file.c
+++ b/arch/loongarch/kernel/machine_kexec_file.c
@@ -14,6 +14,7 @@
#include <linux/kernel.h>
#include <linux/kexec.h>
#include <linux/memblock.h>
+#include <linux/memory_hotplug.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/types.h>
@@ -75,6 +76,11 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
cmem->max_nr_ranges = nr_ranges;
cmem->nr_ranges = 0;
for_each_mem_range(i, &start, &end) {
+ if (WARN_ON_ONCE(cmem->nr_ranges >= cmem->max_nr_ranges)) {
+ ret = -EAGAIN;
+ goto out;
+ }
+
cmem->ranges[cmem->nr_ranges].start = start;
cmem->ranges[cmem->nr_ranges].end = end - 1;
cmem->nr_ranges++;
@@ -163,12 +169,15 @@ int load_other_segments(struct kimage *image,
void *headers;
unsigned long headers_sz;
+ get_online_mems();
ret = prepare_elf_headers(&headers, &headers_sz);
if (ret < 0) {
+ put_online_mems();
pr_err("Preparing elf core header failed\n");
goto out_err;
}
+ put_online_mems();
kbuf.buffer = headers;
kbuf.bufsz = headers_sz;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
--
2.34.1
^ permalink raw reply related
* [PATCH v14 07/17] riscv: kexec_file: Fix potential buffer overflow in prepare_elf_headers()
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
Sashiko AI code review pointed out there is a TOCTOU (Time-of-Check to
Time-of-Use) race condition in prepare_elf_headers() between the initial
pass that counts System RAM ranges and the second pass that populates them.
If a memory hotplug event occurs between these two steps, the number of
memory regions may increase, causing an out-of-bounds write to
the cmem->ranges[] array.
Directly introducing get_online_mems() inside prepare_elf_headers() would
trigger an immediate recursive read-after-write deadlock when invoked by
the runtime hotplug notification path (which already holds the hotplug
write lock).
To eliminate the TOCTOU window safely without deadlock risks, move the
get_online_mems() read lock to the top-level architecture image loaders.
Since these top-level loaders are strictly executed on the initial system
call path and are never re-entered by the runtime hotplug notifier, this
approach physically isolates the locking contexts. The system memory ranges
are forced to be statically frozen during the entire layout generation,
eradicating the buffer overflow vulnerability.
Cc: Paul Walmsley <pjw@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: songshuaishuai@tinylab.org
Cc: bjorn@rivosinc.com
Cc: leitao@debian.org
Fixes: 8acea455fafa ("RISC-V: Support for kexec_file on panic")
Reviewed-by: Guo Ren <guoren@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/riscv/kernel/machine_kexec_file.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
index 3f7766057cac..a88362dfbd89 100644
--- a/arch/riscv/kernel/machine_kexec_file.c
+++ b/arch/riscv/kernel/machine_kexec_file.c
@@ -8,6 +8,7 @@
*/
#include <linux/kexec.h>
#include <linux/elf.h>
+#include <linux/memory_hotplug.h>
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/libfdt.h>
@@ -48,6 +49,9 @@ static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg)
{
struct crash_mem *cmem = arg;
+ if (WARN_ON_ONCE(cmem->nr_ranges >= cmem->max_nr_ranges))
+ return -EAGAIN;
+
cmem->ranges[cmem->nr_ranges].start = res->start;
cmem->ranges[cmem->nr_ranges].end = res->end;
cmem->nr_ranges++;
@@ -281,12 +285,15 @@ int load_extra_segments(struct kimage *image, unsigned long kernel_start,
if (image->type == KEXEC_TYPE_CRASH) {
void *headers;
unsigned long headers_sz;
+ get_online_mems();
ret = prepare_elf_headers(&headers, &headers_sz);
if (ret) {
+ put_online_mems();
pr_err("Preparing elf core header failed\n");
goto out;
}
+ put_online_mems();
kbuf.buffer = headers;
kbuf.bufsz = headers_sz;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
--
2.34.1
^ permalink raw reply related
* [PATCH v14 06/17] arm64: kexec_file: Fix potential buffer overflow in prepare_elf_headers()
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
Sashiko AI code review pointed out there is a TOCTOU (Time-of-Check to
Time-of-Use) race condition in prepare_elf_headers() between the initial
pass that counts System RAM ranges and the second pass that populates them.
If a memory hotplug event occurs between these two steps, the number of
memory regions may increase, causing an out-of-bounds write to
the cmem->ranges[] array.
Directly introducing get_online_mems() inside prepare_elf_headers() would
trigger an immediate recursive read-after-write deadlock when invoked by
the runtime hotplug notification path (which already holds the hotplug
write lock).
To eliminate the TOCTOU window safely without deadlock risks, move the
get_online_mems() read lock to the top-level architecture image loaders.
Since these top-level loaders are strictly executed on the initial system
call path and are never re-entered by the runtime hotplug notifier, this
approach physically isolates the locking contexts. The system memory ranges
are forced to be statically frozen during the entire layout generation,
eradicating the buffer overflow vulnerability.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Breno Leitao <leitao@debian.org>
Cc: stable@vger.kernel.org
Fixes: 3751e728cef2 ("arm64: kexec_file: add crash dump support")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/arm64/kernel/kexec_image.c | 4 ++++
arch/arm64/kernel/machine_kexec_file.c | 5 +++++
2 files changed, 9 insertions(+)
diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
index 79efeaeb71e9..884e446f08e3 100644
--- a/arch/arm64/kernel/kexec_image.c
+++ b/arch/arm64/kernel/kexec_image.c
@@ -12,6 +12,7 @@
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/kexec.h>
+#include <linux/memory_hotplug.h>
#include <linux/pe.h>
#include <linux/string.h>
#include <asm/byteorder.h>
@@ -96,11 +97,14 @@ static void *image_load(struct kimage *image,
#ifdef CONFIG_CRASH_DUMP
if (image->type == KEXEC_TYPE_CRASH) {
+ get_online_mems();
ret = prepare_elf_headers(&headers, &headers_sz);
if (ret) {
pr_err("Preparing elf core header failed\n");
+ put_online_mems();
return ERR_PTR(ret);
}
+ put_online_mems();
image->elf_headers = headers;
image->elf_headers_sz = headers_sz;
}
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index daf81a873bbd..c0ace89ded92 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -59,6 +59,11 @@ int prepare_elf_headers(void **addr, unsigned long *sz)
cmem->max_nr_ranges = nr_ranges;
cmem->nr_ranges = 0;
for_each_mem_range(i, &start, &end) {
+ if (WARN_ON_ONCE(cmem->nr_ranges >= cmem->max_nr_ranges)) {
+ ret = -EAGAIN;
+ goto out;
+ }
+
cmem->ranges[cmem->nr_ranges].start = start;
cmem->ranges[cmem->nr_ranges].end = end - 1;
cmem->nr_ranges++;
--
2.34.1
^ permalink raw reply related
* [PATCH v14 05/17] x86/kexec: Fix potential buffer overflow in prepare_elf_headers()
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
Sashiko AI code review pointed out a there is a TOCTOU (Time-of-Check to
Time-of-Use) race condition in prepare_elf_headers() between the initial
pass that counts System RAM ranges and the second pass that populates them.
If a memory hotplug event occurs between these two steps, the number of
memory regions may increase, causing an out-of-bounds write to
the cmem->ranges[] array.
Directly introducing get_online_mems() inside prepare_elf_headers() would
trigger an immediate recursive read-after-write deadlock when invoked by
the runtime hotplug notification path (which already holds the hotplug
write lock).
To eliminate the TOCTOU window safely without deadlock risks, move the
get_online_mems() read lock to the top-level architecture image loaders.
Since these top-level loaders are strictly executed on the initial system
call path and are never re-entered by the runtime hotplug notifier, this
approach physically isolates the locking contexts. The system memory ranges
are forced to be statically frozen during the entire layout generation,
eradicating the buffer overflow vulnerability.
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: stable@vger.kernel.org
Fixes: 8d5f894a3108 ("x86: kexec_file: lift CRASH_MAX_RANGES limit on crash_mem buffer")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/x86/kernel/crash.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index cd796818d94d..f319308b06ee 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -25,6 +25,7 @@
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/memblock.h>
+#include <linux/memory_hotplug.h>
#include <asm/bootparam.h>
#include <asm/processor.h>
@@ -226,6 +227,9 @@ static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg)
{
struct crash_mem *cmem = arg;
+ if (WARN_ON_ONCE(cmem->nr_ranges >= cmem->max_nr_ranges))
+ return -EAGAIN;
+
cmem->ranges[cmem->nr_ranges].start = res->start;
cmem->ranges[cmem->nr_ranges].end = res->end;
cmem->nr_ranges++;
@@ -419,10 +423,14 @@ int crash_load_segments(struct kimage *image)
.buf_max = ULONG_MAX, .top_down = false };
/* Prepare elf headers and add a segment */
+ get_online_mems();
ret = prepare_elf_headers(&kbuf.buffer, &kbuf.bufsz, &pnum);
- if (ret)
+ if (ret) {
+ put_online_mems();
return ret;
+ }
+ put_online_mems();
image->elf_headers = kbuf.buffer;
image->elf_headers_sz = kbuf.bufsz;
kbuf.memsz = kbuf.bufsz;
--
2.34.1
^ permalink raw reply related
* [PATCH v14 04/17] arm64: kexec: Fix image->elf_headers memory leak during retry loop
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
Sashiko AI code review pointed out a potential memory leak of
image->elf_headers when load_other_segments() fails on error paths.
In the arm64 kexec_file file-load path, kexec_image.c runs a retry loop
calling kexec_add_buffer() to find a suitable location for the kernel
segment. On each iteration, load_other_segments() is invoked to allocate
and populate alternative segments such as initrd, DTB, and ELF headers.
However, if a placement or allocation failure occurs later in
load_other_segments() (e.g., when adding initrd or dtb), the execution
jumps to the out_err label. While this path restores image->nr_segments
via orig_segments, it returns an error back to the caller without freeing
the previously allocated image->elf_headers vmalloc buffer.
As a result, the retry loop in image_load() unconditionally allocates
new ELF headers on the next iteration and overwrites image->elf_headers,
permanently leaking the memory blocks allocated in previous iterations.
To fix this, decouple the ELF header allocation from the target-seeking
retry loop. Since the contents and size of ELF headers only depend on
the host memory layout and do not change with the kernel's physical
placement, move prepare_elf_headers() completely outside and prior to
the while retry loop in image_load().
Concurrently, remove the prepare_elf_headers() call from inside
load_other_segments() and have it directly reuse the single, pre-allocated
image->elf_headers. Also, ensure that image->nr_segments is explicitly
rolled back to kernel_segment_number on retry failures to safely discard
stale segment tracking state.
This optimization eliminates redundant memory allocation/deallocation
overhead during kexec placement retries and eradicates the Use-After-Free
and memory leak risk.
Fixes: 108aa503657e ("arm64: kexec_file: try more regions if loading segments fails")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/arm64/include/asm/kexec.h | 3 ++-
arch/arm64/kernel/kexec_image.c | 22 ++++++++++++++++++++--
arch/arm64/kernel/machine_kexec_file.c | 16 +++-------------
3 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
index 892e5bebda95..cc2f36b1b0d4 100644
--- a/arch/arm64/include/asm/kexec.h
+++ b/arch/arm64/include/asm/kexec.h
@@ -127,7 +127,8 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image);
extern int load_other_segments(struct kimage *image,
unsigned long kernel_load_addr, unsigned long kernel_size,
char *initrd, unsigned long initrd_len,
- char *cmdline);
+ char *cmdline, void *headers, unsigned long headers_size);
+extern int prepare_elf_headers(void **addr, unsigned long *sz);
#endif
#endif /* __ASSEMBLER__ */
diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
index b70f4df15a1a..79efeaeb71e9 100644
--- a/arch/arm64/kernel/kexec_image.c
+++ b/arch/arm64/kernel/kexec_image.c
@@ -44,6 +44,11 @@ static void *image_load(struct kimage *image,
struct kexec_buf kbuf = {};
unsigned long text_offset, kernel_segment_number;
struct kexec_segment *kernel_segment;
+#ifdef CONFIG_CRASH_DUMP
+ /* load elf core header */
+ unsigned long headers_sz;
+ void *headers;
+#endif
int ret;
/*
@@ -89,6 +94,18 @@ static void *image_load(struct kimage *image,
kernel_segment_number = image->nr_segments;
+#ifdef CONFIG_CRASH_DUMP
+ if (image->type == KEXEC_TYPE_CRASH) {
+ ret = prepare_elf_headers(&headers, &headers_sz);
+ if (ret) {
+ pr_err("Preparing elf core header failed\n");
+ return ERR_PTR(ret);
+ }
+ image->elf_headers = headers;
+ image->elf_headers_sz = headers_sz;
+ }
+#endif
+
/*
* The location of the kernel segment may make it impossible to satisfy
* the other segment requirements, so we try repeatedly to find a
@@ -99,7 +116,8 @@ static void *image_load(struct kimage *image,
kernel_segment = &image->segment[kernel_segment_number];
ret = load_other_segments(image, kernel_segment->mem,
kernel_segment->memsz, initrd,
- initrd_len, cmdline);
+ initrd_len, cmdline,
+ headers, headers_sz);
if (!ret)
break;
@@ -107,7 +125,7 @@ static void *image_load(struct kimage *image,
* We couldn't find space for the other segments; erase the
* kernel segment and try the next available hole.
*/
- image->nr_segments -= 1;
+ image->nr_segments = kernel_segment_number;
kbuf.buf_min = kernel_segment->mem + kernel_segment->memsz;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
}
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index e31fabed378a..daf81a873bbd 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -40,7 +40,7 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
}
#ifdef CONFIG_CRASH_DUMP
-static int prepare_elf_headers(void **addr, unsigned long *sz)
+int prepare_elf_headers(void **addr, unsigned long *sz)
{
struct crash_mem *cmem;
unsigned int nr_ranges;
@@ -92,7 +92,8 @@ int load_other_segments(struct kimage *image,
unsigned long kernel_load_addr,
unsigned long kernel_size,
char *initrd, unsigned long initrd_len,
- char *cmdline)
+ char *cmdline, void *headers,
+ unsigned long headers_sz)
{
struct kexec_buf kbuf = {};
void *dtb = NULL;
@@ -105,16 +106,7 @@ int load_other_segments(struct kimage *image,
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(&headers, &headers_sz);
- if (ret) {
- pr_err("Preparing elf core header failed\n");
- goto out_err;
- }
-
kbuf.buffer = headers;
kbuf.bufsz = headers_sz;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
@@ -128,9 +120,7 @@ int load_other_segments(struct kimage *image,
vfree(headers);
goto out_err;
}
- image->elf_headers = headers;
image->elf_load_addr = kbuf.mem;
- image->elf_headers_sz = headers_sz;
kexec_dprintk("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
--
2.34.1
^ permalink raw reply related
* [PATCH v14 03/17] powerpc/crash: sort crash memory ranges before preparing elfcorehdr
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
From: Sourabh Jain <sourabhjain@linux.ibm.com>
During a memory hot-remove event, the elfcorehdr is rebuilt to exclude
the removed memory. While updating the crash memory ranges for this
operation, the crash memory ranges array can become unsorted. This
happens because remove_mem_range() may split a memory range into two
parts and append the higher-address part as a separate range at the end
of the array.
So far, no issues have been observed due to the unsorted crash memory
ranges. However, this could lead to problems once crash memory range
removal is handled by generic code, as introduced in the upcoming
patches in this series.
Currently, powerpc uses a platform-specific function,
remove_mem_range(), to exclude hot-removed memory from the crash memory
ranges. This function performs the same task as the generic
crash_exclude_mem_range() in crash_core.c. The generic helper also
ensures that the crash memory ranges remain sorted. So remove the
redundant powerpc-specific implementation and instead call
crash_exclude_mem_range_guarded() (which internally calls
crash_exclude_mem_range()) to exclude the hot-removed memory ranges.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan he <bhe@redhat.com>
Cc: Jinjie Ruan <ruanjinjie@huawei.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
Cc: linux-kernel@vger.kernel.org
Acked-by: Baoquan He <bhe@redhat.com>
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/powerpc/include/asm/kexec_ranges.h | 4 +-
arch/powerpc/kexec/crash.c | 5 +-
arch/powerpc/kexec/ranges.c | 87 +------------------------
3 files changed, 7 insertions(+), 89 deletions(-)
diff --git a/arch/powerpc/include/asm/kexec_ranges.h b/arch/powerpc/include/asm/kexec_ranges.h
index 14055896cbcb..ad95e3792d10 100644
--- a/arch/powerpc/include/asm/kexec_ranges.h
+++ b/arch/powerpc/include/asm/kexec_ranges.h
@@ -7,7 +7,9 @@
void sort_memory_ranges(struct crash_mem *mrngs, bool merge);
struct crash_mem *realloc_mem_ranges(struct crash_mem **mem_ranges);
int add_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size);
-int remove_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size);
+int crash_exclude_mem_range_guarded(struct crash_mem **mem_ranges,
+ unsigned long long mstart,
+ unsigned long long mend);
int get_exclude_memory_ranges(struct crash_mem **mem_ranges);
int get_reserved_memory_ranges(struct crash_mem **mem_ranges);
int get_crash_memory_ranges(struct crash_mem **mem_ranges);
diff --git a/arch/powerpc/kexec/crash.c b/arch/powerpc/kexec/crash.c
index a520f851c3a6..d634db67becc 100644
--- a/arch/powerpc/kexec/crash.c
+++ b/arch/powerpc/kexec/crash.c
@@ -493,7 +493,7 @@ static void update_crash_elfcorehdr(struct kimage *image, struct memory_notify *
struct crash_mem *cmem = NULL;
struct kexec_segment *ksegment;
void *ptr, *mem, *elfbuf = NULL;
- unsigned long elfsz, memsz, base_addr, size;
+ unsigned long elfsz, memsz, base_addr, size, end;
ksegment = &image->segment[image->elfcorehdr_index];
mem = (void *) ksegment->mem;
@@ -512,7 +512,8 @@ static void update_crash_elfcorehdr(struct kimage *image, struct memory_notify *
if (image->hp_action == KEXEC_CRASH_HP_REMOVE_MEMORY) {
base_addr = PFN_PHYS(mn->start_pfn);
size = mn->nr_pages * PAGE_SIZE;
- ret = remove_mem_range(&cmem, base_addr, size);
+ end = base_addr + size - 1;
+ ret = crash_exclude_mem_range_guarded(&cmem, base_addr, end);
if (ret) {
pr_err("Failed to remove hot-unplugged memory from crash memory ranges\n");
goto out;
diff --git a/arch/powerpc/kexec/ranges.c b/arch/powerpc/kexec/ranges.c
index 867135560e5c..6c58bcc3e130 100644
--- a/arch/powerpc/kexec/ranges.c
+++ b/arch/powerpc/kexec/ranges.c
@@ -553,7 +553,7 @@ int get_usable_memory_ranges(struct crash_mem **mem_ranges)
#endif /* CONFIG_KEXEC_FILE */
#ifdef CONFIG_CRASH_DUMP
-static int crash_exclude_mem_range_guarded(struct crash_mem **mem_ranges,
+int crash_exclude_mem_range_guarded(struct crash_mem **mem_ranges,
unsigned long long mstart,
unsigned long long mend)
{
@@ -641,89 +641,4 @@ int get_crash_memory_ranges(struct crash_mem **mem_ranges)
pr_err("Failed to setup crash memory ranges\n");
return ret;
}
-
-/**
- * remove_mem_range - Removes the given memory range from the range list.
- * @mem_ranges: Range list to remove the memory range to.
- * @base: Base address of the range to remove.
- * @size: Size of the memory range to remove.
- *
- * (Re)allocates memory, if needed.
- *
- * Returns 0 on success, negative errno on error.
- */
-int remove_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size)
-{
- u64 end;
- int ret = 0;
- unsigned int i;
- u64 mstart, mend;
- struct crash_mem *mem_rngs = *mem_ranges;
-
- if (!size)
- return 0;
-
- /*
- * Memory range are stored as start and end address, use
- * the same format to do remove operation.
- */
- end = base + size - 1;
-
- for (i = 0; i < mem_rngs->nr_ranges; i++) {
- mstart = mem_rngs->ranges[i].start;
- mend = mem_rngs->ranges[i].end;
-
- /*
- * Memory range to remove is not part of this range entry
- * in the memory range list
- */
- if (!(base >= mstart && end <= mend))
- continue;
-
- /*
- * Memory range to remove is equivalent to this entry in the
- * memory range list. Remove the range entry from the list.
- */
- if (base == mstart && end == mend) {
- for (; i < mem_rngs->nr_ranges - 1; i++) {
- mem_rngs->ranges[i].start = mem_rngs->ranges[i+1].start;
- mem_rngs->ranges[i].end = mem_rngs->ranges[i+1].end;
- }
- mem_rngs->nr_ranges--;
- goto out;
- }
- /*
- * Start address of the memory range to remove and the
- * current memory range entry in the list is same. Just
- * move the start address of the current memory range
- * entry in the list to end + 1.
- */
- else if (base == mstart) {
- mem_rngs->ranges[i].start = end + 1;
- goto out;
- }
- /*
- * End address of the memory range to remove and the
- * current memory range entry in the list is same.
- * Just move the end address of the current memory
- * range entry in the list to base - 1.
- */
- else if (end == mend) {
- mem_rngs->ranges[i].end = base - 1;
- goto out;
- }
- /*
- * Memory range to remove is not at the edge of current
- * memory range entry. Split the current memory entry into
- * two half.
- */
- else {
- size = mem_rngs->ranges[i].end - end + 1;
- mem_rngs->ranges[i].end = base - 1;
- ret = add_mem_range(mem_ranges, end + 1, size);
- }
- }
-out:
- return ret;
-}
#endif /* CONFIG_CRASH_DUMP */
--
2.34.1
^ permalink raw reply related
* [PATCH v14 02/17] powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr()
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
In get_crash_memory_ranges(), if crash_exclude_mem_range() failed
after realloc_mem_ranges() has successfully allocated the cmem
memory, it just returns an error but leaves cmem pointing to
the allocated memory, nor is it freed in the caller
update_crash_elfcorehdr(), which cause a memory leak, goto out
to free the cmem.
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Fixes: 849599b702ef ("powerpc/crash: add crash memory hotplug support")
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/powerpc/kexec/crash.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/powerpc/kexec/crash.c b/arch/powerpc/kexec/crash.c
index e6539f213b3d..a520f851c3a6 100644
--- a/arch/powerpc/kexec/crash.c
+++ b/arch/powerpc/kexec/crash.c
@@ -502,7 +502,7 @@ static void update_crash_elfcorehdr(struct kimage *image, struct memory_notify *
ret = get_crash_memory_ranges(&cmem);
if (ret) {
pr_err("Failed to get crash mem range\n");
- return;
+ goto out;
}
/*
--
2.34.1
^ permalink raw reply related
* [PATCH v14 00/17] arm64/riscv: Add support for crashkernel CMA reservation
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
The crash memory allocation, and the exclude of crashk_res, crashk_low_res
and crashk_cma memory are almost identical across different architectures,
This patch set handle them in crash core in a general way, which eliminate
a lot of duplication code.
And add support for crashkernel CMA reservation for arm64 and riscv.
Also add support for arm64 crash hotplug.
This patch set is rebased on v7.1-rc1.
Basic second kernel boot test were performed on QEMU platforms for x86,
ARM64 and RISC-V architectures with the following parameters:
"cma=256M crashkernel=4G crashkernel=64M,cma"
For first kernel, there will be such log:
# dmesg | grep crash
[ 0.000000] crashkernel low memory reserved: 0xe8000000 - 0xf0000000 (128 MB)
[ 0.000000] crashkernel reserved: 0x000000023e600000 - 0x000000033e600000 (4096 MB)
[ 0.000000] crashkernel CMA reserved: 64 MB in 1 ranges
# dmesg | grep cma
[ 0.000000] cma: Reserved 256 MiB at 0x00000000f0000000
[ 0.000000] cma: Reserved 64 MiB at 0x0000000100000000
For second kernel, there will be such log:
[ 0.000000] OF: fdt: Looking for usable-memory-range property...
[ 0.000000] OF: fdt: cap_mem_regions[0]: base=0x000000023e600000, size=0x0000000100000000
[ 0.000000] OF: fdt: cap_mem_regions[1]: base=0x00000000e8000000, size=0x0000000008000000
[ 0.000000] OF: fdt: cap_mem_regions[2]: base=0x0000000100000000, size=0x0000000004000000
Changes in v14:
- Fix image->elf_headers memory leak during retry loop for arm64 as Sashiko
AI code review pointed out.
- Solve the hotplug notifier arch_crash_handle_hotplug_event() AA
self-deadlock problem as Sashiko AI code review pointed out.
- Fix the TOCTOU issue in prepare_elf_headers() by get_online_mems().
- -ENOMEM -> -EAGAIN as Breno suggested.
- Add support for arm64 crash hotplug.
- Link to v13: https://lore.kernel.org/all/20260511030454.1730881-1-ruanjinjie@huawei.com/
Changes in v13:
- Rebased on v7.1-rc1.
- Update the commit message.
- Add Reviewed-by.
- Link to v12: https://lore.kernel.org/all/20260402072701.628293-1-ruanjinjie@huawei.com/
Changes in v12:
- Remove the unused "nr_mem_ranges" for x86.
- Add "Fix crashk_low_res not exclude bug" test log.
- Provide a separate patch for each architecture for using
crash_prepare_headers(), which will make the review more convenient.
- Add Reviewed-by and Tested-by.
- Link to v11: https://lore.kernel.org/all/20260328074013.3589544-1-ruanjinjie@huawei.com/
Changes in v11:
- Avoid silently drop crash memory if the crash kernel is built without
CONFIG_CMA.
- Remove unnecessary "cmem->nr_ranges = 0" for arch_crash_populate_cmem()
as we use kvzalloc().
- Provide a separate patch for each architecture to fix the existing
buffer overflow issue.
- Add Acked-bys for arm64.
Changes in v10:
- Fix crashk_low_res not excluded bug in the existing
RISC-V code.
- Fix an existing memory leak issue in the existing PowerPC code.
- Fix the ordering issue of adding CMA ranges to
"linux,usable-memory-range".
- Fix an existing concurrency issue. A Concurrent memory hotplug may occur
between reading memblock and attempting to fill cmem during kexec_load()
for almost all existing architectures.
- Link to v9: https://lore.kernel.org/all/20260323072745.2481719-1-ruanjinjie@huawei.com/
Changes in v9:
- Collect Reviewed-by and Acked-by, and prepare for Sashiko AI review.
- Link to v8: https://lore.kernel.org/all/20260302035315.3892241-1-ruanjinjie@huawei.com/
Changes in v8:
- Fix the build issues reported by kernel test robot and Sourabh.
- Link to v7: https://lore.kernel.org/all/20260226130437.1867658-1-ruanjinjie@huawei.com/
Changes in v7:
- Correct the inclusion of CMA-reserved ranges for kdump kernel in of/kexec
for arm64 and riscv.
- Add Acked-by.
- Link to v6: https://lore.kernel.org/all/20260224085342.387996-1-ruanjinjie@huawei.com/
Changes in v6:
- Update the crash core exclude code as Mike suggested.
- Rebased on v7.0-rc1.
- Add acked-by.
- Link to v5: https://lore.kernel.org/all/20260212101001.343158-1-ruanjinjie@huawei.com/
Jinjie Ruan (16):
riscv: kexec_file: Fix crashk_low_res not exclude bug
powerpc/crash: Fix possible memory leak in update_crash_elfcorehdr()
arm64: kexec: Fix image->elf_headers memory leak during retry loop
x86/kexec: Fix potential buffer overflow in prepare_elf_headers()
arm64: kexec_file: Fix potential buffer overflow in
prepare_elf_headers()
riscv: kexec_file: Fix potential buffer overflow in
prepare_elf_headers()
LoongArch: kexec: Fix potential buffer overflow in
prepare_elf_headers()
crash: Add crash_prepare_headers() to exclude crash kernel memory
arm64: kexec_file: Use crash_prepare_headers() helper to simplify code
x86/kexec: Use crash_prepare_headers() helper to simplify code
riscv: kexec_file: Use crash_prepare_headers() helper to simplify code
LoongArch: kexec: Use crash_prepare_headers() helper to simplify code
crash: Use crash_exclude_core_ranges() on powerpc
arm64: kexec: Add support for crashkernel CMA reservation
riscv: kexec: Add support for crashkernel CMA reservation
arm64/crash: Add crash hotplug support
Sourabh Jain (1):
powerpc/crash: sort crash memory ranges before preparing elfcorehdr
.../admin-guide/kernel-parameters.txt | 16 +--
arch/arm64/Kconfig | 3 +
arch/arm64/include/asm/kexec.h | 14 +-
arch/arm64/kernel/Makefile | 1 +
arch/arm64/kernel/crash.c | 125 ++++++++++++++++++
arch/arm64/kernel/kexec_image.c | 22 ++-
arch/arm64/kernel/machine_kexec_file.c | 78 ++++++-----
arch/arm64/mm/init.c | 5 +-
arch/loongarch/kernel/machine_kexec_file.c | 43 +++---
arch/powerpc/include/asm/kexec_ranges.h | 1 -
arch/powerpc/kexec/crash.c | 7 +-
arch/powerpc/kexec/ranges.c | 101 +-------------
arch/riscv/kernel/machine_kexec_file.c | 42 +++---
arch/riscv/mm/init.c | 5 +-
arch/x86/kernel/crash.c | 92 ++-----------
drivers/of/fdt.c | 9 +-
drivers/of/kexec.c | 9 ++
include/linux/crash_core.h | 11 ++
include/linux/crash_reserve.h | 4 +-
kernel/crash_core.c | 102 +++++++++++++-
20 files changed, 392 insertions(+), 298 deletions(-)
create mode 100644 arch/arm64/kernel/crash.c
--
2.34.1
^ permalink raw reply
* [PATCH v14 01/17] riscv: kexec_file: Fix crashk_low_res not exclude bug
From: Jinjie Ruan @ 2026-05-25 8:49 UTC (permalink / raw)
To: corbet, skhan, catalin.marinas, will, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, pjw, palmer, aou, alex, tglx, mingo, bp,
dave.hansen, hpa, robh, saravanak, akpm, bhe, rppt,
pasha.tatashin, pratyush, ruirui.yang, rdunlap, pmladek,
feng.tang, dapeng1.mi, kees, elver, kuba, lirongqing, ebiggers,
paulmck, thuth, ardb, masahiroy, mark.rutland, maz, james.morse,
leitao, sourabhjain, yeoreum.yun, coxu, jbohac, ryan.roberts,
cfsworks, tangyouling, ritesh.list, songshuaishuai, junhui.liu,
vishal.moola, kas, debug, namcao, liaoyuanhong, fuqiang.wang,
seanjc, guoren, chenjiahao16, hbathini, bgwin, takahiro.akashi,
lizhengyu3, x86, linux-doc, linux-kernel, linux-arm-kernel,
loongarch, linuxppc-dev, linux-riscv, devicetree, kexec
Cc: ruanjinjie
In-Reply-To: <20260525084932.934910-1-ruanjinjie@huawei.com>
As done in commit 944a45abfabc ("arm64: kdump: Reimplement crashkernel=X")
and commit 4831be702b95 ("arm64/kexec: Fix missing extra range for
crashkres_low.") for arm64, while implementing crashkernel=X,[high,low],
riscv should have excluded the "crashk_low_res" reserved ranges from
the crash kernel memory to prevent them from being exported through
/proc/vmcore, and the exclusion would need an extra crash_mem range.
Just simply tested on qemu with crashkernel=4G with kexec in [1] mentioned
in [2]. And the second kernel can be started normally.
# dmesg | grep crash
[ 0.000000] crashkernel low memory reserved: 0xf8000000 - 0x100000000 (128 MB)
[ 0.000000] crashkernel reserved: 0x000000017fe00000 - 0x000000027fe00000 (4096 MB)
Cc: Guo Ren <guoren@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
[1]: https://github.com/chenjh005/kexec-tools/tree/build-test-riscv-v2
[2]: https://lore.kernel.org/all/20230726175000.2536220-1-chenjiahao16@huawei.com/
Fixes: 5882e5acf18d ("riscv: kdump: Implement crashkernel=X,[high,low]")
Reviewed-by: Guo Ren <guoren@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/riscv/kernel/machine_kexec_file.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
index 54e2d9552e93..3f7766057cac 100644
--- a/arch/riscv/kernel/machine_kexec_file.c
+++ b/arch/riscv/kernel/machine_kexec_file.c
@@ -61,7 +61,7 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
unsigned int nr_ranges;
int ret;
- nr_ranges = 1; /* For exclusion of crashkernel region */
+ nr_ranges = 2; /* For exclusion of crashkernel region */
walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
cmem = kmalloc_flex(*cmem, ranges, nr_ranges);
@@ -76,8 +76,16 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
/* Exclude crashkernel region */
ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
- if (!ret)
- ret = crash_prepare_elf64_headers(cmem, true, addr, sz);
+ if (ret)
+ goto out;
+
+ if (crashk_low_res.end) {
+ ret = crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end);
+ if (ret)
+ goto out;
+ }
+
+ ret = crash_prepare_elf64_headers(cmem, true, addr, sz);
out:
kfree(cmem);
--
2.34.1
^ permalink raw reply related
* [PATCH v3] crypto: nx: fix nx_crypto_ctx_exit argument
From: Sam James @ 2026-05-25 7:56 UTC (permalink / raw)
To: Breno Leitão, Nayna Jain, Paulo Flabiano Smorigo,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP), Herbert Xu, David S. Miller,
Ard Biesheuvel, Eric Biggers
Cc: Sam James, Eric Biggers, stable, Calvin Buckley, Brad Spengler,
linux-crypto, linuxppc-dev, linux-kernel
In-Reply-To: <b8b1b6fe740187c70349cd04a820d57324e0f70c.1779509289.git.sam@gentoo.org>
nx_crypto_ctx_shash_exit calls nx_crypto_ctx_exit with crypto_shash_ctx(...)
but crypto_shash_ctx gives a nx_crypto_ctx *, not a crypto_tfm *.
Fix the type in nx_crypto_ctx_exit and drop the bogus crypto_tfm_ctx
call.
This fixes the following oops:
BUG: Unable to handle kernel data access at 0xc0403effffffffc8
Faulting instruction address: 0xc000000000396cb4
Oops: Kernel access of bad area, sig: 11 [#15]
Call Trace:
nx_crypto_ctx_shash_exit+0x24/0x60
crypto_shash_exit_tfm+0x28/0x40
crypto_destroy_tfm+0x98/0x140
crypto_exit_ahash_using_shash+0x20/0x40
crypto_destroy_tfm+0x98/0x140
hash_release+0x1c/0x30
alg_sock_destruct+0x38/0x60
__sk_destruct+0x48/0x2b0
af_alg_release+0x58/0xb0
__sock_release+0x68/0x150
sock_close+0x20/0x40
__fput+0x110/0x3a0
sys_close+0x48/0xa0
system_call_exception+0x140/0x2d0
system_call_common+0xf4/0x258
.. which came from hardlink(1) opportunistically using AF_ALG.
The same problem exists with nx_crypto_ctx_skcipher_exit getting a context
it wasn't expecting, but apparently nobody hit that for years.
Cc: Eric Biggers <ebiggers@kernel.org>
Cc: stable@vger.kernel.org
Fixes: bfd9efddf990 ("crypto: nx - convert AES-ECB to skcipher API")
Fixes: 9420e628e7d8 ("crypto: nx - Use API partial block handling")
Acked-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Eric Biggers <ebiggers@kernel.org>
Reported-by: Calvin Buckley <calvin@cmpct.info>
Tested-by: Calvin Buckley <calvin@cmpct.info>
Suggested-by: Brad Spengler <brad.spengler@opensrcsec.com>
Signed-off-by: Sam James <sam@gentoo.org>
---
v3: Fix doc tag.
v2: Add stable cc, fix doc for tfm param.
v1: https://lore.kernel.org/all/a3e89c1e8342ffa415b0d29725a0571a4f355d34.1779472902.git.sam@gentoo.org/
v2: https://lore.kernel.org/all/b8b1b6fe740187c70349cd04a820d57324e0f70c.1779509289.git.sam@gentoo.org/
drivers/crypto/nx/nx.c | 6 ++----
drivers/crypto/nx/nx.h | 2 +-
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/crypto/nx/nx.c b/drivers/crypto/nx/nx.c
index 78135fb13f5c..1b7509e2ce44 100644
--- a/drivers/crypto/nx/nx.c
+++ b/drivers/crypto/nx/nx.c
@@ -714,15 +714,13 @@ int nx_crypto_ctx_aes_xcbc_init(struct crypto_shash *tfm)
/**
* nx_crypto_ctx_exit - destroy a crypto api context
*
- * @tfm: the crypto transform pointer for the context
+ * @nx_ctx: the crypto api context
*
* As crypto API contexts are destroyed, this exit hook is called to free the
* memory associated with it.
*/
-void nx_crypto_ctx_exit(struct crypto_tfm *tfm)
+void nx_crypto_ctx_exit(struct nx_crypto_ctx *nx_ctx)
{
- struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm);
-
kfree_sensitive(nx_ctx->kmem);
nx_ctx->csbcpb = NULL;
nx_ctx->csbcpb_aead = NULL;
diff --git a/drivers/crypto/nx/nx.h b/drivers/crypto/nx/nx.h
index 36974f08490a..6dfabfbf8192 100644
--- a/drivers/crypto/nx/nx.h
+++ b/drivers/crypto/nx/nx.h
@@ -153,7 +153,7 @@ int nx_crypto_ctx_aes_ctr_init(struct crypto_skcipher *tfm);
int nx_crypto_ctx_aes_cbc_init(struct crypto_skcipher *tfm);
int nx_crypto_ctx_aes_ecb_init(struct crypto_skcipher *tfm);
int nx_crypto_ctx_sha_init(struct crypto_shash *tfm);
-void nx_crypto_ctx_exit(struct crypto_tfm *tfm);
+void nx_crypto_ctx_exit(struct nx_crypto_ctx *nx_ctx);
void nx_crypto_ctx_skcipher_exit(struct crypto_skcipher *tfm);
void nx_crypto_ctx_aead_exit(struct crypto_aead *tfm);
void nx_crypto_ctx_shash_exit(struct crypto_shash *tfm);
base-commit: 79bd2dded182b1d458b18e62684b7f82ffc682e5
--
2.54.0
^ permalink raw reply related
* Re: [PATCH] misc: eeprom: at24: Make VCC supply description requirement optional
From: Paul Menzel @ 2026-05-25 7:07 UTC (permalink / raw)
To: Mark Brown
Cc: Bartosz Golaszewski, Arnd Bergmann, Greg Kroah-Hartman,
Liam Girdwood, Madhavan Srinivasan, Michael Ellerman,
linuxppc-dev, linux-i2c, linux-kernel
In-Reply-To: <ahN2m3kCbyTUNXzZ@sirena.org.uk>
Dear Mark,
Thank you for taking the time to review and respond.
Am 25.05.26 um 00:07 schrieb Mark Brown:
> On Sun, May 24, 2026 at 10:05:33AM +0200, Paul Menzel wrote:
>
>> Some platforms (e.g. IBM Power System S822LC (8335-GCA POWER8)) do not
>> describe the EEPROM’s VCC supply in firmware-provided device trees.
>> Using `devm_regulator_get()` on such systems falls back to a dummy
>> regulator with a kernel warning:
>
>> Switch to `devm_regulator_get_optional()` and treat -ENODEV as “no
>> supply described”. When `vcc_reg` is NULL, skip all
>> regulator_enable/disable calls; the hardware is assumed to be always
>> powered. Linux now logs:
>
> This is not appropriate unless the device can actually operate without
> power, any driver could be used in a system where the firmware does not
> describe the regultors and it'd obviously be pointless and error prone
> to scatter bodges like this on every single call to a regulator API
> function.
How should the warning on the POWER server be addressed then?
Kind regards,
Paul
^ permalink raw reply
* Re: [PATCH] powerpc: Export set_memory_encrypted and set_memory_decrypted
From: Christoph Hellwig @ 2026-05-25 6:21 UTC (permalink / raw)
To: T.J. Mercier
Cc: maddy, mpe, npiggin, chleroy, linuxppc-dev, mripard, sumit.semwal,
lkp, linux-kernel, iommu, linux-mm, agordeev, gerald.schaefer,
linux-s390, Dan Williams, Tom Lendacky, x86
In-Reply-To: <20260522225853.878411-1-tjmercier@google.com>
On Fri, May 22, 2026 at 03:58:53PM -0700, T.J. Mercier wrote:
> After commit fd55edff8a0a ("dma-buf: heaps: system: Turn the heap into a
> module") the system dma-buf heaps can be built as a module. The
> system_cc_shared heap uses set_memory_encrypted and set_memory_decrypted
> but those functions are not exported on powerpc. This can result in a
> build error like:
I'd much rather revert the above commit. Yes, x86 has exported these
since 2017, but that's a really bad idea, and we should fix it instead
of spreading the export.
Setting memory decrypted is a dangerous operations and should only
be available to core code. We should have various allocators for
decrypted code, but not export the functionality to random code.
^ permalink raw reply
* Re: [PATCH] misc: eeprom: at24: Make VCC supply description requirement optional
From: Mark Brown @ 2026-05-24 22:07 UTC (permalink / raw)
To: Paul Menzel
Cc: Bartosz Golaszewski, Arnd Bergmann, Greg Kroah-Hartman,
Liam Girdwood, Madhavan Srinivasan, Michael Ellerman,
linuxppc-dev, linux-i2c, linux-kernel
In-Reply-To: <20260524080533.8749-2-pmenzel@molgen.mpg.de>
[-- Attachment #1: Type: text/plain, Size: 847 bytes --]
On Sun, May 24, 2026 at 10:05:33AM +0200, Paul Menzel wrote:
> Some platforms (e.g. IBM Power System S822LC (8335-GCA POWER8)) do not
> describe the EEPROM’s VCC supply in firmware-provided device trees.
> Using `devm_regulator_get()` on such systems falls back to a dummy
> regulator with a kernel warning:
> Switch to `devm_regulator_get_optional()` and treat -ENODEV as “no
> supply described”. When `vcc_reg` is NULL, skip all
> regulator_enable/disable calls; the hardware is assumed to be always
> powered. Linux now logs:
This is not appropriate unless the device can actually operate without
power, any driver could be used in a system where the firmware does not
describe the regultors and it'd obviously be pointless and error prone
to scatter bodges like this on every single call to a regulator API
function.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply
* Re: [PATCH] MAINTAINERS: powerpc: update VMX AES entries
From: Eric Biggers @ 2026-05-24 21:35 UTC (permalink / raw)
To: Thorsten Blum
Cc: Herbert Xu, David S. Miller, Breno Leitão, Nayna Jain,
Paulo Flabiano Smorigo, Ard Biesheuvel, linux-crypto,
linuxppc-dev, linux-kernel
In-Reply-To: <20260524212943.799757-3-thorsten.blum@linux.dev>
On Sun, May 24, 2026 at 11:29:45PM +0200, Thorsten Blum wrote:
> Commit 7cf2082e74ce ("lib/crypto: powerpc/aes: Migrate POWER8 optimized
> code into library") removed arch/powerpc/crypto/aes.c and moved
> arch/powerpc/crypto/aesp8-ppc.pl to lib/crypto/powerpc/.
>
> However, the "IBM Power VMX Cryptographic instructions" entry still
> references the removed file and no longer covers the moved aesp8-ppc.pl.
>
> Remove the stale entry, add lib/crypto/powerpc/aesp8-ppc.pl, and tighten
> the arch/powerpc/crypto/aesp8-ppc.* pattern to match the remaining
> header only.
>
> Fixes: 7cf2082e74ce ("lib/crypto: powerpc/aes: Migrate POWER8 optimized code into library")
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Acked-by: Eric Biggers <ebiggers@kernel.org>
If this doesn't get picked up through the powerpc tree, I can take this
through libcrypto-next.
- Eric
^ permalink raw reply
* [PATCH] MAINTAINERS: powerpc: update VMX AES entries
From: Thorsten Blum @ 2026-05-24 21:29 UTC (permalink / raw)
To: Herbert Xu, David S. Miller, Breno Leitão, Nayna Jain,
Paulo Flabiano Smorigo, Eric Biggers, Ard Biesheuvel
Cc: linux-crypto, linuxppc-dev, linux-kernel, Thorsten Blum
Commit 7cf2082e74ce ("lib/crypto: powerpc/aes: Migrate POWER8 optimized
code into library") removed arch/powerpc/crypto/aes.c and moved
arch/powerpc/crypto/aesp8-ppc.pl to lib/crypto/powerpc/.
However, the "IBM Power VMX Cryptographic instructions" entry still
references the removed file and no longer covers the moved aesp8-ppc.pl.
Remove the stale entry, add lib/crypto/powerpc/aesp8-ppc.pl, and tighten
the arch/powerpc/crypto/aesp8-ppc.* pattern to match the remaining
header only.
Fixes: 7cf2082e74ce ("lib/crypto: powerpc/aes: Migrate POWER8 optimized code into library")
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
MAINTAINERS | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index b539be153f6a..c48cdb05e6dc 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12349,13 +12349,13 @@ L: linux-crypto@vger.kernel.org
S: Supported
F: arch/powerpc/crypto/Kconfig
F: arch/powerpc/crypto/Makefile
-F: arch/powerpc/crypto/aes.c
F: arch/powerpc/crypto/aes_cbc.c
F: arch/powerpc/crypto/aes_ctr.c
F: arch/powerpc/crypto/aes_xts.c
-F: arch/powerpc/crypto/aesp8-ppc.*
+F: arch/powerpc/crypto/aesp8-ppc.h
F: arch/powerpc/crypto/ppc-xlate.pl
F: arch/powerpc/crypto/vmx.c
+F: lib/crypto/powerpc/aesp8-ppc.pl
F: lib/crypto/powerpc/gf128hash.h
F: lib/crypto/powerpc/ghashp8-ppc.pl
^ permalink raw reply related
* [PATCH] powerpc: use sysfs_emit{_at} in sysfs show functions
From: Thorsten Blum @ 2026-05-24 13:00 UTC (permalink / raw)
To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Mahesh J Salgaonkar, Oliver O'Halloran,
Geoff Levand
Cc: linuxppc-dev, linux-kernel, Thorsten Blum
Replace sprintf() with sysfs_emit() and sysfs_emit_at() in sysfs show
functions, which are preferred for formatting sysfs output because they
provide safer bounds checking.
While the current code only emits strings that fit easily within
PAGE_SIZE, use sysfs_emit() and sysfs_emit_at() to follow secure coding
best practices.
This is a mechanical cleanup with a few simple edge cases:
- In domains_show(), drop the redundant n < 0 check since neither
sprintf() nor sysfs_emit() return negative values.
- In powercap_show() and psr_show(), also drop the dead ret < 0 checks.
- In ps3_fw_version_show(), normalize the output by adding a terminating
newline as suggested by checkpatch.
- In vio's modalias_show(), replace the deprecated strcpy() [1] followed
by strlen() with sysfs_emit().
Leave validate_show() and the variable-length hv-gpci helpers unchanged
since they already have explicit bounds handling, and converting those
would be more than a mechanical conversion.
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/powerpc/kernel/cacheinfo.c | 13 +++++----
arch/powerpc/kernel/eeh_sysfs.c | 8 ++---
arch/powerpc/kernel/fadump.c | 10 +++----
arch/powerpc/kernel/iommu.c | 3 +-
arch/powerpc/kernel/security.c | 13 +++++----
arch/powerpc/kernel/sysfs.c | 23 ++++++++-------
arch/powerpc/perf/core-book3s.c | 3 +-
arch/powerpc/perf/hv-24x7.c | 18 +++++-------
arch/powerpc/perf/hv-gpci.c | 5 ++--
arch/powerpc/perf/kvm-hv-pmu.c | 3 +-
arch/powerpc/perf/vpa-pmu.c | 3 +-
.../powerpc/platforms/83xx/mcu_mpc8349emitx.c | 3 +-
arch/powerpc/platforms/cell/spu_base.c | 5 ++--
arch/powerpc/platforms/powernv/idle.c | 3 +-
arch/powerpc/platforms/powernv/opal-dump.c | 11 +++----
arch/powerpc/platforms/powernv/opal-elog.c | 9 +++---
arch/powerpc/platforms/powernv/opal-flash.c | 4 +--
.../powerpc/platforms/powernv/opal-powercap.c | 12 +++-----
arch/powerpc/platforms/powernv/opal-psr.c | 12 +++-----
arch/powerpc/platforms/powernv/subcore.c | 3 +-
arch/powerpc/platforms/ps3/setup.c | 3 +-
arch/powerpc/platforms/pseries/cmm.c | 5 ++--
arch/powerpc/platforms/pseries/dlpar.c | 3 +-
arch/powerpc/platforms/pseries/ibmebus.c | 5 ++--
arch/powerpc/platforms/pseries/papr_scm.c | 5 ++--
arch/powerpc/platforms/pseries/power.c | 3 +-
.../platforms/pseries/pseries_energy.c | 3 +-
arch/powerpc/platforms/pseries/suspend.c | 3 +-
arch/powerpc/platforms/pseries/vas-sysfs.c | 3 +-
arch/powerpc/platforms/pseries/vio.c | 29 +++++++++----------
arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c | 3 +-
31 files changed, 118 insertions(+), 111 deletions(-)
diff --git a/arch/powerpc/kernel/cacheinfo.c b/arch/powerpc/kernel/cacheinfo.c
index 90d51d9b3ed2..04e5ea38bdc0 100644
--- a/arch/powerpc/kernel/cacheinfo.c
+++ b/arch/powerpc/kernel/cacheinfo.c
@@ -18,6 +18,7 @@
#include <linux/of.h>
#include <linux/percpu.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <asm/cputhreads.h>
#include <asm/smp.h>
@@ -596,7 +597,7 @@ static ssize_t size_show(struct kobject *k, struct kobj_attribute *attr, char *b
if (cache_size_kb(cache, &size_kb))
return -ENODEV;
- return sprintf(buf, "%uK\n", size_kb);
+ return sysfs_emit(buf, "%uK\n", size_kb);
}
static struct kobj_attribute cache_size_attr =
@@ -613,7 +614,7 @@ static ssize_t line_size_show(struct kobject *k, struct kobj_attribute *attr, ch
if (cache_get_line_size(cache, &line_size))
return -ENODEV;
- return sprintf(buf, "%u\n", line_size);
+ return sysfs_emit(buf, "%u\n", line_size);
}
static struct kobj_attribute cache_line_size_attr =
@@ -629,7 +630,7 @@ static ssize_t nr_sets_show(struct kobject *k, struct kobj_attribute *attr, char
if (cache_nr_sets(cache, &nr_sets))
return -ENODEV;
- return sprintf(buf, "%u\n", nr_sets);
+ return sysfs_emit(buf, "%u\n", nr_sets);
}
static struct kobj_attribute cache_nr_sets_attr =
@@ -645,7 +646,7 @@ static ssize_t associativity_show(struct kobject *k, struct kobj_attribute *attr
if (cache_associativity(cache, &associativity))
return -ENODEV;
- return sprintf(buf, "%u\n", associativity);
+ return sysfs_emit(buf, "%u\n", associativity);
}
static struct kobj_attribute cache_assoc_attr =
@@ -657,7 +658,7 @@ static ssize_t type_show(struct kobject *k, struct kobj_attribute *attr, char *b
cache = index_kobj_to_cache(k);
- return sprintf(buf, "%s\n", cache_type_string(cache));
+ return sysfs_emit(buf, "%s\n", cache_type_string(cache));
}
static struct kobj_attribute cache_type_attr =
@@ -671,7 +672,7 @@ static ssize_t level_show(struct kobject *k, struct kobj_attribute *attr, char *
index = kobj_to_cache_index_dir(k);
cache = index->cache;
- return sprintf(buf, "%d\n", cache->level);
+ return sysfs_emit(buf, "%d\n", cache->level);
}
static struct kobj_attribute cache_level_attr =
diff --git a/arch/powerpc/kernel/eeh_sysfs.c b/arch/powerpc/kernel/eeh_sysfs.c
index 706e1eb95efe..b9785f105f75 100644
--- a/arch/powerpc/kernel/eeh_sysfs.c
+++ b/arch/powerpc/kernel/eeh_sysfs.c
@@ -9,6 +9,7 @@
#include <linux/of.h>
#include <linux/pci.h>
#include <linux/stat.h>
+#include <linux/sysfs.h>
#include <asm/ppc-pci.h>
#include <asm/pci-bridge.h>
@@ -31,7 +32,7 @@ static ssize_t eeh_show_##_name(struct device *dev, \
if (!edev) \
return 0; \
\
- return sprintf(buf, _format "\n", edev->_memb); \
+ return sysfs_emit(buf, _format "\n", edev->_memb); \
} \
static DEVICE_ATTR(_name, 0444, eeh_show_##_name, NULL);
@@ -49,8 +50,7 @@ static ssize_t eeh_pe_state_show(struct device *dev,
return -ENODEV;
state = eeh_ops->get_state(edev->pe, NULL);
- return sprintf(buf, "0x%08x 0x%08x\n",
- state, edev->pe->state);
+ return sysfs_emit(buf, "0x%08x 0x%08x\n", state, edev->pe->state);
}
static ssize_t eeh_pe_state_store(struct device *dev,
@@ -87,7 +87,7 @@ static ssize_t eeh_notify_resume_show(struct device *dev,
if (!edev || !edev->pe)
return -ENODEV;
- return sprintf(buf, "%d\n", pdn->last_allow_rc);
+ return sysfs_emit(buf, "%d\n", pdn->last_allow_rc);
}
static ssize_t eeh_notify_resume_store(struct device *dev,
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index 501d43bf18f3..a313b1653124 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -1422,7 +1422,7 @@ static ssize_t enabled_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
- return sprintf(buf, "%d\n", fw_dump.fadump_enabled);
+ return sysfs_emit(buf, "%d\n", fw_dump.fadump_enabled);
}
/*
@@ -1434,28 +1434,28 @@ static ssize_t hotplug_ready_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
- return sprintf(buf, "%d\n", 1);
+ return sysfs_emit(buf, "%d\n", 1);
}
static ssize_t mem_reserved_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
- return sprintf(buf, "%ld\n", fw_dump.reserve_dump_area_size);
+ return sysfs_emit(buf, "%ld\n", fw_dump.reserve_dump_area_size);
}
static ssize_t registered_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
- return sprintf(buf, "%d\n", fw_dump.dump_registered);
+ return sysfs_emit(buf, "%d\n", fw_dump.dump_registered);
}
static ssize_t bootargs_append_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
- return sprintf(buf, "%s\n", (char *)__va(fw_dump.param_area));
+ return sysfs_emit(buf, "%s\n", (char *)__va(fw_dump.param_area));
}
static ssize_t bootargs_append_store(struct kobject *kobj,
diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index d122e8447831..ee1b5cb557c9 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -13,6 +13,7 @@
#include <linux/init.h>
#include <linux/types.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <linux/mm.h>
#include <linux/spinlock.h>
#include <linux/string.h>
@@ -141,7 +142,7 @@ late_initcall(fail_iommu_debugfs);
static ssize_t fail_iommu_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return sprintf(buf, "%d\n", dev->archdata.fail_iommu);
+ return sysfs_emit(buf, "%d\n", dev->archdata.fail_iommu);
}
static ssize_t fail_iommu_store(struct device *dev,
diff --git a/arch/powerpc/kernel/security.c b/arch/powerpc/kernel/security.c
index fbb7ebd8aa08..600596cb4ffb 100644
--- a/arch/powerpc/kernel/security.c
+++ b/arch/powerpc/kernel/security.c
@@ -11,6 +11,7 @@
#include <linux/nospec.h>
#include <linux/prctl.h>
#include <linux/seq_buf.h>
+#include <linux/sysfs.h>
#include <linux/debugfs.h>
#include <asm/asm-prototypes.h>
@@ -163,13 +164,13 @@ ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, cha
}
if (thread_priv)
- return sprintf(buf, "Vulnerable: L1D private per thread\n");
+ return sysfs_emit(buf, "Vulnerable: L1D private per thread\n");
if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) &&
!security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR))
- return sprintf(buf, "Not affected\n");
+ return sysfs_emit(buf, "Not affected\n");
- return sprintf(buf, "Vulnerable\n");
+ return sysfs_emit(buf, "Vulnerable\n");
}
ssize_t cpu_show_l1tf(struct device *dev, struct device_attribute *attr, char *buf)
@@ -352,14 +353,14 @@ ssize_t cpu_show_spec_store_bypass(struct device *dev, struct device_attribute *
default:
type = "unknown";
}
- return sprintf(buf, "Mitigation: Kernel entry/exit barrier (%s)\n", type);
+ return sysfs_emit(buf, "Mitigation: Kernel entry/exit barrier (%s)\n", type);
}
if (!security_ftr_enabled(SEC_FTR_L1D_FLUSH_HV) &&
!security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR))
- return sprintf(buf, "Not affected\n");
+ return sysfs_emit(buf, "Not affected\n");
- return sprintf(buf, "Vulnerable\n");
+ return sysfs_emit(buf, "Vulnerable\n");
}
static int ssb_prctl_get(struct task_struct *task)
diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
index 6b3dd6decdf9..329c1690b5ed 100644
--- a/arch/powerpc/kernel/sysfs.c
+++ b/arch/powerpc/kernel/sysfs.c
@@ -5,6 +5,7 @@
#include <linux/percpu.h>
#include <linux/init.h>
#include <linux/sched.h>
+#include <linux/sysfs.h>
#include <linux/export.h>
#include <linux/nodemask.h>
#include <linux/cpumask.h>
@@ -63,7 +64,7 @@ static ssize_t show_smt_snooze_delay(struct device *dev,
{
pr_warn_once("%s (%d) read from unsupported smt_snooze_delay\n",
current->comm, current->pid);
- return sprintf(buf, "100\n");
+ return sysfs_emit(buf, "100\n");
}
static DEVICE_ATTR(smt_snooze_delay, 0644, show_smt_snooze_delay,
@@ -100,7 +101,7 @@ static ssize_t show_##NAME(struct device *dev, \
struct cpu *cpu = container_of(dev, struct cpu, dev); \
unsigned long val; \
smp_call_function_single(cpu->dev.id, read_##NAME, &val, 1); \
- return sprintf(buf, "%lx\n", val); \
+ return sysfs_emit(buf, "%lx\n", val); \
} \
static ssize_t __used \
store_##NAME(struct device *dev, struct device_attribute *attr, \
@@ -183,7 +184,7 @@ static void add_write_permission_dev_attr(struct device_attribute *attr)
static ssize_t show_dscr_default(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return sprintf(buf, "%lx\n", dscr_default);
+ return sysfs_emit(buf, "%lx\n", dscr_default);
}
/**
@@ -272,7 +273,7 @@ static ssize_t show_pw20_state(struct device *dev,
value &= PWRMGTCR0_PW20_WAIT;
- return sprintf(buf, "%u\n", value ? 1 : 0);
+ return sysfs_emit(buf, "%u\n", value ? 1 : 0);
}
static void do_store_pw20_state(void *val)
@@ -337,7 +338,7 @@ static ssize_t show_pw20_wait_time(struct device *dev,
time = pw20_wt;
}
- return sprintf(buf, "%llu\n", time > 0 ? time : 0);
+ return sysfs_emit(buf, "%llu\n", time > 0 ? time : 0);
}
static void set_pw20_wait_entry_bit(void *val)
@@ -394,7 +395,7 @@ static ssize_t show_altivec_idle(struct device *dev,
value &= PWRMGTCR0_AV_IDLE_PD_EN;
- return sprintf(buf, "%u\n", value ? 1 : 0);
+ return sysfs_emit(buf, "%u\n", value ? 1 : 0);
}
static void do_store_altivec_idle(void *val)
@@ -459,7 +460,7 @@ static ssize_t show_altivec_idle_wait_time(struct device *dev,
time = altivec_idle_wt;
}
- return sprintf(buf, "%llu\n", time > 0 ? time : 0);
+ return sysfs_emit(buf, "%llu\n", time > 0 ? time : 0);
}
static void set_altivec_idle_wait_entry_bit(void *val)
@@ -746,7 +747,7 @@ static struct device_attribute pa6t_attrs[] = {
#ifdef CONFIG_PPC_SVM
static ssize_t show_svm(struct device *dev, struct device_attribute *attr, char *buf)
{
- return sprintf(buf, "%u\n", is_secure_guest());
+ return sysfs_emit(buf, "%u\n", is_secure_guest());
}
static DEVICE_ATTR(svm, 0444, show_svm, NULL);
@@ -780,7 +781,7 @@ static ssize_t idle_purr_show(struct device *dev,
u64 val;
smp_call_function_single(cpu->dev.id, read_idle_purr, &val, 1);
- return sprintf(buf, "%llx\n", val);
+ return sysfs_emit(buf, "%llx\n", val);
}
static DEVICE_ATTR(idle_purr, 0400, idle_purr_show, NULL);
@@ -810,7 +811,7 @@ static ssize_t idle_spurr_show(struct device *dev,
u64 val;
smp_call_function_single(cpu->dev.id, read_idle_spurr, &val, 1);
- return sprintf(buf, "%llx\n", val);
+ return sysfs_emit(buf, "%llx\n", val);
}
static DEVICE_ATTR(idle_spurr, 0400, idle_spurr_show, NULL);
@@ -1143,7 +1144,7 @@ static ssize_t show_physical_id(struct device *dev,
{
struct cpu *cpu = container_of(dev, struct cpu, dev);
- return sprintf(buf, "%d\n", get_hard_smp_processor_id(cpu->dev.id));
+ return sysfs_emit(buf, "%d\n", get_hard_smp_processor_id(cpu->dev.id));
}
static DEVICE_ATTR(physical_id, 0444, show_physical_id, NULL);
diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index 2e6adf5b95c4..bb65f0abc462 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -10,6 +10,7 @@
#include <linux/perf_event.h>
#include <linux/percpu.h>
#include <linux/hardirq.h>
+#include <linux/sysfs.h>
#include <linux/uaccess.h>
#include <asm/reg.h>
#include <asm/pmc.h>
@@ -2204,7 +2205,7 @@ ssize_t power_events_sysfs_show(struct device *dev,
pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr);
- return sprintf(page, "event=0x%02llx\n", pmu_attr->id);
+ return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
}
static struct pmu power_pmu = {
diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c
index 243c0a1c8cda..abb4cfb11fcc 100644
--- a/arch/powerpc/perf/hv-24x7.c
+++ b/arch/powerpc/perf/hv-24x7.c
@@ -12,6 +12,7 @@
#include <linux/rbtree.h>
#include <linux/module.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <linux/vmalloc.h>
#include <asm/cputhreads.h>
@@ -434,19 +435,19 @@ static ssize_t cpumask_show(struct device *dev,
static ssize_t sockets_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return sprintf(buf, "%d\n", phys_sockets);
+ return sysfs_emit(buf, "%d\n", phys_sockets);
}
static ssize_t chipspersocket_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return sprintf(buf, "%d\n", phys_chipspersocket);
+ return sysfs_emit(buf, "%d\n", phys_chipspersocket);
}
static ssize_t coresperchip_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return sprintf(buf, "%d\n", phys_coresperchip);
+ return sysfs_emit(buf, "%d\n", phys_coresperchip);
}
static struct attribute *device_str_attr_create_(char *name, char *str)
@@ -1061,7 +1062,7 @@ static ssize_t catalog_read(struct file *filp, struct kobject *kobj,
static ssize_t domains_show(struct device *dev, struct device_attribute *attr,
char *page)
{
- int d, n, count = 0;
+ int d, count = 0;
const char *str;
for (d = 0; d < HV_PERF_DOMAIN_MAX; d++) {
@@ -1069,12 +1070,7 @@ static ssize_t domains_show(struct device *dev, struct device_attribute *attr,
if (!str)
continue;
- n = sprintf(page, "%d: %s\n", d, str);
- if (n < 0)
- break;
-
- count += n;
- page += n;
+ count += sysfs_emit_at(page, count, "%d: %s\n", d, str);
}
return count;
}
@@ -1095,7 +1091,7 @@ static ssize_t _name##_show(struct device *dev, \
ret = -EIO; \
goto e_free; \
} \
- ret = sprintf(buf, _fmt, _expr); \
+ ret = sysfs_emit(buf, _fmt, _expr); \
e_free: \
kmem_cache_free(hv_page_cache, page); \
return ret; \
diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c
index c7a1fe5918c5..1135f9739ead 100644
--- a/arch/powerpc/perf/hv-gpci.c
+++ b/arch/powerpc/perf/hv-gpci.c
@@ -11,6 +11,7 @@
#include <linux/init.h>
#include <linux/perf_event.h>
+#include <linux/sysfs.h>
#include <asm/firmware.h>
#include <asm/hvcall.h>
#include <asm/io.h>
@@ -85,7 +86,7 @@ static ssize_t _name##_show(struct device *dev, \
if (hret) \
return -EIO; \
\
- return sprintf(page, _format, caps._name); \
+ return sysfs_emit(page, _format, caps._name); \
} \
static struct device_attribute hv_caps_attr_##_name = __ATTR_RO(_name)
@@ -93,7 +94,7 @@ static ssize_t kernel_version_show(struct device *dev,
struct device_attribute *attr,
char *page)
{
- return sprintf(page, "0x%x\n", COUNTER_INFO_VERSION_CURRENT);
+ return sysfs_emit(page, "0x%x\n", COUNTER_INFO_VERSION_CURRENT);
}
static ssize_t cpumask_show(struct device *dev,
diff --git a/arch/powerpc/perf/kvm-hv-pmu.c b/arch/powerpc/perf/kvm-hv-pmu.c
index ae264c9080ef..aa72b96b5a8c 100644
--- a/arch/powerpc/perf/kvm-hv-pmu.c
+++ b/arch/powerpc/perf/kvm-hv-pmu.c
@@ -16,6 +16,7 @@
#include <linux/perf_event.h>
#include <linux/spinlock_types.h>
#include <linux/spinlock.h>
+#include <linux/sysfs.h>
#include <asm/types.h>
#include <asm/kvm_ppc.h>
@@ -48,7 +49,7 @@ static ssize_t kvmppc_events_sysfs_show(struct device *dev,
struct perf_pmu_events_attr *pmu_attr;
pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr);
- return sprintf(page, "event=0x%02llx\n", pmu_attr->id);
+ return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
}
/* Holds the hostwide stats */
diff --git a/arch/powerpc/perf/vpa-pmu.c b/arch/powerpc/perf/vpa-pmu.c
index 840733468959..bff4cfab7b94 100644
--- a/arch/powerpc/perf/vpa-pmu.c
+++ b/arch/powerpc/perf/vpa-pmu.c
@@ -8,6 +8,7 @@
#include <linux/module.h>
#include <linux/perf_event.h>
+#include <linux/sysfs.h>
#include <asm/kvm_ppc.h>
#include <asm/kvm_book3s_64.h>
@@ -26,7 +27,7 @@ static ssize_t vpa_pmu_events_sysfs_show(struct device *dev,
pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr);
- return sprintf(page, "event=0x%02llx\n", pmu_attr->id);
+ return sysfs_emit(page, "event=0x%02llx\n", pmu_attr->id);
}
#define VPA_PMU_EVENT_ATTR(_name, _id) \
diff --git a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
index 9b693594a5f7..c3fbec1f1d24 100644
--- a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
+++ b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
@@ -15,6 +15,7 @@
#include <linux/i2c.h>
#include <linux/gpio/driver.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <linux/kthread.h>
#include <linux/property.h>
#include <linux/reboot.h>
@@ -77,7 +78,7 @@ static ssize_t show_status(struct device *d,
return -ENODEV;
mcu->reg_ctrl = ret;
- return sprintf(buf, "%02x\n", ret);
+ return sysfs_emit(buf, "%02x\n", ret);
}
static DEVICE_ATTR(status, 0444, show_status, NULL);
diff --git a/arch/powerpc/platforms/cell/spu_base.c b/arch/powerpc/platforms/cell/spu_base.c
index 0ec7b3bdda56..8452153d4650 100644
--- a/arch/powerpc/platforms/cell/spu_base.c
+++ b/arch/powerpc/platforms/cell/spu_base.c
@@ -20,6 +20,7 @@
#include <linux/mutex.h>
#include <linux/linux_logo.h>
#include <linux/syscore_ops.h>
+#include <linux/sysfs.h>
#include <asm/spu.h>
#include <asm/spu_priv1.h>
#include <asm/spu_csa.h>
@@ -638,8 +639,8 @@ static ssize_t spu_stat_show(struct device *dev,
{
struct spu *spu = container_of(dev, struct spu, dev);
- return sprintf(buf, "%s %llu %llu %llu %llu "
- "%llu %llu %llu %llu %llu %llu %llu %llu\n",
+ return sysfs_emit(buf,
+ "%s %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
spu_state_names[spu->stats.util_state],
spu_acct_time(spu, SPU_UTIL_USER),
spu_acct_time(spu, SPU_UTIL_SYSTEM),
diff --git a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c
index 6cd461f82968..33103a98cfd5 100644
--- a/arch/powerpc/platforms/powernv/idle.c
+++ b/arch/powerpc/platforms/powernv/idle.c
@@ -8,6 +8,7 @@
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <linux/of.h>
#include <linux/device.h>
#include <linux/cpu.h>
@@ -171,7 +172,7 @@ static u8 fastsleep_workaround_applyonce;
static ssize_t show_fastsleep_workaround_applyonce(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return sprintf(buf, "%u\n", fastsleep_workaround_applyonce);
+ return sysfs_emit(buf, "%u\n", fastsleep_workaround_applyonce);
}
static ssize_t store_fastsleep_workaround_applyonce(struct device *dev,
diff --git a/arch/powerpc/platforms/powernv/opal-dump.c b/arch/powerpc/platforms/powernv/opal-dump.c
index 2e4bffa74163..0586821d7af4 100644
--- a/arch/powerpc/platforms/powernv/opal-dump.c
+++ b/arch/powerpc/platforms/powernv/opal-dump.c
@@ -8,6 +8,7 @@
#include <linux/kobject.h>
#include <linux/mm.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <linux/vmalloc.h>
#include <linux/pagemap.h>
#include <linux/delay.h>
@@ -40,7 +41,7 @@ static ssize_t dump_id_show(struct dump_obj *dump_obj,
struct dump_attribute *attr,
char *buf)
{
- return sprintf(buf, "0x%x\n", dump_obj->id);
+ return sysfs_emit(buf, "0x%x\n", dump_obj->id);
}
static const char* dump_type_to_string(uint32_t type)
@@ -58,15 +59,15 @@ static ssize_t dump_type_show(struct dump_obj *dump_obj,
char *buf)
{
- return sprintf(buf, "0x%x %s\n", dump_obj->type,
- dump_type_to_string(dump_obj->type));
+ return sysfs_emit(buf, "0x%x %s\n", dump_obj->type,
+ dump_type_to_string(dump_obj->type));
}
static ssize_t dump_ack_show(struct dump_obj *dump_obj,
struct dump_attribute *attr,
char *buf)
{
- return sprintf(buf, "ack - acknowledge dump\n");
+ return sysfs_emit(buf, "ack - acknowledge dump\n");
}
/*
@@ -114,7 +115,7 @@ static ssize_t init_dump_show(struct dump_obj *dump_obj,
struct dump_attribute *attr,
char *buf)
{
- return sprintf(buf, "1 - initiate Service Processor(FSP) dump\n");
+ return sysfs_emit(buf, "1 - initiate Service Processor(FSP) dump\n");
}
static int64_t dump_fips_init(uint8_t type)
diff --git a/arch/powerpc/platforms/powernv/opal-elog.c b/arch/powerpc/platforms/powernv/opal-elog.c
index 2b8331922ab9..6cacd3fd3cd5 100644
--- a/arch/powerpc/platforms/powernv/opal-elog.c
+++ b/arch/powerpc/platforms/powernv/opal-elog.c
@@ -40,7 +40,7 @@ static ssize_t elog_id_show(struct elog_obj *elog_obj,
struct elog_attribute *attr,
char *buf)
{
- return sprintf(buf, "0x%llx\n", elog_obj->id);
+ return sysfs_emit(buf, "0x%llx\n", elog_obj->id);
}
static const char *elog_type_to_string(uint64_t type)
@@ -55,16 +55,15 @@ static ssize_t elog_type_show(struct elog_obj *elog_obj,
struct elog_attribute *attr,
char *buf)
{
- return sprintf(buf, "0x%llx %s\n",
- elog_obj->type,
- elog_type_to_string(elog_obj->type));
+ return sysfs_emit(buf, "0x%llx %s\n", elog_obj->type,
+ elog_type_to_string(elog_obj->type));
}
static ssize_t elog_ack_show(struct elog_obj *elog_obj,
struct elog_attribute *attr,
char *buf)
{
- return sprintf(buf, "ack - acknowledge log message\n");
+ return sysfs_emit(buf, "ack - acknowledge log message\n");
}
static ssize_t elog_ack_store(struct elog_obj *elog_obj,
diff --git a/arch/powerpc/platforms/powernv/opal-flash.c b/arch/powerpc/platforms/powernv/opal-flash.c
index a3f7a2928767..5ca5f6329a2d 100644
--- a/arch/powerpc/platforms/powernv/opal-flash.c
+++ b/arch/powerpc/platforms/powernv/opal-flash.c
@@ -238,7 +238,7 @@ static ssize_t manage_show(struct kobject *kobj,
struct manage_flash_t *const args_buf = &manage_flash_data;
int rc;
- rc = sprintf(buf, "%d\n", args_buf->status);
+ rc = sysfs_emit(buf, "%d\n", args_buf->status);
/* Set status to default*/
args_buf->status = FLASH_NO_OP;
return rc;
@@ -321,7 +321,7 @@ static ssize_t update_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
struct update_flash_t *const args_buf = &update_flash_data;
- return sprintf(buf, "%d\n", args_buf->status);
+ return sysfs_emit(buf, "%d\n", args_buf->status);
}
/*
diff --git a/arch/powerpc/platforms/powernv/opal-powercap.c b/arch/powerpc/platforms/powernv/opal-powercap.c
index 9bb73cb42a65..bf18b333281e 100644
--- a/arch/powerpc/platforms/powernv/opal-powercap.c
+++ b/arch/powerpc/platforms/powernv/opal-powercap.c
@@ -10,6 +10,7 @@
#include <linux/of.h>
#include <linux/kobject.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <asm/opal.h>
@@ -56,16 +57,11 @@ static ssize_t powercap_show(struct kobject *kobj, struct kobj_attribute *attr,
goto out;
}
ret = opal_error_code(opal_get_async_rc(msg));
- if (!ret) {
- ret = sprintf(buf, "%u\n", be32_to_cpu(pcap));
- if (ret < 0)
- ret = -EIO;
- }
+ if (!ret)
+ ret = sysfs_emit(buf, "%u\n", be32_to_cpu(pcap));
break;
case OPAL_SUCCESS:
- ret = sprintf(buf, "%u\n", be32_to_cpu(pcap));
- if (ret < 0)
- ret = -EIO;
+ ret = sysfs_emit(buf, "%u\n", be32_to_cpu(pcap));
break;
default:
ret = opal_error_code(ret);
diff --git a/arch/powerpc/platforms/powernv/opal-psr.c b/arch/powerpc/platforms/powernv/opal-psr.c
index 24d0a894d965..19228181cb6f 100644
--- a/arch/powerpc/platforms/powernv/opal-psr.c
+++ b/arch/powerpc/platforms/powernv/opal-psr.c
@@ -10,6 +10,7 @@
#include <linux/of.h>
#include <linux/kobject.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <asm/opal.h>
@@ -50,16 +51,11 @@ static ssize_t psr_show(struct kobject *kobj, struct kobj_attribute *attr,
goto out;
}
ret = opal_error_code(opal_get_async_rc(msg));
- if (!ret) {
- ret = sprintf(buf, "%u\n", be32_to_cpu(psr));
- if (ret < 0)
- ret = -EIO;
- }
+ if (!ret)
+ ret = sysfs_emit(buf, "%u\n", be32_to_cpu(psr));
break;
case OPAL_SUCCESS:
- ret = sprintf(buf, "%u\n", be32_to_cpu(psr));
- if (ret < 0)
- ret = -EIO;
+ ret = sysfs_emit(buf, "%u\n", be32_to_cpu(psr));
break;
default:
ret = opal_error_code(ret);
diff --git a/arch/powerpc/platforms/powernv/subcore.c b/arch/powerpc/platforms/powernv/subcore.c
index 393e747541fb..f7668ef1ac1f 100644
--- a/arch/powerpc/platforms/powernv/subcore.c
+++ b/arch/powerpc/platforms/powernv/subcore.c
@@ -12,6 +12,7 @@
#include <linux/gfp.h>
#include <linux/smp.h>
#include <linux/stop_machine.h>
+#include <linux/sysfs.h>
#include <asm/cputhreads.h>
#include <asm/cpuidle.h>
@@ -409,7 +410,7 @@ static ssize_t __used store_subcores_per_core(struct device *dev,
static ssize_t show_subcores_per_core(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return sprintf(buf, "%x\n", subcores_per_core);
+ return sysfs_emit(buf, "%x\n", subcores_per_core);
}
static DEVICE_ATTR(subcores_per_core, 0644,
diff --git a/arch/powerpc/platforms/ps3/setup.c b/arch/powerpc/platforms/ps3/setup.c
index 150c09b58ae8..ca2608a70f4d 100644
--- a/arch/powerpc/platforms/ps3/setup.c
+++ b/arch/powerpc/platforms/ps3/setup.c
@@ -10,6 +10,7 @@
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/root_dev.h>
+#include <linux/sysfs.h>
#include <linux/console.h>
#include <linux/export.h>
#include <linux/memblock.h>
@@ -183,7 +184,7 @@ static int ps3_set_dabr(unsigned long dabr, unsigned long dabrx)
static ssize_t ps3_fw_version_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
- return sprintf(buf, "%s", ps3_firmware_version_str);
+ return sysfs_emit(buf, "%s\n", ps3_firmware_version_str);
}
static int __init ps3_setup_sysfs(void)
diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c
index 8d83df12430f..38e22125b96f 100644
--- a/arch/powerpc/platforms/pseries/cmm.c
+++ b/arch/powerpc/platforms/pseries/cmm.c
@@ -18,6 +18,7 @@
#include <linux/sched.h>
#include <linux/stringify.h>
#include <linux/swap.h>
+#include <linux/sysfs.h>
#include <linux/device.h>
#include <linux/balloon.h>
#include <asm/firmware.h>
@@ -333,7 +334,7 @@ static int cmm_thread(void *dummy)
struct device_attribute *attr, \
char *buf) \
{ \
- return sprintf(buf, format, ##args); \
+ return sysfs_emit(buf, format, ##args); \
} \
static DEVICE_ATTR(name, 0444, show_##name, NULL)
@@ -343,7 +344,7 @@ CMM_SHOW(loaned_target_kb, "%lu\n", PAGES2KB(loaned_pages_target));
static ssize_t show_oom_pages(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return sprintf(buf, "%lu\n", PAGES2KB(oom_freed_pages));
+ return sysfs_emit(buf, "%lu\n", PAGES2KB(oom_freed_pages));
}
static ssize_t store_oom_pages(struct device *dev,
diff --git a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c
index a7c451c2507d..f4d33b8dffd8 100644
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -14,6 +14,7 @@
#include <linux/spinlock.h>
#include <linux/cpu.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <linux/of.h>
#include "of_helpers.h"
@@ -798,7 +799,7 @@ static ssize_t dlpar_store(const struct class *class, const struct class_attribu
static ssize_t dlpar_show(const struct class *class, const struct class_attribute *attr,
char *buf)
{
- return sprintf(buf, "%s\n", "memory,cpu,dt");
+ return sysfs_emit(buf, "%s\n", "memory,cpu,dt");
}
static CLASS_ATTR_RW(dlpar);
diff --git a/arch/powerpc/platforms/pseries/ibmebus.c b/arch/powerpc/platforms/pseries/ibmebus.c
index cad2deb7e70d..2d0f991da2c8 100644
--- a/arch/powerpc/platforms/pseries/ibmebus.c
+++ b/arch/powerpc/platforms/pseries/ibmebus.c
@@ -46,6 +46,7 @@
#include <linux/of.h>
#include <linux/slab.h>
#include <linux/stat.h>
+#include <linux/sysfs.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <asm/ibmebus.h>
@@ -399,7 +400,7 @@ static ssize_t devspec_show(struct device *dev,
struct platform_device *ofdev;
ofdev = to_platform_device(dev);
- return sprintf(buf, "%pOF\n", ofdev->dev.of_node);
+ return sysfs_emit(buf, "%pOF\n", ofdev->dev.of_node);
}
static DEVICE_ATTR_RO(devspec);
@@ -409,7 +410,7 @@ static ssize_t name_show(struct device *dev,
struct platform_device *ofdev;
ofdev = to_platform_device(dev);
- return sprintf(buf, "%pOFn\n", ofdev->dev.of_node);
+ return sysfs_emit(buf, "%pOFn\n", ofdev->dev.of_node);
}
static DEVICE_ATTR_RO(name);
diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index 63eca4ebb5e5..75da96c08cdd 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -8,6 +8,7 @@
#include <linux/ioport.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <linux/ndctl.h>
#include <linux/sched.h>
#include <linux/libnvdimm.h>
@@ -1062,8 +1063,8 @@ static ssize_t health_bitmap_inject_show(struct device *dev,
struct nvdimm *dimm = to_nvdimm(dev);
struct papr_scm_priv *p = nvdimm_provider_data(dimm);
- return sprintf(buf, "%#llx\n",
- READ_ONCE(p->health_bitmap_inject_mask));
+ return sysfs_emit(buf, "%#llx\n",
+ READ_ONCE(p->health_bitmap_inject_mask));
}
static DEVICE_ATTR_ADMIN_RO(health_bitmap_inject);
diff --git a/arch/powerpc/platforms/pseries/power.c b/arch/powerpc/platforms/pseries/power.c
index 3676cb297767..7b9dfe829f25 100644
--- a/arch/powerpc/platforms/pseries/power.c
+++ b/arch/powerpc/platforms/pseries/power.c
@@ -11,6 +11,7 @@
#include <linux/kobject.h>
#include <linux/string.h>
+#include <linux/sysfs.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <asm/machdep.h>
@@ -22,7 +23,7 @@ unsigned long rtas_poweron_auto; /* default and normal state is 0 */
static ssize_t auto_poweron_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
- return sprintf(buf, "%lu\n", rtas_poweron_auto);
+ return sysfs_emit(buf, "%lu\n", rtas_poweron_auto);
}
static ssize_t auto_poweron_store(struct kobject *kobj,
diff --git a/arch/powerpc/platforms/pseries/pseries_energy.c b/arch/powerpc/platforms/pseries/pseries_energy.c
index 2c661b798235..fdaf85ecd39b 100644
--- a/arch/powerpc/platforms/pseries/pseries_energy.c
+++ b/arch/powerpc/platforms/pseries/pseries_energy.c
@@ -12,6 +12,7 @@
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/seq_file.h>
+#include <linux/sysfs.h>
#include <linux/device.h>
#include <linux/cpu.h>
#include <linux/of.h>
@@ -242,7 +243,7 @@ static ssize_t get_best_energy_data(struct device *dev,
if (rc != H_SUCCESS)
return -EINVAL;
- return sprintf(page, "%lu\n", retbuf[1] >> 32);
+ return sysfs_emit(page, "%lu\n", retbuf[1] >> 32);
}
/* Wrapper functions */
diff --git a/arch/powerpc/platforms/pseries/suspend.c b/arch/powerpc/platforms/pseries/suspend.c
index c51db63d3e88..a9928d75624a 100644
--- a/arch/powerpc/platforms/pseries/suspend.c
+++ b/arch/powerpc/platforms/pseries/suspend.c
@@ -7,6 +7,7 @@
#include <linux/delay.h>
#include <linux/suspend.h>
#include <linux/stat.h>
+#include <linux/sysfs.h>
#include <asm/firmware.h>
#include <asm/hvcall.h>
#include <asm/machdep.h>
@@ -121,7 +122,7 @@ static ssize_t show_hibernate(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- return sprintf(buf, "%d\n", KERN_DT_UPDATE);
+ return sysfs_emit(buf, "%d\n", KERN_DT_UPDATE);
}
static DEVICE_ATTR(hibernate, 0644, show_hibernate, store_hibernate);
diff --git a/arch/powerpc/platforms/pseries/vas-sysfs.c b/arch/powerpc/platforms/pseries/vas-sysfs.c
index 4f6fbbb672ae..00c6ffd3ef39 100644
--- a/arch/powerpc/platforms/pseries/vas-sysfs.c
+++ b/arch/powerpc/platforms/pseries/vas-sysfs.c
@@ -10,6 +10,7 @@
#include <linux/miscdevice.h>
#include <linux/kobject.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <linux/mm.h>
#include "vas.h"
@@ -58,7 +59,7 @@ static ssize_t update_total_credits_store(struct vas_cop_feat_caps *caps,
#define sysfs_caps_entry_read(_name) \
static ssize_t _name##_show(struct vas_cop_feat_caps *caps, char *buf) \
{ \
- return sprintf(buf, "%d\n", atomic_read(&caps->_name)); \
+ return sysfs_emit(buf, "%d\n", atomic_read(&caps->_name)); \
}
struct vas_sysfs_entry {
diff --git a/arch/powerpc/platforms/pseries/vio.c b/arch/powerpc/platforms/pseries/vio.c
index 08e2add48adb..572bdf42335e 100644
--- a/arch/powerpc/platforms/pseries/vio.c
+++ b/arch/powerpc/platforms/pseries/vio.c
@@ -14,6 +14,7 @@
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/stat.h>
+#include <linux/sysfs.h>
#include <linux/device.h>
#include <linux/init.h>
#include <linux/slab.h>
@@ -942,14 +943,14 @@ static ssize_t cmo_##name##_show(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \
- return sprintf(buf, "%lu\n", to_vio_dev(dev)->cmo.name); \
+ return sysfs_emit(buf, "%lu\n", to_vio_dev(dev)->cmo.name); \
}
static ssize_t cmo_allocs_failed_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct vio_dev *viodev = to_vio_dev(dev);
- return sprintf(buf, "%d\n", atomic_read(&viodev->cmo.allocs_failed));
+ return sysfs_emit(buf, "%d\n", atomic_read(&viodev->cmo.allocs_failed));
}
static ssize_t cmo_allocs_failed_store(struct device *dev,
@@ -998,7 +999,7 @@ static DEVICE_ATTR_RW(cmo_allocs_failed);
#define viobus_cmo_rd_attr(name) \
static ssize_t cmo_bus_##name##_show(const struct bus_type *bt, char *buf) \
{ \
- return sprintf(buf, "%lu\n", vio_cmo.name); \
+ return sysfs_emit(buf, "%lu\n", vio_cmo.name); \
} \
static struct bus_attribute bus_attr_cmo_bus_##name = \
__ATTR(cmo_##name, S_IRUGO, cmo_bus_##name##_show, NULL)
@@ -1007,7 +1008,7 @@ static struct bus_attribute bus_attr_cmo_bus_##name = \
static ssize_t \
cmo_##name##_##var##_show(const struct bus_type *bt, char *buf) \
{ \
- return sprintf(buf, "%lu\n", vio_cmo.name.var); \
+ return sysfs_emit(buf, "%lu\n", vio_cmo.name.var); \
} \
static BUS_ATTR_RO(cmo_##name##_##var)
@@ -1022,7 +1023,7 @@ viobus_cmo_pool_rd_attr(excess, free);
static ssize_t cmo_high_show(const struct bus_type *bt, char *buf)
{
- return sprintf(buf, "%lu\n", vio_cmo.high);
+ return sysfs_emit(buf, "%lu\n", vio_cmo.high);
}
static ssize_t cmo_high_store(const struct bus_type *bt, const char *buf,
@@ -1535,7 +1536,7 @@ machine_device_initcall(pseries, vio_device_init);
static ssize_t name_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return sprintf(buf, "%s\n", to_vio_dev(dev)->name);
+ return sysfs_emit(buf, "%s\n", to_vio_dev(dev)->name);
}
static DEVICE_ATTR_RO(name);
@@ -1544,7 +1545,7 @@ static ssize_t devspec_show(struct device *dev,
{
struct device_node *of_node = dev->of_node;
- return sprintf(buf, "%pOF\n", of_node);
+ return sysfs_emit(buf, "%pOF\n", of_node);
}
static DEVICE_ATTR_RO(devspec);
@@ -1556,17 +1557,13 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
const char *cp;
dn = dev->of_node;
- if (!dn) {
- strcpy(buf, "\n");
- return strlen(buf);
- }
+ if (!dn)
+ return sysfs_emit(buf, "\n");
cp = of_get_property(dn, "compatible", NULL);
- if (!cp) {
- strcpy(buf, "\n");
- return strlen(buf);
- }
+ if (!cp)
+ return sysfs_emit(buf, "\n");
- return sprintf(buf, "vio:T%sS%s\n", vio_dev->type, cp);
+ return sysfs_emit(buf, "vio:T%sS%s\n", vio_dev->type, cp);
}
static DEVICE_ATTR_RO(modalias);
diff --git a/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c b/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c
index f9e64f54dc14..f63b89adf9f3 100644
--- a/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c
+++ b/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c
@@ -7,6 +7,7 @@
#include <linux/kernel.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <linux/errno.h>
#include <linux/module.h>
#include <linux/interrupt.h>
@@ -61,7 +62,7 @@ static ssize_t fsl_timer_wakeup_show(struct device *dev,
}
mutex_unlock(&sysfs_lock);
- return sprintf(buf, "%lld\n", interval);
+ return sysfs_emit(buf, "%lld\n", interval);
}
static ssize_t fsl_timer_wakeup_store(struct device *dev,
^ permalink raw reply related
* [powerpc:merge] BUILD SUCCESS 3af068d1f05b10756292a435d6e90bdba83747d7
From: kernel test robot @ 2026-05-24 11:13 UTC (permalink / raw)
To: Madhavan Srinivasan; +Cc: linuxppc-dev
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git merge
branch HEAD: 3af068d1f05b10756292a435d6e90bdba83747d7 Automatic merge of 'next' into merge (2026-05-22 09:59)
elapsed time: 2786m
configs tested: 275
configs skipped: 11
The following configs have been built successfully.
More configs may be tested in the coming days.
tested configs:
alpha allnoconfig gcc-15.2.0
alpha allyesconfig gcc-15.2.0
alpha defconfig gcc-15.2.0
arc allmodconfig clang-16
arc allmodconfig gcc-15.2.0
arc allnoconfig gcc-15.2.0
arc allyesconfig clang-23
arc allyesconfig gcc-15.2.0
arc defconfig gcc-15.2.0
arc randconfig-001-20260523 gcc-10.5.0
arc randconfig-001-20260524 clang-23
arc randconfig-002-20260523 gcc-14.3.0
arc randconfig-002-20260524 clang-23
arm allnoconfig clang-23
arm allnoconfig gcc-15.2.0
arm allyesconfig clang-16
arm allyesconfig gcc-15.2.0
arm defconfig clang-23
arm defconfig gcc-15.2.0
arm randconfig-001-20260523 gcc-10.5.0
arm randconfig-001-20260524 clang-23
arm randconfig-002-20260523 clang-19
arm randconfig-002-20260524 clang-23
arm randconfig-003-20260523 clang-23
arm randconfig-003-20260524 clang-23
arm randconfig-004-20260523 gcc-10.5.0
arm randconfig-004-20260524 clang-23
arm64 allmodconfig clang-19
arm64 allmodconfig clang-23
arm64 allnoconfig gcc-15.2.0
arm64 defconfig gcc-15.2.0
arm64 randconfig-001-20260523 gcc-15.2.0
arm64 randconfig-002-20260523 gcc-8.5.0
arm64 randconfig-003-20260523 gcc-9.5.0
arm64 randconfig-004-20260523 clang-23
csky allmodconfig gcc-15.2.0
csky allnoconfig gcc-15.2.0
csky defconfig gcc-15.2.0
csky randconfig-001-20260523 gcc-9.5.0
csky randconfig-002-20260523 gcc-15.2.0
hexagon allmodconfig clang-17
hexagon allmodconfig gcc-15.2.0
hexagon allnoconfig clang-23
hexagon allnoconfig gcc-15.2.0
hexagon defconfig clang-23
hexagon defconfig gcc-15.2.0
hexagon randconfig-001-20260523 clang-23
hexagon randconfig-001-20260524 gcc-8.5.0
hexagon randconfig-002-20260523 clang-23
hexagon randconfig-002-20260524 gcc-8.5.0
i386 allmodconfig clang-20
i386 allmodconfig gcc-14
i386 allnoconfig gcc-14
i386 allnoconfig gcc-15.2.0
i386 allyesconfig clang-20
i386 allyesconfig gcc-14
i386 buildonly-randconfig-001-20260523 gcc-14
i386 buildonly-randconfig-001-20260524 gcc-14
i386 buildonly-randconfig-002-20260523 clang-20
i386 buildonly-randconfig-002-20260524 gcc-14
i386 buildonly-randconfig-003-20260523 gcc-14
i386 buildonly-randconfig-003-20260524 gcc-14
i386 buildonly-randconfig-004-20260523 gcc-12
i386 buildonly-randconfig-004-20260524 gcc-14
i386 buildonly-randconfig-005-20260523 clang-20
i386 buildonly-randconfig-005-20260524 gcc-14
i386 buildonly-randconfig-006-20260523 gcc-14
i386 buildonly-randconfig-006-20260524 gcc-14
i386 defconfig clang-20
i386 defconfig gcc-15.2.0
i386 randconfig-001 clang-20
i386 randconfig-001-20260523 gcc-14
i386 randconfig-001-20260524 gcc-14
i386 randconfig-002 gcc-14
i386 randconfig-002-20260523 gcc-12
i386 randconfig-002-20260524 gcc-14
i386 randconfig-003 gcc-14
i386 randconfig-003-20260523 gcc-14
i386 randconfig-003-20260524 gcc-14
i386 randconfig-004 clang-20
i386 randconfig-004-20260523 gcc-12
i386 randconfig-004-20260524 gcc-14
i386 randconfig-005 gcc-14
i386 randconfig-005-20260523 gcc-14
i386 randconfig-005-20260524 gcc-14
i386 randconfig-006 gcc-14
i386 randconfig-006-20260523 gcc-14
i386 randconfig-006-20260524 gcc-14
i386 randconfig-007 gcc-14
i386 randconfig-007-20260523 gcc-14
i386 randconfig-007-20260524 gcc-14
i386 randconfig-011-20260523 gcc-14
i386 randconfig-012-20260523 gcc-14
i386 randconfig-013-20260523 gcc-14
i386 randconfig-014-20260523 clang-20
i386 randconfig-015-20260523 clang-20
i386 randconfig-016-20260523 clang-20
i386 randconfig-017-20260523 clang-20
loongarch allmodconfig clang-19
loongarch allmodconfig clang-23
loongarch allnoconfig clang-23
loongarch allnoconfig gcc-15.2.0
loongarch defconfig clang-19
loongarch randconfig-001-20260523 gcc-15.2.0
loongarch randconfig-001-20260524 gcc-8.5.0
loongarch randconfig-002-20260523 gcc-15.2.0
loongarch randconfig-002-20260524 gcc-8.5.0
m68k allmodconfig gcc-15.2.0
m68k allnoconfig gcc-15.2.0
m68k allyesconfig clang-16
m68k allyesconfig gcc-15.2.0
m68k defconfig clang-19
m68k defconfig gcc-15.2.0
microblaze allnoconfig gcc-15.2.0
microblaze allyesconfig gcc-15.2.0
microblaze defconfig clang-19
microblaze defconfig gcc-15.2.0
mips allmodconfig gcc-15.2.0
mips allnoconfig gcc-15.2.0
mips allyesconfig gcc-15.2.0
nios2 allmodconfig gcc-11.5.0
nios2 allnoconfig clang-23
nios2 allnoconfig gcc-11.5.0
nios2 defconfig clang-19
nios2 defconfig gcc-11.5.0
nios2 randconfig-001-20260523 gcc-11.5.0
nios2 randconfig-001-20260524 gcc-8.5.0
nios2 randconfig-002-20260523 gcc-9.5.0
nios2 randconfig-002-20260524 gcc-8.5.0
openrisc allmodconfig gcc-15.2.0
openrisc allnoconfig clang-23
openrisc allnoconfig gcc-15.2.0
openrisc defconfig gcc-15.2.0
parisc allmodconfig gcc-15.2.0
parisc allnoconfig clang-23
parisc allnoconfig gcc-15.2.0
parisc allyesconfig clang-19
parisc allyesconfig gcc-15.2.0
parisc defconfig gcc-15.2.0
parisc randconfig-001-20260523 gcc-15.2.0
parisc randconfig-001-20260524 clang-23
parisc randconfig-002-20260523 gcc-9.5.0
parisc randconfig-002-20260524 clang-23
parisc64 defconfig clang-19
parisc64 defconfig gcc-15.2.0
powerpc allmodconfig gcc-15.2.0
powerpc allnoconfig clang-23
powerpc allnoconfig gcc-15.2.0
powerpc randconfig-001-20260523 gcc-15.2.0
powerpc randconfig-001-20260524 clang-23
powerpc randconfig-002-20260523 gcc-8.5.0
powerpc randconfig-002-20260524 clang-23
powerpc64 randconfig-001-20260523 clang-16
powerpc64 randconfig-001-20260524 clang-23
powerpc64 randconfig-002-20260523 clang-20
powerpc64 randconfig-002-20260524 clang-23
riscv allmodconfig clang-23
riscv allnoconfig clang-23
riscv allnoconfig gcc-15.2.0
riscv allyesconfig clang-16
riscv defconfig clang-23
riscv defconfig gcc-15.2.0
riscv nommu_virt_defconfig clang-23
riscv randconfig-001-20260523 gcc-8.5.0
riscv randconfig-001-20260524 gcc-15.2.0
riscv randconfig-002-20260523 gcc-8.5.0
riscv randconfig-002-20260524 gcc-15.2.0
s390 allmodconfig clang-18
s390 allmodconfig clang-19
s390 allnoconfig clang-23
s390 allyesconfig gcc-15.2.0
s390 defconfig clang-23
s390 defconfig gcc-15.2.0
s390 randconfig-001-20260523 clang-23
s390 randconfig-001-20260524 gcc-15.2.0
s390 randconfig-002-20260523 clang-23
s390 randconfig-002-20260524 gcc-15.2.0
sh allmodconfig gcc-15.2.0
sh allnoconfig clang-23
sh allnoconfig gcc-15.2.0
sh allyesconfig clang-19
sh allyesconfig gcc-15.2.0
sh defconfig gcc-14
sh defconfig gcc-15.2.0
sh randconfig-001-20260523 gcc-15.2.0
sh randconfig-001-20260524 gcc-15.2.0
sh randconfig-002-20260523 gcc-11.5.0
sh randconfig-002-20260524 gcc-15.2.0
sparc allnoconfig clang-23
sparc allnoconfig gcc-15.2.0
sparc defconfig gcc-15.2.0
sparc randconfig-001-20260523 gcc-8.5.0
sparc randconfig-002-20260523 gcc-8.5.0
sparc64 allmodconfig clang-23
sparc64 defconfig clang-20
sparc64 defconfig gcc-14
sparc64 randconfig-001-20260523 clang-23
sparc64 randconfig-002-20260523 gcc-15.2.0
um allmodconfig clang-19
um allnoconfig clang-23
um allyesconfig gcc-14
um allyesconfig gcc-15.2.0
um defconfig clang-23
um defconfig gcc-14
um i386_defconfig gcc-14
um randconfig-001-20260523 gcc-14
um randconfig-002-20260523 gcc-14
um x86_64_defconfig clang-23
um x86_64_defconfig gcc-14
x86_64 allmodconfig clang-20
x86_64 allnoconfig clang-20
x86_64 allnoconfig clang-23
x86_64 allyesconfig clang-20
x86_64 buildonly-randconfig-001-20260523 gcc-14
x86_64 buildonly-randconfig-001-20260524 clang-20
x86_64 buildonly-randconfig-002-20260523 gcc-14
x86_64 buildonly-randconfig-002-20260524 clang-20
x86_64 buildonly-randconfig-003-20260523 gcc-14
x86_64 buildonly-randconfig-003-20260524 clang-20
x86_64 buildonly-randconfig-004-20260523 clang-20
x86_64 buildonly-randconfig-004-20260524 clang-20
x86_64 buildonly-randconfig-005-20260523 gcc-14
x86_64 buildonly-randconfig-005-20260524 clang-20
x86_64 buildonly-randconfig-006-20260523 clang-20
x86_64 buildonly-randconfig-006-20260524 clang-20
x86_64 defconfig gcc-14
x86_64 kexec clang-20
x86_64 randconfig-001-20260523 clang-20
x86_64 randconfig-001-20260524 clang-20
x86_64 randconfig-002-20260523 gcc-14
x86_64 randconfig-002-20260524 clang-20
x86_64 randconfig-003-20260523 clang-20
x86_64 randconfig-003-20260524 clang-20
x86_64 randconfig-004-20260523 clang-20
x86_64 randconfig-004-20260524 clang-20
x86_64 randconfig-005-20260523 gcc-14
x86_64 randconfig-005-20260524 clang-20
x86_64 randconfig-006-20260523 gcc-14
x86_64 randconfig-006-20260524 clang-20
x86_64 randconfig-011-20260523 gcc-14
x86_64 randconfig-011-20260524 clang-20
x86_64 randconfig-012-20260523 clang-20
x86_64 randconfig-012-20260524 clang-20
x86_64 randconfig-013-20260523 gcc-14
x86_64 randconfig-013-20260524 clang-20
x86_64 randconfig-014-20260523 clang-20
x86_64 randconfig-014-20260524 clang-20
x86_64 randconfig-015-20260523 gcc-14
x86_64 randconfig-015-20260524 clang-20
x86_64 randconfig-016-20260523 clang-20
x86_64 randconfig-016-20260524 clang-20
x86_64 randconfig-071-20260523 gcc-14
x86_64 randconfig-071-20260524 gcc-14
x86_64 randconfig-072-20260523 gcc-14
x86_64 randconfig-072-20260524 gcc-14
x86_64 randconfig-073-20260523 gcc-14
x86_64 randconfig-073-20260524 gcc-14
x86_64 randconfig-074-20260523 clang-20
x86_64 randconfig-074-20260524 gcc-14
x86_64 randconfig-075-20260523 clang-20
x86_64 randconfig-075-20260524 gcc-14
x86_64 randconfig-076-20260523 clang-20
x86_64 randconfig-076-20260524 gcc-14
x86_64 rhel-9.4 clang-20
x86_64 rhel-9.4-bpf gcc-14
x86_64 rhel-9.4-func clang-20
x86_64 rhel-9.4-kselftests clang-20
x86_64 rhel-9.4-kunit gcc-14
x86_64 rhel-9.4-ltp gcc-14
x86_64 rhel-9.4-rust clang-20
xtensa allnoconfig clang-23
xtensa allnoconfig gcc-15.2.0
xtensa allyesconfig gcc-15.2.0
xtensa randconfig-001-20260523 gcc-15.2.0
xtensa randconfig-002-20260523 gcc-8.5.0
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply
* [PATCH] misc: eeprom: at24: Make VCC supply description requirement optional
From: Paul Menzel @ 2026-05-24 8:05 UTC (permalink / raw)
To: Bartosz Golaszewski, Arnd Bergmann, Greg Kroah-Hartman,
Liam Girdwood, Mark Brown
Cc: Paul Menzel, Madhavan Srinivasan, Michael Ellerman, linuxppc-dev,
linux-i2c, linux-kernel
Some platforms (e.g. IBM Power System S822LC (8335-GCA POWER8)) do not
describe the EEPROM’s VCC supply in firmware-provided device trees.
Using `devm_regulator_get()` on such systems falls back to a dummy
regulator with a kernel warning:
at24 0-0051: supply vcc not found, using dummy regulator
at24 0-0051: 16384 byte 24c128 EEPROM, writable, 1 bytes/write
at24 0-0052: supply vcc not found, using dummy regulator
at24 0-0052: 256 byte 24c02 EEPROM, writable, 1 bytes/write
at24 0-0053: supply vcc not found, using dummy regulator
at24 0-0053: 256 byte 24c02 EEPROM, writable, 1 bytes/write
at24 0-0054: supply vcc not found, using dummy regulator
at24 0-0054: 256 byte 24c02 EEPROM, writable, 1 bytes/write
[…]
at24 12-0050: supply vcc not found, using dummy regulator
at24 12-0050: 16384 byte 24c128 EEPROM, writable, 1 bytes/write
at24 12-0051: supply vcc not found, using dummy regulator
at24 12-0051: 16384 byte 24c128 EEPROM, writable, 1 bytes/write
Switch to `devm_regulator_get_optional()` and treat -ENODEV as “no
supply described”. When `vcc_reg` is NULL, skip all
regulator_enable/disable calls; the hardware is assumed to be always
powered. Linux now logs:
at24 0-0051: 16384 byte 24c128 EEPROM, writable, 1 bytes/write
at24 0-0052: 256 byte 24c02 EEPROM, writable, 1 bytes/write
at24 0-0053: 256 byte 24c02 EEPROM, writable, 1 bytes/write
at24 0-0054: 256 byte 24c02 EEPROM, writable, 1 bytes/write
at24 0-0055: 256 byte 24c02 EEPROM, writable, 1 bytes/write
[…]
at24 12-0050: 16384 byte 24c128 EEPROM, writable, 1 bytes/write
at24 12-0051: 16384 byte 24c128 EEPROM, writable, 1 bytes/write
Assisted-by: Claude Sonnet 4.6
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
---
drivers/misc/eeprom/at24.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 0200288d3a7a..7e1050f8759a 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -699,9 +699,12 @@ static int at24_probe(struct i2c_client *client)
at24->offset_adj = at24_get_offset_adj(flags, byte_len);
at24->client_regmaps[0] = regmap;
- at24->vcc_reg = devm_regulator_get(dev, "vcc");
- if (IS_ERR(at24->vcc_reg))
- return PTR_ERR(at24->vcc_reg);
+ at24->vcc_reg = devm_regulator_get_optional(dev, "vcc");
+ if (IS_ERR(at24->vcc_reg)) {
+ if (PTR_ERR(at24->vcc_reg) != -ENODEV)
+ return PTR_ERR(at24->vcc_reg);
+ at24->vcc_reg = NULL;
+ }
writable = !(flags & AT24_FLAG_READONLY);
if (writable) {
@@ -754,9 +757,12 @@ static int at24_probe(struct i2c_client *client)
full_power = acpi_dev_state_d0(&client->dev);
if (full_power) {
- err = regulator_enable(at24->vcc_reg);
- if (err)
- return dev_err_probe(dev, err, "Failed to enable vcc regulator\n");
+ if (at24->vcc_reg) {
+ err = regulator_enable(at24->vcc_reg);
+ if (err) {
+ return dev_err_probe(dev, err, "Failed to enable vcc regulator\n");
+ }
+ }
pm_runtime_set_active(dev);
}
@@ -771,7 +777,7 @@ static int at24_probe(struct i2c_client *client)
err = at24_read(at24, 0, &test_byte, 1);
if (err) {
pm_runtime_disable(dev);
- if (!pm_runtime_status_suspended(dev))
+ if (!pm_runtime_status_suspended(dev) && at24->vcc_reg)
regulator_disable(at24->vcc_reg);
return -ENODEV;
}
@@ -808,7 +814,7 @@ static void at24_remove(struct i2c_client *client)
pm_runtime_disable(&client->dev);
if (acpi_dev_state_d0(&client->dev)) {
- if (!pm_runtime_status_suspended(&client->dev))
+ if (!pm_runtime_status_suspended(&client->dev) && at24->vcc_reg)
regulator_disable(at24->vcc_reg);
pm_runtime_set_suspended(&client->dev);
}
@@ -819,6 +825,8 @@ static int __maybe_unused at24_suspend(struct device *dev)
struct i2c_client *client = to_i2c_client(dev);
struct at24_data *at24 = i2c_get_clientdata(client);
+ if (!at24->vcc_reg)
+ return 0;
return regulator_disable(at24->vcc_reg);
}
@@ -827,6 +835,8 @@ static int __maybe_unused at24_resume(struct device *dev)
struct i2c_client *client = to_i2c_client(dev);
struct at24_data *at24 = i2c_get_clientdata(client);
+ if (!at24->vcc_reg)
+ return 0;
return regulator_enable(at24->vcc_reg);
}
--
2.53.0
^ permalink raw reply related
* Re: [PATCH] crypto: nx: fix nx_crypto_ctx_exit argument
From: Breno Leitao @ 2026-05-24 7:10 UTC (permalink / raw)
To: Sam James
Cc: Nayna Jain, Paulo Flabiano Smorigo, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Herbert Xu, David S. Miller, Eric Biggers, Ard Biesheuvel,
Eric Biggers, Calvin Buckley, Brad Spengler, linux-crypto,
linuxppc-dev, linux-kernel
In-Reply-To: <a3e89c1e8342ffa415b0d29725a0571a4f355d34.1779472902.git.sam@gentoo.org>
On Fri, May 22, 2026 at 07:01:42PM +0000, Sam James wrote:
> nx_crypto_ctx_shash_exit calls nx_crypto_ctx_exit with crypto_shash_ctx(...)
> but crypto_shash_ctx gives a nx_crypto_ctx *, not a crypto_tfm *.
>
> Fix the type in nx_crypto_ctx_exit and drop the bogus crypto_tfm_ctx
> call.
>
> This fixes the following oops:
>
> BUG: Unable to handle kernel data access at 0xc0403effffffffc8
> Faulting instruction address: 0xc000000000396cb4
> Oops: Kernel access of bad area, sig: 11 [#15]
> Call Trace:
> nx_crypto_ctx_shash_exit+0x24/0x60
> crypto_shash_exit_tfm+0x28/0x40
> crypto_destroy_tfm+0x98/0x140
> crypto_exit_ahash_using_shash+0x20/0x40
> crypto_destroy_tfm+0x98/0x140
> hash_release+0x1c/0x30
> alg_sock_destruct+0x38/0x60
> __sk_destruct+0x48/0x2b0
> af_alg_release+0x58/0xb0
> __sock_release+0x68/0x150
> sock_close+0x20/0x40
> __fput+0x110/0x3a0
> sys_close+0x48/0xa0
> system_call_exception+0x140/0x2d0
> system_call_common+0xf4/0x258
>
> .. which came from hardlink(1) opportunistically using AF_ALG.
>
> The same problem exists with nx_crypto_ctx_skcipher_exit getting a context
> it wasn't expecting, but apparently nobody hit that for years.
>
> Cc: Eric Biggers <ebiggers@kernel.org>
> Fixes: bfd9efddf990 ("crypto: nx - convert AES-ECB to skcipher API")
> Fixes: 9420e628e7d8 ("crypto: nx - Use API partial block handling")
> Reported-by: Calvin Buckley <calvin@cmpct.info>
> Tested-by: Calvin Buckley <calvin@cmpct.info>
> Suggested-by: Brad Spengler <brad.spengler@opensrcsec.com>
> Signed-off-by: Sam James <sam@gentoo.org>
Acked-by: Breno Leitao <leitao@debian.org>
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox