Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp184200yba; Wed, 3 Apr 2019 06:56:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzo4ZyelzSvxZCcOsiTSGm+guwmijlm2R7cmOpSrytg8tiDcPwjPuWajjDDJFerpyfW93/Y X-Received: by 2002:a63:c23:: with SMTP id b35mr32537415pgl.298.1554299797653; Wed, 03 Apr 2019 06:56:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554299797; cv=none; d=google.com; s=arc-20160816; b=gdSkMndMAwMc035ZUClhixuiJWtGoi2z8M7lAR7Elo5p1TrAsCrq7VpHcouviqdxbN QMb099xVUb7IgKVrGTzClcH7jgIGVF5uyJCAo6IUVahZNqQZELKVd6mlUSBmKi/djNpZ SBdttu0P5F+740Y9W1IpRJC7pQfpPJUtBW6Ry2CwTFUpYUtL3MvmB4i2OVEobAU8SwZA 7JL6MJf4w1RDNf2Y1zTK9VJzVD+7MN1YMq7FLwp72HaKkiw6Yj6y/8mDb3K4cC2+YJPP uvO6McIF0r0YB971TYCy2nKvyRVgH0JuybGXpKpgi/xrlcKhz1UZGTVWyEzyAzTOEYJd 69Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=Y0bEWdZVKV4TP5FihrmUZWCIr/KuK3q2HAG9WN+vMQo=; b=NN755IPi4zpFLf2lPMFuhBTZJoAfUEEdlnpr4L5UAbQZeUB5eS4g7thREt/Dv3M4GU YPTgVAQ4qlgCilN2dGbe+d5FNfbOM5St2Mejbwl2DkZfJVODbJsgUR7TS/xhQHMkeoUU oa3BMM8qjh+whYRcyd8PLL7gi1ao7b7pxiSlMaGk7Y8f/0PKqPVnPS+RMorbwDqCe0ay 7L5Gqa82l1pIU9lW+RGacc5j0eZ40IhG6GsoShhLhWFIAIdoUgkXHxBsK8osvjbTRGzz AXViJ4zc04bE4Jt95oWgN0JH3F9z15HNEIFBkiN5i9V0SuDrV3EbJ8HT+naItFLzkz7Q fI+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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cirrus.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i1si13512027pgq.528.2019.04.03.06.56.22; Wed, 03 Apr 2019 06:56:37 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726409AbfDCNzl (ORCPT + 99 others); Wed, 3 Apr 2019 09:55:41 -0400 Received: from mx0a-001ae601.pphosted.com ([67.231.149.25]:52274 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725959AbfDCNzl (ORCPT ); Wed, 3 Apr 2019 09:55:41 -0400 Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x33DtW6n021944; Wed, 3 Apr 2019 08:55:32 -0500 Authentication-Results: ppops.net; spf=none smtp.mailfrom=ckeepax@opensource.cirrus.com Received: from mail4.cirrus.com ([87.246.98.35]) by mx0a-001ae601.pphosted.com with ESMTP id 2rm59s20yv-1; Wed, 03 Apr 2019 08:55:32 -0500 Received: from EX17.ad.cirrus.com (unknown [172.20.9.81]) by mail4.cirrus.com (Postfix) with ESMTP id 215E9611C8BE; Wed, 3 Apr 2019 08:56:49 -0500 (CDT) Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EX17.ad.cirrus.com (172.20.9.81) with Microsoft SMTP Server id 14.3.408.0; Wed, 3 Apr 2019 14:55:31 +0100 Received: from ediswmail.ad.cirrus.com (ediswmail.ad.cirrus.com [198.61.86.93]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 61B862DD; Wed, 3 Apr 2019 14:55:31 +0100 (BST) Date: Wed, 3 Apr 2019 14:55:31 +0100 From: Charles Keepax To: , , CC: , Subject: Regulator Potential Deadlock Message-ID: <20190403135531.GB81578@ediswmail.ad.cirrus.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904030096 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Guys, Was testing some of my hardware and hit this potential lockup: Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock((work_completion)(&(&rdev->disable_work)->work)); lock(regulator_list_mutex); lock((work_completion)(&(&rdev->disable_work)->work)); lock(regulator_list_mutex); *** DEADLOCK *** Looks like it comes from this patch: commit f8702f9e4aa7 ("regulator: core: Use ww_mutex for regulators locking") The basic problem appears to be that regulator_unregister takes the regulator_list_mutex and then calls flush_work on disable_work. But regulator_disable_work calls regulator_lock_dependent which will also take the regulator_list_mutex. Resulting in a deadlock if the flush_work call actually needs to flush the work. The locking appears to have got quite complex since last time I looked at it and I am having a little difficulty working out exactly is protecting what. I am wondering if the flush_work can just be moved outside the regulator_list_mutex in regulator_unregister since that mutex doesn't seem to protect the against the work being queued anyway? I will keep looking into this over the next couple of days, any pointers or ideas anyone has would be greatly appreciated. Finally, as it looks like it might take a couple of days to figure out the locking, I am leaving on holiday on Saturday so if you don't see a fix from my by then it might be a couple of weeks before I can look at it again. Thanks, Charles