NULL pointer dereference when booting ppc64_guest_defconfig in QEMU on -next
Subsystems (12)
Hi all,
I am not really sure whose bug this is, as it only appears when three seemingly independent patch series are applied together, so I have added the patch authors and their committers (along with the tracing maintainers) to this thread. Feel free to expand or reduce that list as necessary.
Our continuous integration has noticed a crash when booting ppc64_guest_defconfig in QEMU on the past few -next versions.
https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/23311154492/job/67811527112
This does not appear to be clang related, as it can be reproduced with GCC 15.2.0 as well. Through multiple bisects, I was able to land on applying:
mm: improve RSS counter approximation accuracy for proc interfaces [1] vdso/datastore: Allocate data pages dynamically [2]
kho: fix deferred init of kho scratch [3]
and their dependent changes on top of 7.0-rc4 is enough to reproduce this (at least on two of my machines with the same commands). I have attached the diff from the result of the following 'git apply' commands below, done in a linux-next checkout.
$ git checkout v7.0-rc4 HEAD is now at f338e7738378 Linux 7.0-rc4
# [1]
$ git diff 60ddf3eed4999bae440d1cf9e5868ccb3f308b64^..087dd6d2cc12c82945ab859194c32e8e977daae3 | git apply -3v ...
# [2]
# Fix trivial conflict in init/main.c around headers
$ git diff dc432ab7130bb39f5a351281a02d4bc61e85a14a^..05988dba11791ccbb458254484826b32f17f4ad2 | git apply -3v ...
# [3]
# Fix conflict in kernel/liveupdate/kexec_handover.c due to lack of kho_mem_retrieve(), just add pfn_is_kho_scratch()
$ git show 4a78467ffb537463486968232daef1e8a2f105e3 | git apply -3v ...
$ make -skj"$(nproc)" ARCH=powerpc CROSS_COMPILE=powerpc64-linux- mrproper ppc64_guest_defconfig vmlinux
$ curl -LSs https://github.com/ClangBuiltLinux/boot-utils/releases/download/20241120-044434/ppc64-rootfs.cpio.zst | zstd -d >rootfs.cpio
$ qemu-system-ppc64 \
-display none \
-nodefaults \
-cpu power8 \
-machine pseries \
-vga none \
-kernel vmlinux \
-initrd rootfs.cpio \
-m 1G \
-serial mon:stdio
...
[ 0.000000][ T0] Linux version 7.0.0-rc4-dirty (nathan@framework-amd-ryzen-maxplus-395) (powerpc64-linux-gcc (GCC) 15.2.0, GNU ld (GNU Binutils) 2.45) #1 SMP PREEMPT Thu Mar 19 15:45:53 MST 2026
...
[ 0.216764][ T1] vgaarb: loaded
[ 0.217590][ T1] clocksource: Switched to clocksource timebase
[ 0.221007][ T12] BUG: Kernel NULL pointer dereference at 0x00000010
[ 0.221049][ T12] Faulting instruction address: 0xc00000000044947c
[ 0.221237][ T12] Oops: Kernel access of bad area, sig: 11 [#1]
[ 0.221276][ T12] BE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries
[ 0.221359][ T12] Modules linked in:
[ 0.221556][ T12] CPU: 0 UID: 0 PID: 12 Comm: kworker/u4:0 Not tainted 7.0.0-rc4-dirty #1 PREEMPTLAZY
[ 0.221631][ T12] Hardware name: IBM pSeries (emulated by qemu) POWER8 (architected) 0x4d0200 0xf000004 of:SLOF,HEAD pSeries
[ 0.221765][ T12] Workqueue: trace_init_wq tracer_init_tracefs_work_func
[ 0.222065][ T12] NIP: c00000000044947c LR: c00000000041a584 CTR: c00000000053aa90
[ 0.222084][ T12] REGS: c000000003bc7960 TRAP: 0380 Not tainted (7.0.0-rc4-dirty)
[ 0.222111][ T12] MSR: 8000000000009032 <SF,EE,ME,IR,DR,RI> CR: 44000204 XER: 00000000
[ 0.222287][ T12] CFAR: c000000000449420 IRQMASK: 0
[ 0.222287][ T12] GPR00: c00000000041a584 c000000003bc7c00 c000000001c08100 c000000002892f20
[ 0.222287][ T12] GPR04: c0000000019cfa68 c0000000019cfa60 0000000000000001 0000000000000064
[ 0.222287][ T12] GPR08: 0000000000000002 0000000000000000 c000000003bba000 0000000000000010
[ 0.222287][ T12] GPR12: c00000000053aa90 c000000002c50000 c000000001ab25f8 c000000001626690
[ 0.222287][ T12] GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
[ 0.222287][ T12] GPR20: c000000001624868 c000000001ab2708 c0000000019cfa08 c000000001a00d18
[ 0.222287][ T12] GPR24: c0000000019cfa18 fffffffffffffef7 c000000003051205 c0000000019cfa68
[ 0.222287][ T12] GPR28: 0000000000000000 c0000000019cfa60 c000000002894e90 0000000000000000
[ 0.222526][ T12] NIP [c00000000044947c] __find_event_file+0x9c/0x110
[ 0.222572][ T12] LR [c00000000041a584] init_tracer_tracefs+0x274/0xcc0
[ 0.222643][ T12] Call Trace:
[ 0.222690][ T12] [c000000003bc7c00] [c000000000b943b0] tracefs_create_file+0x1a0/0x2b0 (unreliable)
[ 0.222766][ T12] [c000000003bc7c50] [c00000000041a584] init_tracer_tracefs+0x274/0xcc0
[ 0.222791][ T12] [c000000003bc7dc0] [c000000002046f1c] tracer_init_tracefs_work_func+0x50/0x320
[ 0.222809][ T12] [c000000003bc7e50] [c000000000276958] process_one_work+0x1b8/0x530
[ 0.222828][ T12] [c000000003bc7f10] [c00000000027778c] worker_thread+0x1dc/0x3d0
[ 0.222883][ T12] [c000000003bc7f90] [c000000000284c44] kthread+0x194/0x1b0
[ 0.222900][ T12] [c000000003bc7fe0] [c00000000000cf30] start_kernel_thread+0x14/0x18
[ 0.222961][ T12] Code: 7c691b78 7f63db78 2c090000 40820018 e89c0000 49107f21 60000000 2c030000 41820048 ebff0000 7c3ff040 41820038 <e93f0010> 7fa3eb78 81490058 e8890018
[ 0.223190][ T12] ---[ end trace 0000000000000000 ]---
...Interestingly, turning on CONFIG_KASAN appears to hide this, maybe pointing to some sort of memory corruption (or something timing related)? If there is any other information I can provide, I am more than happy to do so.
[1]: https://lore.kernel.org/[email protected]/
[2]: https://lore.kernel.org/[email protected]/
[3]: https://lore.kernel.org/[email protected]/
Cheers,
Nathan
Documentation/core-api/percpu-counter-tree.rst new file +75 -0
@@ -0,0 +1,75 @@ +======================================== +The Hierarchical Per-CPU Counters (HPCC) +======================================== + +:Author: Mathieu Desnoyers + +Introduction +============ + +Counters come in many varieties, each with their own trade offs: + + * A global atomic counter provides a fast read access to the current + sum, at the expense of cache-line bouncing on updates. This leads to + poor performance of frequent updates from various cores on large SMP + systems. + + * A per-cpu split counter provides fast updates to per-cpu counters, + at the expense of a slower aggregation (sum). The sum operation needs + to iterate over all per-cpu counters to calculate the current total. + +The hierarchical per-cpu counters attempt to provide the best of both +worlds (fast updates, and fast sum) by relaxing requirements on the sum +accuracy. It allows quickly querying an approximated sum value, along +with the possible min/max ranges of the associated precise sum. The +exact precise sum can still be calculated with an iteration on all +per-cpu counter, but the availability of an approximated sum value with +possible precise sum min/max ranges allows eliminating candidates which +are certainly outside of a known target range without the overhead of +precise sums. + +Overview +======== + +The herarchical per-cpu counters are organized as a tree with the tree +root at the bottom (last level) and the first level of the tree +consisting of per-cpu counters. + +The intermediate tree levels contain carry propagation counters. When +reaching a threshold (batch size), the carry is propagated down the +tree. + +This allows reading an approximated value at the root, which has a +bounded accuracy (minimum/maximum possible precise sum range) determined +by the tree topology. + +Use Cases +========= + +Use cases HPCC is meant to handle invove tracking resources which are +used across many CPUs to quickly sum as feedback for decision making to +apply throttling, quota limits, sort tasks, and perform memory or task +migration decisions. When considering approximated sums within the +accuracy range of the decision threshold, the user can either: + + * Be conservative and fast: Consider that the sum has reached the + limit as soon as the given limit is within the approximation range. + + * Be aggressive and fast: Consider that the sum is over the + limit only when the approximation range is over the given limit. + + * Be precise and slow: Do a precise comparison with the limit, which + requires a precise sum when the limit is within the approximated + range. + +One use-case for these hierarchical counters is to implement a two-pass +algorithm to speed up sorting picking a maximum/minimunm sum value from +a set. A first pass compares the approximated values, and then a second +pass only needs the precise sum for counter trees which are within the +possible precise sum range of the counter tree chosen by the first pass. + +Functions and structures +======================== + +.. kernel-doc:: include/linux/percpu_counter_tree.h +.. kernel-doc:: lib/percpu_counter_tree.c
include/linux/kexec_handover.h +6 -0
@@ -35,6 +35,7 @@ void *kho_restore_vmalloc(const struct kho_vmalloc *preservation);int kho_add_subtree (const char *name,void *fdt);void kho_remove_subtree (void *fdt);int kho_retrieve_subtree (const char *name,phys_addr_t *phys); +bool pfn_is_kho_scratch (unsigned long pfn);void kho_memory_init (void );
@@ -109,6 +110,11 @@ static inline int kho_retrieve_subtree(const char *name, phys_addr_t *phys)return -EOPNOTSUPP ; } +static inline bool pfn_is_kho_scratch (unsigned long pfn) +{ +return false; +} +static inline void kho_memory_init (void ) { } static inline void kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
include/linux/memblock.h +0 -2
@@ -614,11 +614,9 @@ static inline void memtest_report_meminfo(struct seq_file *m) { }#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH void memblock_set_kho_scratch_only (void );void memblock_clear_kho_scratch_only (void ); -void memmap_init_kho_scratch_pages (void );#else static inline void memblock_set_kho_scratch_only (void ) { }static inline void memblock_clear_kho_scratch_only (void ) { } -static inline void memmap_init_kho_scratch_pages (void ) {}#endif #endif /* _LINUX_MEMBLOCK_H */
include/linux/mm.h +14 -5
@@ -3057,38 +3057,47 @@ static inline bool get_user_page_fast_only(unsigned long addr, {return get_user_pages_fast_only (addr,1 , gup_flags, pagep) ==1 ; } + +static inline struct percpu_counter_tree_level_item *get_rss_stat_items (struct mm_struct *mm) +{ +unsigned long ptr = (unsigned long )mm; + + ptr += offsetof(struct mm_struct , flexible_array); +return (struct percpu_counter_tree_level_item *)ptr; +} +/* * per-process(per-mm_struct) statistics. */ static inline unsigned long get_mm_counter (struct mm_struct *mm,int member) { -return percpu_counter_read_positive (&mm->rss_stat[member]); +return percpu_counter_tree_approximate_sum_positive (&mm->rss_stat[member]); }static inline unsigned long get_mm_counter_sum (struct mm_struct *mm,int member) { -return percpu_counter_sum_positive (&mm->rss_stat[member]); +return percpu_counter_tree_precise_sum_positive (&mm->rss_stat[member]); }void mm_trace_rss_stat (struct mm_struct *mm,int member);static inline void add_mm_counter (struct mm_struct *mm,int member,long value) { -percpu_counter_add (&mm->rss_stat[member], value); +percpu_counter_tree_add (&mm->rss_stat[member], value);mm_trace_rss_stat (mm, member); }static inline void inc_mm_counter (struct mm_struct *mm,int member) { -percpu_counter_inc (&mm->rss_stat[member]); +percpu_counter_tree_add (&mm->rss_stat[member],1 );mm_trace_rss_stat (mm, member); }static inline void dec_mm_counter (struct mm_struct *mm,int member) { -percpu_counter_dec (&mm->rss_stat[member]); +percpu_counter_tree_add (&mm->rss_stat[member],-1 );mm_trace_rss_stat (mm, member); }
include/linux/mm_types.h +39 -15
99 lines not on this page · raw message
include/linux/percpu_counter_tree.h new file +367 -0
367 lines not on this page · raw message
include/linux/vdso_datastore.h +6 -0
@@ -2,9 +2,15 @@#ifndef _LINUX_VDSO_DATASTORE_H#define _LINUX_VDSO_DATASTORE_H +#ifdef CONFIG_HAVE_GENERIC_VDSO #include <linux/mm_types.h> extern const struct vm_special_mapping vdso_vvar_mapping;struct vm_area_struct *vdso_install_vvar_mapping (struct mm_struct *mm,unsigned long addr); +void __init vdso_setup_data_pages (void ); +#else /* !CONFIG_HAVE_GENERIC_VDSO */ +static inline void vdso_setup_data_pages (void ) { } +#endif /* CONFIG_HAVE_GENERIC_VDSO */ +#endif /* _LINUX_VDSO_DATASTORE_H */
include/trace/events/kmem.h +1 -1
@@ -448,7 +448,7 @@ TRACE_EVENT(rss_stat,*/ __entry->curr = current->mm == mm && !(current->flags &PF_KTHREAD ); __entry->member = member; - __entry->size = (percpu_counter_sum_positive (&mm->rss_stat[member]) + __entry->size = (percpu_counter_tree_approximate_sum_positive (&mm->rss_stat[member]) <<PAGE_SHIFT ); ),
init/main.c +4 -0
@@ -105,6 +105,8 @@#include <linux/ptdump.h> #include <linux/time_namespace.h> #include <linux/unaligned.h> +#include <linux/percpu_counter_tree.h> +#include <linux/vdso_datastore.h> #include <net/net_namespace.h> #include <asm/io.h>
@@ -1067,6 +1069,7 @@ void start_kernel(void)vfs_caches_init_early ();sort_main_extable ();trap_init (); +percpu_counter_tree_subsystem_init ();mm_core_init ();maple_tree_init ();poking_init ();
@@ -1119,6 +1122,7 @@ void start_kernel(void)srcu_init ();hrtimers_init ();softirq_init (); +vdso_setup_data_pages ();timekeeping_init ();time_init ();
kernel/fork.c +13 -9
@@ -134,6 +134,11 @@*/ #define MAX_THREADS FUTEX_TID_MASK +/* +* Batch size of rss stat approximation +*/ +#define RSS_STAT_BATCH_SIZE 32 +/* * Protected counters by write_lock_irq(&tasklist_lock) */
@@ -627,14 +632,12 @@ static void check_mm(struct mm_struct *mm) "Please make sure 'struct resident_page_types[]' is updated as well");for (i =0 ; i <NR_MM_COUNTERS ; i++) { -long x =percpu_counter_sum (&mm->rss_stat[i]); - -if (unlikely (x)) { +if (unlikely (percpu_counter_tree_precise_compare_value (&mm->rss_stat[i],0 ) !=0 ))pr_alert ("BUG: Bad rss-counter state mm:%p type:%s val:%ld Comm:%s Pid:%d\n" , - mm, resident_page_types[i], x, + mm, resident_page_types[i], +percpu_counter_tree_precise_sum (&mm->rss_stat[i]), current->comm,task_pid_nr (current)); - } }if (mm_pgtables_bytes (mm))
@@ -732,7 +735,7 @@ void __mmdrop(struct mm_struct *mm)put_user_ns (mm->user_ns);mm_pasid_drop (mm);mm_destroy_cid (mm); -percpu_counter_destroy_many (mm->rss_stat,NR_MM_COUNTERS ); +percpu_counter_tree_destroy_many (mm->rss_stat,NR_MM_COUNTERS );free_mm (mm); }
@@ -1125,8 +1128,9 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,if (mm_alloc_cid (mm, p)) goto fail_cid; -if (percpu_counter_init_many (mm->rss_stat,0 ,GFP_KERNEL_ACCOUNT , -NR_MM_COUNTERS )) +if (percpu_counter_tree_init_many (mm->rss_stat,get_rss_stat_items (mm), +NR_MM_COUNTERS ,RSS_STAT_BATCH_SIZE , +GFP_KERNEL_ACCOUNT )) goto fail_pcpu; mm->user_ns =get_user_ns (user_ns);
@@ -3008,7 +3012,7 @@ void __init mm_cache_init(void)* dynamically sized based on the maximum CPU number this system * can have, taking hotplug into account (nr_cpu_ids). */ - mm_size =sizeof (struct mm_struct ) +cpumask_size () +mm_cid_size (); + mm_size =sizeof (struct mm_struct ) +cpumask_size () +mm_cid_size () +get_rss_stat_items_size (); mm_cachep = kmem_cache_create_usercopy("mm_struct", mm_size, ARCH_MIN_MMSTRUCT_ALIGN,
kernel/liveupdate/kexec_handover.c +34 -1
@@ -1333,6 +1333,23 @@ int kho_retrieve_subtree(const char *name, phys_addr_t *phys) }EXPORT_SYMBOL_GPL (kho_retrieve_subtree); +bool pfn_is_kho_scratch (unsigned long pfn) +{ +unsigned int i; +phys_addr_t scratch_start, scratch_end, phys =__pfn_to_phys (pfn); + +for (i =0 ; i < kho_scratch_cnt; i++) { + scratch_start = kho_scratch[i].addr; + scratch_end = kho_scratch[i].addr + kho_scratch[i].size; + +if (scratch_start <= phys && phys < scratch_end) +return true; + } + +return false; +} +EXPORT_SYMBOL_GPL (pfn_is_kho_scratch); +static __init int kho_out_fdt_setup (void ) {void *root = kho_out.fdt;
@@ -1421,12 +1438,27 @@ static __init int kho_init(void) }fs_initcall (kho_init); +static void __init kho_init_scratch_pages (void ) +{ +if (!IS_ENABLED (CONFIG_DEFERRED_STRUCT_PAGE_INIT )) +return ; + +for (int i =0 ; i < kho_scratch_cnt; i++) { +unsigned long pfn =PFN_DOWN (kho_scratch[i].addr); +unsigned long end_pfn =PFN_UP (kho_scratch[i].addr + kho_scratch[i].size); +int nid =early_pfn_to_nid (pfn); + +for (; pfn < end_pfn; pfn++) +init_deferred_page (pfn, nid); + } +} +static void __init kho_release_scratch (void ) {phys_addr_t start, end;u64 i; -memmap_init_kho_scratch_pages (); +kho_init_scratch_pages ();/* * Mark scratch mem as CMA before we return it. That way we
@@ -1453,6 +1485,7 @@ void __init kho_memory_init(void)kho_mem_deserialize (phys_to_virt (kho_in.mem_map_phys)); }else {kho_reserve_scratch (); +kho_init_scratch_pages (); } }
lib/Kconfig +12 -0
@@ -52,6 +52,18 @@ config PACKING_KUNIT_TEST When in doubt, say N. +config PERCPU_COUNTER_TREE_TEST + tristate "Hierarchical Per-CPU counter test" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + This builds Kunit tests for the hierarchical per-cpu counters. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in Documentation/dev-tools/kunit/. + + When in doubt, say N. + config BITREVERSE tristate
lib/Makefile +1 -0
@@ -181,6 +181,7 @@ obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o obj-$(CONFIG_TEXTSEARCH_BM) += ts_bm.o obj-$(CONFIG_TEXTSEARCH_FSM) += ts_fsm.o obj-$(CONFIG_SMP) += percpu_counter.o +obj-$(CONFIG_SMP) += percpu_counter_tree.o obj-$(CONFIG_AUDIT_GENERIC) += audit.o obj-$(CONFIG_AUDIT_COMPAT_GENERIC) += compat_audit.o
lib/percpu_counter_tree.c new file +702 -0
702 lines not on this page · raw message
lib/tests/Makefile +2 -0
@@ -56,4 +56,6 @@ obj-$(CONFIG_UTIL_MACROS_KUNIT) += util_macros_kunit.o obj-$(CONFIG_RATELIMIT_KUNIT_TEST) += test_ratelimit.o obj-$(CONFIG_UUID_KUNIT_TEST) += uuid_kunit.o +obj-$(CONFIG_PERCPU_COUNTER_TREE_TEST) += percpu_counter_tree_kunit.o + obj-$(CONFIG_TEST_RUNTIME_MODULE) += module/
lib/tests/percpu_counter_tree_kunit.c new file +399 -0
399 lines not on this page · raw message
lib/vdso/datastore.c +63 -34
158 lines not on this page · raw message
mm/memblock.c +0 -22
@@ -959,28 +959,6 @@ __init void memblock_clear_kho_scratch_only(void) { kho_scratch_only = false; } - -__init void memmap_init_kho_scratch_pages (void ) -{ -phys_addr_t start, end; -unsigned long pfn; -int nid; -u64 i; - -if (!IS_ENABLED (CONFIG_DEFERRED_STRUCT_PAGE_INIT )) -return ; - -/* -* Initialize struct pages for free scratch memory. -* The struct pages for reserved scratch memory will be set up in -* reserve_bootmem_region() -*/ -__for_each_mem_range (i, &memblock.memory,NULL ,NUMA_NO_NODE , -MEMBLOCK_KHO_SCRATCH , &start, &end, &nid) { -for (pfn =PFN_UP (start); pfn <PFN_DOWN (end); pfn++) -init_deferred_page (pfn, nid); - } -}#endif /**
mm/mm_init.c +12 -5
@@ -786,7 +786,8 @@ void __meminit reserve_bootmem_region(phys_addr_t start,for_each_valid_pfn (pfn,PFN_DOWN (start),PFN_UP (end)) {struct page *page =pfn_to_page (pfn); -__init_deferred_page (pfn, nid); +if (!pfn_is_kho_scratch (pfn)) +__init_deferred_page (pfn, nid);/* * no need for atomic set_bit because the struct
@@ -1996,9 +1997,12 @@ static void __init deferred_free_pages(unsigned long pfn,/* Free a large naturally-aligned chunk if possible */ if (nr_pages ==MAX_ORDER_NR_PAGES &&IS_MAX_ORDER_ALIGNED (pfn)) { -for (i =0 ; i < nr_pages; i += pageblock_nr_pages) +for (i =0 ; i < nr_pages; i += pageblock_nr_pages) { +if (pfn_is_kho_scratch (page_to_pfn (page + i))) +continue ;init_pageblock_migratetype (page + i,MIGRATE_MOVABLE , false); + }__free_pages_core (page,MAX_PAGE_ORDER ,MEMINIT_EARLY );return ; }
@@ -2007,7 +2011,7 @@ static void __init deferred_free_pages(unsigned long pfn,accept_memory (PFN_PHYS (pfn), nr_pages *PAGE_SIZE );for (i =0 ; i < nr_pages; i++, page++, pfn++) { -if (pageblock_aligned (pfn)) +if (pageblock_aligned (pfn) && !pfn_is_kho_scratch (pfn))init_pageblock_migratetype (page,MIGRATE_MOVABLE , false);__free_pages_core (page,0 ,MEMINIT_EARLY );
@@ -2078,9 +2082,11 @@ deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn,unsigned long mo_pfn =ALIGN (spfn +1 ,MAX_ORDER_NR_PAGES );unsigned long chunk_end =min (mo_pfn, epfn); - nr_pages +=deferred_init_pages (zone, spfn, chunk_end); -deferred_free_pages (spfn, chunk_end - spfn); +// KHO scratch is MAX_ORDER_NR_PAGES aligned. +if (!pfn_is_kho_scratch (spfn)) +deferred_init_pages (zone, spfn, chunk_end); +deferred_free_pages (spfn, chunk_end - spfn); spfn = chunk_end;if (can_resched)
@@ -2088,6 +2094,7 @@ deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn,else touch_nmi_watchdog (); } + nr_pages += epfn - spfn; }return nr_pages;
Quoted 47 lines · Nathan Chancellor
Hi all,
I am not really sure whose bug this is, as it only appears when three seemingly independent patch series are applied together, so I have added the patch authors and their committers (along with the tracing maintainers) to this thread. Feel free to expand or reduce that list as necessary.
Our continuous integration has noticed a crash when booting
ppc64_guest_defconfigin QEMU on the past few -next versions.https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/23311154492/job/67811527112
This does not appear to be clang related, as it can be reproduced with GCC 15.2.0 as well. Through multiple bisects, I was able to land on applying:
mm: improve RSS counter approximation accuracy for proc interfaces [1] vdso/datastore: Allocate data pages dynamically [2]
kho: fix deferred init of kho scratch [3]and their dependent changes on top of 7.0-rc4 is enough to reproduce this (at least on two of my machines with the same commands). I have attached the diff from the result of the following 'git apply' commands below, done in a linux-next checkout.
$ git checkout v7.0-rc4 HEAD is now at f338e7738378 Linux 7.0-rc4# [1]
$ git diff 60ddf3eed4999bae440d1cf9e5868ccb3f308b64^..087dd6d2cc12c82945ab859194c32e8e977daae3 | git apply -3v ...# [2]
# Fix trivial conflict ininit/main.caround headers$ git diff dc432ab7130bb39f5a351281a02d4bc61e85a14a^..05988dba11791ccbb458254484826b32f17f4ad2 | git apply -3v ...# [3]
# Fix conflict inkernel/liveupdate/kexec_handover.cdue to lack ofkho_mem_retrieve(), just addpfn_is_kho_scratch()$ git show 4a78467ffb537463486968232daef1e8a2f105e3 | git apply -3v ...$ make -skj"$(nproc)" ARCH=powerpc CROSS_COMPILE=powerpc64-linux- mrproper ppc64_guest_defconfig vmlinux$ curl -LSs https://github.com/ClangBuiltLinux/boot-utils/releases/download/20241120-044434/ppc64-rootfs.cpio.zst | zstd -d >rootfs.cpio
Quoted 10 lines
$ qemu-system-ppc64 \
-display none \
-nodefaults \
-cpu power8 \
-machine pseries \
-vga none \
-kernel vmlinux \
-initrd rootfs.cpio \
-m 1G \
-serial mon:stdioThanks, such a detailed steps to reproduce! Interestingly, the combination of my compiler (GCC 13.3.0) and QEMU (8.2.2) don't trigger this bug.
Quoted 38 lines
[ 0.000000][ T0] Linux version 7.0.0-rc4-dirty (nathan@framework-amd-ryzen-maxplus-395) (powerpc64-linux-gcc (GCC) 15.2.0, GNU ld (GNU Binutils) 2.45) #1 SMP PREEMPT Thu Mar 19 15:45:53 MST 2026 ... [ 0.216764][ T1] vgaarb: loaded [ 0.217590][ T1] clocksource: Switched to clocksource timebase [ 0.221007][ T12] BUG: Kernel NULL pointer dereference at 0x00000010 [ 0.221049][ T12] Faulting instruction address: 0xc00000000044947c [ 0.221237][ T12] Oops: Kernel access of bad area, sig: 11 [#1] [ 0.221276][ T12] BE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries [ 0.221359][ T12] Modules linked in: [ 0.221556][ T12] CPU: 0 UID: 0 PID: 12 Comm: kworker/u4:0 Not tainted 7.0.0-rc4-dirty #1 PREEMPTLAZY [ 0.221631][ T12] Hardware name: IBM pSeries (emulated by qemu) POWER8 (architected) 0x4d0200 0xf000004 of:SLOF,HEAD pSeries [ 0.221765][ T12] Workqueue: trace_init_wq tracer_init_tracefs_work_func [ 0.222065][ T12] NIP: c00000000044947c LR: c00000000041a584 CTR: c00000000053aa90 [ 0.222084][ T12] REGS: c000000003bc7960 TRAP: 0380 Not tainted (7.0.0-rc4-dirty) [ 0.222111][ T12] MSR: 8000000000009032 <SF,EE,ME,IR,DR,RI> CR: 44000204 XER: 00000000 [ 0.222287][ T12] CFAR: c000000000449420 IRQMASK: 0 [ 0.222287][ T12] GPR00: c00000000041a584 c000000003bc7c00 c000000001c08100 c000000002892f20 [ 0.222287][ T12] GPR04: c0000000019cfa68 c0000000019cfa60 0000000000000001 0000000000000064 [ 0.222287][ T12] GPR08: 0000000000000002 0000000000000000 c000000003bba000 0000000000000010 [ 0.222287][ T12] GPR12: c00000000053aa90 c000000002c50000 c000000001ab25f8 c000000001626690 [ 0.222287][ T12] GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 [ 0.222287][ T12] GPR20: c000000001624868 c000000001ab2708 c0000000019cfa08 c000000001a00d18 [ 0.222287][ T12] GPR24: c0000000019cfa18 fffffffffffffef7 c000000003051205 c0000000019cfa68 [ 0.222287][ T12] GPR28: 0000000000000000 c0000000019cfa60 c000000002894e90 0000000000000000 [ 0.222526][ T12] NIP [c00000000044947c] __find_event_file+0x9c/0x110 [ 0.222572][ T12] LR [c00000000041a584] init_tracer_tracefs+0x274/0xcc0 [ 0.222643][ T12] Call Trace: [ 0.222690][ T12] [c000000003bc7c00] [c000000000b943b0] tracefs_create_file+0x1a0/0x2b0 (unreliable) [ 0.222766][ T12] [c000000003bc7c50] [c00000000041a584] init_tracer_tracefs+0x274/0xcc0 [ 0.222791][ T12] [c000000003bc7dc0] [c000000002046f1c] tracer_init_tracefs_work_func+0x50/0x320 [ 0.222809][ T12] [c000000003bc7e50] [c000000000276958] process_one_work+0x1b8/0x530 [ 0.222828][ T12] [c000000003bc7f10] [c00000000027778c] worker_thread+0x1dc/0x3d0 [ 0.222883][ T12] [c000000003bc7f90] [c000000000284c44] kthread+0x194/0x1b0 [ 0.222900][ T12] [c000000003bc7fe0] [c00000000000cf30] start_kernel_thread+0x14/0x18 [ 0.222961][ T12] Code: 7c691b78 7f63db78 2c090000 40820018 e89c0000 49107f21 60000000 2c030000 41820048 ebff0000 7c3ff040 41820038 <e93f0010> 7fa3eb78 81490058 e8890018 [ 0.223190][ T12] ---[ end trace 0000000000000000 ]--- ...
Quoted 4 lines
Interestingly, turning on
CONFIG_KASANappears to hide this, maybe pointing to some sort of memory corruption (or something timing related)? If there is any other information I can provide, I am more than happy to do so.
I don't have much idea on how things end up causing NULL-pointer-deref... but let's point out suspicious things.
Quoted 1 line
@Mathieu: In patch 1/3 description,
Quoted 4 lines
Changes since v7:
- Explicitly initialize the subsystem fromstart_kernel()right aftermm_core_init()so it is up and running before the creation of the first mm at boot.
But how does this work when someone calls mm_cpumask() on init_mm early? Looks like it will behave incorrectly because get_rss_stat_items_size() returns zero?
While it doesn't crash on my environment, it triggers a two warnings (with -smp 2 option added). IIUC the cpu bit should have been set in setup_arch(), but at the wrong location. After the percpu_counter_tree_subsystem_init() function is called, the bit doesn't appear to be set.
[ 1.392787][ T1] ------------[ cut here ]------------ [ 1.392935][ T1] WARNING: arch/powerpc/mm/mmu_context.c:106 at switch_mm_irqs_off+0x190/0x1c0, CPU#0: swapper/0/1 [ 1.393187][ T1] Modules linked in: [ 1.393458][ T1] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.0.0-rc4-next-20260319 #1 PREEMPTLAZY [ 1.393600][ T1] Hardware name: IBM pSeries (emulated by qemu) POWER8 (architected) 0x4d0200 0xf000004 of:SLOF,HEAD pSeries [ 1.393711][ T1] NIP: c00000000014e390 LR: c00000000014e30c CTR: 0000000000000000 [ 1.393752][ T1] REGS: c000000003def7b0 TRAP: 0700 Not tainted (7.0.0-rc4-next-20260319) [ 1.393807][ T1] MSR: 8000000002021032 <SF,VEC,ME,IR,DR,RI> CR: 2800284a XER: 00000000 [ 1.393944][ T1] CFAR: c00000000014e328 IRQMASK: 3 [ 1.393944][ T1] GPR00: c00000000014e36c c000000003defa50 c000000001bb8100 c0000000028d8c80 [ 1.393944][ T1] GPR04: c000000004ddc04a 000000000000000a 0000000022222222 2222222222222222 [ 1.393944][ T1] GPR08: 2222222222222222 0000000000000000 0000000000000001 0000000000008000 [ 1.393944][ T1] GPR12: c000000000521e80 c000000002c70000 c00000000000fff0 0000000000000000 [ 1.393944][ T1] GPR16: 0000000000000000 c00000000606c600 c000000003623ac0 0000000000000000 [ 1.393944][ T1] GPR20: c000000004c66300 c00000000606fc00 0000000000000001 0000000000000001 [ 1.393944][ T1] GPR24: c000000006069c00 c00000000272c500 0000000000000000 0000000000000000 [ 1.393944][ T1] GPR28: c000000003d68200 0000000000000000 c0000000028d8a80 c00000000272bd00 [ 1.394355][ T1] NIP [c00000000014e390] switch_mm_irqs_off+0x190/0x1c0 [ 1.394395][ T1] LR [c00000000014e30c] switch_mm_irqs_off+0x10c/0x1c0 [ 1.394519][ T1] Call Trace: [ 1.394584][ T1] [c000000003defa50] [c00000000014e36c] switch_mm_irqs_off+0x16c/0x1c0 (unreliable) [ 1.394676][ T1] [c000000003defab0] [c0000000006edbf0] begin_new_exec+0x534/0xf60 [ 1.394732][ T1] [c000000003defb20] [c000000000795538] load_elf_binary+0x494/0x1d1c [ 1.394765][ T1] [c000000003defc70] [c0000000006eb910] bprm_execve+0x380/0x720 [ 1.394796][ T1] [c000000003defd00] [c0000000006ed5a8] kernel_execve+0x12c/0x1bc [ 1.394831][ T1] [c000000003defd50] [c00000000000eda8] run_init_process+0xf8/0x160 [ 1.394864][ T1] [c000000003defde0] [c0000000000100b4] kernel_init+0xcc/0x268 [ 1.394899][ T1] [c000000003defe50] [c00000000000cf14] ret_from_kernel_user_thread+0x14/0x1c [ 1.394946][ T1] ---- interrupt: 0 at 0x0 [ 1.395205][ T1] Code: 7fe4fb78 7f83e378 48009171 60000000 4bffff98 60000000 60000000 60000000 0fe00000 4bffff00 60000000 60000000 <0fe00000> 4bffff98 60000000 60000000 [ 1.395420][ T1] ---[ end trace 0000000000000000 ]--- [ 1.526024][ T67] mount (67) used greatest stack depth: 28432 bytes left [ 1.605803][ T69] mount (69) used greatest stack depth: 27872 bytes left [ 1.667853][ T71] mkdir (71) used greatest stack depth: 27248 bytes left Saving 256 bits of creditable seed for next boot [ 1.926636][ T80] ------------[ cut here ]------------ [ 1.926719][ T80] WARNING: arch/powerpc/mm/mmu_context.c:51 at switch_mm_irqs_off+0x180/0x1c0, CPU#0: S01seedrng/80 [ 1.926782][ T80] Modules linked in: [ 1.926910][ T80] CPU: 0 UID: 0 PID: 80 Comm: S01seedrng Tainted: G W 7.0.0-rc4-next-20260319 #1 PREEMPTLAZY [ 1.926990][ T80] Tainted: [W]=WARN [ 1.927025][ T80] Hardware name: IBM pSeries (emulated by qemu) POWER8 (architected) 0x4d0200 0xf000004 of:SLOF,HEAD pSeries [ 1.927091][ T80] NIP: c00000000014e380 LR: c00000000014e24c CTR: c000000000232894 [ 1.927131][ T80] REGS: c000000004d5f800 TRAP: 0700 Tainted: G W (7.0.0-rc4-next-20260319) [ 1.927179][ T80] MSR: 8000000000029032 <SF,EE,ME,IR,DR,RI> CR: 28002828 XER: 20000000 [ 1.927253][ T80] CFAR: c00000000014e280 IRQMASK: 1 [ 1.927253][ T80] GPR00: c0000000002328ec c000000004d5faa0 c000000001bb8100 0000000000000080 [ 1.927253][ T80] GPR04: c0000000028d8280 c000000004509c00 0000000000000002 c00000000272c700 [ 1.927253][ T80] GPR08: fffffffffffffffe c0000000028d8280 0000000000000000 0000000048002828 [ 1.927253][ T80] GPR12: c000000000232894 c000000002c70000 0000000000000000 0000000000000002 [ 1.927253][ T80] GPR16: 0000000000000000 000001002f0a2958 000001002f0a2950 ffffffffffffffff [ 1.927253][ T80] GPR20: 0000000000000000 0000000000000000 c000000002ab1400 c00000000272c700 [ 1.927253][ T80] GPR24: 0000000000000000 c0000000028d8a80 0000000000000000 0000000000000000 [ 1.927253][ T80] GPR28: c000000004509c00 0000000000000000 c00000000272bd00 c0000000028d8280 [ 1.927629][ T80] NIP [c00000000014e380] switch_mm_irqs_off+0x180/0x1c0 [ 1.927678][ T80] LR [c00000000014e24c] switch_mm_irqs_off+0x4c/0x1c0 [ 1.927715][ T80] Call Trace: [ 1.927737][ T80] [c000000004d5faa0] [c000000004d5faf0] 0xc000000004d5faf0 (unreliable) [ 1.927804][ T80] [c000000004d5fb00] [c0000000002328ec] do_shoot_lazy_tlb+0x58/0x84 [ 1.927853][ T80] [c000000004d5fb30] [c000000000388304] smp_call_function_many_cond+0x6a0/0x8d8 [ 1.927902][ T80] [c000000004d5fc20] [c000000000388624] on_each_cpu_cond_mask+0x40/0x7c [ 1.927943][ T80] [c000000004d5fc50] [c000000000232ad4] __mmdrop+0x88/0x2ec [ 1.927986][ T80] [c000000004d5fce0] [c000000000242104] do_exit+0x350/0xde4 [ 1.928028][ T80] [c000000004d5fdb0] [c000000000242de0] do_group_exit+0x48/0xbc [ 1.928072][ T80] [c000000004d5fdf0] [c000000000242e74] pid_child_should_wake+0x0/0x84 [ 1.928128][ T80] [c000000004d5fe10] [c000000000030218] system_call_exception+0x148/0x3c0 [ 1.928176][ T80] [c000000004d5fe50] [c00000000000c6d4] system_call_common+0xf4/0x258 [ 1.928217][ T80] ---- interrupt: c00 at 0x7fff8ade507c [ 1.928253][ T80] NIP: 00007fff8ade507c LR: 00007fff8ade5034 CTR: 0000000000000000 [ 1.928291][ T80] REGS: c000000004d5fe80 TRAP: 0c00 Tainted: G W (7.0.0-rc4-next-20260319) [ 1.928333][ T80] MSR: 800000000280f032 <SF,VEC,VSX,EE,PR,FP,ME,IR,DR,RI> CR: 24002824 XER: 00000000 [ 1.928413][ T80] IRQMASK: 0 [ 1.928413][ T80] GPR00: 00000000000000ea 00007fffe75beb50 00007fff8aed7300 0000000000000000 [ 1.928413][ T80] GPR04: 0000000000000000 00007fffe75beda0 00007fffe75bedb0 0000000000000000 [ 1.928413][ T80] GPR08: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 [ 1.928413][ T80] GPR12: 0000000000000000 00007fff8afaae00 00007fffca692568 0000000133cf0440 [ 1.928413][ T80] GPR16: 0000000000000000 000001002f0a2958 000001002f0a2950 ffffffffffffffff [ 1.928413][ T80] GPR20: 0000000000000000 0000000000000000 00007fffe75bf838 00007fff8afa0000 [ 1.928413][ T80] GPR24: 0000000126911328 0000000000000001 00007fff8af9dc00 00007fffe75bf818 [ 1.928413][ T80] GPR28: 0000000000000003 fffffffffffff000 0000000000000000 00007fff8afa3e10 [ 1.928765][ T80] NIP [00007fff8ade507c] 0x7fff8ade507c [ 1.928795][ T80] LR [00007fff8ade5034] 0x7fff8ade5034 [ 1.928835][ T80] ---- interrupt: c00 [ 1.928924][ T80] Code: 7c0803a6 4e800020 60000000 60000000 7fe4fb78 7f83e378 48009171 60000000 4bffff98 60000000 60000000 60000000 <0fe00000> 4bffff00 60000000 60000000 [ 1.929054][ T80] ---[ end trace 0000000000000000 ]---
Quoted 3 lines
@Michal: Something my AI buddy pointed out... (that I think is valid):
mm/mm_init.c deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, · line 2081
Quoted 9 lines
mm/mm_init.c +0
-1@@ -2078,9 +2082,11 @@ deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn,unsigned long mo_pfn =ALIGN (spfn +1 ,MAX_ORDER_NR_PAGES );unsigned long chunk_end =min (mo_pfn, epfn); - nr_pages +=deferred_init_pages (zone, spfn, chunk_end);
Previously, deferred_init_pages() returned nr of pages to add, which is (end_pfn (= chunk_end) - spfn).
mm/mm_init.c deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, · line 2087
Quoted 4 lines
mm/mm_init.c +3
-1-deferred_free_pages (spfn, chunk_end - spfn); +// KHO scratch is MAX_ORDER_NR_PAGES aligned. +if (!pfn_is_kho_scratch (spfn)) +deferred_init_pages (zone, spfn, chunk_end);
But since the function is not always called with the change, the calculation is moved to...
mm/mm_init.c deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, · line 2097
Quoted 9 lines
mm/mm_init.c +2
-0+deferred_free_pages (spfn, chunk_end - spfn); spfn = chunk_end;if (can_resched)@@ -2088,6 +2094,7 @@ deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn,else touch_nmi_watchdog (); } + nr_pages += epfn - spfn;
Here.
But this is incorrect, because here we have:
Quoted 13 lines
static unsigned long
__initdeferred_init_memmap_chunk(unsigned longstart_pfn, unsigned longend_pfn,
struct zone *zone, boolcan_resched){ int nid = zone_to_nid(zone); unsigned long nr_pages = 0; phys_addr_t start, end; u64 i = 0; for_each_free_mem_range(i, nid, 0, &start, &end, NULL) { unsigned long spfn = PFN_UP(start); unsigned long epfn = PFN_DOWN(end);
Quoted 7 lines
if (spfn >= end_pfn)
break;
spfn = max(spfn, start_pfn);
epfn = min(epfn, end_pfn);
while (spfn < epfn) {The loop condition is (spfn < epfn), and by the time the loop terminates...
Quoted 8 lines
unsigned long mo_pfn = ALIGN(spfn + 1, MAX_ORDER_NR_PAGES);
unsigned long chunk_end = min(mo_pfn, epfn);
// KHO scratch is MAX_ORDER_NR_PAGES aligned.
if (!pfn_is_kho_scratch(spfn))
deferred_init_pages(zone, spfn, chunk_end);
deferred_free_pages(spfn, chunk_end - spfn);Quoted 8 lines
spfn = chunk_end;
if (can_resched)
cond_resched();
else
touch_nmi_watchdog();
}
nr_pages += epfn - spfn;epfn - spfn <= 0.
So the number of pages returned by deferred_init_memmap_chunk() becomes incorrect.
The equivalent translation of what's there before would be doing nr_pages += chunk_end - spfn; within the loop.
Signature · 2 lines
Cheers, Harry / Hyeonggon
Quoted 293 lines · Harry Yoo
Quoted 47 lines · Nathan Chancellor
Hi all,
I am not really sure whose bug this is, as it only appears when three seemingly independent patch series are applied together, so I have added the patch authors and their committers (along with the tracing maintainers) to this thread. Feel free to expand or reduce that list as necessary.
Our continuous integration has noticed a crash when booting
ppc64_guest_defconfigin QEMU on the past few -next versions.https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/23311154492/job/67811527112
This does not appear to be clang related, as it can be reproduced with GCC 15.2.0 as well. Through multiple bisects, I was able to land on applying:
mm: improve RSS counter approximation accuracy for proc interfaces [1] vdso/datastore: Allocate data pages dynamically [2]
kho: fix deferred init of kho scratch [3]and their dependent changes on top of 7.0-rc4 is enough to reproduce this (at least on two of my machines with the same commands). I have attached the diff from the result of the following 'git apply' commands below, done in a linux-next checkout.
$ git checkout v7.0-rc4 HEAD is now at f338e7738378 Linux 7.0-rc4# [1]
$ git diff 60ddf3eed4999bae440d1cf9e5868ccb3f308b64^..087dd6d2cc12c82945ab859194c32e8e977daae3 | git apply -3v ...# [2]
# Fix trivial conflict ininit/main.caround headers$ git diff dc432ab7130bb39f5a351281a02d4bc61e85a14a^..05988dba11791ccbb458254484826b32f17f4ad2 | git apply -3v ...# [3]
# Fix conflict inkernel/liveupdate/kexec_handover.cdue to lack ofkho_mem_retrieve(), just addpfn_is_kho_scratch()$ git show 4a78467ffb537463486968232daef1e8a2f105e3 | git apply -3v ...$ make -skj"$(nproc)" ARCH=powerpc CROSS_COMPILE=powerpc64-linux- mrproper ppc64_guest_defconfig vmlinux$ curl -LSs https://github.com/ClangBuiltLinux/boot-utils/releases/download/20241120-044434/ppc64-rootfs.cpio.zst | zstd -d >rootfs.cpioQuoted 10 lines
$ qemu-system-ppc64 \ -display none \ -nodefaults \ -cpu power8 \ -machine pseries \ -vga none \ -kernel vmlinux \ -initrd rootfs.cpio \ -m 1G \ -serial mon:stdioThanks, such a detailed steps to reproduce! Interestingly, the combination of my compiler (GCC 13.3.0) and QEMU (8.2.2) don't trigger this bug.
Quoted 38 lines
[ 0.000000][ T0] Linux version 7.0.0-rc4-dirty (nathan@framework-amd-ryzen-maxplus-395) (powerpc64-linux-gcc (GCC) 15.2.0, GNU ld (GNU Binutils) 2.45) #1 SMP PREEMPT Thu Mar 19 15:45:53 MST 2026 ... [ 0.216764][ T1] vgaarb: loaded [ 0.217590][ T1] clocksource: Switched to clocksource timebase [ 0.221007][ T12] BUG: Kernel NULL pointer dereference at 0x00000010 [ 0.221049][ T12] Faulting instruction address: 0xc00000000044947c [ 0.221237][ T12] Oops: Kernel access of bad area, sig: 11 [#1] [ 0.221276][ T12] BE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries [ 0.221359][ T12] Modules linked in: [ 0.221556][ T12] CPU: 0 UID: 0 PID: 12 Comm: kworker/u4:0 Not tainted 7.0.0-rc4-dirty #1 PREEMPTLAZY [ 0.221631][ T12] Hardware name: IBM pSeries (emulated by qemu) POWER8 (architected) 0x4d0200 0xf000004 of:SLOF,HEAD pSeries [ 0.221765][ T12] Workqueue: trace_init_wq tracer_init_tracefs_work_func [ 0.222065][ T12] NIP: c00000000044947c LR: c00000000041a584 CTR: c00000000053aa90 [ 0.222084][ T12] REGS: c000000003bc7960 TRAP: 0380 Not tainted (7.0.0-rc4-dirty) [ 0.222111][ T12] MSR: 8000000000009032 <SF,EE,ME,IR,DR,RI> CR: 44000204 XER: 00000000 [ 0.222287][ T12] CFAR: c000000000449420 IRQMASK: 0 [ 0.222287][ T12] GPR00: c00000000041a584 c000000003bc7c00 c000000001c08100 c000000002892f20 [ 0.222287][ T12] GPR04: c0000000019cfa68 c0000000019cfa60 0000000000000001 0000000000000064 [ 0.222287][ T12] GPR08: 0000000000000002 0000000000000000 c000000003bba000 0000000000000010 [ 0.222287][ T12] GPR12: c00000000053aa90 c000000002c50000 c000000001ab25f8 c000000001626690 [ 0.222287][ T12] GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 [ 0.222287][ T12] GPR20: c000000001624868 c000000001ab2708 c0000000019cfa08 c000000001a00d18 [ 0.222287][ T12] GPR24: c0000000019cfa18 fffffffffffffef7 c000000003051205 c0000000019cfa68 [ 0.222287][ T12] GPR28: 0000000000000000 c0000000019cfa60 c000000002894e90 0000000000000000 [ 0.222526][ T12] NIP [c00000000044947c] __find_event_file+0x9c/0x110 [ 0.222572][ T12] LR [c00000000041a584] init_tracer_tracefs+0x274/0xcc0 [ 0.222643][ T12] Call Trace: [ 0.222690][ T12] [c000000003bc7c00] [c000000000b943b0] tracefs_create_file+0x1a0/0x2b0 (unreliable) [ 0.222766][ T12] [c000000003bc7c50] [c00000000041a584] init_tracer_tracefs+0x274/0xcc0 [ 0.222791][ T12] [c000000003bc7dc0] [c000000002046f1c] tracer_init_tracefs_work_func+0x50/0x320 [ 0.222809][ T12] [c000000003bc7e50] [c000000000276958] process_one_work+0x1b8/0x530 [ 0.222828][ T12] [c000000003bc7f10] [c00000000027778c] worker_thread+0x1dc/0x3d0 [ 0.222883][ T12] [c000000003bc7f90] [c000000000284c44] kthread+0x194/0x1b0 [ 0.222900][ T12] [c000000003bc7fe0] [c00000000000cf30] start_kernel_thread+0x14/0x18 [ 0.222961][ T12] Code: 7c691b78 7f63db78 2c090000 40820018 e89c0000 49107f21 60000000 2c030000 41820048 ebff0000 7c3ff040 41820038 <e93f0010> 7fa3eb78 81490058 e8890018 [ 0.223190][ T12] ---[ end trace 0000000000000000 ]--- ...Quoted 4 lines
Interestingly, turning on
CONFIG_KASANappears to hide this, maybe pointing to some sort of memory corruption (or something timing related)? If there is any other information I can provide, I am more than happy to do so.I don't have much idea on how things end up causing NULL-pointer-deref... but let's point out suspicious things.
Quoted 1 line
@Mathieu: In patch 1/3 description,
Quoted 4 lines
Changes since v7:
- Explicitly initialize the subsystem fromstart_kernel()right aftermm_core_init()so it is up and running before the creation of the first mm at boot.But how does this work when someone calls
mm_cpumask()oninit_mmearly? Looks like it will behave incorrectly becauseget_rss_stat_items_size()returns zero?While it doesn't crash on my environment, it triggers a two warnings (with -smp 2 option added). IIUC the cpu bit should have been set in
setup_arch(), but at the wrong location. After thepercpu_counter_tree_subsystem_init()function is called, the bit doesn't appear to be set.[ 1.392787][ T1] ------------[ cut here ]------------ [ 1.392935][ T1] WARNING: arch/powerpc/mm/mmu_context.c:106 at switch_mm_irqs_off+0x190/0x1c0, CPU#0: swapper/0/1 [ 1.393187][ T1] Modules linked in: [ 1.393458][ T1] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.0.0-rc4-next-20260319 #1 PREEMPTLAZY [ 1.393600][ T1] Hardware name: IBM pSeries (emulated by qemu) POWER8 (architected) 0x4d0200 0xf000004 of:SLOF,HEAD pSeries [ 1.393711][ T1] NIP: c00000000014e390 LR: c00000000014e30c CTR: 0000000000000000 [ 1.393752][ T1] REGS: c000000003def7b0 TRAP: 0700 Not tainted (7.0.0-rc4-next-20260319) [ 1.393807][ T1] MSR: 8000000002021032 <SF,VEC,ME,IR,DR,RI> CR: 2800284a XER: 00000000 [ 1.393944][ T1] CFAR: c00000000014e328 IRQMASK: 3 [ 1.393944][ T1] GPR00: c00000000014e36c c000000003defa50 c000000001bb8100 c0000000028d8c80 [ 1.393944][ T1] GPR04: c000000004ddc04a 000000000000000a 0000000022222222 2222222222222222 [ 1.393944][ T1] GPR08: 2222222222222222 0000000000000000 0000000000000001 0000000000008000 [ 1.393944][ T1] GPR12: c000000000521e80 c000000002c70000 c00000000000fff0 0000000000000000 [ 1.393944][ T1] GPR16: 0000000000000000 c00000000606c600 c000000003623ac0 0000000000000000 [ 1.393944][ T1] GPR20: c000000004c66300 c00000000606fc00 0000000000000001 0000000000000001 [ 1.393944][ T1] GPR24: c000000006069c00 c00000000272c500 0000000000000000 0000000000000000 [ 1.393944][ T1] GPR28: c000000003d68200 0000000000000000 c0000000028d8a80 c00000000272bd00 [ 1.394355][ T1] NIP [c00000000014e390] switch_mm_irqs_off+0x190/0x1c0 [ 1.394395][ T1] LR [c00000000014e30c] switch_mm_irqs_off+0x10c/0x1c0 [ 1.394519][ T1] Call Trace: [ 1.394584][ T1] [c000000003defa50] [c00000000014e36c] switch_mm_irqs_off+0x16c/0x1c0 (unreliable) [ 1.394676][ T1] [c000000003defab0] [c0000000006edbf0] begin_new_exec+0x534/0xf60 [ 1.394732][ T1] [c000000003defb20] [c000000000795538] load_elf_binary+0x494/0x1d1c [ 1.394765][ T1] [c000000003defc70] [c0000000006eb910] bprm_execve+0x380/0x720 [ 1.394796][ T1] [c000000003defd00] [c0000000006ed5a8] kernel_execve+0x12c/0x1bc [ 1.394831][ T1] [c000000003defd50] [c00000000000eda8] run_init_process+0xf8/0x160 [ 1.394864][ T1] [c000000003defde0] [c0000000000100b4] kernel_init+0xcc/0x268 [ 1.394899][ T1] [c000000003defe50] [c00000000000cf14] ret_from_kernel_user_thread+0x14/0x1c [ 1.394946][ T1] ---- interrupt: 0 at 0x0 [ 1.395205][ T1] Code: 7fe4fb78 7f83e378 48009171 60000000 4bffff98 60000000 60000000 60000000 0fe00000 4bffff00 60000000 60000000 <0fe00000> 4bffff98 60000000 60000000 [ 1.395420][ T1] ---[ end trace 0000000000000000 ]--- [ 1.526024][ T67] mount (67) used greatest stack depth: 28432 bytes left [ 1.605803][ T69] mount (69) used greatest stack depth: 27872 bytes left [ 1.667853][ T71] mkdir (71) used greatest stack depth: 27248 bytes left Saving 256 bits of creditable seed for next boot [ 1.926636][ T80] ------------[ cut here ]------------ [ 1.926719][ T80] WARNING: arch/powerpc/mm/mmu_context.c:51 at switch_mm_irqs_off+0x180/0x1c0, CPU#0: S01seedrng/80 [ 1.926782][ T80] Modules linked in: [ 1.926910][ T80] CPU: 0 UID: 0 PID: 80 Comm: S01seedrng Tainted: G W 7.0.0-rc4-next-20260319 #1 PREEMPTLAZY [ 1.926990][ T80] Tainted: [W]=WARN [ 1.927025][ T80] Hardware name: IBM pSeries (emulated by qemu) POWER8 (architected) 0x4d0200 0xf000004 of:SLOF,HEAD pSeries [ 1.927091][ T80] NIP: c00000000014e380 LR: c00000000014e24c CTR: c000000000232894 [ 1.927131][ T80] REGS: c000000004d5f800 TRAP: 0700 Tainted: G W (7.0.0-rc4-next-20260319) [ 1.927179][ T80] MSR: 8000000000029032 <SF,EE,ME,IR,DR,RI> CR: 28002828 XER: 20000000 [ 1.927253][ T80] CFAR: c00000000014e280 IRQMASK: 1 [ 1.927253][ T80] GPR00: c0000000002328ec c000000004d5faa0 c000000001bb8100 0000000000000080 [ 1.927253][ T80] GPR04: c0000000028d8280 c000000004509c00 0000000000000002 c00000000272c700 [ 1.927253][ T80] GPR08: fffffffffffffffe c0000000028d8280 0000000000000000 0000000048002828 [ 1.927253][ T80] GPR12: c000000000232894 c000000002c70000 0000000000000000 0000000000000002 [ 1.927253][ T80] GPR16: 0000000000000000 000001002f0a2958 000001002f0a2950 ffffffffffffffff [ 1.927253][ T80] GPR20: 0000000000000000 0000000000000000 c000000002ab1400 c00000000272c700 [ 1.927253][ T80] GPR24: 0000000000000000 c0000000028d8a80 0000000000000000 0000000000000000 [ 1.927253][ T80] GPR28: c000000004509c00 0000000000000000 c00000000272bd00 c0000000028d8280 [ 1.927629][ T80] NIP [c00000000014e380] switch_mm_irqs_off+0x180/0x1c0 [ 1.927678][ T80] LR [c00000000014e24c] switch_mm_irqs_off+0x4c/0x1c0 [ 1.927715][ T80] Call Trace: [ 1.927737][ T80] [c000000004d5faa0] [c000000004d5faf0] 0xc000000004d5faf0 (unreliable) [ 1.927804][ T80] [c000000004d5fb00] [c0000000002328ec] do_shoot_lazy_tlb+0x58/0x84 [ 1.927853][ T80] [c000000004d5fb30] [c000000000388304] smp_call_function_many_cond+0x6a0/0x8d8 [ 1.927902][ T80] [c000000004d5fc20] [c000000000388624] on_each_cpu_cond_mask+0x40/0x7c [ 1.927943][ T80] [c000000004d5fc50] [c000000000232ad4] __mmdrop+0x88/0x2ec [ 1.927986][ T80] [c000000004d5fce0] [c000000000242104] do_exit+0x350/0xde4 [ 1.928028][ T80] [c000000004d5fdb0] [c000000000242de0] do_group_exit+0x48/0xbc [ 1.928072][ T80] [c000000004d5fdf0] [c000000000242e74] pid_child_should_wake+0x0/0x84 [ 1.928128][ T80] [c000000004d5fe10] [c000000000030218] system_call_exception+0x148/0x3c0 [ 1.928176][ T80] [c000000004d5fe50] [c00000000000c6d4] system_call_common+0xf4/0x258 [ 1.928217][ T80] ---- interrupt: c00 at 0x7fff8ade507c [ 1.928253][ T80] NIP: 00007fff8ade507c LR: 00007fff8ade5034 CTR: 0000000000000000 [ 1.928291][ T80] REGS: c000000004d5fe80 TRAP: 0c00 Tainted: G W (7.0.0-rc4-next-20260319) [ 1.928333][ T80] MSR: 800000000280f032 <SF,VEC,VSX,EE,PR,FP,ME,IR,DR,RI> CR: 24002824 XER: 00000000 [ 1.928413][ T80] IRQMASK: 0 [ 1.928413][ T80] GPR00: 00000000000000ea 00007fffe75beb50 00007fff8aed7300 0000000000000000 [ 1.928413][ T80] GPR04: 0000000000000000 00007fffe75beda0 00007fffe75bedb0 0000000000000000 [ 1.928413][ T80] GPR08: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 [ 1.928413][ T80] GPR12: 0000000000000000 00007fff8afaae00 00007fffca692568 0000000133cf0440 [ 1.928413][ T80] GPR16: 0000000000000000 000001002f0a2958 000001002f0a2950 ffffffffffffffff [ 1.928413][ T80] GPR20: 0000000000000000 0000000000000000 00007fffe75bf838 00007fff8afa0000 [ 1.928413][ T80] GPR24: 0000000126911328 0000000000000001 00007fff8af9dc00 00007fffe75bf818 [ 1.928413][ T80] GPR28: 0000000000000003 fffffffffffff000 0000000000000000 00007fff8afa3e10 [ 1.928765][ T80] NIP [00007fff8ade507c] 0x7fff8ade507c [ 1.928795][ T80] LR [00007fff8ade5034] 0x7fff8ade5034 [ 1.928835][ T80] ---- interrupt: c00 [ 1.928924][ T80] Code: 7c0803a6 4e800020 60000000 60000000 7fe4fb78 7f83e378 48009171 60000000 4bffff98 60000000 60000000 60000000 <0fe00000> 4bffff00 60000000 60000000 [ 1.929054][ T80] ---[ end trace 0000000000000000 ]---Quoted 3 lines
@Michal: Something my AI buddy pointed out... (that I think is valid):
mm/mm_init.c deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, · line 2081
Quoted 9 lines
mm/mm_init.c +0
-1@@ -2078,9 +2082,11 @@ deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn,unsigned long mo_pfn =ALIGN (spfn +1 ,MAX_ORDER_NR_PAGES );unsigned long chunk_end =min (mo_pfn, epfn); - nr_pages +=deferred_init_pages (zone, spfn, chunk_end);Previously,
deferred_init_pages()returned nr of pages to add, which is (end_pfn(=chunk_end) - spfn).mm/mm_init.c deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, · line 2087
Quoted 4 lines
mm/mm_init.c +3
-1-deferred_free_pages (spfn, chunk_end - spfn); +// KHO scratch is MAX_ORDER_NR_PAGES aligned. +if (!pfn_is_kho_scratch (spfn)) +deferred_init_pages (zone, spfn, chunk_end);But since the function is not always called with the change, the calculation is moved to...
mm/mm_init.c deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, · line 2097
Quoted 9 lines
mm/mm_init.c +2
-0+deferred_free_pages (spfn, chunk_end - spfn); spfn = chunk_end;if (can_resched)@@ -2088,6 +2094,7 @@ deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn,else touch_nmi_watchdog (); } + nr_pages += epfn - spfn;Here.
But this is incorrect, because here we have:
Quoted 13 lines
static unsigned long
__initdeferred_init_memmap_chunk(unsigned longstart_pfn, unsigned longend_pfn,
struct zone *zone, boolcan_resched){ int nid = zone_to_nid(zone); unsigned long nr_pages = 0; phys_addr_t start, end; u64 i = 0; for_each_free_mem_range(i, nid, 0, &start, &end, NULL) { unsigned long spfn = PFN_UP(start); unsigned long epfn = PFN_DOWN(end);Quoted 7 lines
if (spfn >= end_pfn) break; spfn = max(spfn, start_pfn); epfn = min(epfn, end_pfn); while (spfn < epfn) {The loop condition is (spfn < epfn), and by the time the loop terminates...
Quoted 8 lines
unsigned long mo_pfn = ALIGN(spfn + 1, MAX_ORDER_NR_PAGES); unsigned long chunk_end = min(mo_pfn, epfn); // KHO scratch is MAX_ORDER_NR_PAGES aligned. if (!pfn_is_kho_scratch(spfn)) deferred_init_pages(zone, spfn, chunk_end); deferred_free_pages(spfn, chunk_end - spfn);Quoted 8 lines
spfn = chunk_end; if (can_resched) cond_resched(); else touch_nmi_watchdog(); } nr_pages += epfn - spfn;
Quoted 7 lines
epfn - spfn <= 0.
So the number of pages returned by
deferred_init_memmap_chunk()becomes incorrect.The equivalent translation of what's there before would be doing
nr_pages += chunk_end - spfn;within the loop.
Good point, thank you. This patch has already been removed from mm-new.
Quoted 3 lines
--
Cheers,
Harry / Hyeonggon
Mathieu Desnoyers
reviewerOn 2026-03-20 00:17, Harry Yoo wrote:
[...]
Quoted 11 lines
Quoted 1 line
@Mathieu: In patch 1/3 description,
Quoted 4 lines
Changes since v7:
- Explicitly initialize the subsystem fromstart_kernel()right aftermm_core_init()so it is up and running before the creation of the first mm at boot.But how does this work when someone calls
mm_cpumask()oninit_mmearly? Looks like it will behave incorrectly becauseget_rss_stat_items_size()returns zero?
It doesn't work as expected at all. I missed that all users of mm_cpumask() end up relying on get_rss_stat_items_size(), which now calls percpu_counter_tree_items_size(), which depends on initialization from percpu_counter_tree_subsystem_init().
If you add a call to percpu_counter_tree_subsystem_init in arch/powerpc/kernel/setup_arch() just before:
VM_WARN_ON(cpumask_test_cpu(smp_processor_id(), mm_cpumask(&init_mm)));
cpumask_set_cpu(smp_processor_id(), mm_cpumask(&init_mm));Does the warning go away ?
Alternatively, would could use a lazy initialization invoking percpu_counter_tree_subsystem_init from percpu_counter_tree_items_size when the initialization is not already done.
Any preference ?
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Quoted 19 lines · Mathieu Desnoyers
On 2026-03-20 00:17, Harry Yoo wrote:
[...]Quoted 11 lines
Quoted 1 line
@Mathieu: In patch 1/3 description,
Quoted 4 lines
Changes since v7:
- Explicitly initialize the subsystem fromstart_kernel()right aftermm_core_init()so it is up and running before the creation of the first mm at boot.But how does this work when someone calls
mm_cpumask()oninit_mmearly? Looks like it will behave incorrectly becauseget_rss_stat_items_size()returns zero?It doesn't work as expected at all. I missed that all users of
mm_cpumask()end up relying onget_rss_stat_items_size(), which now callspercpu_counter_tree_items_size(), which depends on initialization frompercpu_counter_tree_subsystem_init().
Quoted 7 lines
If you add a call to
percpu_counter_tree_subsystem_initin arch/powerpc/kernel/setup_arch() just before:VM_WARN_ON(cpumask_test_cpu(smp_processor_id(), mm_cpumask(&init_mm))); cpumask_set_cpu(smp_processor_id(), mm_cpumask(&init_mm));Does the warning go away ?
Hmm it goes away, but I'm not sure if it is it okay to use nr_cpu_ids before setup_nr_cpu_ids() is called?
Quoted 3 lines
Alternatively, would could use a lazy initialization invoking
percpu_counter_tree_subsystem_initfrompercpu_counter_tree_items_sizewhen the initialization is not already done.
So this probably isn't a way to go?
Hmm perhaps we should treat init_mm as a special case in mm_cpus_allowed() and mm_cpumask().
Signature · 2 lines
Cheers, Harry / Hyeonggon
Mathieu Desnoyers
reviewerQuoted 23 lines · Harry Yoo (Oracle)
Quoted 22 lines · Mathieu Desnoyers
On 2026-03-20 00:17, Harry Yoo wrote:
[...]Quoted 11 lines
Quoted 1 line
@Mathieu: In patch 1/3 description,
Quoted 4 lines
Changes since v7:
- Explicitly initialize the subsystem fromstart_kernel()right aftermm_core_init()so it is up and running before the creation of the first mm at boot.But how does this work when someone calls
mm_cpumask()oninit_mmearly? Looks like it will behave incorrectly becauseget_rss_stat_items_size()returns zero?It doesn't work as expected at all. I missed that all users of
mm_cpumask()end up relying onget_rss_stat_items_size(), which now callspercpu_counter_tree_items_size(), which depends on initialization frompercpu_counter_tree_subsystem_init().If you add a call to
percpu_counter_tree_subsystem_initin arch/powerpc/kernel/setup_arch() just before:
Quoted 7 lines
Quoted 4 lines
VM_WARN_ON(cpumask_test_cpu(smp_processor_id(), mm_cpumask(&init_mm))); cpumask_set_cpu(smp_processor_id(), mm_cpumask(&init_mm));Does the warning go away ?
Hmm it goes away, but I'm not sure if it is it okay to use
nr_cpu_idsbeforesetup_nr_cpu_ids()is called?
AFAIU on powerpc setup_nr_cpu_ids() is called near the end of smp_setup_cpu_maps(), which is called early in setup_arch, at least before the two lines which use mm_cpumask.
Quoted 5 lines
Quoted 3 lines
Alternatively, would could use a lazy initialization invoking
percpu_counter_tree_subsystem_initfrompercpu_counter_tree_items_sizewhen the initialization is not already done.So this probably isn't a way to go?
I'd favor explicit initialization, so the inter-dependencies are clear.
Quoted 2 lines
Hmm perhaps we should treat
init_mmas a special case inmm_cpus_allowed()andmm_cpumask().
I'd prefer not to go there if boot sequence permits and keep things simple.
I think we're in a situation very similar to tree RCU, here is what is done in rcu_init_geometry:
static bool initialized;
if (initialized) {
/*
* Warn if setup_nr_cpu_ids() had not yet been invoked,
* unless nr_cpus_ids == NR_CPUS, in which case who cares?
*/
WARN_ON_ONCE(old_nr_cpu_ids != nr_cpu_ids);
return;
}
old_nr_cpu_ids = nr_cpu_ids;
initialized = true;Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Mathieu Desnoyers
reviewerQuoted 16 lines · Mathieu Desnoyers
Quoted 15 lines · Harry Yoo (Oracle)
Quoted 14 lines · Mathieu Desnoyers
On 2026-03-20 00:17, Harry Yoo wrote:
[...]Quoted 11 lines
Quoted 1 line
[1]: https://lore.kernel.org/20260227153730.1556542-4- [email protected]/
@Mathieu: In patch 1/3 description,
Quoted 4 lines
Changes since v7:
- Explicitly initialize the subsystem fromstart_kernel()right aftermm_core_init()so it is up and running before the creation of the first mm at boot.But how does this work when someone calls
mm_cpumask()oninit_mmearly? Looks like it will behave incorrectly becauseget_rss_stat_items_size()returns zero?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
It doesn't work as expected at all. I missed that all users of
mm_cpumask()end up relying onget_rss_stat_items_size(), which now callspercpu_counter_tree_items_size(), which depends on initialization frompercpu_counter_tree_subsystem_init().If you add a call to
percpu_counter_tree_subsystem_initin arch/powerpc/kernel/setup_arch() just before:
[...]
One thing we could do to catch this kind of init sequence issue is to add a WARN_ON_ONCE in percpu_counter_tree_items_size:
size_t percpu_counter_tree_items_size(void)
{
if (WARN_ON_ONCE(!nr_cpus_order))
return 0;
return counter_config->nr_items * sizeof(struct percpu_counter_tree_level_item);
}Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
++ linuxppc-dev
Quoted 20 lines · Mathieu Desnoyers
Quoted 19 lines · Mathieu Desnoyers
Quoted 18 lines · Harry Yoo (Oracle)
Quoted 17 lines · Mathieu Desnoyers
On 2026-03-20 00:17, Harry Yoo wrote:
[...]Quoted 14 lines
Quoted 2 lines
[1]: https://lore.kernel.org/20260227153730.1556542-4-
[email protected]/@Mathieu: In patch 1/3 description,
Quoted 5 lines
Changes since v7:
- Explicitly initialize the subsystem fromstart_kernel()right aftermm_core_init()so it is up and running before the creation of
the first mm at boot.But how does this work when someone calls
mm_cpumask()oninit_mmearly?
Looks like it will behave incorrectly becauseget_rss_stat_items_size()returns zero?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
It doesn't work as expected at all. I missed that all users of
mm_cpumask()
end up relying onget_rss_stat_items_size(), which now callspercpu_counter_tree_items_size(), which depends on initialization frompercpu_counter_tree_subsystem_init().If you add a call to
percpu_counter_tree_subsystem_initin arch/powerpc/kernel/setup_arch() just before:
Even though powerpc is showing the warning because of VM_WARN_ON_ONCE(), but this looks more of a generic problem, where use of mm_cpumask() before and after percpu_counter_tree_items_size() could lead to different results (as you also pointed above).
Looks like this is causing regressions in linux-next with warnings similar to what Harry also pointed out. Do we have any solution for this, or are we planning to hold on to this patch[1] and maybe even remove it temporarily from linux-next, until this is fixed?
[1]: https://lore.kernel.org/all/[email protected]/
[ 0.000000] WARNING: arch/powerpc/mm/mmu_context.c:106 at switch_mm_irqs_off+0x1a0/0x1d0, CPU#2: swapper/0 [ 0.000000] Modules linked in: [ 0.000000] CPU: 2 UID: 0 PID: 0 Comm: swapper Not tainted 7.0.0-rc4-next-20260317-00008-g5585e414f073 #4 PREEMPTLAZY [ 0.000000] Hardware name: IBM PowerNV (emulated by qemu) POWER10 0x801200 opal:v7.1 PowerNV [ 0.000000] NIP: c00000000008f3b0 LR: c00000000008f330 CTR: c000000000090e20 [ 0.000000] REGS: c000000003cb79b0 TRAP: 0700 Not tainted (7.0.0-rc4-next-20260317-00008-g5585e414f073) [ 0.000000] MSR: 9000000002021033 <SF,HV,VEC,ME,IR,DR,RI,LE> CR:24022224 XER: 00000000 <...> [ 0.000000] NIP [c00000000008f3b0] switch_mm_irqs_off+0x1a0/0x1d0 [ 0.000000] LR [c00000000008f330] switch_mm_irqs_off+0x120/0x1d0 [ 0.000000] Call Trace: [ 0.000000] [c000000003cb7c50] [0500210400000080] 0x500210400000080 (unreliable) [ 0.000000] [c000000003cb7cb0] [c0000000000ad850] start_using_temp_mm+0x34/0xb0 [ 0.000000] [c000000003cb7cf0] [c0000000000ae8b8] patch_mem+0x110/0x530 [ 0.000000] [c000000003cb7d70] [c000000000077f30] ftrace_modify_code+0x114/0x154 [ 0.000000] [c000000003cb7dd0] [c00000000036a690] ftrace_process_locs+0x408/0x810 [ 0.000000] [c000000003cb7ec0] [c0000000030584ec] ftrace_init+0x68/0x1c4 [ 0.000000] [c000000003cb7f30] [c00000000300d3b8] start_kernel+0x680/0xc44 [ 0.000000] [c000000003cb7fe0] [c00000000000e99c] start_here_common+0x1c/0x20
-ritesh
Andrew Morton
maintainerQuoted 4 lines · On Sat, 21 Mar 2026 06:42:41 +0530 Ritesh Harjani (IBM)…
Looks like this is causing regressions in linux-next with warnings similar to what Harry also pointed out. Do we have any solution for this, or are we planning to hold on to this patch[1] and maybe even remove it temporarily from linux-next, until this is fixed?
Yes, I'll disable this patchset.
Quoted 27 lines · Mathieu Desnoyers
Quoted 26 lines · Harry Yoo (Oracle)
Quoted 25 lines · Mathieu Desnoyers
On 2026-03-20 00:17, Harry Yoo wrote:
[...]Quoted 11 lines
Quoted 1 line
@Mathieu: In patch 1/3 description,
Quoted 4 lines
Changes since v7:
- Explicitly initialize the subsystem fromstart_kernel()right aftermm_core_init()so it is up and running before the creation of the first mm at boot.But how does this work when someone calls
mm_cpumask()oninit_mmearly? Looks like it will behave incorrectly becauseget_rss_stat_items_size()returns zero?It doesn't work as expected at all. I missed that all users of
mm_cpumask()end up relying onget_rss_stat_items_size(), which now callspercpu_counter_tree_items_size(), which depends on initialization frompercpu_counter_tree_subsystem_init().If you add a call to
percpu_counter_tree_subsystem_initin arch/powerpc/kernel/setup_arch() just before:VM_WARN_ON(cpumask_test_cpu(smp_processor_id(), mm_cpumask(&init_mm))); cpumask_set_cpu(smp_processor_id(), mm_cpumask(&init_mm));
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Does the warning go away ?
Hmm it goes away, but I'm not sure if it is it okay to use
nr_cpu_idsbeforesetup_nr_cpu_ids()is called?AFAIU on powerpc
setup_nr_cpu_ids()is called near the end ofsmp_setup_cpu_maps(), which is called early insetup_arch, at least before the two lines which usemm_cpumask.
Right.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Alternatively, would could use a lazy initialization invoking
percpu_counter_tree_subsystem_initfrompercpu_counter_tree_items_sizewhen the initialization is not already done.So this probably isn't a way to go?
I'd favor explicit initialization, so the inter-dependencies are clear.
Ack.
Quoted 9 lines
Quoted 2 lines
Hmm perhaps we should treat
init_mmas a special case inmm_cpus_allowed()andmm_cpumask().I'd prefer not to go there if boot sequence permits and keep things simple.
I think we're in a situation very similar to tree RCU, here is what is done in
rcu_init_geometry:
Quoted 13 lines
static bool initialized;
if (initialized) {
/*
* Warn if setup_nr_cpu_ids() had not yet been invoked,
* unless nr_cpus_ids == NR_CPUS, in which case who cares?
*/
WARN_ON_ONCE(old_nr_cpu_ids != nr_cpu_ids);
return;
}
old_nr_cpu_ids = nr_cpu_ids;
initialized = true;Yeah, as long as nr_cpus_order doesn't change after init, that will work for HPCC. powerpc seems to be a special case that calls mm_cpumask() very early in the boot process, so explicitly calling the init function seems to be fair.
By the way, thinking about it differently - it would probably be simpler to just eliminate mm_cpumask's dependency on HPCC init dependency by placing those cpumasks before percpu counter tree items... (but yeah, that would make mm_struct a bit larger due to alignment requirements)
Signature · 2 lines
Cheers, Harry / Hyeonggon
Quoted 31 lines · Mathieu Desnoyers
Quoted 27 lines · Mathieu Desnoyers
Quoted 26 lines · Harry Yoo (Oracle)
Quoted 25 lines · Mathieu Desnoyers
On 2026-03-20 00:17, Harry Yoo wrote:
[...]Quoted 10 lines
Quoted 2 lines
[1]: https://lore.kernel.org/20260227153730.1556542-4-
[email protected]/@Mathieu: In patch 1/3 description,
Quoted 5 lines
Changes since v7:
- Explicitly initialize the subsystem fromstart_kernel()right aftermm_core_init()so it is up and running before the creation of
the first mm at boot.Quoted 4 lines
But how does this work when someone calls
mm_cpumask()oninit_mmearly?
Looks like it will behave incorrectly becauseget_rss_stat_items_size()returns zero?It doesn't work as expected at all. I missed that all users of
mm_cpumask()
end up relying onget_rss_stat_items_size(), which now callspercpu_counter_tree_items_size(), which depends on initialization frompercpu_counter_tree_subsystem_init().If you add a call to
percpu_counter_tree_subsystem_initin arch/powerpc/kernel/setup_arch() just before:[...]
Quoted 8 lines
One thing we could do to catch this kind of init sequence issue is to add a
WARN_ON_ONCEinpercpu_counter_tree_items_size:
size_tpercpu_counter_tree_items_size(void){ if (WARN_ON_ONCE(!nr_cpus_order)) return 0; return counter_config->nr_items * sizeof(struct percpu_counter_tree_level_item);
Looks good!
Signature · 2 lines
Cheers, Harry / Hyeonggon
Mathieu Desnoyers
reviewerQuoted 8 lines · Andrew Morton
Quoted 4 lines · On Sat, 21 Mar 2026 06:42:41 +0530 Ritesh Harjani (IBM)…
Looks like this is causing regressions in linux-next with warnings similar to what Harry also pointed out. Do we have any solution for this, or are we planning to hold on to this patch[1] and maybe even remove it temporarily from linux-next, until this is fixed?
Yes, I'll disable this patchset.
Hi Andrew,
I have prepared fixes for this issue. On which branch should I rebase them ? Do you still have the HPCC series in your branch or should I send it anew ?
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Andrew Morton
maintainerQuoted 8 lines · On Thu, 2 Apr 2026 11:30:53 -0400 Mathieu Desnoyers…
Quoted 7 lines · Andrew Morton
Quoted 4 lines · On Sat, 21 Mar 2026 06:42:41 +0530 Ritesh Harjani (IBM)…
Looks like this is causing regressions in linux-next with warnings similar to what Harry also pointed out. Do we have any solution for this, or are we planning to hold on to this patch[1] and maybe even remove it temporarily from linux-next, until this is fixed?
Quoted 7 lines
Quoted 1 line
Yes, I'll disable this patchset.
Hi Andrew,
I have prepared fixes for this issue. On which branch should I rebase them ? Do you still have the HPCC series in your branch or should I send it anew ?
Cool thanks.
It's best to do a full resend after -rc1 please, presumably against mainline. Show reviewers the latest version, refresh memories, etc.