Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5722909yba; Tue, 30 Apr 2019 21:25:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9lBPULixwjLFyHLr9WZgnmBT3iSNXd7TB0hz+jciVThKxwSLrPq6WqVOCtc258jKOgURJ X-Received: by 2002:aa7:8e0d:: with SMTP id c13mr77874594pfr.193.1556684744691; Tue, 30 Apr 2019 21:25:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556684744; cv=none; d=google.com; s=arc-20160816; b=IPG/Od6E+GAOyB+tT3Gc+it66TJ1ONfQ934tPZA6CR5x41w6nizxvyN5X1WLLXo537 TeRROzVxDU83zl6oT/dwXdDDu4t/4TfS0CLQ0HXpUKrF+vGSfNE/COu/Kmv/vwK/5iVE nlROmCOVJeFHQUUWrMXKRIi7yQBehAS4ZP/PMmP2lf89o3FtQ1nowlIfJXTOZhEpg2vj yD2i+4dYRokx/E95qgrV/yGhFRGVO/3TPJ/TXQzgZhFVdvhGO7VNVY7f2K6BFZe4eFW1 u17hCNvOaTAsSMWlpntIn3u401qfhSN9nryEk9kli+2gdR0Dt7EJYTGm2PcGvNbphD/V tTrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature; bh=pBoLy+r9g7h47G/CrvStbUkQjp+3KvcL5JPdb6KoTz8=; b=H0+Hc0ZR+3BZBtAWYBNLk0JBYao92YJ/Ufzrhq+v7GG8zNyYv3yInWLiZ0G5T0xi/V nkDqb3TSh1xr9u88et7XRL4fugBKjI2zcoDmxC75G95oqG7QqThbeWYBwsz44N5Px4wg NYNAdQJhz8STxzAS90qMb8NAWRNYALC/AIf3aq2mk/Nlws5RtPVSVgjX9P22jAf4xc6q g69yqU/nqA/XSy0eagu22FYmT9UZ7QAj8erm8TaBKbO5WNBtHmifCzM9YtFH9qN4TI4+ VPE6rbHFHs1l/0xQU5//Y+0xLOdw3ZW72MzXV+dFvfB5AVTnmnoXkEojm9r1EzefCDtD rE+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=E7D9mBcf; dkim=pass header.i=@codeaurora.org header.s=default header.b="RfBwtPi/"; 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 i63si40916662pli.195.2019.04.30.21.25.29; Tue, 30 Apr 2019 21:25:44 -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=@codeaurora.org header.s=default header.b=E7D9mBcf; dkim=pass header.i=@codeaurora.org header.s=default header.b="RfBwtPi/"; 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 S1726079AbfEAEXE (ORCPT + 99 others); Wed, 1 May 2019 00:23:04 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:56052 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725298AbfEAEXE (ORCPT ); Wed, 1 May 2019 00:23:04 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 184C7608D4; Wed, 1 May 2019 04:23:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1556684583; bh=9yPzt7cVWcZKP8nlRDpsy/7HZAKxdDrFJEzcJkPStZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E7D9mBcflXuLQkvW89gPzPY86YW25tNk3H07hoySU+c/Ghgj+F0Qc8XpSH24jD3p6 Wdemz5LtQg7Qw8ZESsbTaLLwT6VmZDzQSsB0jRn1yUYsu5ww5B0u3/AHJH0CGosx+0 Ske/2pExBTJdhRe560F4C+3nz+ea4wF9q4XQa8z0= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from prsood-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: prsood@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id BBC5960115; Wed, 1 May 2019 04:23:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1556684582; bh=9yPzt7cVWcZKP8nlRDpsy/7HZAKxdDrFJEzcJkPStZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RfBwtPi/edPbtS6tz27A7MR7i6+FNk6fpUQzRXpHW2RWBpAN/+0+bCYuXh6AiishN BAa0OCzMIaRVMF9P9IU1EumZyE/xuunPMBrGP1UBR3L7XQPsJoYfJ8UjFP4sh4sdBL oWgybQSjCKHhVHAj9f5SA+Q1e/dBg9LVJos+S3Hk= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org BBC5960115 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=prsood@codeaurora.org From: Prateek Sood To: gregkh@linuxfoundation.org, rafael@kernel.org Cc: sramana@codeaurora.org, prsood@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH V2] drivers: core: Remove glue dirs early only when refcount is 1 Date: Wed, 1 May 2019 09:52:47 +0530 Message-Id: <1556684567-26710-1-git-send-email-prsood@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1556632540-17382-1-git-send-email-prsood@codeaurora.org> References: <1556632540-17382-1-git-send-email-prsood@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.