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 BB0C0C2BA1B for ; Wed, 12 Mar 2025 06:35:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61185280003; Wed, 12 Mar 2025 02:35:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59A88280001; Wed, 12 Mar 2025 02:35:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 444E8280003; Wed, 12 Mar 2025 02:35:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 215B0280001 for ; Wed, 12 Mar 2025 02:35:22 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9C5E4120BC8 for ; Wed, 12 Mar 2025 06:35:22 +0000 (UTC) X-FDA: 83211937284.10.C12BEA2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id CAE21140006 for ; Wed, 12 Mar 2025 06:35:20 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=s5OTgyGp; spf=pass (imf26.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 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=1741761321; 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=L01F4tka81VK1WGhlNJbg+RT6azDphkZ5PvXfllUquU=; b=APeU3TSntu5aOdXV0fYP/BOfDBCTLFI29EEfyMZUNprgmNH+zqGTy32VF1VZVhgF2liJum kjjyOH1/XiZu0rdMyeW0C+hveG50vNkXAIA5O3mPP86lTTS0Qkr7xgBs1HceaW3hk6Fyxd sHx9lw3MJCkKpLxqauLDYARvikIstdc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=s5OTgyGp; spf=pass (imf26.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741761321; a=rsa-sha256; cv=none; b=mMK2JSE0ZrhhwvSoUAdLPNXF6vAxSoqXWuY3q+7fyQS+Yjv55hmWWs8ZZF7QT+elJF/I+k w5xaPnpTxrUR8GaDz68pHvDgdWCyt0gyyXt8icoc+IDl3m9/MRalmsUOxguJ/8vFHSSmFl xw2AxsAbPg+VXOuiKkS8i6/BIq9xDZU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A9EFC5C47AF; Wed, 12 Mar 2025 06:33:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 407D8C4CEE3; Wed, 12 Mar 2025 06:35:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741761319; bh=5mdaPZVI9H0/LV5hmobVgKrUIL2iuMSKhSTxPs81fPU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=s5OTgyGpaumshikTp+iDDuLZlaDN5ZFNt0xhyxhEjxDoGdrRr5fCFJqupGsQ1e9mc x5+ujh1N69RbM6sMUkTLS3DxQMtFw4J494229H1wYU5SpwxEIdYz9MdPy8mIFSl7pw l37VuFqhXXoOyw7aw+nwsTVBrmtEviGrZHfYnDThjgKfYUlSm8F0VvgI37TsJEXPQg Z/TS0S2P3vKV4E8YK2hLZIT0IUPWeSPBaDZrgP63fW1/ioeooSw+E437KEQCfrER7m 3bE2KZoye8/AcR9u24hQHDyQiTnD+Psif0K5SR2GQnCkTLYx0lBk09w8YpbQLP/phf PvVxVGjqV5khg== Date: Wed, 12 Mar 2025 08:34:56 +0200 From: Mike Rapoport To: "Russell King (Oracle)" Cc: Mark Brown , Andrew Morton , Alexander Gordeev , Andreas Larsson , Andy Lutomirski , 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 , Matt Turner , Max Filippov , Michael Ellerman , Michal Simek , Palmer Dabbelt , Peter Zijlstra , Richard Weinberger , Stafford Horne , Thomas Bogendoerfer , Thomas Gleixner , Vasily Gorbik , Vineet Gupta , Will Deacon , 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 10/13] arch, mm: set high_memory in free_area_init() Message-ID: References: <20250306185124.3147510-1-rppt@kernel.org> <20250306185124.3147510-11-rppt@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: CAE21140006 X-Rspamd-Server: rspam08 X-Stat-Signature: ifwzxkmprttmxdqkm3bghg6y1xj5h6h5 X-HE-Tag: 1741761320-833008 X-HE-Meta: U2FsdGVkX194iDDfTmZvy13oGALkT4m5ZWxPhCYkPEUi/0BmQsQCo86ldJKtljIwORSNO1oheEEKQ043fmA8O1uK3y876pdrt9KGUVCqrPrKe08G5zdUWQnv/o4g++redhcSiBBbkt7CkTSb6XoSX4NHf5mOWoBom7ETlmgbW0nqGaSQGORgt2caujjToTNNlEM/DW3pHCMJY8l8rqGq9x1+H3rlisyip57zWRT0falrAvVC8eNmWmuIC5w/+gyMR7Ct8anEZPAvUcKDOTZJrPxu+ZXPlVcjHLRv8x1Vw6sxFOiW9q2Ffmnzirp0pbbs2n0PDOBz756MqV0fDWaDVLanhrpqzbDuYZNspdXaWUEBRSJwm+l5DrEzj89KZaLeFK9Hw9+ej8a6UtrQPanKnPAyAgijAAY80UKoEtpjNSLtk05nxLVhCSBwtJGvBe80LfC14t7SC0icZ+yhCe6c4M5flxFvoE9o0yvd6h1ji8REpmz5qQMoCnJpLJRHWAVlCbDby1WWORch/FlbcTWGRelYCOA+XraiSGrvzYXAAmhBGU5hy9rU6kp8yOGYvGNkNbZPJuyXIb3+nkAGpR91HAAswnlbeqoS7N3Tt4uxN6r+x5QBeMtKskz1Fby4FPEARZlfR9I8v0qriD/em2P+mc3iCz+iBuJq2riNHs8RdA9NVipIXlNgrzop2oGe23KHzek5WeC5LDYwo0jPM2GJZZUl4ENrI4QK9/evu4URxPGlw60uzQszao/k9p/T8ubsbn3/kNRuDFB7fYr6VwtpOKjAl6VhbfBOKhzTQcZSnD5o5yPMG3yZEtG3zuAtEl1LjUCiblvI4R/z+CWa5uGwHIXYa9nkE5gen/yWIiQjyfWy8Aw0MiOP2kpfdcPASEDi8/MzG0hdW7UK0OupOK79lVAmUisX+kna4DPTCIGWCUeDcZUC+GRpYpoadbLIkztOsKsUayhpKTcz0uVAndi LW5cP6/d ZPulfO6QUPfaSVBJFhvKcuknz0hewjmUNi2N1aVK9GsNlucz411cgLMot4q1i/SUUFk1iqTTc9zpIlgLNM6GJB6Ayk3azSVBikvxkpZjuZd4MqZ1wqSP5DOGw0/qRWjV+GwwwqON64mFib3/Y6jyxRbC/tYvGo4BTKKjr2aLSUoy51nhwTqVbN8+muIweO3JKKctdHBJdWwM1clsJ03KnPFnobjRVlJPOQZtt8s5e74cbFQvCEtlHymOMqTFRa1Vc2q95qAEctgIYveZRqYEzdTKpm/wngR4dDjrhmpB0Oaci6Q8pOPMqmcB+XBf/FHrbVs4LbIdTrZytFao= 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: On Tue, Mar 11, 2025 at 09:59:32PM +0000, Russell King (Oracle) wrote: > On Tue, Mar 11, 2025 at 05:51:06PM +0000, Mark Brown wrote: > > On Thu, Mar 06, 2025 at 08:51:20PM +0200, 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. > > > > > > Remove per-architecture calculation of high_memory and add a generic > > > version to free_area_init(). > > > > This patch appears to be causing breakage on a number of 32 bit arm > > platforms, including qemu's virt-2.11,gic-version=3. Affected platforms > > die on boot with no output, a bisect with qemu points at this commit and > > those for physical platforms appear to be converging on the same place. > > I'm not convinced that the old and the new code is doing the same > thing. > > The new code: > > + phys_addr_t highmem = memblock_end_of_DRAM(); > + > +#ifdef CONFIG_HIGHMEM > + unsigned long pfn = arch_zone_lowest_possible_pfn[ZONE_HIGHMEM]; > + > + if (arch_has_descending_max_zone_pfns() || highmem > PFN_PHYS(pfn)) > + highmem = PFN_PHYS(pfn); > +#endif > + > + high_memory = phys_to_virt(highmem - 1) + 1; > > First, when CONFIG_HIGHMEM is disabled, this code assumes that the last > byte of DRAM declared to memblock is the highmem limit. This _could_ > overflow phys_to_virt() and lead to an invalid value for high_memory. > > Second, arch_zone_lowest_possible_pfn[ZONE_HIGHMEM] is the _start_ of > highmem. This is not what arch code sets high_memory to - because > the start of highmem may not contiguously follow on from lowmem. > > In arch/arm/mm/mmu.c, lowmem_limit is computed to be the highest + 1 > physical address that lowmem can possibly be, taking into account the > amount of vmalloc memory that is required. This is used to set > high_memory. > > We also limit the amount of usable RAM via memblock_set_current_limit() > which memblock_end_of_DRAM() doesn't respect. > > I don't think the proposed generic version is suitable for 32-bit arm. Unless I'm missing something, both memblock.current_limit and start of ZONE_HIGHMEM are set to arm_lowmem_limit which will be different from memblock_end_of_DRAM() only for machines with more than nearly 4GiB of RAM and those will supposedly use HIGHMEM anyway. But this does not matter anyway because failures Mark reported happen because 32-bit arm uses high_memory before mem_init() and that what causes the hangs. Here's the fix I have, I'll send v2 shortly. diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index e492d58a0386..f02f872ea8a9 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -1250,6 +1250,8 @@ void __init adjust_lowmem_bounds(void) arm_lowmem_limit = lowmem_limit; + high_memory = __va(arm_lowmem_limit - 1) + 1; + if (!memblock_limit) memblock_limit = arm_lowmem_limit; diff --git a/arch/arm/mm/nommu.c b/arch/arm/mm/nommu.c index 65903ed5e80d..1a8f6914ee59 100644 --- a/arch/arm/mm/nommu.c +++ b/arch/arm/mm/nommu.c @@ -146,6 +146,7 @@ void __init adjust_lowmem_bounds(void) phys_addr_t end; adjust_lowmem_bounds_mpu(); end = memblock_end_of_DRAM(); + high_memory = __va(end - 1) + 1; memblock_set_current_limit(end); } diff --git a/mm/mm_init.c b/mm/mm_init.c index 545e11f1a3ba..0aef4bef93c4 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1765,14 +1765,20 @@ static bool arch_has_descending_max_zone_pfns(void) static void set_high_memory(void) { + unsigned long pfn = arch_zone_lowest_possible_pfn[ZONE_HIGHMEM]; phys_addr_t highmem = memblock_end_of_DRAM(); -#ifdef CONFIG_HIGHMEM - unsigned long pfn = arch_zone_lowest_possible_pfn[ZONE_HIGHMEM]; + /* + * Some architectures (e.g. ARM) set high_memory very early and + * use it in arch setup code. + * If an architecture already set high_memory don't overwrite it + */ + if (high_memory) + return; - if (arch_has_descending_max_zone_pfns() || highmem > PFN_PHYS(pfn)) + if (IS_ENABLED(CONFIG_HIGHMEM) && + (arch_has_descending_max_zone_pfns() || highmem > PFN_PHYS(pfn))) highmem = PFN_PHYS(pfn); -#endif high_memory = phys_to_virt(highmem - 1) + 1; } -- Sincerely yours, Mike.