Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3163283rwb; Sun, 25 Sep 2022 01:14:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM492fImLNySXq2o88JPOngIphcAP0faWez+OfFt9RmVoUBm5FKmILf8Df7Cmm5xFOVxoMLj X-Received: by 2002:a17:90b:4a0c:b0:202:b4ed:1a2b with SMTP id kk12-20020a17090b4a0c00b00202b4ed1a2bmr30043296pjb.67.1664093685543; Sun, 25 Sep 2022 01:14:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664093685; cv=none; d=google.com; s=arc-20160816; b=R+xnudyIsdMmikqBXopril2jt8Vf43RmlcDEgw6vb1K0GPLVKLcTaoO+YVIgufUB6q pttFdN5pIK6E3qfCgMVUJWT4fnH5BTCEckEsMQQUzO7IdlfLZM75BETVuR/7lTfWll4N GsWmFpN2IA7T6TGBknBNmKfzgrGkba+VBqbKEZV73exx5I1Fyn9o1Q7y3IhMt7B6J7Z4 GqqAiLn6fszcWNTq/fEIuyBlxpBLVwoW+47OV0a8G/lszzSt39Li27rlyxTXfXoLyYaH 7+nkUP2s0lt+2P53Dt6xSgvWFMUiXgYihlnFx+aATFUigpcT3yKOM+73YzlwUtZ2C3n9 D+Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=XJ0Z8vsVTn/Vd6LCihmKjoSXcpO91zfLe+joK/VV72c=; b=vIkQa5pb8xdQA9CWgZevhGUXBTkpeINiMvsO3q0GvUMG2xuNjF+Z9mPZ+p+BpwZ3XM PKnp6xlHtR1A5R5tLsgUjLnsU0z0bhH0dyFVFEB6IxUiJk8OruGXobJYwhFqunBb+bM+ 39W3BMDn9YBNOVYTenvk95FfP69+1AkabPDhVK+n/ejFRoovaFbzYXb3qfC5U7fJGYZI qbeRtV78Vwjy24JmcPTiNgviPKoOi3tX3j/DwgMcvn5U4Pn0F3ckppCbpvJ7Jtpzg/i2 I9xWXspZEhrZgEIdG35ujjj97Vpcd3CLz59DFHi3Z7l94oaK/17SufpSAqPGeeF8F0V2 dJ5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=EOD228gF; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s6-20020a17090a764600b00202fbc97a02si2048646pjl.68.2022.09.25.01.14.34; Sun, 25 Sep 2022 01:14:45 -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=@semihalf.com header.s=google header.b=EOD228gF; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230413AbiIYHzn (ORCPT + 99 others); Sun, 25 Sep 2022 03:55:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230248AbiIYHzl (ORCPT ); Sun, 25 Sep 2022 03:55:41 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 434E61A071 for ; Sun, 25 Sep 2022 00:55:21 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id n83so4898442oif.11 for ; Sun, 25 Sep 2022 00:55:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date; bh=XJ0Z8vsVTn/Vd6LCihmKjoSXcpO91zfLe+joK/VV72c=; b=EOD228gFhDIRPpt3AjSXx6PMpOvthtcqHdDVzrIoS2qqrPcD2M2fziVKateT0eDPUG cE0k/JTvoDo/2Knw3Nv9xv6XGifQ6bbmFMVISNfkTe+Fj310R5dttIhOXqlJ0BOXpF6w oMfpBfYnRiGFIVZ9m+HAph8YiUYo9bjkaf+OIUQpIvlcrCYgpxiPktyJLlgIP5HrW4S5 SIJc9Yf1IDN8eA2PPYgKsk91yIY9+DLmmdA2+eenHA6k/sTrPjETTcC1P/KcVkMoqDes rbyNuQz91VlWD2R+iNl7ZBwdCBj9RpNhjAzpO+Kg2fOSeNnKUU/QL/GNPlogM003KTbP U9SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date; bh=XJ0Z8vsVTn/Vd6LCihmKjoSXcpO91zfLe+joK/VV72c=; b=K7EA5M40JFmRpIOTfFEcPlUz/1f7LrgUz5hS1LbnOhvGgKXmSqd+KNY1JhM0vlfy0e AHNI018a4Gl3d67+SC+prBlq0WG9dnZXIuM6lq16g/rfJJVF85zulKMC5i76INfpBlP0 0A3WcYXDmGS9Jvv8X1ppra/SLtulOMyreQko5WtEuxKdgA+eddGp9wfDRe9qSL2bSr0D Js6kS0Ny4tF3sh10TlYx1FYDbVTDBtQIdGq7UK8vVZnKod542NVFedeTHX1LSJPAW50y GmUNpKHZ6NsJaNi9slK+Dw1WpD+8SQicNQxIWJIrWz2NInIEQFSgN+Wm5K3yS0FoGVSI hvmw== X-Gm-Message-State: ACrzQf12KJo6L25jwjwnxEeyLFGJ2LT4s7aR64Uir3sKtF2Hy7zh9ENb 43YizVbjNyzKJDIcofL7e1/idOyKRBEFww+aj9F1zg== X-Received: by 2002:a05:6808:2012:b0:34f:c816:cdf5 with SMTP id q18-20020a056808201200b0034fc816cdf5mr12421683oiw.45.1664092520381; Sun, 25 Sep 2022 00:55:20 -0700 (PDT) MIME-Version: 1.0 References: <20220921114444.2247083-1-gregkh@linuxfoundation.org> In-Reply-To: From: Marcin Wojtas Date: Sun, 25 Sep 2022 09:55:10 +0200 Message-ID: Subject: Re: [PATCH net] net: mvpp2: debugfs: fix problem with previous memory leak fix To: "Russell King (Oracle)" Cc: Greg Kroah-Hartman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , stable Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 niedz., 25 wrz 2022 o 08:58 Russell King (Oracle) napisa=C5=82(a): > > On Sun, Sep 25, 2022 at 01:27:06AM +0200, Marcin Wojtas wrote: > > Hi Russell, > > > > czw., 22 wrz 2022 o 19:08 Marcin Wojtas napisa=C5=82(= a): > > > > > > Hi, > > > > > > Thank you both for the patches. > > > > > > > > > czw., 22 wrz 2022 o 18:05 Russell King (Oracle) > > > napisa=C5=82(a): > > > > > > > > On Wed, Sep 21, 2022 at 01:44:44PM +0200, Greg Kroah-Hartman wrote: > > > > > In commit fe2c9c61f668 ("net: mvpp2: debugfs: fix memory leak whe= n using > > > > > debugfs_lookup()"), if the module is unloaded, the directory will= still > > > > > be present if the module is loaded again and creating the directo= ry will > > > > > fail, causing the creation of additional child debugfs entries fo= r the > > > > > individual devices to fail. > > > > > > > > > > As this module never cleaned up the root directory it created, ev= en when > > > > > loaded, and unloading/loading a module is not a normal operation,= none > > > > > of would normally happen. > > > > > > > > > > To clean all of this up, use a tiny reference counted structure t= o hold > > > > > the root debugfs directory for the driver, and then clean it up w= hen the > > > > > last user of it is removed from the system. This should resolve = the > > > > > previously reported problems, and the original memory leak that > > > > > fe2c9c61f668 ("net: mvpp2: debugfs: fix memory leak when using > > > > > debugfs_lookup()") was attempting to fix. > > > > > > > > For the record... I have a better fix for this, but I haven't been = able > > > > to get it into a state suitable for submission yet. > > > > > > > > http://www.home.armlinux.org.uk/~rmk/misc/mvpp2-debugfs.diff > > > > > > > > Not yet against the net tree. Might have time tomorrow to do that, = not > > > > sure at the moment. Medical stuff is getting in the way. :( > > > > > > > > > > I'd lean towards this version - it is a bit more compact. I'll try to > > > test that tomorrow or during the weekend. > > > > > > > I improved the patch compile and work (tested on my CN913x board). > > Feel free to submit (if you wish, I can do it too - please let me know > > your preference): > > https://github.com/semihalf-wojtas-marcin/Linux-Kernel/commit/0abb75115= ffb2772f595bb3346573e27e650018b > > I don't see what the compile fixes were in that - it looks like my patch I overlooked drivers/net/ethernet/marvell/mvpp2/mvpp2.h diff (I applied patch manually), but I double-checked and it was there, so you are right. > ported onto current -net. Obvious changes: Yes, it's applied on top of net/net-next. > > - moved mvpp2_dbgfs_exit() declaration from after mvpp2_dbgfs_cleanup() > to before. > - moved definition of mvpp2_root to the top of the file (as no effect > on the code.) These are irrelevant. The most important part was: --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -7714,8 +7714,8 @@ module_init(mvpp2_driver_init); static void __exit mvpp2_driver_exit(void) { - mvpp2_dbgfs_exit(); platform_driver_unregister(&mvpp2_driver); + mvpp2_dbgfs_exit(); } module_exit(mvpp2_driver_exit); Otherwise, I observed NULL-pointer dereference when mvpp2_remove()->mvpp2_dbgfs_cleanup(). > > and the change to port it: > > - dropped my mvpp2_dbgfs_init() hunk (because it's different in -net) > - removed static declaration of mvpp2_root in mvpp2_dbgfs_init() > > I'm not seeing any other changes. > > Note that Sasha has submitted a revert of Greg's original patch for > mainline, so my original patch should apply as-is if that revert > happens - and I don't see any compile issues with it. > Sure. In order to avoid misunderstandings, I stop here and leave the submission to you. Thanks, Marcin