Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3288894rwa; Tue, 23 Aug 2022 02:04:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Ats9W75eTE3mEEKJj87FeyQe5Zk9048eJIeCDItMr+p9p9qE2OKJbl5psRJ2YiFzlaJs0 X-Received: by 2002:a17:907:8a09:b0:731:610:ff8d with SMTP id sc9-20020a1709078a0900b007310610ff8dmr15236737ejc.399.1661245460797; Tue, 23 Aug 2022 02:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661245460; cv=none; d=google.com; s=arc-20160816; b=tjgC2WcfVBolheVikIyQPwSi/YQsVHG0Xiw2mNj2JDyWeYB27QazqwCRo6kQN4bqFk OZex9MVePBVrxBtXlub+B+9Dt9Tcba3dEQ2SQjNRvyMiUE+zvHL9LNeaMi18deV9Bo1u bU9dvVHrWE2qt/BoKgp4lRbFOapC0r3JtKshecu1wVlhWQa4eNAd2862iwTctXYk9ZNT 9YBH44R297WMk6q4wJF9up/1QYYlpl6aKa7KIzktAl1I1dxpVNWk34uD2Bc9YtfA6ftt GvIAYMy2NwY3iQHW5RGhJtZ/ZcMTo9w6yOkhU6r0vAesP4rdLCer9PUdWSbwpF4Lw6ko 2iKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=dsmv2HWtXdyoSrM7X25yViaz1yQI9MEMGWUi+MfjE0g=; b=FYcXcJeN6lNyNsGSoYNYaloub5jQS2Cd/CZWU+aC6FvaK43//EdFwBj03zYvSbROdO H20HnX6j6gGbBijpzV0Xylj1b25jZqVipQloPMlrDCLezC1pIu0mxOqQLpOkkhOzJ6Vr UZhhpDKOBuoPQiZS1hG+73DXQiWDo2wO53dicljTO9u7Yezbagmujdbf90pxmF4BLUth BKnS3DwWS5kNl5NIz1+rcIdkiIRXbTRxZ26TLUCJYbwwjNEgaYBi83gCM1EBPkdTEOBX 7gANtxSw8ti+0+nixAyfNisL+scx7ZMD5O8wjaT6iBNq7LRHFUfUuoKezZTX48Ms5cle spvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=BGbqcAus; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z8-20020a05640235c800b00447102675d6si1775912edc.606.2022.08.23.02.03.55; Tue, 23 Aug 2022 02:04:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=BGbqcAus; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243041AbiHWI1M (ORCPT + 99 others); Tue, 23 Aug 2022 04:27:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243800AbiHWIVn (ORCPT ); Tue, 23 Aug 2022 04:21:43 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7ADF71706; Tue, 23 Aug 2022 01:12:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1661242378; x=1692778378; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=dsmv2HWtXdyoSrM7X25yViaz1yQI9MEMGWUi+MfjE0g=; b=BGbqcAusKcLIyRblNhfi4BhRxGfzA8XQ7BgxiegR9i/HxXXXVs5SgZO2 9pbFZgmUHz/amsdF+K3uPLFq9IdlOxtQ96qTxc3WbP4VeNhIECo8k0hB6 UcKz5OQfuCJa8083MXcuiGRZcE6HmM3//dlGI387AOlJTYOiaZSUXVq6T j3jz/5ZUXYHydJ2cxJLax6fA0YGwNiDuTwSFJSvmTNDogXDxSczc/K5u+ 7FT1OmJmRwO4Y7rLlEVKXwO838gAVmrkEvK3jaEAYJHUxeQ57UAK0XWLP USH6IA+KEvmkLEgVdTs8YkKtjF5F8ugx5FivBrfsu2IRJ/KLVbc/pZdRX w==; Date: Tue, 23 Aug 2022 10:12:33 +0200 From: Vincent Whitchurch To: Lars-Peter Clausen CC: Jonathan Cameron , kernel , "linux-iio@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Peter Rosin Subject: Re: [PATCH] iio: buffer: Silence lock nesting splat Message-ID: References: <20220816080828.1218667-1-vincent.whitchurch@axis.com> <20220820120640.6d1b928d@jic23-huawei> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 20, 2022 at 01:08:28PM +0200, Lars-Peter Clausen wrote: > There are two different approaches for this kind of nested locking. One > is to use mutex_lock_nested(). This works if there is a strict > hierarchy. The I2C framework for example has a function to determine the > position of a I2C mux in the hierarchy and uses that for locking. See > https://elixir.bootlin.com/linux/latest/source/drivers/i2c/i2c-core-base.c#L1151. > > I'm not sure this directly translates to IIO since the > consumers/producers don't have to be a in strict hierarchy.? And if it > is a complex graph it can be difficult to figure out the right level for > mutex_lock_nested(). > > The other method is to mark each mutex as its own class. lockdep does > the lock checking based on the lock class and by default the same mutex > of different instances is considered the same class to keep the resource > requirements for the checker lower. > > Regmap for example does this. See > https://elixir.bootlin.com/linux/latest/source/drivers/base/regmap/regmap.c#L795. > > This could be a solution for IIO with the downside how the additional > work for the checker. But as long as there are only a few IIO devices > per system that should be OK. We could also only set the per device lock > class if in kernel consumers are enabled. The second method certainly sounds like a better fix, since it also still warns if one actually takes the same iio_dev mutex twice. I'll respin the patch. Thanks.