Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp628491ybk; Wed, 13 May 2020 08:54:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAXnyDUhQk+59LjtVhC+2eNScQk816JZIR5v4BE0QMWgh/bZhsQlpnOwyWdRvl1d1RchTq X-Received: by 2002:a05:6402:1f6:: with SMTP id i22mr260234edy.271.1589385292437; Wed, 13 May 2020 08:54:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589385292; cv=none; d=google.com; s=arc-20160816; b=GN9SuPLlk2zHgcK9QuhCsj6uiFsCdpVeY3k3DDlDs4x6rrJmkPHK3ztgUB5TtRBJLQ xCfwEM4BA2kb/bO2/YzUGga0XUr3RIgUeOW0btb2BuPd8+c/3jjWLoxI9qXwn+kQjtz+ FCcqVKquUaqGPgKA3lMy2C+MMXAcEaRyMmBTO/DlRux8TeaxByXYUq14IqgyiiAd5FM1 Ti1Rs1807qaNRHVOryzJzYSN4d03nxCv6zGSrYThcplcBbVCrnk1od33TJnhIfrhdKPE if85B3iSaiNOtqRZFy2tUYSo9lmREwSn5qXMcWOM1K/aXB5c1+0/moqnjp95kF2nStv8 +5bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=dAc2/p9/ye87n+oDzeojjYRRxgpdmDIY9Lqiy5g0GGQ=; b=X8QoM4fes0+fKPXmgQxMmokOLzzPE8UHZCTTZgM1LSJfkaso3HJB7hW+8Rdef46DvT +EhB5+C5A5fjN6BoVyBHdkmi2g6DqgyJWveOpXNKAmBiBVlkvNi0EkArEw2aqvrTKadU XkUTfwnEcjY/5pxs68uWS/9nw7zLk3vsCU6nDZ4mGzK1M1o7uIJxUFHUYtoCPeWKCgwJ LG2aA2/vxf1d9VgvnQLIz2sBK8pwXNlx/W3oxRNeY0Kt+PNS6BUrjbcAEy+Ewu1ODjuD V0JI7oRQHMCYvCFAT6zH9NCtlz+oTB9Qe9ZTPJVPWCorTRNsfYQg34MhP26gJOKYFOKm a1Nw== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w14si10318443edf.402.2020.05.13.08.54.28; Wed, 13 May 2020 08:54:52 -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; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730616AbgEMPvb (ORCPT + 99 others); Wed, 13 May 2020 11:51:31 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:44200 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729467AbgEMPva (ORCPT ); Wed, 13 May 2020 11:51:30 -0400 Received: by mail-ot1-f68.google.com with SMTP id j4so13767537otr.11 for ; Wed, 13 May 2020 08:51:29 -0700 (PDT) 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=dAc2/p9/ye87n+oDzeojjYRRxgpdmDIY9Lqiy5g0GGQ=; b=sba5PDbZAVH+2kccsiBH3k2SS1V/JG6LJ1SOyhkKI5vv2i6u6+5B7EaCrvATF9XnKQ xVo9FfrbTNzbJzr+hP/trXvWKt9gWHcQ1AKkFWUHloEKGQliQSmLkONcPTn3gza9qccx UaywyhmDJCE3eLJKAOiDrP68+FDXf6g5GmhzBvDL1aKGxSxnkT3dGn1Inu3GOiRzOC7P 3zvx+URRVKC+oPEonWma+21lKvJROaqENwtM8uCZt1CTHJCUWAwgP1fjFUfFvFhMCxZI yPm7sOfVjNM9EBR5JeCI5mDiM8pf70SnYaXNYoJSpdmG8B55j9eKUbQ04uXF6AnUvHhI B3YQ== X-Gm-Message-State: AOAM531Sb5xFcLoDk8oBU/R36oapAwDprO2V61mhELn6e+LMwAvFLESi 3cYJAQ0reSfODNIsoYTjANurvSGHs4KJFNiPf9o= X-Received: by 2002:a9d:6ac8:: with SMTP id m8mr79195otq.262.1589385089449; Wed, 13 May 2020 08:51:29 -0700 (PDT) MIME-Version: 1.0 References: <20200513151840.36400-1-heikki.krogerus@linux.intel.com> <20200513154228.GC1360420@kroah.com> In-Reply-To: <20200513154228.GC1360420@kroah.com> From: "Rafael J. Wysocki" Date: Wed, 13 May 2020 17:51:18 +0200 Message-ID: Subject: Re: [PATCH] kobject: Make sure the parent does not get released before its children To: Greg Kroah-Hartman Cc: Heikki Krogerus , Linux Kernel Mailing List , Naresh Kamboju , kernel test robot , Brendan Higgins , Randy Dunlap , "Rafael J. Wysocki" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 13, 2020 at 5:42 PM Greg Kroah-Hartman wrote: > > On Wed, May 13, 2020 at 06:18:40PM +0300, Heikki Krogerus wrote: > > In the function kobject_cleanup(), kobject_del(kobj) is > > called before the kobj->release(). That makes it possible to > > release the parent of the kobject before the kobject itself. > > > > To fix that, adding function __kboject_del() that does > > everything that kobject_del() does except release the parent > > reference. kobject_cleanup() then calls __kobject_del() > > instead of kobject_del(), and separately decrements the > > reference count of the parent kobject after kobj->release() > > has been called. > > > > Reported-by: Naresh Kamboju > > Reported-by: kernel test robot > > Fixes: 7589238a8cf3 ("Revert "software node: Simplify software_node_release() function"") > > Cc: Brendan Higgins > > Cc: Randy Dunlap > > Suggested-by: "Rafael J. Wysocki" > > Signed-off-by: Heikki Krogerus > > --- > > lib/kobject.c | 30 ++++++++++++++++++++---------- > > 1 file changed, 20 insertions(+), 10 deletions(-) > > > > diff --git a/lib/kobject.c b/lib/kobject.c > > index 65fa7bf70c57..32432036bef8 100644 > > --- a/lib/kobject.c > > +++ b/lib/kobject.c > > @@ -599,14 +599,7 @@ int kobject_move(struct kobject *kobj, struct kobject *new_parent) > > } > > EXPORT_SYMBOL_GPL(kobject_move); > > > > -/** > > - * kobject_del() - Unlink kobject from hierarchy. > > - * @kobj: object. > > - * > > - * This is the function that should be called to delete an object > > - * successfully added via kobject_add(). > > - */ > > -void kobject_del(struct kobject *kobj) > > +static void __kobject_del(struct kobject *kobj) > > { > > struct kernfs_node *sd; > > const struct kobj_type *ktype; > > @@ -625,9 +618,23 @@ void kobject_del(struct kobject *kobj) > > > > kobj->state_in_sysfs = 0; > > kobj_kset_leave(kobj); > > - kobject_put(kobj->parent); > > kobj->parent = NULL; > > } > > + > > +/** > > + * kobject_del() - Unlink kobject from hierarchy. > > + * @kobj: object. > > + * > > + * This is the function that should be called to delete an object > > + * successfully added via kobject_add(). > > + */ > > +void kobject_del(struct kobject *kobj) > > +{ > > + struct kobject *parent = kobj->parent; > > + > > + __kobject_del(kobj); > > + kobject_put(parent); > > +} > > EXPORT_SYMBOL(kobject_del); > > > > /** > > @@ -663,6 +670,7 @@ EXPORT_SYMBOL(kobject_get_unless_zero); > > */ > > static void kobject_cleanup(struct kobject *kobj) > > { > > + struct kobject *parent = kobj->parent; > > struct kobj_type *t = get_ktype(kobj); > > const char *name = kobj->name; > > > > @@ -684,7 +692,7 @@ static void kobject_cleanup(struct kobject *kobj) > > if (kobj->state_in_sysfs) { > > pr_debug("kobject: '%s' (%p): auto cleanup kobject_del\n", > > kobject_name(kobj), kobj); > > - kobject_del(kobj); > > + __kobject_del(kobj); > > } > > > > if (t && t->release) { > > @@ -698,6 +706,8 @@ static void kobject_cleanup(struct kobject *kobj) > > pr_debug("kobject: '%s': free name\n", name); > > kfree_const(name); > > } > > + > > + kobject_put(parent); > > } > > > > #ifdef CONFIG_DEBUG_KOBJECT_RELEASE > > -- > > 2.26.2 > > > > Is this the older patch we talked about before, or something else? > > I can't remember how we left that thread... This is an alternative that you said might work. :-)