From patchwork Sun Aug 13 10:10:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 9897657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 962E3602A7 for ; Sun, 13 Aug 2017 10:10:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86E6D286EF for ; Sun, 13 Aug 2017 10:10:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A87A286F3; Sun, 13 Aug 2017 10:10:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 06A8A286EF for ; Sun, 13 Aug 2017 10:10:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Subject:References: In-Reply-To:Message-ID:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xgTg8i6kRTanELMbMgufZLkmqjCvPEZFgyukNMEu8cs=; b=cKMH638zlpfAdH 6yIK9nYx15LSSevOVwMDgb8eITyESkUE1dXxVYbARaunRyLAokqMyas0tvKz0+IwT/qtl3ToBCySt 7E4/CuEvn3Dveww1OHIbpoKM3aqlhKHdkGN1U5F0iZ+aiac7BGf7QczvoxHzjqO8Pesvy1h+pn3Ax qvydMN5RUR6buJVVPEz3ltWQMC57qSNUet81mD2QRN84jx54MuEuOuzZ1558CVjb7tSmNVV9DvOP+ DdVJ3ZpTfLQ1+qinrPPdMgOZ8UA70GL9mK7IM4OAdouFQrGfDPAhM1Et7plYSe2fsZ9nSXl32qQKl kNxUH8cfb2Xq5ZCQ+Fhw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dgprA-0005vE-Nk; Sun, 13 Aug 2017 10:10:52 +0000 Received: from mout.kundenserver.de ([217.72.192.74]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dgpr6-0005pq-Ag for linux-arm-kernel@lists.infradead.org; Sun, 13 Aug 2017 10:10:50 +0000 Received: from oxbsltgw65.schlund.de ([172.19.249.155]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MfIB0-1dwshP0I4Q-00OsK7; Sun, 13 Aug 2017 12:10:09 +0200 Date: Sun, 13 Aug 2017 12:10:06 +0200 (CEST) From: Stefan Wahren To: Leo Yan , Daniel Lezcano Message-ID: <37728512.316309.1502619006183@email.1und1.de> In-Reply-To: <20170813035040.GA13637@leoy-linaro> References: <1980049531.494543.1502543973258@email.1und1.de> <20170813035040.GA13637@leoy-linaro> Subject: Re: [Bug] ARM: cpuidle: possible memleak MIME-Version: 1.0 X-Priority: 3 Importance: Medium X-Mailer: Open-Xchange Mailer v7.8.2-Rev34 X-Originating-Client: open-xchange-appsuite X-Provags-ID: V03:K0:0vb40iHFA/HiW3LMGWvegBgv5/pxueOfltw2acAZyxtCQGUzXvB OFcycxh7ASABQkqs/VK5oe5otj4xQ6kGFeQWdsHdax9BMmvmuJ0cYuKv7wlvGGDlTNf2qqT Zd1I34Izonu495W7R5T5FJPIsfWMgx4rm6+HiLnEReDn+YpPGQHhjO/iuew2J70jF+KU/uT v81azRpohme6DSX1Kygsw== X-UI-Out-Filterresults: notjunk:1; V01:K0:Dc62hirZBAk=:FuLKknF2u4/epzIk+VNvEO 31KZPWgYWCKFfUIeHjQy6A7Xt6PO9haNw8l7vse5jOJ2Z+dMkmzDVvWQ5RC0g6k8NY5ctCMxN cVNWe0QH297jycxE9H7WcpEdCNEOObiuHc+B3MmqDx2s6kSTpHlu/3TgYRAo1LvcnppPyJ5pg AmnM/O7pffEYJl7bbCeIHTP7sERg9i+UQlTY5m3bIqDpWi1jEyOza9j0fk/s8xGzfuzpP6GhL VP9suzYd+Syjp4kfXRy+YyBf7EayjO1VcTjZlQjNJLdGQTHjDlfS0y1TT/n3L5+ajCHDsatz9 AlGEPjL+HWZfJ4tUOkhTBe/4YMpGfaIH0B8Xrl+zsk3aggb00cLHl83L4tMG9qK4IBsBDFYha fq7rfkG74o9hXcLkaLmD8Ezjl9TAd4tX5iYzNBhOYcwErug6sIOjnHH9h0eTgbNYMBh2pLOKM ZcJsVzSNlXtV1w+UeDBi/smy7uJ/FC0/xjCs0DuHXxn49PPLMMzgNMYtPkfXOyJUoz+0aEs1Q izyaX46WBc0H5eORYAW2I/5dswGekE0F9DlS9cDIeYTKUJUmHGIrVLMX+YGzNzctgXgtPVkFY Xsp0weu+wnJBV2BdSSlzMHn3OO/Oc8xU9xQmN+4a3z6xl/HFcS+UoH046CVMgPm9Ctxiq009w 0bVhsv46XTkMoc/OcFHRNB6zfnk3PELm0o8KHBq7fSU52yLxXtS/uKIMOjD87uxj4CeyjN+tC dkxWt8ICt8OBV/RH4KkXzrGd8EVeh67znpFqVJqFW2gYkcAbb5l7r3dT/0Y= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170813_031048_716802_7B4DD917 X-CRM114-Status: GOOD ( 13.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pm@vger.kernel.org, "Rafael J. Wysocki" , linux-arm-kernel@lists.infradead.org, Sudeep Holla Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Leo, > Leo Yan hat am 13. August 2017 um 05:50 geschrieben: > > > Hi Stefan, > > On Sat, Aug 12, 2017 at 03:19:33PM +0200, Stefan Wahren wrote: > > Hi, > > > > if i additionally enable kmemleak (on top of multi_v7_defconfig) on RPi 3 (4 cores) with 4.13-rc4, i get the following output from kmemleak: > > > > unreferenced object 0xede0dc00 (size 1024): > > comm "swapper/0", pid 1, jiffies 4294937431 (age 744.510s) > > hex dump (first 32 bytes): > > 94 9e 0b c1 00 00 00 00 00 00 00 00 00 00 00 00 ................ > > 57 46 49 00 00 00 00 00 00 00 00 00 00 00 00 00 WFI............. > > backtrace: > > [] arm_idle_init+0x44/0x1ac > > [] do_one_initcall+0x3c/0x16c > > [] kernel_init_freeable+0x110/0x1d0 > > [] kernel_init+0x8/0x114 > > [] ret_from_fork+0x14/0x3c > > [] 0xffffffff > > > > If i revert the last commit in cpuidle-arm d50a7d8acd78 ("ARM: cpuidle: Support asymmetric idle definition") then kmemleak stays calm. > > I cannot reproduce the error at my side, I also tried to disable idle > states but cannot trigger the failure. So first thing is to know the > reason for registeration failure and finally introduce the memory > leaking. Could you point out the dts you are using for idle states > binding? thanks for you quick response. Sorry, i forgot to mention that arch/arm64/boot/dts/broadcom/bcm2837.dtsi doesn't contain any idle states. So the error path of dt_init_idle_driver() is expected. If i get it right, the clean up loop after out_fail only handles registered drivers (better label name or a comment would be helpful). So combined with your fix the following fixes the memleak for me (didn't test the clean up loop): diff --git a/drivers/cpuidle/cpuidle-arm.c b/drivers/cpuidle/cpuidle-arm.c index 7080c38..827ab25 100644 --- a/drivers/cpuidle/cpuidle-arm.c +++ b/drivers/cpuidle/cpuidle-arm.c @@ -104,12 +104,14 @@ static int __init arm_idle_init(void) ret = dt_init_idle_driver(drv, arm_idle_state_match, 1); if (ret <= 0) { ret = ret ? : -ENODEV; + kfree(drv); goto out_fail; } ret = cpuidle_register_driver(drv); if (ret) { pr_err("Failed to register cpuidle driver\n"); + kfree(drv); goto out_fail; } @@ -152,11 +154,13 @@ static int __init arm_idle_init(void) out_fail: while (--cpu >= 0) { dev = per_cpu(cpuidle_devices, cpu); - cpuidle_unregister_device(dev); - kfree(dev); - drv = cpuidle_get_driver(); + drv = cpuidle_get_cpu_driver(dev); + cpuidle_unregister_driver(drv); kfree(drv); + + cpuidle_unregister_device(dev); + kfree(dev); } return ret;