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: 9897659 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 B8F88603B4 for ; Sun, 13 Aug 2017 10:11:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA6BA286EF for ; Sun, 13 Aug 2017 10:11:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B0A2286F1; Sun, 13 Aug 2017 10:11:58 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CFF6286F1 for ; Sun, 13 Aug 2017 10:11:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752402AbdHMKKz (ORCPT ); Sun, 13 Aug 2017 06:10:55 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:60707 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751403AbdHMKKw (ORCPT ); Sun, 13 Aug 2017 06:10:52 -0400 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 Cc: "Rafael J. Wysocki" , Sudeep Holla , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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= Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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;