Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1400895rwd; Thu, 15 Jun 2023 10:02:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4XR54D1J4C8FlFQOJQ6jP/4SGxP32Y8jcjQUUjG0iyy9+ozT0/ErWO5LKk49iydFJrTun9 X-Received: by 2002:a17:902:ec8b:b0:1b3:f72e:13a0 with SMTP id x11-20020a170902ec8b00b001b3f72e13a0mr6824313plg.6.1686848520777; Thu, 15 Jun 2023 10:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686848520; cv=none; d=google.com; s=arc-20160816; b=vIOOeR/5Lb2nFWYLjkOZn0Df1WkoInaega6kkV/6pu7yAwz+hi9U+ZlP7PvC2hGjoo P7Mho5MqFCvIupp5m64e/P2vjMYQ9NxkWrNeR6NOmUI/miYr9SQg6Zwiwk2BlGdVrVEf HqBhJasqvsGDEdxuc67P18F1jDRB2yw5bbcPSXLBi1DJafv2vIRlebisGbFxsTnnZy0h +bM8TLDG/7KfEsAk6YanFxeXfiJdUGTMseZ7MGNIrG68e00uiZpRiOKZgesU8Aojf859 Fbb16pq8RenJi+jeUJsF96X67VVCB+ZQ5/Ij9aBOYOCIEqfQwUoE5KRO/paqoOkxtkTL At2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=t6PovFpjFBYWRGm0duMC6FIzWHNsIOLZyw/VPBtnplM=; b=XkVnumGXR1IQ0ouvC0nR/PGvSe/xwyEjIZaxBAdBWzsHQO6bZP0EQ4ygkji88BLVst sJN+Afg8lNjdHyW/QCK3bZ3QLXndoxzZj3QpWOml0o0P6kBfvajlgHecQOBGEmvk2yWZ ZZXs8+CfvD0hwuEQFvPul3GKELDrqrEX3smBx696Jdr3eNvISYywxMHMSvxTqXYBhCZJ FF5eTSYh2lVC/15KXxrtjxcQQ3U5ZffEC4FlDNjMZprGvThAIQVp0r3vT35dAph2Sxwz zOeplRprv1KJWU+RQYG3dLp8Q1PdHGIGnAI0MaCkgIqpxbpjvX0d4nmn3lbHn/5WFqGY eQLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Sp7siHi2; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kk6-20020a170903070600b001a6bb7b7a44si9673367plb.307.2023.06.15.10.01.46; Thu, 15 Jun 2023 10:02:00 -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 header.i=@intel.com header.s=Intel header.b=Sp7siHi2; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237446AbjFOQrc (ORCPT + 99 others); Thu, 15 Jun 2023 12:47:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237131AbjFOQrJ (ORCPT ); Thu, 15 Jun 2023 12:47:09 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BE7B2686 for ; Thu, 15 Jun 2023 09:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686847605; x=1718383605; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=peYeLn9BGLKhNAB74de+wNh8KFc+idh7Mo+rg1C/Ax4=; b=Sp7siHi2Af5uJBP/b7+k9tmp/8W1yUaoeLDwGsWs5lG+ypQ9pGV3aM4b XWaV9toi13NhI1ORWdmG3a+c4JFcNgrSL1wVNtunI4L9Je3qySMBTDK+R 5V7cpUVawkqT7+YFXJrjQiwczXeFdD+qM+Ev10NB/XBEIJZxORgaeOoBt xuzmucSiNLl9/VUw/TKDzTomD1ivP4JvjTA8HCMdBwt4whOTSL00NvxHu fMDPE5157ByrRAvw8XQ9Yg5eKDuvqPcUqLU+jFmAgqT01Ru0FaMlBy+5E UkA5PfSYCYpqoTqW8VVztmPUvMVhHxSUhPArr4+4eYYEx5WWBS/O7P6cd g==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="387506770" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="387506770" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 09:46:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="857040464" X-IronPort-AV: E=Sophos;i="6.00,245,1681196400"; d="scan'208";a="857040464" Received: from mrejmak-mobl.ger.corp.intel.com (HELO [10.252.36.104]) ([10.252.36.104]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 09:46:26 -0700 Message-ID: <9eca7ccc-7955-43d3-178a-998d0f430a4c@linux.intel.com> Date: Thu, 15 Jun 2023 18:46:06 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.11.0 Subject: Re: [PATCH 2/2] soundwire: stream: Make master_list ordered to prevent deadlocks Content-Language: en-US To: Richard Fitzgerald , vkoul@kernel.org, yung-chuan.liao@linux.intel.com Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, patches@opensource.cirrus.com References: <20230615141208.679011-1-rf@opensource.cirrus.com> <20230615141208.679011-2-rf@opensource.cirrus.com> From: Pierre-Louis Bossart In-Reply-To: <20230615141208.679011-2-rf@opensource.cirrus.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 6/15/23 16:12, Richard Fitzgerald wrote: > Always add buses to the stream->master_list in a fixed order. > The unique bus->id is used to order the adding of buses to the > list. > > This prevents lockdep asserts and possible deadlocks on streams > that have multiple buses. > > sdw_acquire_bus_lock() takes bus_lock in the order that buses > are listed in stream->master_list. do_bank_switch() takes all > the msg_lock in the same order. > > To prevent a lockdep assert, and a possible real deadlock, the > relative order of taking these mutexes must always be the same. > > For example, if a stream takes the mutexes in the order > (bus0, bus1) lockdep will assert if another stream takes them > in the order (bus1, bus0). > > More complex relative ordering will also assert, for example > if two streams take (bus0, bus1) and (bus1, bus2), then a third > stream takes (bus2, bus0). > > Previously sdw_stream_add_master() simply added the given bus > to the end of the list, requiring the caller to guarantee that > buses are added in a fixed order. This isn't reasonable or > necessary - it's an internal implementation detail that should > not be exposed by the API. It doesn't really make sense when > there could be multiple independent calling drivers, to say > "you must add your buses in the same order as a different driver, > that you don't know about, added them". Makes sense to me. The other way to look at this is that the notion of 'stream' and dailink are virtually synonyms, and 'sdw_stream_add_master' is called from each DAI of a dailink, hence in a fixed order. But nothing really defines how dailinks include the dais, and in a hypothetical case with multiple controllers, each with multiple links, there would be an ambiguity anyways so using the ida-allocated bus->id is a good solution indeed. Reviewed-by: Pierre-Louis Bossart