From nobody Sun Feb 8 04:31:02 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 845CA326928 for ; Thu, 22 Jan 2026 18:44:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769107488; cv=none; b=C5jzJqgnlvd9H0npz2/kBMPSP5RgI9x+SY1SAK266SK6ZcqBDskvkkc2GNRrCPMrvkjB2jPHVI7+Qj3anqtjVdlExyhxZWcEzIMhhO//i5BU88/PxW6OnJeJEjzzcjkLljZOjNtqtY8Q8Md5FRUycwcFQVkPp8nVZ1v5Zqx3h6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769107488; c=relaxed/simple; bh=HKFPyQQ6hmbAczM0/cvKv4bWPuFTGBzmQ8bqeGgF68Y=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nemdP7GFS1LirgIa+HCFqGP5ibLrycSb2C1zfw3is3FvouOqZwPa+ul7QHqWIR+41lIETCEVp4lPagY5emHms3a0gqyTXBzSxguYMj4nr5RY8MavFcdjBQBIFlgeGt1yfaxes2Ku18h/3EQfdN+cvgOVfOEtNlA6Rpit6b3oJLk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TiktU0N9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TiktU0N9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769107470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=2hi9nw0ROEqCJmA86cR5BCja4mz2cFCx+tgdx6SAHhI=; b=TiktU0N97RsGti6B2MNXAHNz67irer6EpxxjoiHrZoIMUBjzvWeIFybJSWzpv/75WshtXt Gsnd8TEgOk5WIv1wctJZY7KTY08+LWk/oGRJJ7HQ4GeF9jYgJtTRNcjW472JVljTSdwvFP JyrY6gfIcd+AbW5tWngrY8aB84sIUM0= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-450-DrPRUB-MMeeByGpbTwLtaw-1; Thu, 22 Jan 2026 13:44:27 -0500 X-MC-Unique: DrPRUB-MMeeByGpbTwLtaw-1 X-Mimecast-MFC-AGG-ID: DrPRUB-MMeeByGpbTwLtaw_1769107465 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6209F1955D9F; Thu, 22 Jan 2026 18:44:25 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.90.13]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EBA041800665; Thu, 22 Jan 2026 18:44:22 +0000 (UTC) From: Waiman Long To: Mike Rapoport , Andrew Morton , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Wei Yang , David Hildenbrand , "Paul E . McKenney" , Waiman Long Subject: [PATCH v3] mm/mm_init: Don't cond_resched() in deferred_init_memmap_chunk() if called from deferred_grow_zone() Date: Thu, 22 Jan 2026 13:43:43 -0500 Message-ID: <20260122184343.546627-1-longman@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Commit 3acb913c9d5b ("mm/mm_init: use deferred_init_memmap_chunk() in deferred_grow_zone()") made deferred_grow_zone() call deferred_init_memmap_chunk() within a pgdat_resize_lock() critical section with irqs disabled. It did check for irqs_disabled() in deferred_init_memmap_chunk() to avoid calling cond_resched(). For a PREEMPT_RT kernel build, however, spin_lock_irqsave() does not disable interrupt but rcu_read_lock() is called. This leads to the following bug report. BUG: sleeping function called from invalid context at mm/mm_init.c:2091 in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 1, name: swapper/0 preempt_count: 0, expected: 0 RCU nest depth: 1, expected: 0 3 locks held by swapper/0/1: #0: ffff80008471b7a0 (sched_domains_mutex){+.+.}-{4:4}, at: sched_domain= s_mutex_lock+0x28/0x40 #1: ffff003bdfffef48 (&pgdat->node_size_lock){+.+.}-{3:3}, at: deferred_= grow_zone+0x140/0x278 #2: ffff800084acf600 (rcu_read_lock){....}-{1:3}, at: rt_spin_lock+0x1b4= /0x408 CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Tainted: G W 6.19.0= -rc6-test #1 PREEMPT_{RT,(full) } Tainted: [W]=3DWARN Call trace: show_stack+0x20/0x38 (C) dump_stack_lvl+0xdc/0xf8 dump_stack+0x1c/0x28 __might_resched+0x384/0x530 deferred_init_memmap_chunk+0x560/0x688 deferred_grow_zone+0x190/0x278 _deferred_grow_zone+0x18/0x30 get_page_from_freelist+0x780/0xf78 __alloc_frozen_pages_noprof+0x1dc/0x348 alloc_slab_page+0x30/0x110 allocate_slab+0x98/0x2a0 new_slab+0x4c/0x80 ___slab_alloc+0x5a4/0x770 __slab_alloc.constprop.0+0x88/0x1e0 __kmalloc_node_noprof+0x2c0/0x598 __sdt_alloc+0x3b8/0x728 build_sched_domains+0xe0/0x1260 sched_init_domains+0x14c/0x1c8 sched_init_smp+0x9c/0x1d0 kernel_init_freeable+0x218/0x358 kernel_init+0x28/0x208 ret_from_fork+0x10/0x20 Fix it adding a new argument to deferred_init_memmap_chunk() to explicitly tell it if cond_resched() is allowed or not instead of relying on some current state information which may vary depending on the exact kernel configuration options that are enabled. Fixes: 3acb913c9d5b ("mm/mm_init: use deferred_init_memmap_chunk() in defer= red_grow_zone()") Suggested-by: Sebastian Andrzej Siewior Signed-off-by: Waiman Long Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Sebastian Andrzej Siewior --- [v3]: Add a new can_resched argument to deferred_init_memmap_chunk() as suggested by Sebastian. mm/mm_init.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index fc2a6f1e518f..2a809cd8e7fa 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2059,7 +2059,7 @@ static unsigned long __init deferred_init_pages(struc= t zone *zone, */ static unsigned long __init deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, - struct zone *zone) + struct zone *zone, bool can_resched) { int nid =3D zone_to_nid(zone); unsigned long nr_pages =3D 0; @@ -2085,10 +2085,10 @@ deferred_init_memmap_chunk(unsigned long start_pfn,= unsigned long end_pfn, =20 spfn =3D chunk_end; =20 - if (irqs_disabled()) - touch_nmi_watchdog(); - else + if (can_resched) cond_resched(); + else + touch_nmi_watchdog(); } } =20 @@ -2101,7 +2101,7 @@ deferred_init_memmap_job(unsigned long start_pfn, uns= igned long end_pfn, { struct zone *zone =3D arg; =20 - deferred_init_memmap_chunk(start_pfn, end_pfn, zone); + deferred_init_memmap_chunk(start_pfn, end_pfn, zone, true); } =20 static unsigned int __init @@ -2216,7 +2216,7 @@ bool __init deferred_grow_zone(struct zone *zone, uns= igned int order) for (spfn =3D first_deferred_pfn, epfn =3D SECTION_ALIGN_UP(spfn + 1); nr_pages < nr_pages_needed && spfn < zone_end_pfn(zone); spfn =3D epfn, epfn +=3D PAGES_PER_SECTION) { - nr_pages +=3D deferred_init_memmap_chunk(spfn, epfn, zone); + nr_pages +=3D deferred_init_memmap_chunk(spfn, epfn, zone, false); } =20 /* --=20 2.52.0