Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2297028ybf; Mon, 2 Mar 2020 05:59:12 -0800 (PST) X-Google-Smtp-Source: APXvYqwYcNJnmWDiWbTvm4gw0fERmgwQ0kg+bcCSTrFYgA+uJIQKKVaSBmrJNHEIQ+dC769XBjcT X-Received: by 2002:a05:6808:191:: with SMTP id w17mr11177453oic.29.1583157552711; Mon, 02 Mar 2020 05:59:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583157552; cv=none; d=google.com; s=arc-20160816; b=peQCcFEtTg8xPFqn05J+0RdHZgupspR6dtW+m7JruakkTWlcIwwCdpb/B+7VC6BAq1 TSyrceaUOjimLJ9Mu48akHyQG1jyFIJ84vl7+za+ETcufWlcs1RMaFppD1vSL1elmLJ6 aj/179atV2YHUPHTfLGjHvcCmQHHFEMDyCeTFzLzBcrm8ouxD25AYMj0Tn89OTSK/4rY WENgoqN4f+93ylHoD+Sp84BNXhAC9EuAzaFsY38sNikCvpSXrazs/btZ6zbf+y917KBL reXd8n7mO1cl7yAwK+xULDDCwyuzqfhT4l6SucAQktoE/634+80DAcP2KRcj5FEAHHyA Mduw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=rfvy12cE2HA4jYpFxu4MhOHRqTEnSnQHTwhM3oCjYbA=; b=zM+edCp/0/ffVd2GocXf2/2XDkdSA7d3VHBFPusCLAKInovFr41HE/wUBOdnn8RGYV bPdSZfmgf1rSus1bOksDbHkELmr3q4QFStRnjFbn+SaMLYBydjVvUmbLIY1hU4UMlJSl OT871aCe3BWqKJdPF5ZCTkhUOWeU8uyhIQF0UkF2kyBNYx+slg6jfaFAN0606xWxS2Nk r4zjL4ruJBhScAdDPB+akw0kYTGIbZ4mOxF+zLDkoVONY9AMduBP49bspUuJejhTcA1+ zwo0bRUfXYca3srj2lqd/VMWTddhuZSYUpmOrMKHY2r26w66vPA5DRD3atG8hT+N7xUM 0eHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 110si6509457otj.303.2020.03.02.05.59.01; Mon, 02 Mar 2020 05:59:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726805AbgCBN5n (ORCPT + 99 others); Mon, 2 Mar 2020 08:57:43 -0500 Received: from mga03.intel.com ([134.134.136.65]:39949 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726451AbgCBN5n (ORCPT ); Mon, 2 Mar 2020 08:57:43 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Mar 2020 05:57:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,507,1574150400"; d="scan'208";a="351545030" Received: from kuha.fi.intel.com ([10.237.72.53]) by fmsmga001.fm.intel.com with SMTP; 02 Mar 2020 05:57:39 -0800 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Mon, 02 Mar 2020 15:57:38 +0200 Date: Mon, 2 Mar 2020 15:57:38 +0200 From: Heikki Krogerus To: Brendan Higgins Cc: gregkh@linuxfoundation.org, rafael@kernel.org, linux-kernel@vger.kernel.org, davidgow@google.com, Heidi Fahim , Hans de Goede , "Rafael J . Wysocki" Subject: Re: [PATCH v1] Revert "software node: Simplify software_node_release() function" Message-ID: <20200302135738.GD22243@kuha.fi.intel.com> References: <20200228000001.240428-1-brendanhiggins@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200228000001.240428-1-brendanhiggins@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 27, 2020 at 04:00:01PM -0800, Brendan Higgins wrote: > This reverts commit 3df85a1ae51f6b256982fe9d17c2dc5bfb4cc402. > > The reverted commit says "It's possible to release the node ID > immediately when fwnode_remove_software_node() is called, no need to > wait for software_node_release() with that." However, releasing the node > ID before waiting for software_node_release() to be called causes the > node ID to be released before the kobject and the underlying sysfs > entry; this means there is a period of time where a sysfs entry exists > that is associated with an unallocated node ID. > > Once consequence of this is that there is a race condition where it is > possible to call fwnode_create_software_node() with no parent node > specified (NULL) and have it fail with -EEXIST because the node ID that > was assigned is still associated with a stale sysfs entry that hasn't > been cleaned up yet. > > Although it is difficult to reproduce this race condition under normal > conditions, it can be deterministically reproduced with the following > minconfig on UML: > > CONFIG_KUNIT_DRIVER_PE_TEST=y > CONFIG_DEBUG_KERNEL=y > CONFIG_DEBUG_OBJECTS=y > CONFIG_DEBUG_OBJECTS_TIMERS=y > CONFIG_DEBUG_KOBJECT_RELEASE=y > CONFIG_KUNIT=y > > Running the tests with this configuration causes the following failure: > > > kobject: 'node0' ((____ptrval____)): kobject_release, parent (____ptrval____) (delayed 400) > ok 1 - pe_test_uints > sysfs: cannot create duplicate filename '/kernel/software_nodes/node0' > CPU: 0 PID: 28 Comm: kunit_try_catch Not tainted 5.6.0-rc3-next-20200227 #14 > > kobject_add_internal failed for node0 with -EEXIST, don't try to register things with the same name in the same directory. > kobject: 'node0' ((____ptrval____)): kobject_release, parent (____ptrval____) (delayed 100) > # pe_test_uint_arrays: ASSERTION FAILED at drivers/base/test/property-entry-test.c:123 > Expected node is not error, but is: -17 > not ok 2 - pe_test_uint_arrays > > > Reported-by: Heidi Fahim > Signed-off-by: Brendan Higgins > Cc: Heikki Krogerus > Cc: Hans de Goede > Cc: Rafael J. Wysocki Reviewed-by: Heikki Krogerus > --- > drivers/base/swnode.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c > index 0b081dee1e95c..de8d3543e8fe3 100644 > --- a/drivers/base/swnode.c > +++ b/drivers/base/swnode.c > @@ -608,6 +608,13 @@ static void software_node_release(struct kobject *kobj) > { > struct swnode *swnode = kobj_to_swnode(kobj); > > + if (swnode->parent) { > + ida_simple_remove(&swnode->parent->child_ids, swnode->id); > + list_del(&swnode->entry); > + } else { > + ida_simple_remove(&swnode_root_ids, swnode->id); > + } > + > if (swnode->allocated) { > property_entries_free(swnode->node->properties); > kfree(swnode->node); > @@ -773,13 +780,6 @@ void fwnode_remove_software_node(struct fwnode_handle *fwnode) > if (!swnode) > return; > > - if (swnode->parent) { > - ida_simple_remove(&swnode->parent->child_ids, swnode->id); > - list_del(&swnode->entry); > - } else { > - ida_simple_remove(&swnode_root_ids, swnode->id); > - } > - > kobject_put(&swnode->kobj); > } > EXPORT_SYMBOL_GPL(fwnode_remove_software_node); > -- > 2.25.1.481.gfbce0eb801-goog thanks, -- heikki