Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp409503pxu; Tue, 1 Dec 2020 14:33:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPwSMRHTP0MypC2eGsTJ75pF/kzrzufBNCGwh/nb3Tigyo5nvcrqOYmT2gT5LCbUaSxQOk X-Received: by 2002:a17:906:a418:: with SMTP id l24mr5175467ejz.360.1606862005790; Tue, 01 Dec 2020 14:33:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606862005; cv=none; d=google.com; s=arc-20160816; b=VCkJcJIwuQ8Qoxqht0J4TTzND9MwRKTSIpFtX7TSRRChJ8kshpe5JLc4s48SOENwR1 T8wYu2fmg8/brF3z9056RgEIqpT6kTqTOzhP0hwCfp/XNxgg30nEdzYtMWixqPkwgnOP h6xXhkEdGE3rSyqb1vUu2qiqKUXDIvmFNyHv70Ds+J7IGkbc4L9O4kpHNJWkHckbs4C9 bztNJRaUF1ZzMqda6ni9HXBA5QrZYiSIWw9OCuz6mhXzbf022wOXBwZPiCR1hvClb9wI WHSkcSRW46XnhK41YwkOIQW7OaI1VXqhKh+ozsgN3j31R0iVjwHt7D9y7Q5Sih60k/jj OHFQ== 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=1T8jagKcJaMsH9jdSBaeyOcsb90g7JF4p3EQHURhPLY=; b=IaQAnWhCLa75+69gggBF8iU37qJcXJaxudAD9/xV50JgDj9z1rk66YkG5Era8Hth6Q zHPcgjHrJvwM/NabN16hBHAMno3P8lgQqP13VP1JbEF7fJsVIzKaqFeTytUaQSIHcix8 vu6hNZJTaRAw8Hjc22vVqdFzjFCw32DDKzQkm9GsIK7Y9DRWJpXTZZ1uPcVrqqWOgo/S wUPzQLHjTqG9748aVIuOaEEeqgGSwYtHWMSTQKb8ALI7vOgM8z3o9U9wKmQkFjeBqMOE Rl46+h/ZHAw91z3/WtnqVmOt7TMesNBKRc4pIBKw57Ep7GIf2V4DCLzfAmRE/lg7RVEG dGjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JB2vzzow; 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 g8si781256eje.472.2020.12.01.14.33.03; Tue, 01 Dec 2020 14:33:25 -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=JB2vzzow; 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 S2391200AbgLAJaS (ORCPT + 99 others); Tue, 1 Dec 2020 04:30:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:33456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387912AbgLAI6U (ORCPT ); Tue, 1 Dec 2020 03:58:20 -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 3957E22249; Tue, 1 Dec 2020 08:58:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813084; bh=d8IHuYRRoKwpYohJq3GP+buMDjgspo2KGBEpA63w+JI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JB2vzzow1c1qoXljHP92wcB8TG7jHb7fpQoX+TPMyzO2wlLlc/HfyY5PVJ58LDMZS UvPktSGoAjc0Hi4pCMeLNRGLDzBTbx/auS41MZfURbvkWBUSK6S/nslPy3xUR+tGHw WLGX/4r3Y1RxNMiTO44aDN2jr2lsY3OhpNXCKOT4= 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 4.14 28/50] scsi: ufs: Fix race between shutdown and runtime resume flow Date: Tue, 1 Dec 2020 09:53:27 +0100 Message-Id: <20201201084648.544632753@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084644.803812112@linuxfoundation.org> References: <20201201084644.803812112@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 c1792f271ac5d..a3a3ee6e2a002 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -7792,11 +7792,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