From patchwork Fri Jan 3 11:01:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weikang Guo X-Patchwork-Id: 13925486 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 B9334E77188 for ; Fri, 3 Jan 2025 11:02:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 484D86B0082; Fri, 3 Jan 2025 06:02:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 435586B0083; Fri, 3 Jan 2025 06:02:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FD7C6B0085; Fri, 3 Jan 2025 06:02:02 -0500 (EST) 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 0FFAE6B0082 for ; Fri, 3 Jan 2025 06:02:02 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9027EA071F for ; Fri, 3 Jan 2025 11:02:01 +0000 (UTC) X-FDA: 82965849834.11.4D165B9 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf05.hostedemail.com (Postfix) with ESMTP id E1A6D10000A for ; Fri, 3 Jan 2025 11:00:20 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SArUyuD9; spf=pass (imf05.hostedemail.com: domain of guoweikang.kernel@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=guoweikang.kernel@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735902095; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=oHM0PXsr7aSXBTLwpKbXE1u0I3u/fX1OBGk0fCX+rE4=; b=2Xq8EvlvE1jk25gMdlvvstwx8ntd2bnaOKbybayuma9eQmxumVXF4IxZ+a5GiEvx5YJsjA T2U0S7/EVmh/jgsu6uCgckUB6eMmThJ0VBnKG6u5aRzZl2Cmbyj5+zUP2sd9qpN2USG+Lu wJpq7H3JwtGJbWmER1kjwjZfZA4CFWQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735902095; a=rsa-sha256; cv=none; b=MO2GqIrxpmRJ9ftelek18ks3duN5TP6tSR5pgxQPsgRd3aAVXg8VtuG5Np6LB6f0hLNlBw ndRTJgufnUs79RmFKao2vmP8sk1ztz2ZRYOOkE0qKEBxhJCtVO6A0hIiqBAfW8DvzLPV4d 94mFQdmmGGLmIhTGVEEYEJLe++vAyHA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SArUyuD9; spf=pass (imf05.hostedemail.com: domain of guoweikang.kernel@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=guoweikang.kernel@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-216395e151bso122496665ad.0 for ; Fri, 03 Jan 2025 03:01:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735902118; x=1736506918; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=oHM0PXsr7aSXBTLwpKbXE1u0I3u/fX1OBGk0fCX+rE4=; b=SArUyuD9pOJl4rNkeVfjVsuacM9LHG9NRhtZaYM98HUgn++u5mdeokeyYUFThnyUEN KZO1ilnI/aaC0Pp4BS7WUQv5LB5g1Cs4k7Zr46SEVTn19zesJJicTLiPK2QdqwDOwHgx 470dr8CAHi9MHKb/wxgKiUmxZS7AA614sq0J0iOFv3HE8G4wW5gEv/w8ekMmr2F85TXx VqbwATLhkyJzEMlcM02FwPK2UvuFeFgQ1Q7PI9D7mqLfJxWefXp8Rvaz6r8M8RCUVZr9 HRqMORB/+VZNg3GNAav3mP0Qooy4OWhGkYRPDCzzR8Zj72XZiZmQmQHWzmL/BSUdhO8p tWxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735902118; x=1736506918; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oHM0PXsr7aSXBTLwpKbXE1u0I3u/fX1OBGk0fCX+rE4=; b=ma6L7LhO1rGWUTccIww3tEovZOfuhB1jGgdxySanysTTWicBgqUOTP0KGFuuIKZYc1 iPiVL+7P6MRjpNkYEIHBJiDLde7jAzmPbajjUOmdQDHdY/V+Dom1FTxAlCx4JxhvqvGC eVWQ8hLufzqDgg1iTM4cG9QTTGRvV2IU0S+tzYcPs/peCqEyNEdJC1mMPNh9jqnKxSbu eClp8jVJ9RMyGHPzvXdv5cO4oEwS75NWQptRVHnYeEx7jqKV9xP9IB/LHwHW2RVA7zuR /aJOBvqHo1iUQ4EVzlhuULwfroc5+ermn49+bzmvCOfJED8eSjxNpbW6+fHd5KooO/yZ +nlQ== X-Gm-Message-State: AOJu0Ywiik0ciog6JMRe5xl3j3C6mhvuMwnLGuCLe4CAiIPjJ2VCyhxP fWnFHxqd1WOeLOkN4tCeNUjiOQmiu0bCxPe9N6RIUQ7uiAeL9ftc X-Gm-Gg: ASbGncu4e0uex7vbtUVBEUTsTUtWcyhSyogO5/GQbx29qpoLgYOmeARRJhaWGMTuDik x0C1lUbxsCU1QlKJHoMN/kw9E6t0q5+pb68/MWsXfnulcGMnNwyZ9KTB/T8KbvW2OjJ1hm71m/1 JRPCBKEwyDe4R0TGjsGcd9pWcAVKBFOa4Zr/dF8GKSuYFt0hvMy4ltH2kvK8WKFWl4ThXWek2Pz 5CYDvCPaETF1+E1S2w6KSsul+QpYOMM/wn6AZPL1dWJmmyLYTpyy9VLDC0cH5UR1LIQnmmSbgIj VknE X-Google-Smtp-Source: AGHT+IGqoWUXHzIoQUPmvt712Je7EdKpTNDNscgW7lFRcAVslooqJ1ILT6Iyvlp/OUKkMTPJjwT1Cw== X-Received: by 2002:a17:902:da8e:b0:216:6a4a:9a47 with SMTP id d9443c01a7336-219da7effd4mr821552405ad.21.1735902118412; Fri, 03 Jan 2025 03:01:58 -0800 (PST) Received: from localhost.localdomain ([36.110.106.149]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f731dsm237025485ad.200.2025.01.03.03.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2025 03:01:58 -0800 (PST) From: Guo Weikang To: Mike Rapoport , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Guo Weikang Subject: [PATCH v2] mm/memmap: Prevent double scanning of memmap by kmemleak Date: Fri, 3 Jan 2025 19:01:50 +0800 Message-Id: <20250103110150.1352226-1-guoweikang.kernel@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: E1A6D10000A X-Stat-Signature: xn7tmohx47j6kayep8f9fwjnx9xuh91a X-Rspam-User: X-HE-Tag: 1735902020-474203 X-HE-Meta: U2FsdGVkX198hew1BJtibLRSTPVejwn9kT5o87EhDGcujX02Ve86ogC+pNrbvI3eEVPRXk1cBmT3qaFd2IlulaO3UXKRGp0eyydL+Nm/4t8KGKZ6svcnvD7H9YwH6FmDwcO6G8mAJE9VOCgJmeqeeC5uDLe9e6lTUqwcnd4ywzRAnkpOYA/G9MojQVQwbztw+JCaGegt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MQ1r+naG/hVDlZhhZX9yCRh8wwxJqsUJ67gczDF0EE7462wPsy9Fuio0n5nflJXNBlcmGHLuddYl/7IrQ6XMO08h29SVfKxPK4H3HR8ZFEAJVdG3d84IMUWYBZmrGonbrg/HCaHNOYqEnA7zvh9DkFdQ8HslwW73g4Na4XoBa9UiSrW+NUrmp346SOXmzCS/G0MkQLHuylaQ= 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: kmemleak explicitly scans the mem_map through the valid struct page objects. However, memmap_alloc() was also adding this memory to the gray object list, causing it to be scanned twice. Removes memmap_alloc() from the scan list and adds a comment to clarify the behavior. Link: https://lore.kernel.org/lkml/CAOm6qn=FVeTpH54wGDFMHuCOeYtvoTx30ktnv9-w3Nh8RMofEA@mail.gmail.com/ Signed-off-by: Guo Weikang Reviewed-by: Catalin Marinas --- v1 -> v2: Fix CI: Recover __earlyonly_bootmem_alloc that is marked with __ref to prevent init section mismatch WARNING. Links: https://lore.kernel.org/oe-kbuild-all/202501021601.jub4p3EM-lkp@intel.com/ --- include/linux/memblock.h | 4 ++++ mm/mm_init.c | 8 ++++++-- mm/sparse-vmemmap.c | 5 ++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index dee628350cd1..e79eb6ac516f 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -378,6 +378,10 @@ static inline int memblock_get_region_node(const struct memblock_region *r) /* Flags for memblock allocation APIs */ #define MEMBLOCK_ALLOC_ANYWHERE (~(phys_addr_t)0) #define MEMBLOCK_ALLOC_ACCESSIBLE 0 +/* + * MEMBLOCK_ALLOC_NOLEAKTRACE avoids kmemleak tracing. It implies + * MEMBLOCK_ALLOC_ACCESSIBLE + */ #define MEMBLOCK_ALLOC_NOLEAKTRACE 1 /* We are using top down, so it is safe to use 0 here */ diff --git a/mm/mm_init.c b/mm/mm_init.c index 24b68b425afb..71b58f5f2492 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1580,6 +1580,10 @@ static void __init free_area_init_core(struct pglist_data *pgdat) } } +/* + * Kmemleak will explicitly scan mem_map by traversing all valid `struct *page`, + * so memblock does not need to be added to the scan list. + */ void __init *memmap_alloc(phys_addr_t size, phys_addr_t align, phys_addr_t min_addr, int nid, bool exact_nid) { @@ -1587,11 +1591,11 @@ void __init *memmap_alloc(phys_addr_t size, phys_addr_t align, if (exact_nid) ptr = memblock_alloc_exact_nid_raw(size, align, min_addr, - MEMBLOCK_ALLOC_ACCESSIBLE, + MEMBLOCK_ALLOC_NOLEAKTRACE, nid); else ptr = memblock_alloc_try_nid_raw(size, align, min_addr, - MEMBLOCK_ALLOC_ACCESSIBLE, + MEMBLOCK_ALLOC_NOLEAKTRACE, nid); if (ptr && size > 0) diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index cec67c5f37d8..903a5422907b 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -27,7 +27,7 @@ #include #include #include - +#include "internal.h" #include #include @@ -42,8 +42,7 @@ static void * __ref __earlyonly_bootmem_alloc(int node, unsigned long align, unsigned long goal) { - return memblock_alloc_try_nid_raw(size, align, goal, - MEMBLOCK_ALLOC_ACCESSIBLE, node); + return memmap_alloc(size, align, goal, node, false); } void * __meminit vmemmap_alloc_block(unsigned long size, int node)