Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4423345pxv; Tue, 20 Jul 2021 03:32:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmiC1gguDKNxY7QplQtX6w7Mq9FBAQ+w+9TE90dcQLihhxFDJb5ovdrisyHniFuMR7YoYY X-Received: by 2002:a02:666d:: with SMTP id l45mr26640670jaf.0.1626777140885; Tue, 20 Jul 2021 03:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626777140; cv=none; d=google.com; s=arc-20160816; b=qwDCqcyOtJlxDkxE3IGm17v39OrTdK/aX3qMH33xqj2d1i3xAUpfqjvZ4SkfPpLp2a ElI60V15z1uDgGihQjnp9m1/LgzYn2/wddtdRV8SJij4sc658lQ4SfpLuKcRwJe45/vP CU2q3dgvwKpJ3uSaDqE2Xq8YFmJOl2jKk3dmt19ZRiZmFaS4iEc3AyZNlPOCws5G/G4s niYFgnaTuNb0lt6NlcAeEo55M+9soZVhq5pOMl4v/HlVtViPJBrQNH0/GikV8MKbJeZv gPjhQVe25FBOScmJCOCRMTwDYGgFZ5DyJgCFT4Cogb5IHPxLh5wK+BxukluPnhuo3Ovj pw2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Yt6N2aX6RjTV8ey7tH1MG5YP2S2wCxXaUz++48Vz5WQ=; b=GeHJKj7ATrYrPJ6bYrbdQJYXxraL/5wKW2+ofE6uARUbvzn1KE5nGLCPDaBHJSAIsj Q2T8UAhATqqYPon50q9+ZCpIO9XeCgJ1kVhc0iL4HLE8nntf1UpkTVPFONqbC7lbSOVQ ySYHuHDqKJvPFC66ASsHE99OyrBRBWlQGa+9/ficA3u5k5v7T7KgtIA9ILPwMuVbTvxD 8EhqO6DcW5m6PLKqLeHWYLjgOeS0YW4wMGXdhhLJJEfH9qobvfvMlrs+zGv9Y4U4cnqa O+B75JixB559pOn0bSds0wCgmANwM2aOhaC4YYb3/Gnt6JZv3yJTEFFEowK6LEX/m462 v8dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QB0iWyLA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w21si23957429jah.86.2021.07.20.03.32.08; Tue, 20 Jul 2021 03:32:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QB0iWyLA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236430AbhGTJst (ORCPT + 99 others); Tue, 20 Jul 2021 05:48:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233061AbhGTJrn (ORCPT ); Tue, 20 Jul 2021 05:47:43 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98316C061574; Tue, 20 Jul 2021 03:28:21 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id my10so13329439pjb.1; Tue, 20 Jul 2021 03:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Yt6N2aX6RjTV8ey7tH1MG5YP2S2wCxXaUz++48Vz5WQ=; b=QB0iWyLAU0c+xUAm9VED1tGFiyh7uZu9/eseByx7SMUsTl0Sy1RmtfGXVeomNBCEdn zb+33UT4EzVDYRT7YQe9BrjxRY4SupulUBsO1B5Xu5Ul5AgZdHh4WYkzqEBrySoEc+Ep HWLn4jQTCjUTx+0XrRWFiuABmftfWbnajMASyqtHL6HMEwKxr4wjo0wkTm3IEa68spsR ZIPuBmk4Ieq7nS8VmopReVlwJIs7R/PoEiMP44jFpQYRDBtFT+1EuXetCxxa4jQ1LMSW nDFOcvxdksJJlHu0VIf55IBSiP3tnis4v7Zu3Zkprraz/Wd3NYQ7Ks96exnncIt9SsXn HQqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Yt6N2aX6RjTV8ey7tH1MG5YP2S2wCxXaUz++48Vz5WQ=; b=NC7IO4hkgLxX4LzUvWiNrQ8yC6v/s/WgIQbnWuLrpTs2i+GverDhKMj0Qm3/4eTh2h HmfVPPE0Tru2ZJpJlaPPNFr3ITbE/EsFNCUFzvBgz+CyumMsxBj4GiLikvMsRTy1JAJ4 GaVTVWudGR7a915DNUhrYOG7D1I27c9ZQ0qP3dsKhiHyy7BAwUPS7F+xj3p7J57PHLRT ldN/3WHgKYznBQroHZi/u4Ya+yG5v155k2CVBfX+fZCjK/KSMH8f795gQGBwzg+Yqv15 aUjWwQNJZH+7m5VvbHe19lNuLlxrmPr7IY1L6w1zebO4ER5J3ZKsRGS6kTeeGJkKzIUA Nh5A== X-Gm-Message-State: AOAM532Fh6kie/tEDX5w06AWhy0wM9GXiOcVnYLYFI08UbTt1+EF+QvQ 5XVWbrao+ThFhG/u7YoF0SGlosJn2lHzQ4Ue7XA= X-Received: by 2002:a17:90b:3647:: with SMTP id nh7mr29470822pjb.228.1626776901079; Tue, 20 Jul 2021 03:28:21 -0700 (PDT) MIME-Version: 1.0 References: <20210716101602.1891-1-laurentiu.tudor@nxp.com> <2a0f7fa6-b164-eeb4-118a-acd57d79a484@nxp.com> In-Reply-To: <2a0f7fa6-b164-eeb4-118a-acd57d79a484@nxp.com> From: Andy Shevchenko Date: Tue, 20 Jul 2021 13:27:40 +0300 Message-ID: Subject: Re: [PATCH] software node: balance refcount for managed sw nodes To: Laurentiu Tudor Cc: Andy Shevchenko , Jon Nettleton , Heikki Krogerus , Greg Kroah-Hartman , "Rafael J . Wysocki" , ACPI Devel Maling List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 20, 2021 at 12:22 PM Laurentiu Tudor wrote: > On 7/19/2021 3:22 PM, Andy Shevchenko wrote: > > On Mon, Jul 19, 2021 at 03:00:17PM +0300, Laurentiu Tudor wrote: > >> On 7/16/2021 8:21 PM, Jon Nettleton wrote: > >>> On Fri, Jul 16, 2021 at 2:17 PM Andy Shevchenko > >>> wrote: > >>>> > >>>> On Fri, Jul 16, 2021 at 01:16:02PM +0300, laurentiu.tudor@nxp.com wrote: > >>>>> From: Laurentiu Tudor > >>>>> > >>>>> software_node_notify(), on KOBJ_REMOVE drops the refcount twice on managed > >>>>> software nodes, thus leading to underflow errors. Balance the refcount by > >>>>> bumping it in the device_create_managed_software_node() function. > >>>>> > >>>>> The error [1] was encountered after adding a .shutdown() op to our > >>>>> fsl-mc-bus driver. > >>>> > >>>> Looking into the history of adding ->shutdown() to dwc3 driver (it got reverted > >>>> later on), I can tell that probably something is wrong in the ->shutdown() > >>>> method itself. > >>> > >>> Isn't the other alternative to just remove the second kobject_put from > >>> KOBJ_REMOVE ? > >> > >> Or maybe on top of Heikki's suggestion, replace the calls to > >> sysfs_create_link() from KOBJ_ADD with sysfs_create_link_nowarn()? > > > > _noearn will hide the problem. It was there, it was removed from there. > > Perhaps we have to understand the root cause better (some specific flow?). > > > > Any insight from you on the flow when the issue appears? I.o.w. what happened > > on the big picture that we got into the warning you see? > > I encountered the initial issue when trying to shut down a system booted > with ACPI but only after adding a .shutdown() callback to our bus driver > so that the devices are properly taken down. The problem was that > software_node_notify(), on KOBJ_REMOVE was dropping the reference count > twice leading to an underflow error. My initial proposal was to just > bump the refcount in device_create_managed_software_node(). The device > properties that triggered the problem are created here [1]. > > Heikko suggested that instead of manually incrementing the refcount to > use software_node_notify(KOBJ_ADD). This triggered the second issue, a > duplicated sysfs entry warning originating in the usb subsystem: > device_create_managed_software_node() ends up being called twice, once > here [2] and secondly, the place I previous mentioned [1]. This [3] is what I have reported against DWC3 when ->shutdown() has been added there. And here [4] is another thread about the issue with that callback. The ->release() callback is called at put_device() [5] and ->shutdown() is called before that [6]. That said, can you inspect your ->shutdown() implementation once more time and perhaps see if there is anything that can be amended? > [1] > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/acpi/arm64/iort.c#n952 > [2] > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/dwc3/host.c#n111 [3]: https://lore.kernel.org/linux-usb/CAHp75Vd-5U5zgtDfM5C3Jsx51HVYB+rNcHYC2XP=G7dOd=cdTg@mail.gmail.com/ [4]: https://lore.kernel.org/linux-usb/c3c75895-313a-5be7-6421-b32bac741a88@arm.com/T/#u [5]: https://elixir.bootlin.com/linux/latest/source/drivers/base/core.c#L2216 [6]: https://elixir.bootlin.com/linux/latest/source/drivers/base/core.c#L4447 -- With Best Regards, Andy Shevchenko