Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1822027imm; Mon, 3 Sep 2018 10:19:01 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda8Mz+rPAdc9a4yJ/rAh4J/FnXZlk1MuW6pe5Z71ND6CjTV+SVDn7QIpDvMt6wSYd8+xcRE X-Received: by 2002:a62:d44a:: with SMTP id u10-v6mr22921044pfl.144.1535995140923; Mon, 03 Sep 2018 10:19:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995140; cv=none; d=google.com; s=arc-20160816; b=DHraSQHwOe7rIcm8dn+l1oxbTPHO4odxRBbxjrKt2DaC9NvlxX0Im/fqMM73RVAGCU KziiLzyNu9LLJuGAg05VuQbS5x1ccr3xohXW7Iew2Bbp4tCvP71WzN2LpnYTl2fcWmeE bGtUmhpaV+cwCH0QvVX+nDv40tfrXro7s6ebzI1QqRX8qqCv1iLvE5AvC8hDqBf8M/l1 c8RWvIQHFo3UoqrgpPZMnkvzpzMuho6DQKyI/dn1iI6oZpg0/nyrbin5Off807jqfb+4 RqugqwXEy3g/oM+HQc5SUW7cIHuleK9LWpszWhhIrP1GFYNeRqSzAYltxFI45xWNiDzC O9LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Ql6QstdAs2PC4FUnw7NJWGFfbCZBtLSxAzsJQZ1Jm0I=; b=OpPmviQwv1gk7h4MNgAYy4mi48qWDGfWQcrfraHXNOm0qZoMzNWQGUCujjGQlpXFUm vFTd6zp2VxiUhafbffs6kqggsS+UOKHn5JSC46mg1RqAbIhy+i5f8axTAO0aJ3WriUUy SKk+JD8Gv/AOjNTdkr70abjDgnRYBWLYMMLBMiljHnznW4SQ86afagz9UZWioldu5ZOZ +nJXP+9et7mUXD0BRqs7l96/mK7Di7vAQt3xNo08r5fjrOBNswq1MaU91Wi1acWKU6nE YSjW0Yc0Tz/iZCCtUL3qCW4TLFh2mAaZIIjxWbgFEir/ji1/b6opAdQVZKR1MHWkUZBk XB+A== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg2-v6si17114311plb.243.2018.09.03.10.18.46; Mon, 03 Sep 2018 10:19:00 -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; 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 S1730208AbeICVir (ORCPT + 99 others); Mon, 3 Sep 2018 17:38:47 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42874 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728730AbeICVir (ORCPT ); Mon, 3 Sep 2018 17:38:47 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 775D6D12; Mon, 3 Sep 2018 17:17:41 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Sperbeck , Peter Rosin , "Peter Zijlstra (Intel)" , Davidlohr Bueso , Deepa Dinamani , Linus Torvalds , Peter Chang , Philippe Ombredanne , Thomas Gleixner , Will Deacon , Wolfram Sang , Ingo Molnar , Sasha Levin Subject: [PATCH 4.14 048/165] i2c/mux, locking/core: Annotate the nested rt_mutex usage Date: Mon, 3 Sep 2018 18:55:34 +0200 Message-Id: <20180903165657.533076792@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peter Rosin [ Upstream commit 7b94ea50514d1a0dc94f02723b603c27bc0ea597 ] If an i2c topology has instances of nested muxes, then a lockdep splat is produced when when i2c_parent_lock_bus() is called. Here is an example: ============================================ WARNING: possible recursive locking detected -------------------------------------------- insmod/68159 is trying to acquire lock: (i2c_register_adapter#2){+.+.}, at: i2c_parent_lock_bus+0x32/0x50 [i2c_mux] but task is already holding lock: (i2c_register_adapter#2){+.+.}, at: i2c_parent_lock_bus+0x32/0x50 [i2c_mux] other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(i2c_register_adapter#2); lock(i2c_register_adapter#2); *** DEADLOCK *** May be due to missing lock nesting notation 1 lock held by insmod/68159: #0: (i2c_register_adapter#2){+.+.}, at: i2c_parent_lock_bus+0x32/0x50 [i2c_mux] stack backtrace: CPU: 13 PID: 68159 Comm: insmod Tainted: G O Call Trace: dump_stack+0x67/0x98 __lock_acquire+0x162e/0x1780 lock_acquire+0xba/0x200 rt_mutex_lock+0x44/0x60 i2c_parent_lock_bus+0x32/0x50 [i2c_mux] i2c_parent_lock_bus+0x3e/0x50 [i2c_mux] i2c_smbus_xfer+0xf0/0x700 i2c_smbus_read_byte+0x42/0x70 my2c_init+0xa2/0x1000 [my2c] do_one_initcall+0x51/0x192 do_init_module+0x62/0x216 load_module+0x20f9/0x2b50 SYSC_init_module+0x19a/0x1c0 SyS_init_module+0xe/0x10 do_syscall_64+0x6c/0x1a0 entry_SYSCALL_64_after_hwframe+0x42/0xb7 Reported-by: John Sperbeck Tested-by: John Sperbeck Signed-off-by: Peter Rosin Signed-off-by: Peter Zijlstra (Intel) Cc: Davidlohr Bueso Cc: Deepa Dinamani Cc: Greg Kroah-Hartman Cc: Linus Torvalds Cc: Peter Chang Cc: Peter Zijlstra Cc: Philippe Ombredanne Cc: Thomas Gleixner Cc: Will Deacon Cc: Wolfram Sang Link: http://lkml.kernel.org/r/20180720083914.1950-3-peda@axentia.se Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-core-base.c | 2 +- drivers/i2c/i2c-mux.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -638,7 +638,7 @@ static int i2c_check_addr_busy(struct i2 static void i2c_adapter_lock_bus(struct i2c_adapter *adapter, unsigned int flags) { - rt_mutex_lock(&adapter->bus_lock); + rt_mutex_lock_nested(&adapter->bus_lock, i2c_adapter_depth(adapter)); } /** --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c @@ -144,7 +144,7 @@ static void i2c_mux_lock_bus(struct i2c_ struct i2c_mux_priv *priv = adapter->algo_data; struct i2c_adapter *parent = priv->muxc->parent; - rt_mutex_lock(&parent->mux_lock); + rt_mutex_lock_nested(&parent->mux_lock, i2c_adapter_depth(adapter)); if (!(flags & I2C_LOCK_ROOT_ADAPTER)) return; i2c_lock_bus(parent, flags); @@ -181,7 +181,7 @@ static void i2c_parent_lock_bus(struct i struct i2c_mux_priv *priv = adapter->algo_data; struct i2c_adapter *parent = priv->muxc->parent; - rt_mutex_lock(&parent->mux_lock); + rt_mutex_lock_nested(&parent->mux_lock, i2c_adapter_depth(adapter)); i2c_lock_bus(parent, flags); }