Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp456148pxb; Thu, 9 Sep 2021 05:01:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKDacrSxfrjjqSLMwy33GC89/C2+uGTPbW87jarrn49fC3dThVxz00GqC5XNJh2XyOWwV1 X-Received: by 2002:a02:b0d1:: with SMTP id w17mr2503492jah.46.1631188914611; Thu, 09 Sep 2021 05:01:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631188914; cv=none; d=google.com; s=arc-20160816; b=PCtqNpEexN1xxCQZVQFjIWren6C2pz5kjmgdfng6EkdPqW72vsc7vCEcJv8sf043Qb 8n8RPuTO8cAZJEoFsAflHh0HKjh0YbfyK6SraaxL7GiS7XErTS7RVckP8ozIoomzK0pt gKRIDLSmo0cpHwo8AZSUyXwGiQjwUR8cAFz6BMk7L4/ntrv+P/wVUVkUR3bpVmFCr8ka M2OhMJUEux98ROORSsHJNS02nR7bTzFKKW/LKIJ7Q3uBBHlg8+/1yzouGgNpnWQaW8L/ 0ZmrCMMkwfsiVAGQKKALNbPJ9P0B5I1+jMxENchn40pLdWNvYIy9KE+DEqjXxYsiRCJm 4D7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+9HnAOGzGJl7oNnUHXsgF9oFMBYe/HQK9xZ4F9pJH1Y=; b=FBGLtz98YImYE6QprgsqHeE1kyV7ajR+z33mWNiydftH526jO5WoMccoCPCeJsPT2O 3O92CB+FUII7bV8PsDCsocQhdNaj4XwYxZQkMhwbnAvBKNCn3wVJA0IQqAU5bjMMv4re 0wTgWb4DP9DORHXeEMJqbP6p8iKR6CXaFeS+0UlxmVv2bVPK9I5dZ/gJse6KSOGwuETw vxvqCwGM+vXuZ8js3yaFCk9Qn9WoLwZtPuQC4fwPy56Nbu19PY7lJzB6jWU6Rnrh29cM mfKva1r3ssNX1Ym+V1FGkONp4FOUF1SYRU4L0xdxVLvwQyL8DgZETNl7xoh9hOePE6SR CZWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VbKscrxZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m82si1294287ioa.74.2021.09.09.05.01.40; Thu, 09 Sep 2021 05:01:54 -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=@kernel.org header.s=k20201202 header.b=VbKscrxZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241991AbhIIMBL (ORCPT + 99 others); Thu, 9 Sep 2021 08:01:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:34892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237690AbhIIL47 (ORCPT ); Thu, 9 Sep 2021 07:56:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 24E3F61216; Thu, 9 Sep 2021 11:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187926; bh=v8vGB+3mWBq+luhinJRW757yoV4KKwTtTnholGUTLsE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VbKscrxZlvRZCzjJ+Ie5IqlrKKn1T3+PwpCt4617zEhBP1MykaEEWBy+hurgjOQih AwNKAL8Inwz0T8UOr032mhe5lrxX/l5W/8SQ8HiGX0NCNtc/WZtrRnZlqlL5Nj1ECS 5qbUfU/HcB0DhbdXZTs4uL31BwT94SWtf2UswmU7vnJq1vv30ZuiIkWJoEyx1ayabj uxjHYKOSmLD/434djfbsRBx/R/m6sAqDAgIlvXA8DJ2TldkA27RYoXAXccqUloaKNK XJVMkYSOohDO6qQ66b60APYi3U6i7V+S140NqI2n1lu9mX98DtPLADw6nkyyRTUaS+ RIJCZeVUid19Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Pierre-Louis Bossart , Ranjani Sridharan , Bard Liao , Vinod Koul , Sasha Levin , alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 5.14 199/252] soundwire: intel: fix potential race condition during power down Date: Thu, 9 Sep 2021 07:40:13 -0400 Message-Id: <20210909114106.141462-199-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pierre-Louis Bossart [ Upstream commit ea6942dad4b2a7e1735aa0f10f3d0b04b847750f ] The power down sequence sets the link_up flag as false outside of the mutex_lock. This is potentially unsafe. In additional the flow in that sequence can be improved by first testing if the link was powered, setting the link_up flag as false and proceeding with the power down. In case the CPA bits cannot be cleared, we only flag an error since we cannot deal with interrupts any longer. Signed-off-by: Pierre-Louis Bossart Reviewed-by: Ranjani Sridharan Signed-off-by: Bard Liao Link: https://lore.kernel.org/r/20210818024954.16873-2-yung-chuan.liao@linux.intel.com Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/soundwire/intel.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index c11e3d8cd308..f156de765c68 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -537,12 +537,14 @@ static int intel_link_power_down(struct sdw_intel *sdw) mutex_lock(sdw->link_res->shim_lock); - intel_shim_master_ip_to_glue(sdw); - if (!(*shim_mask & BIT(link_id))) dev_err(sdw->cdns.dev, "%s: Unbalanced power-up/down calls\n", __func__); + sdw->cdns.link_up = false; + + intel_shim_master_ip_to_glue(sdw); + *shim_mask &= ~BIT(link_id); if (!*shim_mask) { @@ -559,18 +561,19 @@ static int intel_link_power_down(struct sdw_intel *sdw) link_control &= spa_mask; ret = intel_clear_bit(shim, SDW_SHIM_LCTL, link_control, cpa_mask); + if (ret < 0) { + dev_err(sdw->cdns.dev, "%s: could not power down link\n", __func__); + + /* + * we leave the sdw->cdns.link_up flag as false since we've disabled + * the link at this point and cannot handle interrupts any longer. + */ + } } mutex_unlock(sdw->link_res->shim_lock); - if (ret < 0) { - dev_err(sdw->cdns.dev, "%s: could not power down link\n", __func__); - - return ret; - } - - sdw->cdns.link_up = false; - return 0; + return ret; } static void intel_shim_sync_arm(struct sdw_intel *sdw) -- 2.30.2