Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp811296lqs; Fri, 14 Jun 2024 06:30:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWbHQkZHDn5WlgF3iW3qVt1FoYrNA6Z8X571MYUv5cK7vFdgU9dG1I86OyGSTj5a6SYBBq8Ayjve8lgZDYdAGgNelgsGJxUvVXL5LHiig== X-Google-Smtp-Source: AGHT+IFYVl5zOQ87Ch2dIAuqXa2T6L7F/rqo/Knbhhy+IHR7JbxoguhZEOkxXaRrBQvMHpX957gt X-Received: by 2002:a05:6808:1485:b0:3d2:314b:cd0f with SMTP id 5614622812f47-3d24e8bdb92mr3552424b6e.3.1718371855528; Fri, 14 Jun 2024 06:30:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718371855; cv=pass; d=google.com; s=arc-20160816; b=BPwCBwQ0ruCWfISp86aPMf0eBFuLk8NgrsPkeg/d+sxN8aDGDow1CKbcveEQitoeoO V+w45LxaVSkt4NtrWe3OdZH/E4pvLHVneGL/lRuwLubPAwO5ou7PcfN3dsVcng3IHJtg ljBmcwz/egI24fdtoSZEti90XC0hnwL+OC8UnWySaX5Za9ZwM36ps7FlqxbvjBfh1W9i h30gF/+1M/77LkdDYZLvJGIOXaxW8l+Wdx06r+GObB88LmcujPORTn0f8qFN7BdYhdoT TrzNwIfY8fGQQm365kOKbNMMxvjAt+VsKPYIoyBOPYIynvwG/9SOelwxZia7T8dlm0rR 8+Sw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=W6LtgifkW6+vXdOdWZYDsm/k1XVnlz90Nl+MiPv0cOs=; fh=d08vJrdM+xI3dPu1VGEVKUII+M66My/LtK73kQLAOM4=; b=QTB/BfEl9WUd1IEOlYyZQzZ5JKjqXYI/qqOKM2gMqKrOM1+RHCCz5lT2JamKVQTi6T lEottnO4WKGnHjOc+hh0Wi7/SubcY/jB+SdFVff4G3SlWWAX/NEQsq2Tp9e5TvttkvKt 7CpyRrMoglux5A86qdrINtLarPqRJ7u/0zShi+woKDD0fsPcYH6HLl5yleUoFhUsdpEZ kbWMEdKeHysaZkzEnS+XIULc+OUu77Ai6ogyskYVyE9zxAmi6VarAG79tIg1LG/r6xKw 0HLIDDbIwfhUKEtUO2El7FGp+/UJS7b0aNPxZ9UeB093Y6pWfN1RhPGduiv/wS4IO0Ek dXyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=PvWIGrqN; arc=pass (i=1 spf=pass spfdomain=amazon.com dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-214943-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214943-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 5614622812f47-3d24790582bsi1310806b6e.290.2024.06.14.06.30.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 06:30:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-214943-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=PvWIGrqN; arc=pass (i=1 spf=pass spfdomain=amazon.com dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-214943-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214943-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A7B5F28A339 for ; Fri, 14 Jun 2024 13:30:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 99D732107; Fri, 14 Jun 2024 13:30:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="PvWIGrqN" Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C36E817 for ; Fri, 14 Jun 2024 13:30:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.220 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718371839; cv=none; b=rjf+ycFy0+cgScmESCxroEtUWrvkJ1Scr15cUZ+Za5ZH9xrkku7eQU9Zs/RfG+2IfU493PYiiUhM7tBoO/cZRTxPMMQ84RWaJGGjQjQq5eWBD8a2YVPXyQ1oJt7KHQET6Kbk7GlxczEjOPKE0mdxTdZdK2h7EEEktX/5X6Cii9E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718371839; c=relaxed/simple; bh=IrUqQGQwMsJxdGGWpIHTN9D0+7CLh6RJMSAS0N42slk=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=WVWrUkUfj+IIp0rSVZOA5JBQz2dfMa+Rn+q5GqfGeV6ADKg7LNgsVVau869wm2Ax7cDUVRCa2Pd820dH/QVX37MGy+xuYIoADm0UKqy/wg9GDTPs9yYjnnfpCM42zqVrb9Yz22AqYq01kCUjLJUcJ2Hx55mtClup3yQDpb5yXJ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=PvWIGrqN; arc=none smtp.client-ip=99.78.197.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1718371838; x=1749907838; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=W6LtgifkW6+vXdOdWZYDsm/k1XVnlz90Nl+MiPv0cOs=; b=PvWIGrqNnR5FPRUg1T8sBjw3tKdM+3pALM1y1DqkOx3XcvFpJICS2Akj 1oqIuVOZQOp0unhDCxmI7aJq1TclwpIBGkflgNw9ylTUn/yC0Qqu2uC4y DwXrGVJaBPqhdccVwrl9KP5fEuY2D/5jR/Ztw8PY1jwH6hZiC2ASQAhuT 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D042UWA003.ant.amazon.com (10.13.139.44) To EX19D014EUC004.ant.amazon.com (10.252.51.182) 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; -- 2.34.1