Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp500769yba; Mon, 1 Apr 2019 10:33:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqz64GPCTgFbUdL4UHyr2oEeS/7flyS0qd8gTl5TyFO7gUCuG/qdsd49H8jP3kmcBl1Zua2a X-Received: by 2002:a17:902:b706:: with SMTP id d6mr29660740pls.250.1554139990037; Mon, 01 Apr 2019 10:33:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554139990; cv=none; d=google.com; s=arc-20160816; b=VmYNMebTMuioEcWTwKyOCbDZh5a9zVtjhtWn6hA67NjRNyEmJXStysxe1/J5oKTA4R mtTJr0NAMz7WPpGbTBfKkerbieLgm+HY/fyQuAckOQ4ySL8T2rcuWTElQmsHTuVBt9dd L4JEBmu04ONyb9Ly+HxH545Fitjh8tCYQMbP7mLwl++ErJ+gRJcZT7sN5ttpBbbkVlxf zaDW+W56t/1wBFORcySFkPfoTKnXnRZhtt/tLsNowBCDXhKjoo9K4jOUKiaY078F0l0Q z5q2XyesVKkh8ZPasv7hhieYmCmn4K3KsW+bo00ReSnEsXr3VGHFmnz/Z7Ygfh9gXIJD wCSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rsCADEFmMZFUxcRKAeQLWPWTCXk07TeJ4u7BLR6nUq4=; b=ADVwNx4XmQN30PlGQQjiJfw1eDMsoZbdKB4gciyssG/8tiJdoB+V+PvUaUUpucVBKP rHzlw2U7hJ0vlQZA7wnhn7ZIEN4CGW60IFqURxFxEgYt2lr62UBkpqHrCXfBqMWzTlJ7 gdInLFyebfIQVQRNFf8uX8BkqsBjUXxgwo/lpCL3C0Knhe1PxUB+9B+yeKaArg2lZXY9 wUKIan88BZa9tlWRxvNb+sJdnPtxhADaYjBVW2CdtCB0JV6PZ1/H+pqIkap+j0GPFkVY dru5qLOhxPZNqfCEUdSJbUB7ycpj/vkItVw3Tbe7sB+7d82MmDxd2iFY1VeiIdmW3Cw3 KfWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HDVPLMjg; 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 ct1si9500227plb.419.2019.04.01.10.32.54; Mon, 01 Apr 2019 10:33:10 -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=HDVPLMjg; 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 S1733198AbfDARcU (ORCPT + 99 others); Mon, 1 Apr 2019 13:32:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:40232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387467AbfDARcO (ORCPT ); Mon, 1 Apr 2019 13:32:14 -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 91BC12171F; Mon, 1 Apr 2019 17:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554139934; bh=e21tnhzIBXTZ/hwcND+cZU1nzaTqWuPe/sQxrkgRaO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HDVPLMjgLwO55iyZTTBHQjzXZm2oLwOFRzxp70pecVkH+TIg/R0xzFg3yMK7ug3GH Hefba2vHJ9CU2XFurCZ1Kf4KQ3jkTYtA4NtaY/hQfp3cbMYTg6/5Z3PGNYuuV7wbDW LGywZaz481LkFopjLjFkeNJrEaZjQjKuxYsmCdTA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Shishkin , Sasha Levin Subject: [PATCH 4.4 058/131] stm class: Fix locking in unbinding policy path Date: Mon, 1 Apr 2019 19:02:08 +0200 Message-Id: <20190401170057.179898582@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170051.645954551@linuxfoundation.org> References: <20190401170051.645954551@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 4c127fd16e6b33ecb7badc091480c84ea9aebeb6 ] Right now, if stm device removal has to unbind from a policy (that is, an stm device that has STP policy, gets removed), it will trigger a nested lock on the stm device's policy mutex. This patch fixes the problem by moving the locking from the policy unbinding to policy removal (configfs path), where it's actually needed; the other caller of the policy unbinding function already takes the mutex around the call. Signed-off-by: Alexander Shishkin Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/hwtracing/stm/policy.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/hwtracing/stm/policy.c b/drivers/hwtracing/stm/policy.c index 11ab6d01adf6..94d3abfb737a 100644 --- a/drivers/hwtracing/stm/policy.c +++ b/drivers/hwtracing/stm/policy.c @@ -272,13 +272,17 @@ void stp_policy_unbind(struct stp_policy *policy) { struct stm_device *stm = policy->stm; + /* + * stp_policy_release() will not call here if the policy is already + * unbound; other users should not either, as no link exists between + * this policy and anything else in that case + */ if (WARN_ON_ONCE(!policy->stm)) return; - mutex_lock(&stm->policy_mutex); - stm->policy = NULL; - mutex_unlock(&stm->policy_mutex); + lockdep_assert_held(&stm->policy_mutex); + stm->policy = NULL; policy->stm = NULL; stm_put_device(stm); @@ -287,8 +291,16 @@ void stp_policy_unbind(struct stp_policy *policy) static void stp_policy_release(struct config_item *item) { struct stp_policy *policy = to_stp_policy(item); + struct stm_device *stm = policy->stm; + /* a policy *can* be unbound and still exist in configfs tree */ + if (!stm) + return; + + mutex_lock(&stm->policy_mutex); stp_policy_unbind(policy); + mutex_unlock(&stm->policy_mutex); + kfree(policy); } -- 2.19.1