From patchwork Thu Jun 25 09:35:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Boichat X-Patchwork-Id: 6672991 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D7E549F1C1 for ; Thu, 25 Jun 2015 09:36:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D4CEE2068D for ; Thu, 25 Jun 2015 09:36:18 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 87B9520680 for ; Thu, 25 Jun 2015 09:36:17 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 01ECB2604E2; Thu, 25 Jun 2015 11:36:16 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, NO_DNS_FOR_FROM, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 194A826049B; Thu, 25 Jun 2015 11:36:08 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0CDC42604A7; Thu, 25 Jun 2015 11:36:06 +0200 (CEST) Received: from mail-pd0-f178.google.com (mail-pd0-f178.google.com [209.85.192.178]) by alsa0.perex.cz (Postfix) with ESMTP id 64B0E260464 for ; Thu, 25 Jun 2015 11:36:01 +0200 (CEST) Received: by pdjn11 with SMTP id n11so50015962pdj.0 for ; Thu, 25 Jun 2015 02:36:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=H5MAZ/ijX9f1YmYjvjR4cb5iVhjBT5c3+knTLFyPI5Y=; b=Ysbh6HdNcKzlGq67shVtwnvmh+C7dXcrng5HeSLf2lh0UTz3vlA1yOWx8HT5On4fts X+pR6Xvf/QyHmkPc8fEtyCfQpwky16bK3S7fB9QZTbKgjWvfdqqQE+5ot/unlemK9wo6 0fB4Ipmgzd7fkC/eOIkhGUmQ+Guuep7KaCCz4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=H5MAZ/ijX9f1YmYjvjR4cb5iVhjBT5c3+knTLFyPI5Y=; b=f19BgdF9S20CqHNwxRXWYXF7vbLNi9CBxl99VHaCcYGQxxVraH2a3tQ1tAlNesPXpS rQtfTPPErpucC/y2lFStH8gGRl4dMC+Ja0dS1gButH9hx/yYz0TUXfp7jUwsPB28gHdA tebaOBnYOvoMyPJucPvpThLEYTHpDsiVOF8bNKUSyGgvb7CcKSeOVKmuNJCCK3PNAcPI HFDKWI5FeBi72uccV6lwnWfvieuelJMbRk9JYHjH7S25UOCeFTHhoCdmOU4sfe+Yi0TB 77T138Hk3C2M9AydgOHlmvzH2pT2I3Ec9D5Wc/vUNVftiKQFb+yQC0bvmw7qxMYgwP7M nhTw== X-Gm-Message-State: ALoCoQlhSAe+PbheAXaMTSKHIBXJE8K+L8zaJD/cm6oumSk0IGXkOBsQFJHGIruoGHmnLV3uDRPt X-Received: by 10.66.122.144 with SMTP id ls16mr81551066pab.47.1435224959852; Thu, 25 Jun 2015 02:35:59 -0700 (PDT) Received: from drinkcat.tpe.corp.google.com ([172.30.210.53]) by mx.google.com with ESMTPSA id bp17sm22073602pdb.48.2015.06.25.02.35.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Jun 2015 02:35:59 -0700 (PDT) From: Nicolas Boichat To: Mark Brown Date: Thu, 25 Jun 2015 17:35:03 +0800 Message-Id: <1435224904-35517-1-git-send-email-drinkcat@chromium.org> X-Mailer: git-send-email 2.4.3.573.g4eafbef Cc: Oder Chiou , alsa-devel@alsa-project.org, Lars-Peter Clausen , Anatol Pomozov , Mauro Carvalho Chehab , Takashi Iwai , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Liam Girdwood , Antti Palosaari , Bard Liao , Arjan van de Ven , Ingo Molnar Subject: [alsa-devel] [RFC PATCH 1/2] regmap: add configurable lock class key for lockdep X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Antti Palosaari Lockdep validator complains about recursive locking and deadlock when two different regmap instances are called in a nested order. That happens anytime a regmap read/write call needs to access another regmap. This is because, for performance reason, lockdep groups all locks initialized by the same mutex_init() in the same lock class. Therefore all regmap mutexes are in the same lock class, leading to lockdep "nested locking" warnings if a regmap accesses another regmap. However, depending on the specifics of the driver, this can be perfectly safe (e.g. if there is a clear hierarchy between a "master" regmap that uses another "slave" regmap). In these cases, the warning is false and should be silenced. As a solution, add configuration option to pass custom lock class key for lockdep validator, to be used in the regmap that needs to access another regmap. This removes the need for uglier workarounds in drivers, just to silence this warning (e.g. add custom mutex lock/unlock functions). Cc: Lars-Peter Clausen Cc: Mark Brown Signed-off-by: Antti Palosaari [drinkcat@chromium.org: Reworded the commit message and regmap.h documentation] Signed-off-by: Nicolas Boichat --- I'm trying to revive Antti's patch [1], as we are hitting similar issue with rt5677 driver. I only updated the commit message and documentation, I kept both Signed-off-by and From lines, with a small note highlighting my changes, let me know if that's not appropriate. One issue that was raised by Mark at the time is that a per-regmap_config lock class might not be enough (Mark mentioned clocks as an example). The current implementation should be good enough as long as the clock regmaps do not access each other. If this is a problem, maybe we should consider replacing lockdep_lock_class_key by a boolean use_own_lock_class that would allocate/use a per regmap instance lock class, or have devm_regmap_init take an extra parameter specifying the lock class. [1] https://www.mail-archive.com/linux-media%40vger.kernel.org/msg83490.html drivers/base/regmap/regmap.c | 3 +++ include/linux/regmap.h | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 6273ff0..f5d1131 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -560,6 +560,9 @@ struct regmap *regmap_init(struct device *dev, mutex_init(&map->mutex); map->lock = regmap_lock_mutex; map->unlock = regmap_unlock_mutex; + if (config->lockdep_lock_class_key) + lockdep_set_class(&map->mutex, + config->lockdep_lock_class_key); } map->lock_arg = map; } diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 116655d..09aaaf5 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -135,6 +135,12 @@ typedef void (*regmap_unlock)(void *); * @lock_arg: this field is passed as the only argument of lock/unlock * functions (ignored in case regular lock/unlock functions * are not overridden). + * @lock_class_key: Custom lock class key for lockdep validator. Use that to + * silence false lockdep nested locking warning, when this + * regmap needs to access another regmap during read/write + * operations (directly in read/write functions, or + * indirectly, e.g. through bus accesses). + * Valid only when regmap default mutex locking is used. * @reg_read: Optional callback that if filled will be used to perform * all the reads from the registers. Should only be provided for * devices whose read operation cannot be represented as a simple @@ -198,6 +204,7 @@ struct regmap_config { regmap_lock lock; regmap_unlock unlock; void *lock_arg; + struct lock_class_key *lockdep_lock_class_key; int (*reg_read)(void *context, unsigned int reg, unsigned int *val); int (*reg_write)(void *context, unsigned int reg, unsigned int val);