Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3238492pxk; Tue, 15 Sep 2020 13:51:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZo2B6uRrMPSup5oFGRIPRsiwBevtmz7sar4tl+ecBZ191m08FiELT6UoZxUXfjFgqvrah X-Received: by 2002:a17:906:4046:: with SMTP id y6mr23053574ejj.148.1600203096267; Tue, 15 Sep 2020 13:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600203096; cv=none; d=google.com; s=arc-20160816; b=Kx0KldzKeHEt4Wu871NT01t5BZy1nxDlfDqZzvGvfjSLX6Dn+/9cpCPfM+few5uPBo b+tDrKIegDn3KUndL26m3LHk7kcLpIj3rWsVVwW6gF2l08GRljiIK/eyNg31TqXpG/KJ az9cCAxh3mg+23n65VQ/Nta6emoyo40XgHGncLCYyS9PLt045DvawNtFfBba8tZBEXNC IwY8ClwTV/PgPSNP4Lhr9olZ7JW33FJDOhp1H6ZTprKZIS/NNsWoygzQ0XQSPTxu2kF7 frlZBNTSUT9N1CCvTKbCaejPyhMEEWLlMgv6cYXbYCdGV4LTp0vusULYDmpFzvGkAvEj T/rA== 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:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=AJRAhOU+4QcB7K5Dzsc/jojGM4hcO3KzPBNYaA+aY/k=; b=HfTDWAf9HLaAgBTFgGs0rNC0qSleHEq3fVfJlV7sZ1E0c7PisBkWR8S1Tamcpuy7Ht Tm5MeYMTpXbvRELEOSf1SsuUSCVLqMMSSV9pGABCpzwlXd8m5Ys63PkmJVH9UmhUbTDo rWBo29ca5U4dp3QtbesvUih4dNOA+I7Z3itTEf9z8X+G67N1q18wUhRmvRFJqvCERXjs v9PAxfmpoySuiTSAmVt9Hlp4b/Gqi2aFVLfDXSX+0yP22Sp51waX499cD28kqiwCsBVM Wubsrn2yKp2zgAAv2KjqW6au59cOEixZ+ZwDlYORefaXpQ+p50/14ItnC9gilqGP1x/Q Xsww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TcTPD5Cj; 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 q21si10373798eds.392.2020.09.15.13.51.13; Tue, 15 Sep 2020 13:51:36 -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=default header.b=TcTPD5Cj; 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 S1728084AbgIOUrV (ORCPT + 99 others); Tue, 15 Sep 2020 16:47:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:42646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726454AbgIOUqg (ORCPT ); Tue, 15 Sep 2020 16:46:36 -0400 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3A4F120809; Tue, 15 Sep 2020 20:46:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600202796; bh=biBRsrW4Fs+Y3FfatFGMejxQwq4kpwq0ahfzBoNIGAM=; h=From:To:Cc:Subject:Date:From; b=TcTPD5CjNScvnACas/DuxQfwIjEVgKejo6dLSYhm84AuwpnT25q9TzTumsFBiJbCq 0ltWf08wjOzM7tYCAoEJ6QMl1yuBlSB9OZ/ca/xZNMSyB0B3cLS6X5Pil/J2KyoWpB /+pt0YNu3CMzHZHBvVJXIxUlgKqGHqzwXplGgKCU= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, kernel-team@android.com Cc: Jaegeuk Kim , Alim Akhtar , Avri Altman Subject: [PATCH 1/6] scsi: ufs: atomic update for clkgating_enable Date: Tue, 15 Sep 2020 13:45:27 -0700 Message-Id: <20200915204532.1672300-1-jaegeuk@kernel.org> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jaegeuk Kim When giving a stress test which enables/disables clkgating, we hit device timeout sometimes. This patch avoids subtle racy condition to address it. Cc: Alim Akhtar Cc: Avri Altman Signed-off-by: Jaegeuk Kim --- 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 1d157ff58d817..d929c3d1e58cc 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1791,19 +1791,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) + hba->clk_gating.active_reqs--; + 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.28.0.618.gf4bc123cb7-goog