Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp322956imm; Fri, 25 May 2018 23:51:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZod+TDzERS0IfuJ98mdH7FUU4xuBF8TrxNchFHnjiozNFTgI3PlhDBC7JB0cBEL1v2Ey7zJ X-Received: by 2002:a63:7c04:: with SMTP id x4-v6mr4203172pgc.67.1527317507047; Fri, 25 May 2018 23:51:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527317507; cv=none; d=google.com; s=arc-20160816; b=RznMwqDF5Sx2w3SdBXX0f92/uwtdHPRVDRUp6cxwvyugIbYqbnGHEacX8KxzNyWzgk zKEn7L+W+rKPvmGANYGaDzhYOG/lR4bdAEygd/CxnQSxotfBwjOZyCBisAPpf1PfC9jI sjFAFIZjf+fAGrQvL6K2UD3aj8IygvuqOWb+m4cbQu3TkOX8oQa1fpI9ITEJUKswG5jx m38fxPtthmHlLtpmvJbaq1vmdtyKUOAE1SKSPVhwYKPw/8gTg1OI2vCeL9UTlOQo0qFy BkNylGuKtz5UI9gpqYexWVeRCjy3PR9b0So/YcicbA2e18OkA4kzP7dYi6UQDGfO6jxB S4Cw== 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:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject:arc-authentication-results; bh=jS4GkyLNhcVASQuW5ZedQoA8H37+klJT5n/BIKn93MA=; b=SNZiHgCNtIaOD2DigVdcMfNpoyiXimj4CiKhhgjNE1ZzF8ZNjJgjVZhQQXQ9qDnF12 LPHd5aXDshX99AN5d9KU4Fq9IDOgI864zlBgJWxAPCR04KupK4OwMFUc2GeVMCTI09M9 D0CbHE+b2pSqaXrBwPD5BUugoB62as4ptRpg0/UJCO2NrrsOWhrpEJ+UCUx49RLe125i kQw8/pMnho9FCDlefDorgnxoi6G3uF+Z34477EAUHOrikJ4Pk5aM5kyEE4CfVEnOmA6m gsGsTsXf71D1X+7FOB6wiCMHeRjNjZU1I2ogNhT1R5qQGHRUnScpvM26nDn0eauTLUfX R4yQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b3-v6si5143672pls.119.2018.05.25.23.51.19; Fri, 25 May 2018 23:51:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031201AbeEZGvJ (ORCPT + 99 others); Sat, 26 May 2018 02:51:09 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:8149 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1031142AbeEZGvH (ORCPT ); Sat, 26 May 2018 02:51:07 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 60044C9C95D2F; Sat, 26 May 2018 14:50:54 +0800 (CST) Received: from [127.0.0.1] (10.121.90.40) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.382.0; Sat, 26 May 2018 14:50:47 +0800 Subject: Re: [PATCH] cpufreq: reinitialize new policy min/max when writing scaling_(max|min)_freq To: "Rafael J. Wysocki" CC: "Rafael J. Wysocki" , Viresh Kumar , Linux PM , "Linux Kernel Mailing List" , , References: <1527144234-96396-1-git-send-email-kevin.wangtao@hisilicon.com> From: "Wangtao (Kevin, Kirin)" Message-ID: Date: Sat, 26 May 2018 14:50:46 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.121.90.40] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2018/5/24 15:45, Rafael J. Wysocki 写道: > On Thu, May 24, 2018 at 8:43 AM, Kevin Wangtao > wrote: >> consider such situation, current user_policy.min is 1000000, >> current user_policy.max is 1200000, in cpufreq_set_policy, >> other driver may update policy.min to 1200000, policy.max to >> 1300000. After that, If we input "echo 1300000 > scaling_min_freq", >> then user_policy.min will be 1300000, and user_policy.max is >> still 1200000, because the input value is checked with policy.max >> not user_policy.max. if we get all related cpus offline and >> online again, it will cause cpufreq_init_policy fail because >> user_policy.min is higher than user_policy.max. > > How do you reproduce this, exactly? I can also reproduce this issue with upstream code, write max frequency to scaling_max_freq and scaling_min_freq, run benchmark to let cpu cooling take effect to clip freq, then write the cliped freq to scaling_max_freq, thus user_policy.min is still max frequency but user_policy.max is cliped freq which is lower than max frequency. > >> The solution is when user space tries to write scaling_(max|min)_freq, >> the min/max of new_policy should be reinitialized with min/max >> of user_policy, like what cpufreq_update_policy does. >> >> Signed-off-by: Kevin Wangtao >> --- >> drivers/cpufreq/cpufreq.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c >> index b79c532..8b33e08 100644 >> --- a/drivers/cpufreq/cpufreq.c >> +++ b/drivers/cpufreq/cpufreq.c >> @@ -697,6 +697,8 @@ static ssize_t store_##file_name \ >> struct cpufreq_policy new_policy; \ >> \ >> memcpy(&new_policy, policy, sizeof(*policy)); \ >> + new_policy->min = policy->user_policy.min; \ >> + new_policy->max = policy->user_policy.max; \ > > It looks like you haven't even tried to build this, have you? > >> \ >> ret = sscanf(buf, "%u", &new_policy.object); \ >> if (ret != 1) \ >> -- >> 2.8.1 >> > > . >