From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A28E9C3ABC9 for ; Fri, 16 May 2025 17:02:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3BF046B01FF; Fri, 16 May 2025 13:02:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 393F46B0200; Fri, 16 May 2025 13:02:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2331D6B0201; Fri, 16 May 2025 13:02:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 08F3F6B01FF for ; Fri, 16 May 2025 13:02:08 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5746A120DFA for ; Fri, 16 May 2025 17:02:09 +0000 (UTC) X-FDA: 83449388778.29.D667AC3 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf10.hostedemail.com (Postfix) with ESMTP id 76F6CC001B for ; Fri, 16 May 2025 17:02:07 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lUDxZrq3; spf=pass (imf10.hostedemail.com: domain of rppt@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1747414927; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qUUyy8M43D0dG44GVORUg39KnD5MB3MGDMWFb5IS0pI=; b=UA6r1IKGOSexQIFvDHVz5lh6TaEKhl9DKeE/DaZjFRmDF4pz/hIRSjj/WkQfpsqEl/wUtK ex//qIi7vnKikL7FtDSrkJG4++U3cJBGYMgfFpuA0exrThhwIU8+8XvOViKXd4GWYVdtxT 67t+h9ril3u0yW5ubwjblvCKU1ILJJs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747414927; a=rsa-sha256; cv=none; b=4XYnKojynNb9KivOhTyS01F/XkhuVeIjJU45LJIuKwjlG78+G3F7PYfdb47V/x0zlgYW8H C1D1ZvbowRB6sNdi9RnhlpJnmt4B4svHsOX/+Y+5KarTfzrVhtSNbjKQLl2XOpHIcHebqc WSEA3/C2J3H/IXsxQgLx65bBimxhP2s= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lUDxZrq3; spf=pass (imf10.hostedemail.com: domain of rppt@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 157604A5E3; Fri, 16 May 2025 17:02:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0EECC4CEF0; Fri, 16 May 2025 17:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747414925; bh=cqx2+cIJWTrHCV6/oR0Yq/5mBq5YQMLp47aAmVpBt3g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lUDxZrq3AgKR6R/qdSD5KToNP2iDU/ZdgNHX0l93Wa0Usl43PM+Q69PCMJ+riC91+ GzyY7EaqkfMTyfOZpKxurTSZjkJKwfcYAJzN479Jq1XY715ZFPSbZY5p+660Pml4WJ WVrtggr77MuENEy16G/Cm6GiEnYKWR+qy9NuUFUBtEWcY2PS4Dfe2fo7FR1Ix+D4Oi 47TeVeOimVrXL3v1JgdHRttkQXduRx9X2VuGVrxf0Jjtgu8cmKYzsPNI0B6nhbhtkY it1pWXgcbOjzy34igpeFVY2tv6MHULnoGk6Vy5BS3lI1O4u50PgBdO3vKkRUd646yd GEf103TOWCZUw== Date: Fri, 16 May 2025 20:01:44 +0300 From: Mike Rapoport To: Pratyush Yadav Cc: Andrew Morton , Alexander Gordeev , Andreas Larsson , Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , Borislav Petkov , Brian Cain , Catalin Marinas , Dave Hansen , "David S. Miller" , Dinh Nguyen , Geert Uytterhoeven , Gerald Schaefer , Guo Ren , Heiko Carstens , Helge Deller , Huacai Chen , Ingo Molnar , Jiaxun Yang , Johannes Berg , John Paul Adrian Glaubitz , Madhavan Srinivasan , Mark Brown , Matt Turner , Max Filippov , Michael Ellerman , Michal Simek , Palmer Dabbelt , Peter Zijlstra , Richard Weinberger , Russell King , Stafford Horne , Thomas Bogendoerfer , Thomas Gleixner , Vasily Gorbik , Vineet Gupta , Will Deacon , Praveen Kumar , linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org Subject: Re: [PATCH v2 10/13] arch, mm: set high_memory in free_area_init() Message-ID: References: <20250313135003.836600-1-rppt@kernel.org> <20250313135003.836600-11-rppt@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: hze6dheix9t4n7i47xasm39parixdyeo X-Rspamd-Queue-Id: 76F6CC001B X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1747414927-271895 X-HE-Meta: U2FsdGVkX1+sDIom22mVkaoKz3y2CqPKFoXOqiyZi78lyZKHxPl5i6exqVtLvQR/BwCw9TGWik87na3etVYWCg5EWvq6EKSrQ0yC2mr3yZ4qpShYKbDqDSsmIhPSTRetwyVV93E1F7vyXaGez31byjNDpPq8hUtlNKfI79dKuDAZvIzM/NqH0wiDa4lsLlPxcSxsqLVe1jkP1bBJKlWgPhVsXmaOtETq/gD7i34xvhu2fsZtUXxiBJwlHhkNdu5tPDv9bFyFnTtcGL3/tbCKPcOgD/3JKyGxssJqMPWQ8HRjBuy7XiXoQshUct1YYoz+rR7jjnZEjbyRo2o/9elMCtxquPA6Jn/tmhKVCFm+oKp7/YjKUzXr+47i3EpqNxievVX4qJlAnTTBqrQCjCSY9G9cFoYWZfP08vL3HKppAldB3YTTYnX+FufNML77LZ9ARpxElC8cs8WFlb+yq/ZDimwNmtDslFVH+Pp9GYKAKgiJVqNOtu74iWdzF25B1W74OPCSa+cJBIFBSR3ozcTtjKagO1gXGGVu5IkaP6hWXIEsQBFKpxK5up+c7KbGjtuicb0kTZszrNFH3S0yHlBS0K1eJCNRS+WlTP/cZojzQ/uO6SYKUNuO7CLv/BcfhZqlZz0+lWLz6t2w+in/7ggBgnu/6D/zkSsIvmwx8Fbt/LSr8BiMBqafWljtaZ0O8s6/LQ+ptZ7u3zjmPQ2/Zj7tLKC+Ao+s9806vFaMZ68BLlZ3AvDBnztq/9MrfTcZh3wi90DFo8nfePdkrr1VFXT01loi/AgcKH47nz5FBtkybNgZX5xenLg6Bk2b+CRgQfu3e677otpYc+0FQptBexJ0UtWyWH4R05p8B2uP3F8FlyyyziFYk3bB4xXDE2ZRCemBVavMQldWjTEgFXrNX8j+ENUL6MKU89HP/Rr1FR47ynndtlUGVxDXMbPvvWWhan07HxP5eRZdayzhDdwVsE6 qIV/LOGQ si30Bh2YdsRZa38J8RVbw0+eyjVJbYOxbIQqd9wvZUWUXCr1R2rrsJsXR3U2CU0/9pRKn2Z4tcpkGYg/j1BJuiUN8/QZIdGWZYvWjCdPUCh4Cq6ZmynbzJ5rPQyAEWvbHXHQWscQ4jAQQeXP566asMmiHf80RtTv1988S/lPWDEODarPTOCeL5koFPGU1p3FaIzr99g6RjgnNiGAr2XF+osWMVeoFncj/2VD5movyy26z5Me7+I0rMEFwnI1VSS2Nd0eshU6nzMfW5TXRxXLnJwft0XXbJVVZFi4g1tfD8GEpcxJUnFvKIRU2DoYBQdq7B4DLbBUWqMBPRsVk4eT+adJsdPCiSgaPfP6e X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi Pratyush, On Fri, May 16, 2025 at 05:28:17PM +0200, Pratyush Yadav wrote: > Hi Mike, Andrew, > > On Thu, Mar 13 2025, Mike Rapoport wrote: > > > From: "Mike Rapoport (Microsoft)" > > > > high_memory defines upper bound on the directly mapped memory. > > This bound is defined by the beginning of ZONE_HIGHMEM when a system has > > high memory and by the end of memory otherwise. > > > > All this is known to generic memory management initialization code that > > can set high_memory while initializing core mm structures. > > > > Add a generic calculation of high_memory to free_area_init() and remove > > per-architecture calculation except for the architectures that set and > > use high_memory earlier than that. > > > > Acked-by: Dave Hansen # x86 > > Signed-off-by: Mike Rapoport (Microsoft) > > --- > > arch/alpha/mm/init.c | 1 - > > arch/arc/mm/init.c | 2 -- > > arch/arm64/mm/init.c | 2 -- > > arch/csky/mm/init.c | 1 - > > arch/hexagon/mm/init.c | 6 ------ > > arch/loongarch/kernel/numa.c | 1 - > > arch/loongarch/mm/init.c | 2 -- > > arch/microblaze/mm/init.c | 2 -- > > arch/mips/mm/init.c | 2 -- > > arch/nios2/mm/init.c | 6 ------ > > arch/openrisc/mm/init.c | 2 -- > > arch/parisc/mm/init.c | 1 - > > arch/riscv/mm/init.c | 1 - > > arch/s390/mm/init.c | 2 -- > > arch/sh/mm/init.c | 7 ------- > > arch/sparc/mm/init_32.c | 1 - > > arch/sparc/mm/init_64.c | 2 -- > > arch/um/kernel/um_arch.c | 1 - > > arch/x86/kernel/setup.c | 2 -- > > arch/x86/mm/init_32.c | 3 --- > > arch/x86/mm/numa_32.c | 3 --- > > arch/xtensa/mm/init.c | 2 -- > > mm/memory.c | 8 -------- > > mm/mm_init.c | 30 ++++++++++++++++++++++++++++++ > > mm/nommu.c | 2 -- > > 25 files changed, 30 insertions(+), 62 deletions(-) > > This patch causes a BUG() when built with CONFIG_DEBUG_VIRTUAL and > passing in the cma= commandline parameter: > > ------------[ cut here ]------------ > kernel BUG at arch/x86/mm/physaddr.c:23! > ception 0x06 IP 10:ffffffff812ebbf8 error 0 cr2 0xffff88903ffff000 > CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.15.0-rc6+ #231 PREEMPT(undef) > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Arch Linux 1.16.3-1-1 04/01/2014 > RIP: 0010:__phys_addr+0x58/0x60 > Code: 01 48 89 c2 48 d3 ea 48 85 d2 75 05 e9 91 52 cf 00 0f 0b 48 3d ff ff ff 1f 77 0f 48 8b 05 20 54 55 01 48 01 d0 e9 78 52 cf 00 <0f> 0b 90 0f 1f 44 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 > RSP: 0000:ffffffff82803dd8 EFLAGS: 00010006 ORIG_RAX: 0000000000000000 > RAX: 000000007fffffff RBX: 00000000ffffffff RCX: 0000000000000000 > RDX: 000000007fffffff RSI: 0000000280000000 RDI: ffffffffffffffff > RBP: ffffffff82803e68 R08: 0000000000000000 R09: 0000000000000000 > R10: ffffffff83153180 R11: ffffffff82803e48 R12: ffffffff83c9aed0 > R13: 0000000000000000 R14: 0000001040000000 R15: 0000000000000000 > FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > CR2: ffff88903ffff000 CR3: 0000000002838000 CR4: 00000000000000b0 > Call Trace: > > ? __cma_declare_contiguous_nid+0x6e/0x340 > ? cma_declare_contiguous_nid+0x33/0x70 > ? dma_contiguous_reserve_area+0x2f/0x70 > ? setup_arch+0x6f1/0x870 > ? start_kernel+0x52/0x4b0 > ? x86_64_start_reservations+0x29/0x30 > ? x86_64_start_kernel+0x7c/0x80 > ? common_startup_64+0x13e/0x141 > > The reason is that __cma_declare_contiguous_nid() does: > > highmem_start = __pa(high_memory - 1) + 1; > > If dma_contiguous_reserve_area() (or any other CMA declaration) is > called before free_area_init(), high_memory is uninitialized. Without > CONFIG_DEBUG_VIRTUAL, it will likely work but use the wrong value for > highmem_start. > > Among the architectures this patch touches, the below call > dma_contiguous_reserve_area() _before_ free_area_init(): > > - x86 > - s390 > - mips > - riscv > - xtensa > - loongarch > - csky For most of those this patch didn't really change anything because they initialized high_memory in mem_init() which is a part of free_area_init(). In those cases cma just did highmem_start = __pa(-1) + 1; and everyone was happy :) > The below call it _after_ free_area_init(): > - arm64 > > And the below don't call it at all: > - sparc > - nios2 > - openrisc > - hexagon > - sh > - um > - alpha > > One possible fix would be to move the calls to > dma_contiguous_reserve_area() after free_area_init(). On x86, it would > look like the diff below. The obvious downside is that moving the call > later increases the chances of allocation failure. I'm not sure how much > that actually matters, but at least on x86, that means crash kernel and > hugetlb reservations go before DMA reservation. Also, adding a patch > like that at rc7 is a bit risky. I don't think there's a risk of allocation failure, but moving things around in setup_arch() is always risky :) > The other option would be to revert this. I tried a revert, but it isn't > trivial. It runs into merge conflicts in pretty much all of the arch > files. Maybe reverting patches 11, 12, and 13 as well would make it > easier but I didn't try that. What I think we can do is to add this to mm/cma.c (not even compile tested) diff --git a/mm/cma.c b/mm/cma.c index 15632939f20a..c04be488b099 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -608,7 +608,10 @@ static int __init __cma_declare_contiguous_nid(phys_addr_t *basep, * complain. Find the boundary by adding one to the last valid * address. */ - highmem_start = __pa(high_memory - 1) + 1; + if (IS_ENABLED(CONFIG_HIGHMEM)) + highmem_start = __pa(high_memory - 1) + 1; + else + highmem_start = memblock_end_of_DRAM(); pr_debug("%s(size %pa, base %pa, limit %pa alignment %pa)\n", __func__, &size, &base, &limit, &alignment); so that highmem_start in __cma_declare_contiguous_nid() will be always correct for !HIGHMEM configs and then restore setting of highmem_start in mips::paging_init() as mips is the only architecture that actually set high_memory before free_area_init() before this patch. (for 32 bit configs of x86 there alrady a fixup d893aca973c3 ("x86/mm: restore early initialization of high_memory for 32-bits")) -- Sincerely yours, Mike.