From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 443F2272E56 for ; Wed, 8 Apr 2026 15:32:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775662351; cv=none; b=pt8jjC5jx39tE4bvfUCBSO40HQ1tE4d7NE0gKR7zenkr8N+2fCqrVfyTuiP/C3q+vwKMbofThtMWFE3/8QL8kaCcmhM/6nAcW5KNNaoQKDFShK9tvJUxbomIXkVvLQe3sQZDQQ/kUxxqRk4qAixF6ssd/ljnR7/DgU0wbu0n4I4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775662351; c=relaxed/simple; bh=HO2ZYIG3YM4JE4/kgSviA/LwkaeYL9Ge2VXlcgtxWxY=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=Jss0hOAl2zy5jBK7DcJWIbjfrpSdv5uZh7zv5pwkV8z06pLLyfTK5t3vkjaD84jOmCI9egp+KE/WmoNQroEWaXIuUJ4SOwhM+wcbgoMzkXFwK2SFzq5MLrEybWoNLYoQh0jv0s+wkeJpvOCqZE/ifLP3+UJpAUIrnb3ByesRzuw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=cXAalaX8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="cXAalaX8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70835C19421; Wed, 8 Apr 2026 15:32:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1775662350; bh=HO2ZYIG3YM4JE4/kgSviA/LwkaeYL9Ge2VXlcgtxWxY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=cXAalaX8cQA5O0FWAdJ/j0E31YxR5hXdxTCgFyDdBG9qJqvKpOvZPH4M9x8F+kCfZ r+aoE8qRe9m8d1lmxMGMNq/iAXbL4zNNsMbeDUWioFnq9LZ8JGxoeIisZR184H2Vxy KV02QokV1S7zjW3gTXjWAtmDLzNQJ8ig68XgQBSk= Date: Wed, 8 Apr 2026 08:32:29 -0700 From: Andrew Morton To: "Salunke, Hrushikesh" Cc: "Vlastimil Babka (SUSE)" , , , , , , , , , , , , "David Hildenbrand" Subject: Re: [PATCH] mm/page_alloc: use batch page clearing in kernel_init_pages() Message-Id: <20260408083229.45d1a083f17484d3b2678855@linux-foundation.org> In-Reply-To: <4e8c218b-ac5e-4674-9e1e-acf750f0a5c8@amd.com> References: <20260408092441.435133-1-hsalunke@amd.com> <22b6ff3c-9d41-4eb0-9beb-cb92f3ada89f@kernel.org> <4e8c218b-ac5e-4674-9e1e-acf750f0a5c8@amd.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 8 Apr 2026 16:14:03 +0530 "Salunke, Hrushikesh" wrote: > kernel_init_pages() runs inside the allocator (post_alloc_hook and > __free_pages_prepare), so it inherits whatever context the caller is in. > Testing with CONFIG_DEBUG_ATOMIC_SLEEP=y and CONFIG_PROVE_LOCKING=y, I > hit this during exit_group() -> exit_mmap() -> __zap_vma_range, where a > page allocation happens while the PTE lock and RCU read lock are held, > making the cond_resched() in the clearing loop illegal: > > [ 1997.353228] BUG: sleeping function called from invalid context at mm/page_alloc.c:1235 > [ 1997.353433] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 19725, name: bash > [ 1997.353572] preempt_count: 1, expected: 0 > [ 1997.353706] RCU nest depth: 1, expected: 0 > [ 1997.353837] 3 locks held by bash/19725: > [ 1997.353839] #0: ff38cd415971e540 (&mm->mmap_lock){++++}-{4:4}, at: exit_mmap+0x6e/0x430 > [ 1997.353850] #1: ffffffffb03d6f60 (rcu_read_lock){....}-{1:3}, at: __pte_offset_map+0x2c/0x220 > [ 1997.353855] #2: ff38cd410deb4618 (ptlock_ptr(ptdesc)#2){+.+.}-{3:3}, at: pte_offset_map_lock+0x92/0x170 > [ 1997.353868] Call Trace: > [ 1997.353870] > [ 1997.353873] dump_stack_lvl+0x91/0xb0 > [ 1997.353877] __might_resched+0x15f/0x290 > [ 1997.353882] kernel_init_pages+0x4b/0xa0 > [ 1997.353886] get_page_from_freelist+0x406/0x1e60 > [ 1997.353895] __alloc_frozen_pages_noprof+0x1d8/0x1730 > [ 1997.353912] alloc_pages_mpol+0xa4/0x190 > [ 1997.353917] alloc_pages_noprof+0x59/0xd0 > [ 1997.353919] get_free_pages_noprof+0x11/0x40 > [ 1997.353921] __tlb_remove_folio_pages_size.isra.0+0x7f/0xe0 > [ 1997.353923] __zap_vma_range+0x1bbd/0x1f40 > [ 1997.353931] unmap_vmas+0xd9/0x1d0 > [ 1997.353934] exit_mmap+0x10a/0x430 > [ 1997.353943] __mmput+0x3d/0x130 > [ 1997.353947] do_exit+0x2a7/0xae0 tlb_next_batch() is (fortunately) using GFP_NOWAIT. Perhaps you can alter your patch to not call the cond_resched() if caller is attempting an atomic allocation.