From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x227QKWh5Lr322jkGyxeA1B2qiCIh5up80Wk5hhlUGnYr+t2qKf7Y0N+ouja3HIZViPjiaCaR ARC-Seal: i=1; a=rsa-sha256; t=1517256459; cv=none; d=google.com; s=arc-20160816; b=0aYlte2TCLS/V9E045LhicQIkBeWdZ05IEq4RalVkUqeElbdkYdpgkPhf+MNUk3BvO VxuUzc9QDWmTRJ3bxaaqcHHnmFDFxPigNaQlDITQ4lCHvpxJgai9tsf7tCUBDBDgXV3s 8yUZCQx7Y/VoJxvqYYdgx271NvEmLqu63nlwjlfNF2FqrXNzT1/NnY0HZRLqYpOl2J5a c/uxeSM1XABeFr8HG6+f2u93CGixdyKPdmvCekOv9EFsaZ3t1zttAWNTR8tghLLlw2hK w4UylpYh2Xf93M9pMhx/woklejpcDyP48mZDfdADLCL8W62+ebjgl3bxVUb8mxUPEWTT mSAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Q/FsjsY3axzX6/nev/OLfZG8SXTRG0cZVf+LWtX+uGk=; b=D77aG7pXug08E2VJpS1nPgTaQCwuaoPBaXUo5Jz2LdVgaQoDc9pKmogDax6n9K15H+ 5iI4RUz5XRtCrt9iFMsDrUJniZoagx/DKz1O2qGr/6CNaKrYVGfJFss1oG/ibddOi9f4 HUcCdRGGDC/34vOFKlagwWvus4xMZHy3tg2Z4sKHTcrvpZmOhiQ5i5ZCJDuVqjaljyOE mvlaghH/9fKC9rPKI2s74mu1SBdmUlBLUKrHaLI/UBDAXVoj2Q7+LRLoHRbE0j71BEsp UahCmMgYdt08+1jPYrBdTweJInKXWdBbcdyT87TNkttb47noSkLGW+fhH9s7yU35q2Sf McSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Tang , Doug Smythies , "Rafael J. Wysocki" , Viresh Kumar Subject: [PATCH 4.14 71/71] cpufreq: governor: Ensure sufficiently large sampling intervals Date: Mon, 29 Jan 2018 13:57:39 +0100 Message-Id: <20180129123832.280139710@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123827.271171825@linuxfoundation.org> References: <20180129123827.271171825@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1590958709335377373?= X-GMAIL-MSGID: =?utf-8?q?1590958709335377373?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rafael J. Wysocki commit 56026645e2b6f11ede34a5e6ab69d3eb56f9c8fc upstream. After commit aa7519af450d (cpufreq: Use transition_delay_us for legacy governors as well) the sampling_rate field of struct dbs_data may be less than the tick period which causes dbs_update() to produce incorrect results, so make the code ensure that the value of that field will always be sufficiently large. Fixes: aa7519af450d (cpufreq: Use transition_delay_us for legacy governors as well) Reported-by: Andy Tang Reported-by: Doug Smythies Tested-by: Andy Tang Signed-off-by: Rafael J. Wysocki Acked-by: Viresh Kumar Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/cpufreq_governor.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) --- a/drivers/cpufreq/cpufreq_governor.c +++ b/drivers/cpufreq/cpufreq_governor.c @@ -22,6 +22,8 @@ #include "cpufreq_governor.h" +#define CPUFREQ_DBS_MIN_SAMPLING_INTERVAL (2 * TICK_NSEC / NSEC_PER_USEC) + static DEFINE_PER_CPU(struct cpu_dbs_info, cpu_dbs); static DEFINE_MUTEX(gov_dbs_data_mutex); @@ -47,11 +49,15 @@ ssize_t store_sampling_rate(struct gov_a { struct dbs_data *dbs_data = to_dbs_data(attr_set); struct policy_dbs_info *policy_dbs; + unsigned int sampling_interval; int ret; - ret = sscanf(buf, "%u", &dbs_data->sampling_rate); - if (ret != 1) + + ret = sscanf(buf, "%u", &sampling_interval); + if (ret != 1 || sampling_interval < CPUFREQ_DBS_MIN_SAMPLING_INTERVAL) return -EINVAL; + dbs_data->sampling_rate = sampling_interval; + /* * We are operating under dbs_data->mutex and so the list and its * entries can't be freed concurrently. @@ -430,7 +436,14 @@ int cpufreq_dbs_governor_init(struct cpu if (ret) goto free_policy_dbs_info; - dbs_data->sampling_rate = cpufreq_policy_transition_delay_us(policy); + /* + * The sampling interval should not be less than the transition latency + * of the CPU and it also cannot be too small for dbs_update() to work + * correctly. + */ + dbs_data->sampling_rate = max_t(unsigned int, + CPUFREQ_DBS_MIN_SAMPLING_INTERVAL, + cpufreq_policy_transition_delay_us(policy)); if (!have_governor_per_policy()) gov->gdbs_data = dbs_data;