Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1526213ybm; Thu, 23 May 2019 02:31:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkSJ3gB/TIh1WtCjEDY40bllVI0DI1zj8YbTWZm0oZ+Vp1i46gE9FbD0tN4cZO1VfGxTYv X-Received: by 2002:a17:902:a508:: with SMTP id s8mr77787993plq.186.1558603919395; Thu, 23 May 2019 02:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558603919; cv=none; d=google.com; s=arc-20160816; b=krj2JNJ57shDs1G7/43KWqcCWMNY/3Mm8au5yGMFpxDpLadKXoXBxM3+6OZJACIA3M gHwdlHowh74G3JF8kerkWa6IC0e8/aN9vnwQdvgd/4CmntzT08ihOprXP1kSy7Z35XD3 oiI9zLWby9zyX3TiYdrmR7VmB/ds8dD6AKPhAobkYHR08vSn27NKNc9sDed1grSlQoju z7KEbaBVYE6FWtPVvedvZQzqAobBC392nR/KPVdOOYd4FKWxIWTVyEy9bDS3GQP+EFTL l6UA3L7N/rSqqVz6QQO3JxTmAHXD3gSGi7IiPmkHmoDP4vPSWXMJKwbBhbegAI5+LJes Zh2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=qQG/Dz+q3JTMTmvRPhKGrhtgC1e/05CWbdwWmbSbs0U=; b=RzgGgCuCR+ipkYEobYvNlqnG7FibdPLX5bpImepNZWK1myPd0D7Dx7ljYUDC0AwiLM nCge5YuclZ6daRklNJbhGrqqxKclUfVMCfG5JrNmCFiJyBY/vLYKod80l2jxCbc7d0BW z0m3y7OkGbO6I78ssM3suIhnOD40RZGXCGDhsd4jEiSrLbM1002LfVKJtZDbI/MT/IFS aVPC6XQnPhV34MuOpG7HvxXLhfF+BGsQwsmRROxZw+uvGAoitVpSw19Jr7WEcwY3lkoS Xo8+PIkpNwwJ41PLEbpaJR4Q1rqaHHnGf8ZJlZzUUn1K7T1UQ6iGcxEX4s6xhju2TbZu 5raQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="owHVPK/S"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11si29169457plg.248.2019.05.23.02.31.44; Thu, 23 May 2019 02:31:59 -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; dkim=pass header.i=@linaro.org header.s=google header.b="owHVPK/S"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730394AbfEWJaY (ORCPT + 99 others); Thu, 23 May 2019 05:30:24 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41859 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730283AbfEWJaY (ORCPT ); Thu, 23 May 2019 05:30:24 -0400 Received: by mail-wr1-f65.google.com with SMTP id u16so1564250wrn.8 for ; Thu, 23 May 2019 02:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=qQG/Dz+q3JTMTmvRPhKGrhtgC1e/05CWbdwWmbSbs0U=; b=owHVPK/SPHvRkGKDqN3ABV7GCe7eUovnMPq4gnajGKoTxPDnmsFy1LVzD8WAHKYYJb xWtGG9H4ZaC+xpYDyDOTNqhGNyyUt1KaaIwjhTKkM8kiqSW+5IZhYw58TwkvQJqurEO2 bjEhU1ozg6hBHexysrUznVzhEA4LUcwxnIIu6KlGhrBlDl6FDis2Axz8147S1/OQo6Jg /mxkkJWPAxiiLsiCHyiInQ3CssPCcV2/lLMHb2zA/zyv1eBCCynAClfMhWP7uH/5LAao W3Kr2F0b0PqBnbD9DQqjRp6jAnRmCdDiw5Ayk14QB6BmgEWARBa891iBqxudeWxMzCGe BiKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qQG/Dz+q3JTMTmvRPhKGrhtgC1e/05CWbdwWmbSbs0U=; b=UqBDI7RQqRf4V4t/veYDwHcwYDVlh1Wmy1gurM/YeO7c6nT/EnfnaNs0i5fcnh93OT LKvfP0Ar3IjQpwO0alUw2MwFVCtZw0+VLFMtXliEzJY9YG0rzYr+4mc3PnZH3GXKIcNq Ibc+YliJ9U56Rn/oyoDnemf6+lRne9J20yBI4hVQyScuC0BJTtP2scPyLqgmKvpQDKBm Gkc0vMsPTjmW1I2wBJd6ZwvHsGudk0MhsYWAv1WFxhYiRF9G0mq43QEpcBbS45oFZqKe 7/f9Y+pRnnc5ODxJ87kldbe9JYiHeDbcuizf/ixmkJYXqogWOTpgYoYGst5GYtlY+37L Aa3w== X-Gm-Message-State: APjAAAX3EphEp77P6WcuHgGnOtKgd6CamEajTJgPvwS+vcWEIAT0ep1B 78UWS6HXcVOKI8kmxW9sSSYEBn2wU37/6A== X-Received: by 2002:adf:e90b:: with SMTP id f11mr2427438wrm.291.1558603821998; Thu, 23 May 2019 02:30:21 -0700 (PDT) Received: from [192.168.86.34] (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.googlemail.com with ESMTPSA id o8sm48848496wra.4.2019.05.23.02.30.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 02:30:21 -0700 (PDT) Subject: Re: [PATCH] soundwire: stream: fix bad unlock balance To: Sanyog Kale Cc: Pierre-Louis Bossart , vkoul@kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org References: <20190522162528.5892-1-srinivas.kandagatla@linaro.org> <4744834c-36b1-dd8d-45fa-76c75eb3d5cb@linux.intel.com> <2dc66f9d-e508-d457-a7d6-c06c4336e7b8@linaro.org> <20190523092034.GA23777@buildpc-HP-Z230> From: Srinivas Kandagatla Message-ID: Date: Thu, 23 May 2019 10:30:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190523092034.GA23777@buildpc-HP-Z230> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/05/2019 10:20, Sanyog Kale wrote: > On Thu, May 23, 2019 at 09:43:14AM +0100, Srinivas Kandagatla wrote: >> >> >> On 22/05/2019 17:41, Pierre-Louis Bossart wrote: >>> >>> >>> On 5/22/19 11:25 AM, Srinivas Kandagatla wrote: >>>> This patch fixes below warning due to unlocking without locking. >>>> >>>> ?? ===================================== >>>> ?? WARNING: bad unlock balance detected! >>>> ?? 5.1.0-16506-gc1c383a6f0a2-dirty #1523 Tainted: G?????????????? W >>>> ?? ------------------------------------- >>>> ?? aplay/2954 is trying to release lock (&bus->msg_lock) at: >>>> ?? do_bank_switch+0x21c/0x480 >>>> ?? but there are no more locks to release! >>>> >>>> Signed-off-by: Srinivas Kandagatla >>>> --- >>>> ?? drivers/soundwire/stream.c | 3 ++- >>>> ?? 1 file changed, 2 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c >>>> index 544925ff0b40..d16268f30e4f 100644 >>>> --- a/drivers/soundwire/stream.c >>>> +++ b/drivers/soundwire/stream.c >>>> @@ -814,7 +814,8 @@ static int do_bank_switch(struct >>>> sdw_stream_runtime *stream) >>>> ?????????????????????????? goto error; >>>> ?????????????????? } >>>> -?????????????? mutex_unlock(&bus->msg_lock); >>>> +?????????????? if (mutex_is_locked(&bus->msg_lock)) >>>> +?????????????????????? utex_unlock(&bus->msg_lock); >>> >>> Does this even compile? should be mutex_unlock, no? >>> >>> We also may want to identify the issue in more details without pushing >>> it under the rug. The locking mechanism is far from simple and it's >>> likely there are a number of problems with it. >>> >> msg_lock is taken conditionally during multi link bank switch cases, however >> the unlock is done unconditionally leading to this warning. >> >> Having a closer look show that there could be a dead lock in this path while >> executing sdw_transfer(). And infact there is no need to take msg_lock in >> multi link switch cases as sdw_transfer should take care of this. >> >> Vinod/Sanyog any reason why msg_lock is really required in this path? >> > > In case of multi link we use sdw_transfer_defer instead of sdw_transfer > where lock is not acquired, hence lock is acquired in do_bank_switch for > multi link. we should add same check of multi link to release lock in > do_bank_switch. probably we should just add the lock around the sdw_transfer_defer call in sdw_bank_switch()? This should cleanup the code a bit too. something like: ------------------------------------>cut<----------------------------- diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c index d01060dbee96..f455af5b8151 100644 --- a/drivers/soundwire/stream.c +++ b/drivers/soundwire/stream.c @@ -676,10 +676,13 @@ static int sdw_bank_switch(struct sdw_bus *bus, int m_rt_count) */ multi_link = bus->multi_link && (m_rt_count > 1); - if (multi_link) + if (multi_link) { + mutex_lock(&bus->msg_lock); ret = sdw_transfer_defer(bus, wr_msg, &bus->defer_msg); - else + mutex_unlock(&bus->msg_lock); + } else { ret = sdw_transfer(bus, wr_msg); + } if (ret < 0) { dev_err(bus->dev, "Slave frame_ctrl reg write failed\n"); @@ -742,25 +745,19 @@ static int do_bank_switch(struct sdw_stream_runtime *stream) struct sdw_master_runtime *m_rt = NULL; const struct sdw_master_ops *ops; struct sdw_bus *bus = NULL; - bool multi_link = false; int ret = 0; list_for_each_entry(m_rt, &stream->master_list, stream_node) { bus = m_rt->bus; ops = bus->ops; - if (bus->multi_link) { - multi_link = true; - mutex_lock(&bus->msg_lock); - } - /* Pre-bank switch */ if (ops->pre_bank_switch) { ret = ops->pre_bank_switch(bus); if (ret < 0) { dev_err(bus->dev, "Pre bank switch op failed: %d\n", ret); - goto msg_unlock; + return ret; } } @@ -814,7 +811,6 @@ static int do_bank_switch(struct sdw_stream_runtime *stream) goto error; } - mutex_unlock(&bus->msg_lock); } return ret; @@ -827,16 +823,6 @@ static int do_bank_switch(struct sdw_stream_runtime *stream) kfree(bus->defer_msg.msg); } -msg_unlock: - - if (multi_link) { - list_for_each_entry(m_rt, &stream->master_list, stream_node) { - bus = m_rt->bus; - if (mutex_is_locked(&bus->msg_lock)) - mutex_unlock(&bus->msg_lock); - } - } - return ret; } ------------------------------------>cut<----------------------------- > >> --srini >> >>>> ?????????? } >>>> ?????????? return ret; >>>> >