Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4191221pxu; Tue, 20 Oct 2020 10:19:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySjPU+gMretG0UrJ26m5B3gv8KGcsiqA5MYk8zUxl/eu4OCbWIRdY5JJ0oRcYYLVKJexzf X-Received: by 2002:aa7:cd85:: with SMTP id x5mr4075813edv.0.1603214386630; Tue, 20 Oct 2020 10:19:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603214386; cv=none; d=google.com; s=arc-20160816; b=EKKuP2mrh/VRMwlPMJn9qTSWXqRtXN8Lpu6xaxKKoezgnZ7ysqmN/GtHuD0bCXwsVH hxQZuUG5ZP0gl6BiVdjr5idcMkaWpwDcV5CdnMCqu01Bi8vk4KSV+iTIG2hmQxPuJ6qb lvY6z5U3NlWdRDdq7mgrLFEbgQbrVS7V6ltPlldqYrXF6sLZQ4QkdcilkN2ygmMBn04X q37pv39IHf0nGi3zrIDNlv8l2TTBoqi6FlDSkPqmmyNDv7COvNm34ZLz0jmdHzhcXAT6 PKV1iDD8tQdHpTx6XCVSEPEwFjQyZZlxR//uu6QLYYrlitSrtSvBDyXPB9/lJsr63CVZ KvfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :sender:dkim-signature; bh=7V0ug32c1j1PP+hx2W4Yh8PnNSTX3h6faSFkylQvda0=; b=HVjrfMKEIDGaFGUM43Lz6F/5RL2W30erVzr9+NfLvM+qnX7vhwezPFkiwP8IPVwp0o WS72npBO+k/Qd9xtbQpsHDDjalaycttsDoPGwDs9DFv1NzePG+cFT917OJ54AKvqjxVt Xx4Tm92KYelAsHQtDVgLIpQB7Up7J+NzsCHcDzzbyNUTnHurFXzAemWUdpRmlvfMjmJr ouK48ZUd9BNPhegF9CT82Ce1dp/3MF7iHsqzj0eE6z0RSzhzXRfcj9JXG0GLzwkQN/Z6 iIBIKLhZ3bvq+t4bEfpM79sChIyMYc7zNCWy3XagaZil/vPJgMBJYZDg3DrLopHVm0we dPIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b="eywAp/bz"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qn3si1769500ejb.655.2020.10.20.10.19.23; Tue, 20 Oct 2020 10:19:46 -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=@mg.codeaurora.org header.s=smtp header.b="eywAp/bz"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730404AbgJTCf4 (ORCPT + 99 others); Mon, 19 Oct 2020 22:35:56 -0400 Received: from m42-4.mailgun.net ([69.72.42.4]:62653 "EHLO m42-4.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730415AbgJTCfz (ORCPT ); Mon, 19 Oct 2020 22:35:55 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1603161354; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=7V0ug32c1j1PP+hx2W4Yh8PnNSTX3h6faSFkylQvda0=; b=eywAp/bzcf6xLmnT8DVIciT6wPjO73Z780V5fzkAMxmESyxoaVyiAApDbXfPnICOZCDEjVIV Z4zH7I7HFhUp1767zub88j2OF/e0/icqfpDQx+UKRaXr+Y4ic12uUFp6AKK0nxml2WkCFASR OBdaFldpM4J5E9QgXgjBY4Rptyc= X-Mailgun-Sending-Ip: 69.72.42.4 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n07.prod.us-east-1.postgun.com with SMTP id 5f8e4d0aaad2c3cd1c610815 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 20 Oct 2020 02:35:54 GMT Sender: cang=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id DAA79C43382; Tue, 20 Oct 2020 02:35:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: cang) by smtp.codeaurora.org (Postfix) with ESMTPSA id 31967C433FE; Tue, 20 Oct 2020 02:35:53 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 20 Oct 2020 10:35:53 +0800 From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Bart Van Assche , linux-kernel@vger.kernel.org Subject: Re: [PATCH] scsi: ufs: Make sure clk scaling happens only when hba is runtime ACTIVE In-Reply-To: <1600758548-28576-1-git-send-email-cang@codeaurora.org> References: <1600758548-28576-1-git-send-email-cang@codeaurora.org> Message-ID: <67c4ae5998765daa674a4df696d8d673@codeaurora.org> X-Sender: cang@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Stanley, On 2020-09-22 15:09, Can Guo wrote: > If someone plays with the UFS clk scaling devfreq governor through > sysfs, > ufshcd_devfreq_scale may be called even when hba is not runtime ACTIVE, > which can lead to unexpected error. We cannot just protect it by > calling > pm_runtime_get_sync, because that may cause racing problem since hba > runtime suspend ops needs to suspend clk scaling. In order to fix it, > call > pm_runtime_get_noresume and check hba's runtime status, then only > proceed > if hba is runtime ACTIVE, otherwise just bail. > > governor_store > devfreq_performance_handler > update_devfreq > devfreq_set_target > ufshcd_devfreq_target > ufshcd_devfreq_scale > > Signed-off-by: Can Guo > > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c > index e4cb994..847f355 100644 > --- a/drivers/scsi/ufs/ufshcd.c > +++ b/drivers/scsi/ufs/ufshcd.c > @@ -1294,8 +1294,15 @@ static int ufshcd_devfreq_target(struct device > *dev, > } > spin_unlock_irqrestore(hba->host->host_lock, irq_flags); > > + pm_runtime_get_noresume(hba->dev); > + if (!pm_runtime_active(hba->dev)) { > + pm_runtime_put_noidle(hba->dev); > + ret = -EAGAIN; > + goto out; > + } > start = ktime_get(); > ret = ufshcd_devfreq_scale(hba, scale_up); > + pm_runtime_put(hba->dev); > > trace_ufshcd_profile_clk_scaling(dev_name(hba->dev), > (scale_up ? "up" : "down"), Could you please review this one since we may be the only two users of clk scaling? Thanks, Can Guo.