Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp405708pxu; Tue, 1 Dec 2020 14:26:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJwOu3N7N5B6Fy0K4qWk62sXQZk3x+p9LSIkpSbuzPqp0DfoOAIuNtzdv/b08HeB2HlfhJZL X-Received: by 2002:a50:fe0e:: with SMTP id f14mr1138824edt.159.1606861607422; Tue, 01 Dec 2020 14:26:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606861607; cv=none; d=google.com; s=arc-20160816; b=DbzZU3+dniQjZmIPmMxt2R/URsidLFwRTadDItNzIH+6zK82R0psJiUv0kba7z4bS6 1flBgy6WnaDVhx4napl7wA0iJLhm178PfeWOKg87O1rHYdVlm2QHpjTJcZUcoY4mXj7F kMfiUgljcKFUuzcfxTnTXtaWHZFdcRZ3GbzHxqanG1vyrRh0I8phLG1AlLcJNaiGUz5+ RknQI8gLom6xt6DAboK14hF7aesgsRJLwqvFRRykV3ZF9Z1czbza5AIBNws7GfNbac16 nCbkqNhrHuiaYHEAeN0ugGLI7ze1tlWvyWUs+C4E9NWyVLCY8ivWlB8+5dgJLsjTjYjU 6zGA== 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=2RGblI1tQalioXhxV13+sVlqdDu29kU/p2RPk3bIe+0=; b=lQg2A5ZdYKCTpenJ+Mbn+ynSdb2Ng7N8OxpQZXiom7zkuAwlatgyfOGd/mqKcp9kgm bh7Y/UiMqqMTWUyRmd9vSPoN2O1CAc79xUi7nvQBsj6KXSbdAr5CZCYCApHdJkxqZlMG d8unZBfkUryIjFrGU1MfrQzRTqhqup/hGE9q0GgqfU9/Bh55qQu87dBe61LlV42pIWZW WwDAseFZvLraGmo5JxE6QfrxFF+GkVnPYVTguUAx/Kc6cuiAgrPvnjyRacMpGry2/gjy +rMj6OAaXZ+Zhxw96vSSVbMJXvWqdr4+IVJXIf1yXybC6KPMHkiOoUCGJbOl3pzMlodp MGtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="fiOkyTm/"; 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 h24si961943ejt.452.2020.12.01.14.26.24; Tue, 01 Dec 2020 14:26:47 -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=@linuxfoundation.org header.s=korg header.b="fiOkyTm/"; 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 S2389916AbgLAJMH (ORCPT + 99 others); Tue, 1 Dec 2020 04:12:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:49804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389869AbgLAJLw (ORCPT ); Tue, 1 Dec 2020 04:11:52 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 B1930206CA; Tue, 1 Dec 2020 09:11:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813866; bh=gZUy9sOtSVHr5uqtxS43GBHqAB8ImEcW8gdBUwymuYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fiOkyTm/pqiGjdqNPaibUa/402lkkg3WawUQbe82Rp/IUC10XLLbABWv7kfa6ZJb1 MZxMJ5B2aB3SckY6uYDYHdAJZa6jRj8TPSLcF+b18oO7C7wxwbg5XjbXjLxs3F7tsm e32adSHWxwJ15E+FDg1e6H297XGJi5WOjICrbSYQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Can Guo , Stanley Chu , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.9 087/152] scsi: ufs: Fix race between shutdown and runtime resume flow Date: Tue, 1 Dec 2020 09:53:22 +0100 Message-Id: <20201201084723.274391017@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084711.707195422@linuxfoundation.org> References: <20201201084711.707195422@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: Stanley Chu [ Upstream commit e92643db514803c2c87d72caf5950b4c0a8faf4a ] If UFS host device is in runtime-suspended state while UFS shutdown callback is invoked, UFS device shall be resumed for register accesses. Currently only UFS local runtime resume function will be invoked to wake up the host. This is not enough because if someone triggers runtime resume from block layer, then race may happen between shutdown and runtime resume flow, and finally lead to unlocked register access. To fix this, in ufshcd_shutdown(), use pm_runtime_get_sync() instead of resuming UFS device by ufshcd_runtime_resume() "internally" to let runtime PM framework manage the whole resume flow. Link: https://lore.kernel.org/r/20201119062916.12931-1-stanley.chu@mediatek.com Fixes: 57d104c153d3 ("ufs: add UFS power management support") Reviewed-by: Can Guo Signed-off-by: Stanley Chu Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ufs/ufshcd.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 54928a837dad0..9dd32bb0ff2be 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -8677,11 +8677,7 @@ int ufshcd_shutdown(struct ufs_hba *hba) if (ufshcd_is_ufs_dev_poweroff(hba) && ufshcd_is_link_off(hba)) goto out; - if (pm_runtime_suspended(hba->dev)) { - ret = ufshcd_runtime_resume(hba); - if (ret) - goto out; - } + pm_runtime_get_sync(hba->dev); ret = ufshcd_suspend(hba, UFS_SHUTDOWN_PM); out: -- 2.27.0