From patchwork Fri Nov 14 12:26:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 40818 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 94422240ED for ; Fri, 14 Nov 2014 12:33:54 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id x13sf9053399wgg.5 for ; Fri, 14 Nov 2014 04:33:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=IKF6MBAvYWEETVs4b1MlsdR65tVcGlOr2ACR1sJ7ycs=; b=BkBYXcBs5yrxUjFBHopx29v2cfQcjo9CMHries4HvrJJF2jN3qw5gB8BoEtvygtYQe QWLFCqiGV8FCMFi/AyVheg6RjDYmcY0PWBid1gMqC6EHT1xI8DqvBlvUQX5vEC9mgT9i IkM7w5xfu1KW13ETlUg5M/KaDJlk1FKx2LqwO2Rn0fQx3fcwiF+Uuv32e22UVwVtyFLo Wdlr1tIaGWxLWlR0VdLbz4ialwce/bd4OAEIIOfCw2dKuJG3w7VoB1d/TWjPZn4SDkve W0aeFzJEUOaFMd5fZB+aTxQTQAxIeZD8iOSh+nY85B3Y58GOqjRpqA6U8f3gQNMsSxaA 3xIQ== X-Gm-Message-State: ALoCoQnl3zc9lf7IbaQdzzoV4AChYU5eN0X249HIeXi0Tb0ERd+SLGHG41BBGQMhWkWTmQRIyBOO X-Received: by 10.112.166.102 with SMTP id zf6mr445279lbb.12.1415968433837; Fri, 14 Nov 2014 04:33:53 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.200 with SMTP id x8ls836726lae.76.gmail; Fri, 14 Nov 2014 04:33:53 -0800 (PST) X-Received: by 10.152.36.165 with SMTP id r5mr1619045laj.91.1415968433624; Fri, 14 Nov 2014 04:33:53 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id xo10si41507660lbb.74.2014.11.14.04.33.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Nov 2014 04:33:53 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id gm9so14860028lab.19 for ; Fri, 14 Nov 2014 04:33:53 -0800 (PST) X-Received: by 10.153.7.170 with SMTP id dd10mr7991284lad.44.1415968433525; Fri, 14 Nov 2014 04:33:53 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp755910lbc; Fri, 14 Nov 2014 04:33:52 -0800 (PST) X-Received: by 10.68.111.161 with SMTP id ij1mr9911780pbb.10.1415968083175; Fri, 14 Nov 2014 04:28:03 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id tf10si28257803pab.175.2014.11.14.04.28.02 for ; Fri, 14 Nov 2014 04:28:03 -0800 (PST) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933815AbaKNM1v (ORCPT + 1 other); Fri, 14 Nov 2014 07:27:51 -0500 Received: from cantor2.suse.de ([195.135.220.15]:59475 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935368AbaKNM1Z (ORCPT ); Fri, 14 Nov 2014 07:27:25 -0500 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 67AE575050; Fri, 14 Nov 2014 12:26:59 +0000 (UTC) Received: from ku by ip4-83-240-18-248.cust.nbox.cz with local (Exim 4.83) (envelope-from ) id 1XpFxf-0002e5-4I; Fri, 14 Nov 2014 13:26:47 +0100 From: Jiri Slaby To: stable@vger.kernel.org Cc: Yijing Wang , Weng Meiling , Jiri Slaby Subject: [patch added to the 3.12 stable tree] sysfs: driver core: Fix glue dir race condition by gdp_mutex Date: Fri, 14 Nov 2014 13:26:42 +0100 Message-Id: <1415968006-9521-102-git-send-email-jslaby@suse.cz> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1415968006-9521-1-git-send-email-jslaby@suse.cz> References: <1415968006-9521-1-git-send-email-jslaby@suse.cz> Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Yijing Wang This patch has been added to the 3.12 stable tree. If you have any objections, please let us know. =============== commit e4a60d139060975eb956717e4f63ae348d4d8cc5 upstream. There is a race condition when removing glue directory. It can be reproduced in following test: path 1: Add first child device device_add() get_device_parent() /*find parent from glue_dirs.list*/ list_for_each_entry(k, &dev->class->p->glue_dirs.list, entry) if (k->parent == parent_kobj) { kobj = kobject_get(k); break; } .... class_dir_create_and_add() path2: Remove last child device under glue dir device_del() cleanup_device_parent() cleanup_glue_dir() kobject_put(glue_dir); If path2 has been called cleanup_glue_dir(), but not call kobject_put(glue_dir), the glue dir is still in parent's kset list. Meanwhile, path1 find the glue dir from the glue_dirs.list. Path2 may release glue dir before path1 call kobject_get(). So kernel will report the warning and bug_on. This is a "classic" problem we have of a kref in a list that can be found while the last instance could be removed at the same time. This patch reuse gdp_mutex to fix this race condition. The following calltrace is captured in kernel 3.4, but the latest kernel still has this bug. ----------------------------------------------------- <4>[ 3965.441471] WARNING: at ...include/linux/kref.h:41 kobject_get+0x33/0x40() <4>[ 3965.441474] Hardware name: Romley <4>[ 3965.441475] Modules linked in: isd_iop(O) isd_xda(O)... ... <4>[ 3965.441605] Call Trace: <4>[ 3965.441611] [] warn_slowpath_common+0x7a/0xb0 <4>[ 3965.441615] [] warn_slowpath_null+0x15/0x20 <4>[ 3965.441618] [] kobject_get+0x33/0x40 <4>[ 3965.441624] [] get_device_parent.isra.11+0x135/0x1f0 <4>[ 3965.441627] [] device_add+0xd4/0x6d0 <4>[ 3965.441631] [] ? dev_set_name+0x3c/0x40 .... <2>[ 3965.441912] kernel BUG at ..../fs/sysfs/group.c:65! <4>[ 3965.441915] invalid opcode: 0000 [#1] SMP ... <4>[ 3965.686743] [] sysfs_create_group+0xe/0x10 <4>[ 3965.686748] [] blk_trace_init_sysfs+0x14/0x20 <4>[ 3965.686753] [] blk_register_queue+0x3b/0x120 <4>[ 3965.686756] [] add_disk+0x1cc/0x490 .... ------------------------------------------------------- Signed-off-by: Yijing Wang Signed-off-by: Weng Meiling Signed-off-by: Jiri Slaby --- drivers/base/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 34abf4d8a45f..944fecd32e9f 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -812,12 +812,12 @@ class_dir_create_and_add(struct class *class, struct kobject *parent_kobj) return &dir->kobj; } +static DEFINE_MUTEX(gdp_mutex); static struct kobject *get_device_parent(struct device *dev, struct device *parent) { if (dev->class) { - static DEFINE_MUTEX(gdp_mutex); struct kobject *kobj = NULL; struct kobject *parent_kobj; struct kobject *k; @@ -881,7 +881,9 @@ static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir) glue_dir->kset != &dev->class->p->glue_dirs) return; + mutex_lock(&gdp_mutex); kobject_put(glue_dir); + mutex_unlock(&gdp_mutex); } static void cleanup_device_parent(struct device *dev)