Message ID | 20230810074704.2042664-3-xiaolei.wang@windriver.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp280433vqi; Thu, 10 Aug 2023 02:00:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExJM3VP/UxYnWRXlzrrMDKV6XpVDY2/g+Xh2GyJSMP7MLMhU/aXxPfqI49iN6Csx9PJfpc X-Received: by 2002:a17:902:690c:b0:1b8:4baa:52ff with SMTP id j12-20020a170902690c00b001b84baa52ffmr1596389plk.47.1691658008333; Thu, 10 Aug 2023 02:00:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1691658008; cv=pass; d=google.com; s=arc-20160816; b=HeCVI0ZKHX8C6EE2b6+x24pqcwyfXntEoLs7IGUixmkoPfOYX4FCdwWIwmjIEAULQ8 Jen0Ui2nc6sjGrFJRdCWiU0dT4UUVIqXznBNADij7AHbt6D0CuzzjfwCEyXo4hWVTGTZ 5Qpr9buqFDgrWhZ4yR4lG5QTu/JgzjFC6GbJHghM7qZAztOOVeCHHUKa8Uv1fYV1hkvU zvoq2qmW3EVbCgNy4XSJr6zUJxunzYLAR3ACT/VnriWLaHA115b0zmrA2FbbGmFNyV6c fmPk5HUDFroZiYCfSvwr8BboSr3U8nlMkeyDVqA9H/YzgEWw0Q40mhI6uoQCCV6smN3X T22A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1AKwDMEuXmBcYBNJs59QytxQu62GZx7vOP8eohKBmGc=; fh=glBGht3B7KMhoGavPouAoC22VMdqX5IG52ihPt7JcDA=; b=ONHI+9cluJA0gEv7ozXVDpGj5Ut2kqZ6QwYumSRB0dMDG7DW0f2Sl5gCcDmfUgCE8h nf9ihFW9u7akj98ozT+tUuUvmygtmFRH8Ak1x4vQuDijnJ3vESt8hlxr92HHMMwBlmKj yLPdnzSrTDhbV5HkNxe6GnvuJ5AKblQ1TvY8ya6EHF2SH7JH08gFk2ZFgtDGa21KwwUh jMtEpXZLNSgnHENDpgy+jCan7LoNDKAvqZqMQgNOM7NnPHRe70dE0KtT59CG25PrrB9m tYProz0oyOrbBnF+Grby8AbkhssO9Q23dRA//bpVg5u54nM7mSWkvyDId2S4BbkwTDfa 39jg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@windriver.com header.s=PPS06212021 header.b=ffV9KOlw; arc=pass (i=1 spf=pass spfdomain=windriver.com dkim=pass dkdomain=windriver.com dmarc=pass fromdomain=windriver.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=windriver.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id li11-20020a170903294b00b001bda93595d9si305814plb.604.2023.08.10.01.59.54; Thu, 10 Aug 2023 02:00:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@windriver.com header.s=PPS06212021 header.b=ffV9KOlw; arc=pass (i=1 spf=pass spfdomain=windriver.com dkim=pass dkdomain=windriver.com dmarc=pass fromdomain=windriver.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=windriver.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233219AbjHJHrz (ORCPT <rfc822;m15293943392@gmail.com> + 99 others); Thu, 10 Aug 2023 03:47:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230030AbjHJHrx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 10 Aug 2023 03:47:53 -0400 Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E70D3211C for <linux-kernel@vger.kernel.org>; Thu, 10 Aug 2023 00:47:51 -0700 (PDT) Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 37A6pGa7011895; Thu, 10 Aug 2023 07:47:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= PPS06212021; bh=1AKwDMEuXmBcYBNJs59QytxQu62GZx7vOP8eohKBmGc=; b= ffV9KOlwjVgj2z3VEReeLMFXft/UuWLA1I/d5ijLQjxN+qVtHW8S2wScqu4c7AT5 IWwG67dPeuhkncmhBKB5EwwDpYzZMA+7dtkx6f92HlS1X5epxmSgoBI5Dq3K+87Q 65zG9ZpUSt+q1RgJing+RxpJK/V8y69fJNawzXwqPqkcXh8SchGBFcroPYaURV+S CkfTl3J3GY42awUeYarbDNvvHt/SqYT10nk8JxpYrfd9duLD2xKS5Ep+nxE5w/IW 5+D7K2kUSMZsd0J5eyn/MKCB0wozdHHHi1Xjb8pgZ1pqP2bW/3Ah14vFBXneRJUm LUysNxyTIMpq0zUfbKIUsA== Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2041.outbound.protection.outlook.com [104.47.73.41]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 3schfmgf4f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Aug 2023 07:47:30 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MnJtUhncQcgHNeEXd0YsDgL0k7SA6LfHEPkii/K4RDF2G0x9/q5PIBk+0nuJH/v5GXrmDhGsqlOguOiS0b7yQk30B3UkqGVrS1PwENu6c88uEnxVuWfT9BeaAZM4dIQ7FJOStky/3ccMtTvjfho3EwfJuMM2N/OFBklIrl7ZvunjBPWvZIeUvlKnJzOqgVYgbUKBwZCnC4v4JY1eU7Gdvc1MWmzXXCOsUmn08HbKeN/VEP9xgqTO8G6aZvgKJWY+/Rza3K3o1XmRFl2IttNpHrkJX/g+js3hCVcDrXkvI/m0AM5JJwK1+dyCdcp3nw5THocZa6sERleZf0bGtjR7BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1AKwDMEuXmBcYBNJs59QytxQu62GZx7vOP8eohKBmGc=; b=nUyqEj0jY7EEY3NwiP79wXvfWBrJwcCm6ifOA1S4I18XptD9xBLPYyYsN8qr766dL2wGgOO4QH+23bQgO07vE70QngWNuQl3NlBtByQ5NvTkH+EmocFOYPEr7S6773uuouYnWv6J7uOJIOPkl99cxMWbw++YKX+b3kw5VQoCTpKjDBIVc8xq7I1XCTv6C4ACBsZ/emwW0EJhjDoZSpzly3tSvQv1MOjTUXl/AotVDCuDyn5MONHObnsaLzpVoTv8FMAGiEBElsS51DQU0SJFR3g08jzmQjhxUYt3qLnVu6VSCR5gwJkCqRY+bk2JS3Ttg2/8pUuJWFM6tjrpmWfNhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from SJ0PR11MB5769.namprd11.prod.outlook.com (2603:10b6:a03:420::8) by PH7PR11MB7497.namprd11.prod.outlook.com (2603:10b6:510:270::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Thu, 10 Aug 2023 07:47:29 +0000 Received: from SJ0PR11MB5769.namprd11.prod.outlook.com ([fe80::1b5d:f77d:a3c1:ce4c]) by SJ0PR11MB5769.namprd11.prod.outlook.com ([fe80::1b5d:f77d:a3c1:ce4c%4]) with mapi id 15.20.6652.026; Thu, 10 Aug 2023 07:47:29 +0000 From: Xiaolei Wang <xiaolei.wang@windriver.com> To: catalin.marinas@arm.com, akpm@linux-foundation.org, glider@google.com, andreyknvl@gmail.com, vbabka@suse.cz, zhaoyang.huang@unisoc.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm/kmemleak: No need to check kmemleak_initialized in set_track_prepare() Date: Thu, 10 Aug 2023 15:47:04 +0800 Message-Id: <20230810074704.2042664-3-xiaolei.wang@windriver.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230810074704.2042664-1-xiaolei.wang@windriver.com> References: <20230810074704.2042664-1-xiaolei.wang@windriver.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI2PR02CA0006.apcprd02.prod.outlook.com (2603:1096:4:194::8) To SJ0PR11MB5769.namprd11.prod.outlook.com (2603:10b6:a03:420::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR11MB5769:EE_|PH7PR11MB7497:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f03e3fe-dcfb-45f0-ca62-08db99760bd8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6UH5Ho/H5vbMwneRR/W/ovImbywRmfvn4PFNAhZP/DPR6q+QBKWPaZqZGfZuRm0hLzG3AFGKm95ySSH8hv6LuOsTWXZql4ub4vzZZ35aCtivvSdLMvj7v6XETkjj2W30N1zb0nq4N/Qfm8OPVxg960/+RSKVbGpl19zpV9vT5kmPmntuehbol2AXYVIBfEug7wC/Gfe48Sw+h/aZec1by6eru4AvIR0TdnkSR3uYn6GYBywaRSt374OmgbsgWCNt9dRe1YrlFNABhXKdTC5st/0/D9KWes6aYnv6PXfKu2KfUdGXND/3M2SS7ZOFVtm+w3xdmwHMsKY7rHRlQh9DGh/C6ErW2FebHkJqEA32oyoH0wvLXYXVCeDS3vUW7UdU743HEug0/Btxot5VGCH7JCziwlRAtP5jU774A+zNuiWs15nShFq5yFP7ygiB7l5FMRLB127+nmhVpU0NV8UtiAaD4zCqV8Fun0W7TG3G7zdk1Lu//k84ZNO3dfaYxgFHdY7VUYAPBrXmRkcnU1uJgePtC44SiGW7Ave/3Qn24gstC3NtGP+Q9YmeSKqw4WGLro+Wbkzr14hozUW0f92IdzeCI3KX+302V+wLl68yTKHPuZnLe6oHm/jBlZph4xq10rda40+ILonTe98E6bVDQw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR11MB5769.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(136003)(376002)(366004)(396003)(39850400004)(186006)(1800799006)(451199021)(2616005)(316002)(86362001)(478600001)(6666004)(6506007)(26005)(1076003)(36756003)(5660300002)(8936002)(8676002)(44832011)(6486002)(41300700001)(6512007)(52116002)(4326008)(2906002)(38350700002)(38100700002)(83380400001)(66476007)(66556008)(66946007)(505234007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: clKAeswkRpOgZG09A2/0hYWRDPzptEa9kK279DXCfG8ftj1aIkKGwCbHTJpARc9zDI3K0wuI+t9sMerAb7ZY9dOhXtQfStBpnNMibkYseR3kxTHgfDJasZqc+AAy0VM7yzOZFosLZeZMlOz0VSUFkubtWW/CuIqvask2bj+Y1V3ITAUqLm82v4Eomxet5l0FpW0hXbIje5BWqFU6DflgKXrSnuucZ0fNkSlsyeNmbcq4nXUASfXXGveJEN3DFTbJ2VIr2+caXexIo84tHrS+2SbbOuxkIRvRLktSI0iOYnakZBUWhSV9KYrfx/izrrL97K6jYzhRL6RugzcTxZpyS22IF3jof8cNRbR71Kez+Y4BJNT068IRhlFKhzhgeKihpA8d2YHb4wiv6rHvKQwW2YNd+s1YJSIbxzQORs41vYQg4DS71E/aWJ74eppQY8e73B7TAtkU9Obr5eDkrpirhddp+M2izYTqWTbyrgb74b4JFfDMUfn7TxPh7kUewo9NdDeZIJvX7XT3CsLxVZ6nGMF+NTETrsRW9ZnXgVvaB0DLf6AwZSkv3mzV9f+YAZmFlSYWNATWSOrPTOx1KV/ihCsmVV3PzY3yCCoQ85MYQSQ/dtwJnSh3G/YsDJDW321q0btHP6KgWB+X/3vEtpxaVBvPeduMT4Xze0Ju7USvIGI+d94y7cvLGeELhcMs05cr6Go+ZIU04JINv+8i0cc8EOOHPuC/hCJPrdZD5i90i+RT+wmsHcC5RjL3qNZ4wU2t50N33uRfwdfPgBgjHBXkf3mc9wuIt/CSRbOUWCwCkZ+faIBD0kZobpK1AbTlRrDgbAV+2spNKlvjKRwxb8AlXPSN7H1RzBh+GMwtlxHPspK5BtY6+VFsytiDamM1UO5Jby5W5NkxHUUnVcRoF98QALFptXHIVtBAsh1bWWKMKi+a27EPFegrpSSmE4/OStJRM4iB+MMwFLb1qCmULsG6wYF2KBxPUzQ6Y4g1pf9ZOjoKR61sPmSw9NY8VRtVlZv9HFRWYcH7apcIzBjwGZebzCzYBJLf9xLBEWns0vqM86KJ7I5h3oqb2rgfl3gI3+wjma3fYfrr3PcpfwNczRiawbDnTFf2w8XGVLUr2VwmvWGgjO78HqmGt5DfqjLyNreKN7j0Uo78xf6uy8/2c0PSXO7objYIFBNFSRVhHzIB4acLKyHZDeRRGxsU/E2aHIpHR+Su9nVRXEnDU9zvcPZH3gMp5FBO5J2B0cs9G2MCSeBFYvYJ4UeulLOFtD8DGpyVmB+1lX71itq6QOqp+iUmyneTL8Sc8KtEH/pTp0onPhlmhq+GIHNlwyjkbmI/L7Qinseb8VrK5xwyEsaJZvaRxJ+uS6mJGu8eTxDzawUuwAc3vRiK9P086MDIKVrvi7wkXXvHRNxLHSGYIuPmxzvLirOMu/hESCK8B0zQOfe93EkXFM51TbtJHHAbHxdb87na+EHtttBj9QQiof/QWVUrEy/prTW9piNrsecs92GfD5KfB5EUv4oZJYuSgBtmMMrF6UlKP8AL6HAOBqnoCiLoykw5PR/+YznRyqszYY9pbTxObnrpH1Bs3M5Edvyj9cIf/UlXOIHTAKS4Kv6kd3RjCg== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1f03e3fe-dcfb-45f0-ca62-08db99760bd8 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR11MB5769.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2023 07:47:28.9289 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +6+3MACJ+vZiYVgDlY20LeF2bT7YK7hRRtcsXHjWPNXGBqT/ZHELxSJbboyCayMiVoeMaICrKEJ9HAWsGguiAeeUlUswhT63bPq+z5AEVy8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB7497 X-Proofpoint-GUID: Yc2pXsIeBXjHWopBqFppm6UGCUQoORty X-Proofpoint-ORIG-GUID: Yc2pXsIeBXjHWopBqFppm6UGCUQoORty X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-10_07,2023-08-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 mlxscore=0 malwarescore=0 bulkscore=0 mlxlogscore=674 clxscore=1015 phishscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2306200000 definitions=main-2308100064 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773831987788696022 X-GMAIL-MSGID: 1773831987788696022 |
Series |
Bail out in __stack_depot_save() if the stack_table is not allocated and delete the kmemleak_initialized judgment in set_track_prepare()
|
|
Commit Message
xiaolei wang
Aug. 10, 2023, 7:47 a.m. UTC
The kmemleak_late_init() is defined as a late_initcall. The current
implementation of set_track_prepare() depends on the kmemleak init.
That also means there is no call trace for the memory leak which object
is created before the kmemleak_late_init().
In a previous patch, we have fixed a bug in stack_depot_save() so that
it can be invoked even before stack depot is initialized. So there is
no reason to check the kmemleak_initialized in set_track_prepare().
So delete the kmemleak_initialized judgment in set_track_prepare()
unreferenced object 0xc674ca80 (size 64):
comm "swapper/0", pid 1, jiffies 4294938337 (age 204.880s)
hex dump (first 32 bytes):
80 55 75 c6 80 54 75 c6 00 55 75 c6 80 52 75 c6 .Uu..Tu..Uu..Ru.
00 53 75 c6 00 00 00 00 00 00 00 00 00 00 00 00 .Su..........
Fixes: 56a61617dd22 ("mm: use stack_depot for recording kmemleak's backtrace")
Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>
---
mm/kmemleak.c | 2 --
1 file changed, 2 deletions(-)
Comments
On 8/10/23 09:47, Xiaolei Wang wrote: > The kmemleak_late_init() is defined as a late_initcall. The current > implementation of set_track_prepare() depends on the kmemleak init. > That also means there is no call trace for the memory leak which object > is created before the kmemleak_late_init(). So if I understand correctly, we have the following sequence of events durin boot ... A: stack_depot is initialized ... B: kmemleak is initialized ... before this patchset, we can miss allocations before B, aftewards only before A (which can't be helped), so we now have between A and B. That's nice, but it's weird that can record kmemleak when !kmemleak_initialized. Why can't it be initialized sooner in that case? > In a previous patch, we have fixed a bug in stack_depot_save() so that > it can be invoked even before stack depot is initialized. So there is > no reason to check the kmemleak_initialized in set_track_prepare(). > So delete the kmemleak_initialized judgment in set_track_prepare() > > unreferenced object 0xc674ca80 (size 64): > comm "swapper/0", pid 1, jiffies 4294938337 (age 204.880s) > hex dump (first 32 bytes): > 80 55 75 c6 80 54 75 c6 00 55 75 c6 80 52 75 c6 .Uu..Tu..Uu..Ru. > 00 53 75 c6 00 00 00 00 00 00 00 00 00 00 00 00 .Su.......... > > Fixes: 56a61617dd22 ("mm: use stack_depot for recording kmemleak's backtrace") > Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com> > --- > mm/kmemleak.c | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/mm/kmemleak.c b/mm/kmemleak.c > index a2d34226e3c8..c9f2f816db19 100644 > --- a/mm/kmemleak.c > +++ b/mm/kmemleak.c > @@ -610,8 +610,6 @@ static noinline depot_stack_handle_t set_track_prepare(void) > unsigned long entries[MAX_TRACE]; > unsigned int nr_entries; > > - if (!kmemleak_initialized) > - return 0; > nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 3); > trace_handle = stack_depot_save(entries, nr_entries, GFP_NOWAIT); >
On 8/10/23 12:03, Vlastimil Babka wrote: > On 8/10/23 09:47, Xiaolei Wang wrote: >> The kmemleak_late_init() is defined as a late_initcall. The current >> implementation of set_track_prepare() depends on the kmemleak init. >> That also means there is no call trace for the memory leak which object >> is created before the kmemleak_late_init(). > > So if I understand correctly, we have the following sequence of events durin > boot > > ... > A: stack_depot is initialized > ... > B: kmemleak is initialized > ... > > before this patchset, we can miss allocations before B, aftewards only > before A (which can't be helped), so we now have between A and B. > > That's nice, but it's weird that can record kmemleak when > !kmemleak_initialized. Why can't it be initialized sooner in that case? Looking closer, I think what you want could be achieved by kmemleak_init() setting a variable that is checked in kmemleak_initialized() instead of the kmemleak_initialized that's set too late. I think this should work because: - I assume kmemleak can't record anything before kmemleak_init() - stack depot early init is requested one way or the other - mm_core_init() calls stack_depot_early_init() before kmemleak_init() But I also wonder how kmemleak can even reach set_track_prepare() before kmemleak_init(), maybe that's the issue? >> In a previous patch, we have fixed a bug in stack_depot_save() so that >> it can be invoked even before stack depot is initialized. So there is >> no reason to check the kmemleak_initialized in set_track_prepare(). >> So delete the kmemleak_initialized judgment in set_track_prepare() >> >> unreferenced object 0xc674ca80 (size 64): >> comm "swapper/0", pid 1, jiffies 4294938337 (age 204.880s) >> hex dump (first 32 bytes): >> 80 55 75 c6 80 54 75 c6 00 55 75 c6 80 52 75 c6 .Uu..Tu..Uu..Ru. >> 00 53 75 c6 00 00 00 00 00 00 00 00 00 00 00 00 .Su.......... >> >> Fixes: 56a61617dd22 ("mm: use stack_depot for recording kmemleak's backtrace") >> Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com> >> --- >> mm/kmemleak.c | 2 -- >> 1 file changed, 2 deletions(-) >> >> diff --git a/mm/kmemleak.c b/mm/kmemleak.c >> index a2d34226e3c8..c9f2f816db19 100644 >> --- a/mm/kmemleak.c >> +++ b/mm/kmemleak.c >> @@ -610,8 +610,6 @@ static noinline depot_stack_handle_t set_track_prepare(void) >> unsigned long entries[MAX_TRACE]; >> unsigned int nr_entries; >> >> - if (!kmemleak_initialized) >> - return 0; >> nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 3); >> trace_handle = stack_depot_save(entries, nr_entries, GFP_NOWAIT); >> >
On 8/10/23 9:16 PM, Vlastimil Babka wrote: > CAUTION: This email comes from a non Wind River email account! > Do not click links or open attachments unless you recognize the sender and know the content is safe. > > On 8/10/23 12:03, Vlastimil Babka wrote: >> On 8/10/23 09:47, Xiaolei Wang wrote: >>> The kmemleak_late_init() is defined as a late_initcall. The current >>> implementation of set_track_prepare() depends on the kmemleak init. >>> That also means there is no call trace for the memory leak which object >>> is created before the kmemleak_late_init(). >> So if I understand correctly, we have the following sequence of events durin >> boot >> >> ... >> A: stack_depot is initialized >> ... >> B: kmemleak is initialized >> ... >> >> before this patchset, we can miss allocations before B, aftewards only >> before A (which can't be helped), so we now have between A and B. >> >> That's nice, but it's weird that can record kmemleak when >> !kmemleak_initialized. Why can't it be initialized sooner in that case? > Looking closer, I think what you want could be achieved by kmemleak_init() > setting a variable that is checked in kmemleak_initialized() instead of the > kmemleak_initialized that's set too late. > > I think this should work because: > - I assume kmemleak can't record anything before kmemleak_init() > - stack depot early init is requested one way or the other > - mm_core_init() calls stack_depot_early_init() before kmemleak_init() > > But I also wonder how kmemleak can even reach set_track_prepare() before > kmemleak_init(), maybe that's the issue? Before kmemleak_init, many places also need to allocate kmemleak_object, and also need to save stack in advance, but kmemleak_object is allocated in the form of an array, after kmemleak_init 'object_cache = KMEM_CACHE(kmemleak_object, SLAB_NOLEAKTRACE);' I think there is still some memory not recorded on the backtrace before stack_depot_early_init(), does anyone have a better suggestion? thanks xiaolei > >>> In a previous patch, we have fixed a bug in stack_depot_save() so that >>> it can be invoked even before stack depot is initialized. So there is >>> no reason to check the kmemleak_initialized in set_track_prepare(). >>> So delete the kmemleak_initialized judgment in set_track_prepare() >>> >>> unreferenced object 0xc674ca80 (size 64): >>> comm "swapper/0", pid 1, jiffies 4294938337 (age 204.880s) >>> hex dump (first 32 bytes): >>> 80 55 75 c6 80 54 75 c6 00 55 75 c6 80 52 75 c6 .Uu..Tu..Uu..Ru. >>> 00 53 75 c6 00 00 00 00 00 00 00 00 00 00 00 00 .Su.......... >>> >>> Fixes: 56a61617dd22 ("mm: use stack_depot for recording kmemleak's backtrace") >>> Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com> >>> --- >>> mm/kmemleak.c | 2 -- >>> 1 file changed, 2 deletions(-) >>> >>> diff --git a/mm/kmemleak.c b/mm/kmemleak.c >>> index a2d34226e3c8..c9f2f816db19 100644 >>> --- a/mm/kmemleak.c >>> +++ b/mm/kmemleak.c >>> @@ -610,8 +610,6 @@ static noinline depot_stack_handle_t set_track_prepare(void) >>> unsigned long entries[MAX_TRACE]; >>> unsigned int nr_entries; >>> >>> - if (!kmemleak_initialized) >>> - return 0; >>> nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 3); >>> trace_handle = stack_depot_save(entries, nr_entries, GFP_NOWAIT); >>>
On 8/11/23 04:03, wang xiaolei wrote: > > On 8/10/23 9:16 PM, Vlastimil Babka wrote: >> CAUTION: This email comes from a non Wind River email account! >> Do not click links or open attachments unless you recognize the sender and know the content is safe. >> >> On 8/10/23 12:03, Vlastimil Babka wrote: >>> On 8/10/23 09:47, Xiaolei Wang wrote: >>>> The kmemleak_late_init() is defined as a late_initcall. The current >>>> implementation of set_track_prepare() depends on the kmemleak init. >>>> That also means there is no call trace for the memory leak which object >>>> is created before the kmemleak_late_init(). >>> So if I understand correctly, we have the following sequence of events durin >>> boot >>> >>> ... >>> A: stack_depot is initialized >>> ... >>> B: kmemleak is initialized >>> ... >>> >>> before this patchset, we can miss allocations before B, aftewards only >>> before A (which can't be helped), so we now have between A and B. >>> >>> That's nice, but it's weird that can record kmemleak when >>> !kmemleak_initialized. Why can't it be initialized sooner in that case? >> Looking closer, I think what you want could be achieved by kmemleak_init() >> setting a variable that is checked in kmemleak_initialized() instead of the >> kmemleak_initialized that's set too late. >> >> I think this should work because: >> - I assume kmemleak can't record anything before kmemleak_init() >> - stack depot early init is requested one way or the other >> - mm_core_init() calls stack_depot_early_init() before kmemleak_init() >> >> But I also wonder how kmemleak can even reach set_track_prepare() before >> kmemleak_init(), maybe that's the issue? > > Before kmemleak_init, many places also need to allocate kmemleak_object, > > and also need to save stack in advance, but kmemleak_object is allocated > > in the form of an array, after kmemleak_init 'object_cache = > KMEM_CACHE(kmemleak_object, SLAB_NOLEAKTRACE);' Hm I see, kmemleak has this static mempool so it really can record some objects very early. > I think there is still some memory not recorded on the backtrace before > > stack_depot_early_init(), does anyone have a better suggestion? No we can't record the backtrace earlier. But I don't think it's a problem in practice. AFAIU kmemleak needs to record these very early allocations so if they point to further objects, those are not suspected as orphans. But the early allocations themselves also are very unlikely to be leaks, so does it really matter that we don't have a backtrace for their allocation? Because the backtrace is the only thing that's missing - the object is otherwise recorded even if set_track_prepare() returns 0. > thanks > > xiaolei > >> >>>> In a previous patch, we have fixed a bug in stack_depot_save() so that >>>> it can be invoked even before stack depot is initialized. So there is >>>> no reason to check the kmemleak_initialized in set_track_prepare(). >>>> So delete the kmemleak_initialized judgment in set_track_prepare() >>>> >>>> unreferenced object 0xc674ca80 (size 64): >>>> comm "swapper/0", pid 1, jiffies 4294938337 (age 204.880s) >>>> hex dump (first 32 bytes): >>>> 80 55 75 c6 80 54 75 c6 00 55 75 c6 80 52 75 c6 .Uu..Tu..Uu..Ru. >>>> 00 53 75 c6 00 00 00 00 00 00 00 00 00 00 00 00 .Su.......... >>>> >>>> Fixes: 56a61617dd22 ("mm: use stack_depot for recording kmemleak's backtrace") >>>> Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com> >>>> --- >>>> mm/kmemleak.c | 2 -- >>>> 1 file changed, 2 deletions(-) >>>> >>>> diff --git a/mm/kmemleak.c b/mm/kmemleak.c >>>> index a2d34226e3c8..c9f2f816db19 100644 >>>> --- a/mm/kmemleak.c >>>> +++ b/mm/kmemleak.c >>>> @@ -610,8 +610,6 @@ static noinline depot_stack_handle_t set_track_prepare(void) >>>> unsigned long entries[MAX_TRACE]; >>>> unsigned int nr_entries; >>>> >>>> - if (!kmemleak_initialized) >>>> - return 0; >>>> nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 3); >>>> trace_handle = stack_depot_save(entries, nr_entries, GFP_NOWAIT); >>>>
On Fri, Aug 11, 2023 at 10:09:08AM +0200, Vlastimil Babka wrote: > On 8/11/23 04:03, wang xiaolei wrote: > > On 8/10/23 9:16 PM, Vlastimil Babka wrote: > >> Looking closer, I think what you want could be achieved by kmemleak_init() > >> setting a variable that is checked in kmemleak_initialized() instead of the > >> kmemleak_initialized that's set too late. > >> > >> I think this should work because: > >> - I assume kmemleak can't record anything before kmemleak_init() > >> - stack depot early init is requested one way or the other > >> - mm_core_init() calls stack_depot_early_init() before kmemleak_init() > >> > >> But I also wonder how kmemleak can even reach set_track_prepare() before > >> kmemleak_init(), maybe that's the issue? > > > > Before kmemleak_init, many places also need to allocate kmemleak_object, > > > > and also need to save stack in advance, but kmemleak_object is allocated > > > > in the form of an array, after kmemleak_init 'object_cache = > > KMEM_CACHE(kmemleak_object, SLAB_NOLEAKTRACE);' > > Hm I see, kmemleak has this static mempool so it really can record some > objects very early. Indeed, otherwise we'd get a lot of false positives. > > I think there is still some memory not recorded on the backtrace before > > > > stack_depot_early_init(), does anyone have a better suggestion? > > No we can't record the backtrace earlier. But I don't think it's a problem > in practice. AFAIU kmemleak needs to record these very early allocations so > if they point to further objects, those are not suspected as orphans. But > the early allocations themselves also are very unlikely to be leaks, so does > it really matter that we don't have a backtrace for their allocation? > Because the backtrace is the only thing that's missing - the object is > otherwise recorded even if set_track_prepare() returns 0. It's not a functional problem, just a reporting one. There are rare early leaks (usually false positives) so identifying them would help. That said, I think set_track_prepare() is too conservative in waiting for kmemleak_initialized to be set in kmemleak_late_init(). That's a late_initcall() meant for the scanning thread etc. not the core kmemleak functionality (which is on from early boot). We can instead use a different variable to check in set_track_prepare(), e.g. object_cache. stack_depot_early_init() is called prior to kmemleak_init(), so it should be fine. If "kmemleak_initialized" is confusing, we could rename it to "kmemleak_late_initialized" or "kmemleak_fully_initialized". I'm not too fussed about this as long as we add some comment on why we check object_cache instead of kmemleak_initialized.
diff --git a/mm/kmemleak.c b/mm/kmemleak.c index a2d34226e3c8..c9f2f816db19 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -610,8 +610,6 @@ static noinline depot_stack_handle_t set_track_prepare(void) unsigned long entries[MAX_TRACE]; unsigned int nr_entries; - if (!kmemleak_initialized) - return 0; nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 3); trace_handle = stack_depot_save(entries, nr_entries, GFP_NOWAIT);