Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2124326yba; Sun, 5 May 2019 23:24:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqyEi/CdL6f6DlxhY7a9DmwbD4rimSVmrGLKdD9mpy5RnYNyy577X09bmF96Y/7JbQ9/YSdl X-Received: by 2002:a17:902:1621:: with SMTP id g30mr30019426plg.168.1557123873551; Sun, 05 May 2019 23:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557123873; cv=none; d=google.com; s=arc-20160816; b=IhgLOMuCvfqDORO1ETFaFEp0VMrnNExo2wkdHBJjMaOBW660L/SuzqvHjqh3DG+67y Ung99L2N4tF/g6tpLUm3li8y1uNirwEq/9cvx0mflfwve4EWumD/iwYR7EJxaF9GdPAB gBrYeOMNMdJEZPlwDF7jAofFg+4xzvQyQaF0U9A5osdG1I7zfnLLDzhBITLMKqbrP8JA 7IjinSU6b9S6ewge9g6u8dT0oeSmDN/xKcLul/GzcbuKBu+kMp6S+4y8pHvbhDmAiAZC D9E9o7KPi/fwixWYJK9lcrleRZe/MtQGeawYfJarHi+4vyAENQHcZY7GLqoEWrcoBpHa DqqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=b18WadlpfU9oe5rGG0Q4s+11WJEwPwBvOb1dnLdkGPg=; b=bRA1ORaNkkxTC/ZM9uEqN/f31q5yuuL3mMnA/Xp9SyXhy0f21+1I8g19GnoGYYXiH8 Qgkovh2sU8zIz1k5S5AQSFOjHz9yYDcS7c7mpKJvYvZlom5A8mdZdoCYHkAbQkfGt1j7 j6AQRKsb+uUwti5xCw21zrCzT1jK9hugz6ZN6aHABEhBegFm3dBAd/U+hvlRhBF823Yz eAlzdP+CTY+G8t7CurjJLtmQ8M9eY0Hojabd+/RhhwXzlbIkZbeMEEzitKPNHKfrTiIS Txg9tipw8zDueV1IjHJx+gfr9B9qI4YWLv1b7vMHMobt/+c5DPAEI0clM1V3lxYZhleM oKJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=W5ApHSdO; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12si13461073pfn.135.2019.05.05.23.24.18; Sun, 05 May 2019 23:24:33 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=W5ApHSdO; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726162AbfEFGVc (ORCPT + 99 others); Mon, 6 May 2019 02:21:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:33180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725828AbfEFGVb (ORCPT ); Mon, 6 May 2019 02:21:31 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D2290206A3; Mon, 6 May 2019 06:21:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557123690; bh=Zzsevc3QFsdcI+m74gIccvrYIxck4T0/TqqA55LEfsk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=W5ApHSdOOJKw22qIecHl5v2w3x4janhQpYuAOJ+bv/ZjzuNmaY17JITsB3F8xDp5H 9EA3aOwnyGRjBrgG1yoUS9reCRCZBK9XCzRH3+q8+4jE+mtq4NdcHRRPhYgd4yP65v rB/XbzFfQjdHXjtVPMfQHOfkhCL42ve4tM4dQ80E= Date: Mon, 6 May 2019 08:21:27 +0200 From: Greg KH To: Prateek Sood Cc: rafael@kernel.org, sramana@codeaurora.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] drivers: core: Remove glue dirs early only when refcount is 1 Message-ID: <20190506062127.GC9557@kroah.com> References: <20190501065313.GA30616@kroah.com> <1556711999-16898-1-git-send-email-prsood@codeaurora.org> <0aac6bf3-6691-7c5a-31f1-fb7231c6b585@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0aac6bf3-6691-7c5a-31f1-fb7231c6b585@codeaurora.org> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 06, 2019 at 10:41:34AM +0530, Prateek Sood wrote: > On 5/1/19 5:29 PM, Prateek Sood wrote: > > While loading firmware blobs parallely in different threads, it is possible > > to free sysfs node of glue_dirs in device_del() from a thread while another > > thread is trying to add subdir from device_add() in glue_dirs sysfs node. > > > > CPU1 CPU2 > > fw_load_sysfs_fallback() > > device_add() > > get_device_parent() > > class_dir_create_and_add() > > kobject_add_internal() > > create_dir() // glue_dir > > > > fw_load_sysfs_fallback() > > device_add() > > get_device_parent() > > kobject_get() //glue_dir > > > > device_del() > > cleanup_glue_dir() > > kobject_del() > > > > kobject_add() > > kobject_add_internal() > > create_dir() // in glue_dir > > kernfs_create_dir_ns() > > > > sysfs_remove_dir() //glue_dir->sd=NULL > > sysfs_put() // free glue_dir->sd > > > > kernfs_new_node() > > kernfs_get(glue_dir) > > > > Fix this race by making sure that kernfs_node for glue_dir is released only > > when refcount for glue_dir kobj is 1. > > > > Signed-off-by: Prateek Sood > > > > --- > > > > Changes from v2->v3: > > - Added patch version change related comments. > > > > Changes from v1->v2: > > - Updated callstack from _request_firmware_load() to fw_load_sysfs_fallback(). > > > > > > drivers/base/core.c | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/base/core.c b/drivers/base/core.c > > index 4aeaa0c..3955d07 100644 > > --- a/drivers/base/core.c > > +++ b/drivers/base/core.c > > @@ -1820,12 +1820,15 @@ static inline struct kobject *get_glue_dir(struct device *dev) > > */ > > static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir) > > { > > + unsigned int refcount; > > + > > /* see if we live in a "glue" directory */ > > if (!live_in_glue_dir(glue_dir, dev)) > > return; > > > > mutex_lock(&gdp_mutex); > > - if (!kobject_has_children(glue_dir)) > > + refcount = kref_read(&glue_dir->kref); > > + if (!kobject_has_children(glue_dir) && !--refcount) > > kobject_del(glue_dir); > > kobject_put(glue_dir); > > mutex_unlock(&gdp_mutex); > > > > Folks, > > Please share feedback on the race condition and the patch to > fix it. Please relax, we will get to this eventually, it has only been a week... greg k-h