Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5458110pxu; Tue, 22 Dec 2020 18:40:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyShTmcTFPqzqDJSmVn4pGDtPJfIHYxigkibX/4tSVIBGhVmdxmkMvK5BOEsFzBUONZEjn1 X-Received: by 2002:a17:906:941a:: with SMTP id q26mr22355363ejx.227.1608691217368; Tue, 22 Dec 2020 18:40:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608691217; cv=none; d=google.com; s=arc-20160816; b=I7IbUTyLqsNHZMfNvtZP3to4XtVDbjIGcXHO/xFJyi2U2U4nhtRalmDC4YzYGpHnoo Op+c/CpVgoCEn5uEC0jxil/yK4/1eICM7zl+7CSiTA4WHDUwPIB8ccGbXr4HmrF0iD4i dztvtSu8TKlPmWlhiWaktzMzqaFjN40AaK3Hzs052fWuOudXYca89FHbigNHE7tPjOnp UJ2Xu9vqB4Q8qGcriJPJ2tQ7s9pLELDt2tQWuJRan5BiXM5yUHpIdjfLUot+7hsxzrMK tSPw4C3Gev5xlvA0k3E75fBhRT2QINEMMVOILq271wK5x+t01cOgdpwod0ySqMpA3KtP FnLw== 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=OmZ0C54CYfAg5yx55qf7IGjtNPI9ChLRndhsUZtau94=; b=0Vd8TnlyCCaZkYPkh6SBpojqF7EzbDeSop0g3iLZzuG4Bn/II9b55v22bAmJdvBdJo wByeitOHIp+l7QESaPMXHzw05FGmG0NGr6T/c2Xu0D+qUKt913gMxJ0Aa1PWnAjEngrM wrbM0thTM+5vFd1dTky16H4t3qPrjSZfnWquXiYbJtFy7KLiB2r8zF+pgq6cu18x7Al6 nnD0FDpFX/VMNw39jBjq9yk/0AEWF9KXT8HhLgnYCbx0k94RDWz11OQzml/+f4KY+Le+ REHsj1mWg4OrqLDG7Uzujov5fYprO02aMqJM0CivweVOVO1oc7IWYlDcgLk7DVpnhroy yOXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=G+yu7555; 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 k11si13198760edq.414.2020.12.22.18.39.55; Tue, 22 Dec 2020 18:40:17 -0800 (PST) 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=G+yu7555; 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 S1730669AbgLWCjo (ORCPT + 99 others); Tue, 22 Dec 2020 21:39:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:52560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730064AbgLWCXq (ORCPT ); Tue, 22 Dec 2020 21:23:46 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 18CC422AAF; Wed, 23 Dec 2020 02:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608690210; bh=rMAraAbSoN60xGi383renZXB910pyJXmXglFmSTIQzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G+yu7555hEc5NmGAB5IIp6n9vX9i46vLhXjdvtaeZKFJX55axlGukCdqz+X21VQTP tWS1zLLxCJW8F4BXzMxEhbYcp7NCUvr8TkvQuxVBSSzx2prS7c1MQy1m89Mp7uR/5/ QkfOCWLUGvErqJ8YfXOMN8+yERsVcoqu3uPjcrIjiLvS4QdadGTLLT6wy7vV6tTTUj 9qdC736l8j6NVk+4rvnq9qgyiCe3OhyFsNuGHpc9zLyybRFLJGH+8VYSQOckf4wjJL lKhz/8LH37gNbFMoGQo6qOeBA65z/Q29zmkWSiCeXYO3929Jp3w22xeyvS70b1cLnb SP2KrHcqhoSKw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jaegeuk Kim , Can Guo , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 30/66] scsi: ufs: Atomic update for clkgating_enable Date: Tue, 22 Dec 2020 21:22:16 -0500 Message-Id: <20201223022253.2793452-30-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201223022253.2793452-1-sashal@kernel.org> References: <20201223022253.2793452-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: Jaegeuk Kim [ Upstream commit b664511297644eac34038df877b3ad7bcaa81913 ] While running a stress test which enables/disables clkgating, we occasionally hit device timeout. This patch avoids a subtle race condition to address it. Link: https://lore.kernel.org/r/20201117165839.1643377-3-jaegeuk@kernel.org Reviewed-by: Can Guo Signed-off-by: Jaegeuk Kim Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ufs/ufshcd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index a3a3ee6e2a002..68d3d463e2e16 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1649,19 +1649,19 @@ static ssize_t ufshcd_clkgate_enable_store(struct device *dev, return -EINVAL; value = !!value; + + spin_lock_irqsave(hba->host->host_lock, flags); if (value == hba->clk_gating.is_enabled) goto out; - if (value) { - ufshcd_release(hba); - } else { - spin_lock_irqsave(hba->host->host_lock, flags); + if (value) + __ufshcd_release(hba); + else hba->clk_gating.active_reqs++; - spin_unlock_irqrestore(hba->host->host_lock, flags); - } hba->clk_gating.is_enabled = value; out: + spin_unlock_irqrestore(hba->host->host_lock, flags); return count; } -- 2.27.0