Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1636468iob; Fri, 29 Apr 2022 09:26:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxySc3kv4DDW590YBXTyqOxYIyp5OprjjFUeWZb66V8WH5lKA2Yd3sFNZbdEuBD0Rkp0fRm X-Received: by 2002:a05:6512:3f94:b0:471:9447:f4ab with SMTP id x20-20020a0565123f9400b004719447f4abmr28136936lfa.661.1651249597580; Fri, 29 Apr 2022 09:26:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651249597; cv=none; d=google.com; s=arc-20160816; b=kItS1pZo4cJCs7K1qsDrOisgfFna1oB5xn80ZqbGudx4yUmopGg+OsecItsskcgr04 +IbFkrGGEv4ia0uC2ZSLWoWF5Wj7WXQ1ZIqgr6N8PwmHnwCQpSyJcC7ZJwamsQVyBcjC d9VoM0YEMNoNHlttBFjNZYlu24NPdT7gr48omSIdqqQ6xhQcaV1qt7kM0a3hhs3s52h8 rkRwAivtHEaNhWkSLv/loDecAqVe9sySgw0Lqu/GtXo9h3BpIAqWpQUvLMDB5RqnLCw5 BY75fOs0unAzNc6945FfgHfmq/n18eRSR4VaYcu5PE3+HjVrJZqveinrCqIqFzay5wA5 KZIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=DBjiugNjTGcxTYpY8NtYUO4lD1CkcFG9xhNmaPjxuFw=; b=tVezMEjnO72aOfQFdkrSTlH68myptOg6cxgd5diA8U7YtUBLvkSOre0rCuiW2h3ZgF h+TE/gideZir0fhp60EI8JKzlsRkemQDDeR4a6AHnQPlp+h4oyJSZMkp9e8PksHknank FJMQF4NyL0wffjufQyCJm2WbOiP93X5a4omN9Gf1BS1qiqhLiyC7ghIO2F0AWq7y3jbA W4KrnS5TZHDgpyTTEi0xQ0bP8Odmt7f7mpKU1pRR0IgslvGln6gZ1cQbL1RGpCUdfcki w0PtYbeeRbU7tPnm7cQMZVwXXlr8O6iX4Do4Fu1yCo35PURWSG3nRAkphE3tFFrBBaz6 elxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=arTulElW; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c7-20020a05651200c700b0046d15d8b867si7189820lfp.36.2022.04.29.09.26.09; Fri, 29 Apr 2022 09:26:37 -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=@kernel.org header.s=k20201202 header.b=arTulElW; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350695AbiD1SE7 (ORCPT + 99 others); Thu, 28 Apr 2022 14:04:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245205AbiD1SE6 (ORCPT ); Thu, 28 Apr 2022 14:04:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECD7C972A7; Thu, 28 Apr 2022 11:01:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7CD5EB82EF7; Thu, 28 Apr 2022 18:01:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FFB5C385A9; Thu, 28 Apr 2022 18:01:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651168900; bh=j73iXb7HRmYNvs62beHpaMLechgWJdFxikbQ4RJV4Ew=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=arTulElWhcwZNgmeTTmFxCr7czn03uLlxgEQVPEn9CVlcEMbvRrkd4EJXHmvbSMZ2 grajzT44dJmJGlUT/YtAZhPXTpfeZusEKVKFW3/nfS38asp70m0VXe/Z73TEuudCDo nofjhlUGxzjz1ejBATWeP3SkBaj5wKU+xX9MwShHeu9kQPPLq8+h+XNSPEztkpnBln sO70Pg4FknvIyzw48FwKXHlQLXZi7HYEx4BkVzP8bLM3uM/jzJLuwclqY26sstWLDV vGuqfjf1UffYh8B83NMMeGrxHcB8ZaOOxpiIwErDYTq/s4tb3MGaFfi0/xhmlp/LcZ HyIFJ+wpIFAPw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D38FA5C0387; Thu, 28 Apr 2022 11:01:39 -0700 (PDT) Date: Thu, 28 Apr 2022 11:01:39 -0700 From: "Paul E. McKenney" To: Zqiang Cc: frederic@kernel.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] rcutorture: Fix kmemleak in rcu_test_debug_objects() Message-ID: <20220428180139.GK1790663@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20220427071520.2239030-1-qiang1.zhang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220427071520.2239030-1-qiang1.zhang@intel.com> X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 27, 2022 at 03:15:20PM +0800, Zqiang wrote: > The kmemleak kthread scan to the following: > > unreferenced object 0xffff95d941135b50 (size 16): > comm "swapper/0", pid 1, jiffies 4294667610 (age 1367.451s) > hex dump (first 16 bytes): > f0 c6 c2 bd d9 95 ff ff 00 00 00 00 00 00 00 00 ................ > backtrace: > [<00000000bc81d9b1>] kmem_cache_alloc_trace+0x2f6/0x500 > [<00000000d28be229>] rcu_torture_init+0x1235/0x1354 > [<0000000032c3acd9>] do_one_initcall+0x51/0x210 > [<000000003c117727>] kernel_init_freeable+0x205/0x259 > [<000000003961f965>] kernel_init+0x1a/0x120 > [<000000001998f890>] ret_from_fork+0x22/0x30 > > the rhp object is not released after use, so call kfree() to > release it. > > Signed-off-by: Zqiang Good catch, thank you! I queued this for v5.20 with the wordsmithed commit log shown below. Thanx, Paul ------------------------------------------------------------------------ commit 1a2df31f4026dbc8dc4db17a4c2ed01e67f45c92 Author: Zqiang Date: Wed Apr 27 15:15:20 2022 +0800 rcutorture: Fix memory leak in rcu_test_debug_objects() The kernel memory leak detector located the following: unreferenced object 0xffff95d941135b50 (size 16): comm "swapper/0", pid 1, jiffies 4294667610 (age 1367.451s) hex dump (first 16 bytes): f0 c6 c2 bd d9 95 ff ff 00 00 00 00 00 00 00 00 ................ backtrace: [<00000000bc81d9b1>] kmem_cache_alloc_trace+0x2f6/0x500 [<00000000d28be229>] rcu_torture_init+0x1235/0x1354 [<0000000032c3acd9>] do_one_initcall+0x51/0x210 [<000000003c117727>] kernel_init_freeable+0x205/0x259 [<000000003961f965>] kernel_init+0x1a/0x120 [<000000001998f890>] ret_from_fork+0x22/0x30 This is caused by the rcu_test_debug_objects() function allocating an rcu_head structure, then failing to free it. This commit therefore adds the needed kfree() after the last use of this structure. Signed-off-by: Zqiang Signed-off-by: Paul E. McKenney diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c index bb2e1610d0add..faf6b4c7a7572 100644 --- a/kernel/rcu/rcutorture.c +++ b/kernel/rcu/rcutorture.c @@ -3176,6 +3176,7 @@ static void rcu_test_debug_objects(void) pr_alert("%s: WARN: Duplicate call_rcu() test complete.\n", KBUILD_MODNAME); destroy_rcu_head_on_stack(&rh1); destroy_rcu_head_on_stack(&rh2); + kfree(rhp); #else /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */ pr_alert("%s: !CONFIG_DEBUG_OBJECTS_RCU_HEAD, not testing duplicate call_rcu()\n", KBUILD_MODNAME); #endif /* #else #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */