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 DE310C54E65 for ; Tue, 20 May 2025 15:06:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08C276B0095; Tue, 20 May 2025 11:06:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 065A06B009A; Tue, 20 May 2025 11:06:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBD1D6B009B; Tue, 20 May 2025 11:06:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CC49B6B0095 for ; Tue, 20 May 2025 11:06:58 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 85BCA5A541 for ; Tue, 20 May 2025 15:06:58 +0000 (UTC) X-FDA: 83463613716.22.6831385 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf21.hostedemail.com (Postfix) with ESMTP id DB40B1C0017 for ; Tue, 20 May 2025 15:06:56 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hB+bdiw7; spf=pass (imf21.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 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=1747753616; 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=ecf1eitKSeSIebVwAh84KMJANEExym4QAX6QlVSzYyM=; b=54gBRlc0n7SuG9Erb5jQimSvPXHGAvVYm1qpPWcxRf7epT72MaCqW5otSVLyu4NXLojuMv g/dZluVd0is0TDSNjIWLDPXYiqO4EID3enVpFkqprCbzs82TB9Y65jEv/092cac8Ovs/kU f7m75tVXvo4t8LxJED5SHEtsJtAU57o= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hB+bdiw7; spf=pass (imf21.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 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=1747753616; a=rsa-sha256; cv=none; b=z/yiKaxIjXvav5M5ee4MhnNBoVGM+XxDCgCn+KJujoPezmf025PT2uirxtS6b9IpCvfDSd YXKROT5ix2GTCWuRe7AbTDg+NbGMZyEDqru8YcydwmH1UARNoms6iFdGiLQqMMMQddDJt2 6ivVfjipwu19B2DbkrfoP8XUU89JQtA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 40118A4EBA2; Tue, 20 May 2025 15:06:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAF81C4CEE9; Tue, 20 May 2025 15:06:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747753615; bh=5nGJFy6nrUZcxCfljXCPiovm3928lZBYOBaJ0nYBuCs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hB+bdiw7rCP7qDw3zQtwy4j4c+iRwFTXhAwiS0GR6EI0vt5TSEa/Ue9acRSsVDYHK 1QUyc4M92A7qAh3lKu9Wdq0ZngI9Rja7ZwHjKoDBpEZ+7AvyrCR2OZ1S1Oi86ITH/3 9iFBrQVJZcp5u1iAjw8HWXqgEdZxDorIpKZbxxZ5gOa3Yb4Ukn6oh71w+ii928ARhK DBVK1fXfE6kvvmFgf4fxORsrMyCFETmSDWLp8g8TZOHRvcsR5p7t51MruLrBmFuMZL OjBq1/S6DgxFwUGYU2jPhqJiA6EF+fp1num9ECQzvnkd+uIsNuowXLsuvbPgrQ6ljN 28GQznW2WhzaQ== Date: Tue, 20 May 2025 18:06:49 +0300 From: Mike Rapoport To: David Hildenbrand Cc: Oscar Salvador , Andrew Morton , Alexandre Ghiti , Pratyush Yadav , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] mm/cma: make detection of highmem_start more robust Message-ID: References: <20250519171805.1288393-1-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: DB40B1C0017 X-Rspamd-Server: rspam09 X-Stat-Signature: 9gycj81pt81qhi8qkh3mbuujkx48zm7d X-HE-Tag: 1747753616-127589 X-HE-Meta: U2FsdGVkX1/UFmWOiWIW3NwTcw/uIeJWxn0nikVuLXSj+/th5H0AQpCdKF13CHUR/CCwwZWYZvdeY9xAdLxv6lMtBXZYOamvxaW15qdSJMw89qhwkwdOcU4leLl1U3BSVsUj/DDhpfLFkrUuRNI/CCQ0gJJhRhn3LT1AGZbRFHVUxciCc89eeC8h6d7XB8vIb+b4ut+4Wevx/+2PT3tZNcgRUtjyrTCjC3mV8//HBKecdi4Hyh6v4P/MWZxFY6a99CAnQZnU0zpyCD149qXQmVNnPyrg5ZUDX7FT80NQz2eq9pgpSDAnJ0633F5ZIvylIJ+74f7pm3BJmALpdl7aS1ftbcuUb+WXEr3vY8oqM0whE8NzPPyiTYN+SdnJ4LY/B1y9vt5dpB59hpirsKIfYqCYErT8BBJqnBN3b4jHKIZZlbpfuqfKsQJqj6UJPz0L+9DL94VuAvvzT/tLN1doPPG9e0qY1ld5V5ZhxkxrL33ZZyDTs+t7XeesmwnwrZJPi98Ui7Ne+XSU8vrKhFxWKVxzVIIYOYeLHTIpxLYqlwr51KgdHh1/T53BQEmNKiVZrd22zTKV7SLEjqxEQAqyiHiM74gKg0PQxQjBkIUEaEH7f5uml/UlgD2V8zQIXKs6AyM2h7HE4G8Rqn0tRbGwi7xYZDENJGnxdJVQhUXCc/YnbAdYvCwN2GGVCiaC4WIhbmRjHDV1bXsRF6Tv38uDjTCTQkZZigRNc1c/1O6nc4JvW4PLnCn9O2k5WOGdOn8zehOrRK4nrKXLlSoxYx/7gykEuTdJcbfJ/lyrOEk5sMnnyxxqa1EnxIlSIgq7mSd5r+6AW5RVb9VJa1U7PgNNDF7IBKWkMko24IdZP3wLtfcoRhKJ3GDbuBEy+YfCYWR75UAAOuqz13C6IfSQP/ZSPqS81fd6iwUBIa/Fw/ICiK5LYu6dk2F6yGGms1HNCuZSvOcImcGayNQPTOb9BSU b9kjDaFq izTnvsL39zoAmx+KY9FvVPwPLAQrEyIdqc//7//95kA103WSCNPRfXp6+Uq0Wugma1gPUwk/iaScA+qmGykP932MzoLXFvsf3KfLmuCn0KjwtiU95BXZ010JWXguszVK+QDCfExwVSbFSCrNt373GChsYXXSiOHF+5Zu+ZqlJs/8NiyjdEfUogKO7LJppM+vIW/MisAQOq2PZ7atigOyy+eLy3t0+sGrKoQA9PFbgtjDebnmgnCRsX7OboNIlGuxnGuR4OCr0tUfGNBMo0XGGaerKJRbOO8t2rrfCxjJFrt8EkAFP8TjcFk0rHD11vYGvMSB+pF0E6VQF51gwNCFpsgvGmZVMYU++Vp5W/bg8gOZBFHQ9d+YOX3XnH4XlxsvOJuTe 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, May 20, 2025 at 11:14:28AM +0200, David Hildenbrand wrote: > On 20.05.25 10:30, Oscar Salvador wrote: > > On Mon, May 19, 2025 at 08:18:05PM +0300, Mike Rapoport wrote: > > > From: "Mike Rapoport (Microsoft)" > > > > > > Pratyush Yadav reports the following crash: > > > > > > ------------[ 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. > > > > > > The issue occurs because commit e120d1bc12da ("arch, mm: set high_memory in > > > free_area_init()") moved initialization of high_memory after the call to > > > dma_contiguous_reserve() -> __cma_declare_contiguous_nid() on several > > > architectures. > > > > > > In the case CONFIG_HIGHMEM is enabled, some architectures that actually > > > support HIGHMEM (arm, powerpc and x86) have initialization of high_memory > > > before a possible call to __cma_declare_contiguous_nid() and some > > > initialized high_memory late anyway (arc, csky, microblase, mips, sparc, > > > xtensa) even before the commit e120d1bc12da so they are fine with using > > > uninitialized value of high_memory. > > > > > > And in the case CONFIG_HIGHMEM is disabled high_memory essentially becomes > > > the first address after memory end, so instead of relying on high_memory to > > > calculate highmem_start use memblock_end_of_DRAM() and eliminate the > > > dependency of CMA area creation on high_memory in majority of > > > configurations. > > > > > > Reported-by: Pratyush Yadav > > > Tested-by: Alexandre Ghiti > > > Signed-off-by: Mike Rapoport (Microsoft) > > > > Reviewed-by: Oscar Salvador > > > > I will note though that it is a bit akward to have highmem involved here > > when we might not have CONFIG_HIGHMEM enabled. > > I get that for !CONFIG_HIGHMEM it is a no-op situation, but still I > > wonder whether we could abstract that from this function. Highmem is there for some time now (see f7426b983a6a ("mm: cma: adjust address limit to avoid hitting low/high memory boundary")) We might try abstracting it from that function but I'd prefer not doing it that late in the release cycle. > Same thought here. > > Can't we do some IS_ENABLED(CONFIG_HIGHMEM) magic or similar to not even use > that variable without CONFIG_HIGHMEM? You mean highmem_start or high_memory? high_memory is one of the ways to say "end of directly/linearly addressable memory" and some other places in the kernel (outside arch) still use it regardless of CONFIG_HIGHMEM. And I don't think we have another way to say where directly addressable memory ends, and this IMHO is something that should replace high_memory. > -- > Cheers, > > David / dhildenb > -- Sincerely yours, Mike.