Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4443234pxa; Mon, 10 Aug 2020 09:10:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFZg3rQ0Nqa9btEAMjdfcOfiaaUiyGF+4YwbQv7c0ji9DR+ns8DKVUVudY7FSnvaPxCgn6 X-Received: by 2002:a17:906:12c7:: with SMTP id l7mr3557018ejb.306.1597075839944; Mon, 10 Aug 2020 09:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597075839; cv=none; d=google.com; s=arc-20160816; b=b6nSoYtrUk5JoIFwjNNS2A4R1SVSi8G2XjgGkptHWJ/M5wovzK55PNzNFVCdvcu7PP K9WDqryEXT6W67wZZcRRgXDdFLLPjTN+nbWjxS2NBDUfXtjHDwfIwiid6krSTpzhvcy+ PjNE9x8Cku8Yd9g0EDv+coU8imKduBGGJC3iGR9iHwWDnyt7DdzQFWxlROQ2Gdetljay KuGVvoAJhtwQoGwjuS8Gl5T4wlN2xWZRsFwSsMAnxWTq9VriJbE/3/7Uk5WU+4yRyHLn RR3S8FqvHOM0TYgoJSvgpaLldC6gzP5PgGnYQt4YEUiKxE8ECg3UTgImyINgcIKx19VD fE3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5xK1rJTa+1bU64Gm2yE6OxIUVp1FX2gey1H4hL/7mQA=; b=KPNa3xXkWNjW1XGhaCKS4Xfxi29IzfCnvL9Uls4xz7pnwjmRIScH6J4QZN6S/i2l1R osBKfX7wtEXP++46UzqywiIgwNUWv5PzcW0LTka7c2wsfcBU5khVM9shRVfp4VcKBlkQ Xy3+r2ukzdNaFayB0WC1RUzvyem4R5AFd2qPVmHVgcAlA3fO00IkF4oef1BOC3y6SmIg NlLy2fsf1olP5bjgwBD1/AvAePGgLQTHF3MgW1CtiCz+9LOY+PHIl5XHKMxi9Ea7zPyp eVGWSJq/VjbXc0iR5OsQb4No91Q8Vh083yBqLvytiObh4Rtvky06BLrt84wcmwJHyzet R1rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=Tvk+bsSC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x7si10852816ejv.609.2020.08.10.09.10.16; Mon, 10 Aug 2020 09:10:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=Tvk+bsSC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726910AbgHJQJl (ORCPT + 99 others); Mon, 10 Aug 2020 12:09:41 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:35328 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725873AbgHJQJl (ORCPT ); Mon, 10 Aug 2020 12:09:41 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4BQLWk65PKz2d; Mon, 10 Aug 2020 18:09:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1597075778; bh=jnGr4D1typF3L4cvQAPzJLaKj0mF/wj4jmVrPp2Me4Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Tvk+bsSCrs6bgpYzU6KMHNABcpyYUBxMv3wZFbInjIpbRRQrPreoYIOQuNz7dt1AY 5/nPfhWDkN8vKhgg5hXmNXs4EbD7+cbq/Sps3eblZ8UUDSNmw+/o7u4MkblxNcnkjo J/QhzjVIoMHgpn32iWa4bUIeQ5rX++EA8NaB4yem9C3D+v0jadYpZoBDSN14jlgfdL tscVj2VVzczLJHN3931/3Trp+3r1LkXuETBxkf3g8d8miYAkmFXNRoCKqdAuMFF+rj b9yU9sV2BWlj4iimuo8Koibr02XlMW1wWohcL+Q8TmsXAg5L244bDQyivTQkWXplrZ aoO5jBesVntJw== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.4 at mail Date: Mon, 10 Aug 2020 18:09:36 +0200 From: =?iso-8859-2?Q?Micha=B3_Miros=B3aw?= To: Mark Brown Cc: Dmitry Osipenko , Liam Girdwood , linux-kernel@vger.kernel.org Subject: Re: regulator: deadlock vs memory reclaim Message-ID: <20200810160936.GA1100@qmqm.qmqm.pl> References: <20200809222537.GA5522@qmqm.qmqm.pl> <20200810153928.GD6438@sirena.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200810153928.GD6438@sirena.org.uk> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 10, 2020 at 04:39:28PM +0100, Mark Brown wrote: > On Mon, Aug 10, 2020 at 12:25:37AM +0200, Micha? Miros?aw wrote: > > > regulator_lock_dependent() starts by taking regulator_list_mutex, The > > same mutex covers eg. regulator initialization, including memory allocations > > that happen there. This will deadlock when you have filesystem on eg. eMMC > > (which uses a regulator to control module voltages) and you register > > a new regulator (hotplug a device?) when under memory pressure. > > OK, that's very much a corner case, it only applies in the case of > coupled regulators. The most obvious thing here would be to move the > allocations on registration out of the locked region, we really only > need this in the regulator_find_coupler() call I think. If the > regulator isn't coupled we don't need to take the lock at all. Currently, regulator_lock_dependent() is called by eg. regulator_enable() and regulator_get_voltage(), so actually any regulator can deadlock this way. I concur that the locking rules can (and need to) be relaxed. > > Basically, we have a BKL for regulator_enable() and we're using ww_mutex > > as a recursive mutex with no deadlock prevention whatsoever. The locks > > also seem to cover way to much (eg. initialization even before making the > > regulator visible to the system). > > Could you be more specific about what you're looking at here? There's > nothing too obvious jumping out from the code here other than the bit > around the coupling allocation, otherwise it looks like we're locking > list walks. When you look at the regulator API (regulator_enable() and friends), then in their implementation we always start by .._lock_dependent(), which takes regulator_list_mutex around its work. This mutex is what makes the code deadlock-prone vs memory allocations. I have a feeling that this lock is a workaround for historical requirements (recursive locking of regulator_dev) that might be no longer needed or is just too defensive programming. Hence my other patches and this inquiry. Best Regards, Micha??Miros?aw