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 E0A04C5AE59 for ; Thu, 5 Jun 2025 06:47:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75C4F8D0053; Thu, 5 Jun 2025 02:47:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 733B28D0007; Thu, 5 Jun 2025 02:47:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66FF88D0053; Thu, 5 Jun 2025 02:47:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 495668D0007 for ; Thu, 5 Jun 2025 02:47:58 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5A4791D7D1F for ; Thu, 5 Jun 2025 06:47:57 +0000 (UTC) X-FDA: 83520416994.18.6D43133 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 9B95840009 for ; Thu, 5 Jun 2025 06:47:55 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P3yKLe9f; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of mingo@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=mingo@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749106075; 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=d7MNY3BslcX6QPM/fLQYNW+PEgrUyp0NPzf9zYGHksI=; b=QsaNnsFbOLINKNIVsNw6tP45oV6UBZm1miahNbopKK6FUSU3pPC/JFF8j9xKclXXwkeSAq DesXqoDzhgKBRSHkzFGKeInYk6h4MoN/KXs4uO6S3H20TaW7uPXylSGl7+fZMWO8Ro1Lk9 yIvCmSuTbmVLe3Gso6nV99XaseSqdLA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=P3yKLe9f; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of mingo@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=mingo@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749106075; a=rsa-sha256; cv=none; b=FBZfaidm4iqz7Nt0jOxa7eH0SfU0YagYqHvj3Tk7IE13gfo5RRrd0HmSVQ+Cj0UEeisxrg snfm6xJ/yzvW/TaIGgZU6N1FRa+2qzjhCDpPj/XXyFaULEwN6n2/Q5XfCfEhcp/8GepG2e NILgvP1csxdRtfo6xzPQDT89ZcbNXcM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AEAC15C4A74; Thu, 5 Jun 2025 06:45:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96FC8C4CEE7; Thu, 5 Jun 2025 06:47:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749106074; bh=LphIixm2U6bTC8EwIvMeBprro1C4ApSqd9LbcXniXGg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=P3yKLe9f2CWW02MQUZgkLMtuVa//3TWcD/mGeKP+RB9o0wOjfYB4ujOXX792t/rJJ skpC54U7LcXjRrBznKnaDnF3luNPRwmLAqrm8ohnBPltBtU0a+jTZ+qcxInVGryRR/ Vr5GA8r953s/M78NPihLhyhVeoLD2dwb3/B4h7yGB5l9BBGjlH09oAnwasNc6wo7+q HnD/hG8Ui0pMBF+sG9ji6DGcGhOwqCVavywqf1ywRibRzK8KSIllwQjVdQACd9OoKk HCQPRebtcVC7q/cZYWkFwenzyUb4qEpF7zZYvEAc7Xg5zSOSCziyCV80Ovl5mw5ChP BEPANb+Eq75Mw== Date: Thu, 5 Jun 2025 08:47:47 +0200 From: Ingo Molnar To: Em Sharnoff Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-mm@kvack.org, Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "Edgecombe, Rick P" , Oleg Vasilev , Arthur Petukhovsky , Stefan Radig , Misha Sakhnov Subject: Re: [PATCH] x86/mm: Handle alloc failure in phys_*_init() Message-ID: References: <9f4c0972-a123-4cc3-89f2-ed3490371e65@neon.tech> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9B95840009 X-Stat-Signature: 5ih5c1t3iqgrs9c4ithixq3sx69pypnc X-Rspam-User: X-HE-Tag: 1749106075-272127 X-HE-Meta: U2FsdGVkX18wZDTLI9C0FCsISEa9x+FSWEnONhrLeU0udUU5yAoXeld2S6yz2+RQ7+MevhU654ryiDrVAxj9x1JAmgRl5aovngo1/2lnhEOG1QuzINV/uK4QHAUODSDALQK6czUU97GvxTzHHackq6fDmyD2JmHkP4VpHV3MVROSAaSl3j1WEjRVzHx0XvND2X64mN1gqP1rpzvL45R+pmjFvGYJS7vFyDWcGlu+5qT0ZCzPgGlLZGZiFaGC7GZJ2cejzVYIjtXlQ6xm/LF87UkzCKPeSFyA7kQImcQ7AHw05DBkMvkHWxNzitzpATfp1qsFTCN+LFeA2LZpkLqjEdoQIhE+VLxYz3Xn+68xrHwOED53hE8LnS5zGZL/WZoyXqFk6qcjcHOHZXL8anNUNkg5MPQvYPJ5jQu4086AUy5o3dcfleWASQNyCwKIDPuYatiDe4OWvUxNP09nOmVU2FQBjBOeS2imABxaxUCS44Dda9PsjqC19nXFWlSoHBQrj6SccwAz365wcXd6+KdRLjbwKM2CiyoCXZNsr63pN0vFmsJKoaVYopEcB1UmNmsbKvnXjxMFU6SR0ES7LzoOLEjysbwBja6leO1uw4wNdgl7oFK3sw4YhJ/PYQBJmXip8umiSQxD8EaE91svRZm0BG3COJU9RAaVg3pH9TvW73IfQhpRSehDSxPt+RwnpRfBqW+p85GANWye59w65XbtJPq/ISH/TBoYrscuYezUs9F/yhsHRKwL2+Le7mVUhOK/hto7sWn1Bt8/t2CgRuFZUAR8nVddPRD5jU1WgYkBY70G83F04E48sbcXvcIg5JlAPFhR7yFtBrJMRwuJJ+UYsZSg3GxjxRyQMbU0cpvExJo2KTDJbQunDNR2CG6xgPdEJbDhDnbsljpCiNFH/KF4AgoBElDbs3EOzeMCon9zNv/nAJvB5ZgBh28vi80uQCs2pLXq3SakD+uZ1np/nCm 7FXLlwfT XqlGiPcxl4EXAt7X5JKLkhFj3k3eDlbcnT8aBT86WsJEk5bkYxi4kjnFuSwFjnF+lmvyJbIzTwAj0U74n2OWVRXyDLVLmY6EI/TEiohkO+wQ8tArA5d6k/GyAcFO8/q2DSG8oqyRiryTtIBSCbx3JdptpwbC6CQ7hd51y4avVSQ7/8ILGpVk1pj/0fBt/D+OkfyZ7xbn5sD61SkKhV2e+gNJoc4ZxyjwLf+XCmvPm7me1E0ZT3gPwdjiIA2UnSfCyubvH2GkZ3TJXaXUoNmgCMYgf/FSS2KyLKkCt 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: * Ingo Molnar wrote: > > * Em Sharnoff wrote: > > > tl;dr: > > > > * When setting up page table mappings for physical addresses after boot, > > alloc_low_page() uses GFP_ATOMIC, which is allowed to fail. > > * This isn't currently handled, and results in a null pointer > > dereference when it occurs. > > * This allocation failure can happen during memory hotplug. > > > > To handle failure, change phys_pud_init() and similar functions to > > return zero if allocation failed (either directly or transitively), and > > convert that to -ENOMEM in arch_add_memory(). > > > + /* > > + * Bail only after updating pgd/p4d to keep progress from p4d across retries. > > + */ > > + if (!paddr_last) > > + return 0; > > + > > pgd_changed = true; > > > - init_memory_mapping(start, start + size, params->pgprot); > > + if (!init_memory_mapping(start, start + size, params->pgprot)) > > + return -ENOMEM; > > I agree that it makes total sense to fix all this (especially since you > are actively triggering it), but have you tried also changing it away > from GFP_ATOMIC? There's no real reason why it should be GFP_ATOMIC > AFAICS, other than some historic inertia that nobody bothered to fix. > > Plus, could you please change the return flow from this zero > special-case over to something like ERR_PTR(-ENOMEM) and IS_ERR()? > > *Technically* zero is a valid physical address, although we > intentionally never use it in the kernel AFAIK and wouldn't ever put a > page table there either. ERR_PTR()/IS_ERR() is much easier on the eyes > than the zero special-case. Small correction: since this is a PTE pointer, this is a kernel virtual address, which can never be zero - only physical addresses can be zero (but even they aren't in practice.). My main point wrt. using ERR_PTR()/IS_ERR() instead of 0 remains. Thanks, Ingo