From patchwork Fri Jun 14 13:30:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gowans, James" X-Patchwork-Id: 13698702 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 EF8D8C27C6E for ; Fri, 14 Jun 2024 13:31:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93DF26B013D; Fri, 14 Jun 2024 09:31:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 44F636B013F; Fri, 14 Jun 2024 09:31:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C14A36B013E; Fri, 14 Jun 2024 09:31:33 -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 A84A78D0001 for ; Fri, 14 Jun 2024 09:30:42 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2E67E1C0D47 for ; Fri, 14 Jun 2024 13:30:42 +0000 (UTC) X-FDA: 82229579124.01.98B43F4 Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) by imf12.hostedemail.com (Postfix) with ESMTP id 39D6E40022 for ; Fri, 14 Jun 2024 13:30:39 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=c5LBxYZf; spf=pass (imf12.hostedemail.com: domain of "prvs=888fef242=jgowans@amazon.com" designates 99.78.197.220 as permitted sender) smtp.mailfrom="prvs=888fef242=jgowans@amazon.com"; dmarc=pass (policy=quarantine) header.from=amazon.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718371838; 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:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=W6LtgifkW6+vXdOdWZYDsm/k1XVnlz90Nl+MiPv0cOs=; b=0LugDpm0fElgA8jtqi1q/DpWhBJO5Cbx1/wu2iL+7ZngjYiRHYsRzYDw1xdukRb6FNHDJz KRSn4Y5Q1JKDlyylPMgCyBv/Soj3ds+03/cevHF4z8jFrEvPNtJ51U6E7TOewJMnU1Dxfl RdUXTwVcwKSK8A3VUBZnCJ0ATk/bius= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=c5LBxYZf; spf=pass (imf12.hostedemail.com: domain of "prvs=888fef242=jgowans@amazon.com" designates 99.78.197.220 as permitted sender) smtp.mailfrom="prvs=888fef242=jgowans@amazon.com"; dmarc=pass (policy=quarantine) header.from=amazon.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718371838; a=rsa-sha256; cv=none; b=uGeNsoEMUDB1ouIhpZB46Nd/LTGIejnMYVlGsPebUhbaJ9Ubzf//pdulduAgMYc8OYF4no VuTchGi13A0acQ8dVem7MveSUVvsPc9+HwhjlWGn5HDlSGhJ37xl1UlR9LgIhgo+6jpLn/ 7sc+xM4xAqsu2bZbgJWf2edV5xbM6qM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1718371839; x=1749907839; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=W6LtgifkW6+vXdOdWZYDsm/k1XVnlz90Nl+MiPv0cOs=; b=c5LBxYZfP9LmbCrQFbT6WtRu5M1yr330OUOb3kiB3XUugLkEa29QfKCa lsHXzD/zKWMREbesh2L/138QEcAMd1ddp3yff7C8lMnlr4MqF5t6GYn9e d9/nQUS+EFdCEdRRzAFrwGuJyX/hWdnfFQGrkBxcPHw2Fi/9hSfEgicfd g=; X-IronPort-AV: E=Sophos;i="6.08,237,1712620800"; d="scan'208";a="96832771" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2024 13:30:36 +0000 Received: from EX19MTAEUB001.ant.amazon.com [10.0.43.254:56353] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.22.205:2525] with esmtp (Farcaster) id 2b5aa1d4-dad0-4f2f-93a7-f12dbffe2c77; Fri, 14 Jun 2024 13:30:35 +0000 (UTC) X-Farcaster-Flow-ID: 2b5aa1d4-dad0-4f2f-93a7-f12dbffe2c77 Received: from EX19D014EUC004.ant.amazon.com (10.252.51.182) by EX19MTAEUB001.ant.amazon.com (10.252.51.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 14 Jun 2024 13:30:35 +0000 Received: from u5d18b891348c5b.ant.amazon.com (10.1.213.23) by EX19D014EUC004.ant.amazon.com (10.252.51.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 14 Jun 2024 13:30:31 +0000 From: James Gowans To: Mike Rapoport , Andrew Morton CC: James Gowans , , , Alex Graf Subject: [PATCH] memblocks: Move late alloc warning down to phys alloc Date: Fri, 14 Jun 2024 15:30:16 +0200 Message-ID: <20240614133016.134150-1-jgowans@amazon.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.1.213.23] X-ClientProxiedBy: EX19D042UWA003.ant.amazon.com (10.13.139.44) To EX19D014EUC004.ant.amazon.com (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we3q0VKsbjdeBAq5NF6gmF3Hce9Op9WiRmG p8ZPld3X 2RyTs45/shtwlRKKxTdCPLqEc7wF32R24/ppQPuUZmUvJtMhigJ3KCoVxaga/CEHzVI8PZgLzz/J+iMkAb+7U4teGAmVUGLz/YQ4lERYRBxoYkoGPsfE+O1hGJXee5fHvEoa/UwBX1rbMwvJ4qT3/mhtwexRNHIqqauTH+KNKF+GgqWdGk43nmfZQ1bUxzL8Hy21VTESR/KM07Kb3m/AG35nIhJMnDJpew1WpEEq/Vl3EUUE2OtZVJqE5gh2EacqW5CCYAnWUm3gIvV2KUGc35MUnAYFOZwhe8KFes9cPV+ASLoLMvwGQuKgKptHOu1q60HWSMhqiGRrGs1/u5VJ8vk9ynYyF4Zp6h83AJlTSQ3T2DIE0VK420ausp8QWq3g8335HQiP4y6l2msK0h9q4L0HZO4mybKsdpqIpoP4N4BNjaUhVYfGufyalWaXx7+cIUeYrEd4H19nG8k/QF5bcDDVZ4QfvqZszgG5daCNbxZRQRGLxwv0Gd6Hm5uNd9OBJcK4nQRfwWavcXmTGT9ay06De5N8l8OzP5613z17pq3bUFkgtrNax/gUImpgSI26y0tGR+b2QZLXLBausabxVFH4TdyJs8jPimoXydgSj1d2sgRxM6B4tjLRzMpr3a0qgdz/+6eBs8ylFpmodo8wPGfBxDEe6Dwz+3b3xAKOT/cPww2KfGW8LQ5qfzg== 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: If a driver/subsystem tries to do an allocation after memblocks have been freed and the memory handed to the buddy allocator, it will not actually be legal to use that allocation - the buddy allocator owns the memory. This is handled by the memblocks function which does allocations and returns virtual addresses by printing a warning and doing a kmalloc instead. However, the physical allocation function does not to do this check - callers of the physical alloc function are unprotected against mis-use. Improve the error catching here by moving the check into the physical allocation function which is used by the virtual addr allocation function. Signed-off-by: James Gowans Cc: Mike Rapoport Cc: Andrew Morton Cc: Alex Graf --- mm/memblock.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index d09136e040d3..dd4f237dc1fc 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1457,6 +1457,17 @@ phys_addr_t __init memblock_alloc_range_nid(phys_addr_t size, align = SMP_CACHE_BYTES; } + /* + * Detect any accidental use of these APIs after slab is ready, as at + * this moment memblock may be deinitialized already and its + * internal data may be destroyed (after execution of memblock_free_all) + */ + if (WARN_ON_ONCE(slab_is_available())) { + void *vaddr = kzalloc_node(size, GFP_NOWAIT, nid); + + return vaddr ? virt_to_phys(vaddr) : 0; + } + again: found = memblock_find_in_range_node(size, align, start, end, nid, flags); @@ -1576,13 +1587,6 @@ static void * __init memblock_alloc_internal( { phys_addr_t alloc; - /* - * Detect any accidental use of these APIs after slab is ready, as at - * this moment memblock may be deinitialized already and its - * internal data may be destroyed (after execution of memblock_free_all) - */ - if (WARN_ON_ONCE(slab_is_available())) - return kzalloc_node(size, GFP_NOWAIT, nid); if (max_addr > memblock.current_limit) max_addr = memblock.current_limit;