Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1706903pxb; Thu, 16 Sep 2021 13:31:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGdVlhEOrbbPOUDCGtPdXaZrYkCAdYuY7o72W6lqxgD8sIvw4zqCBt1f2Ehn+k9wpM1N0o X-Received: by 2002:aa7:ce14:: with SMTP id d20mr8450543edv.132.1631824290399; Thu, 16 Sep 2021 13:31:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631824290; cv=none; d=google.com; s=arc-20160816; b=uTmZm8d9fW7LNW1djMnQyDBw85OI2Km6R7Vud7ZBU9fI1k/pL/oAZg8GLLQN8YOlh5 X6HYhrZqVYQR6i7AHdmjKOkZYyLTFNp/eBsw99tXmfW+wDNE5w0qotgzPgOTk+SNHKJO 3JJ4pPWL1VK8DUs4EL/OwkGDeYf+hPJCRpbXzcRnmI+QctnaHdNxjp3F/5Dq6ebmrHNq ClTY05dE4/AWB3uP1VLX8IBNpbjw8L+4zPVv8bEJs2z63HtvLZP0WQgg5r/hmpfYub/e AzmnnmtTOg2MPgJ1AzkDvW6UQA3Z4J4WvN8k21BA15Wz9GhIpsjTtsGN29HYRclj+CKO oHIg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yiIu7gMCpWeeGu8l5pAiQO5KMyeU1YeIgl5KaEuFOKQ=; b=umbklfhWOarPaDj0TETeGmkSwd56HqVd+gJ2MVjDPahFgSIxOV9KB9+vFvQgyGvM37 NYdZPislJCNjW0z/PqtBvvK06METefGuVXgYA22/nxYzpn1AKjMydWKZhHY7oMmX61Kb eFdIctrTq9MXMgR5W2GOOYztUtKh7YHw/w02Eo7+47Sz9ZkUL92sluRNkQCTXBQC4np5 Ua8Va7MfSuERUH9nyj2IB753IL7LXU/3ktmzXjehflzFf6Dz7rCY1TYBZH0GADl1IPq3 zwQtpX8pD5tC0KFFOC6kfEJZR0+Z6PUUG2is3eETnz+8RpstA6J3stqKxhFdB5eMOOfx jCwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o7OqTCdZ; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b1si5634701ejb.600.2021.09.16.13.31.05; Thu, 16 Sep 2021 13:31:30 -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=@linuxfoundation.org header.s=korg header.b=o7OqTCdZ; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242138AbhIPQ3S (ORCPT + 99 others); Thu, 16 Sep 2021 12:29:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:59302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241712AbhIPQUC (ORCPT ); Thu, 16 Sep 2021 12:20:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D769361390; Thu, 16 Sep 2021 16:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808847; bh=GiDCcw8EAI/e3m9h772NNoRn4DlkDc9x34kowoRI6tw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o7OqTCdZBgPgB7bIFDm0B5CDfmOuNcBWcK7zcFKiTZXRy8Y+mb4D37oTtsSl0Ao1m Bkqa6Z+6nqnR1rrOa8DNBGRn9sSa/4mac97T2Vbvu5BtE9r8+TUFEDBiGCGfK+Btit aqZ4B3u3+dnIYgdRe53q1YTPdLE8KplXwuJIvjDI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pierre-Louis Bossart , Ranjani Sridharan , Bard Liao , Vinod Koul , Sasha Levin Subject: [PATCH 5.10 243/306] soundwire: intel: fix potential race condition during power down Date: Thu, 16 Sep 2021 17:59:48 +0200 Message-Id: <20210916155802.349997999@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 6a1e862b16c3..dad4326a2a71 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,20 +561,21 @@ 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. + */ + } } link_control = intel_readl(shim, SDW_SHIM_LCTL); 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