Received: by 10.223.176.5 with SMTP id f5csp3357690wra; Mon, 29 Jan 2018 12:08:46 -0800 (PST) X-Google-Smtp-Source: AH8x227dzl6kPnh0xYRfF9+51kqpnsOaDBUEmZm1qIM/1MozES6OuKZJBfj9RLPYQG++D/e7Y+33 X-Received: by 10.98.80.20 with SMTP id e20mr27736256pfb.148.1517256526245; Mon, 29 Jan 2018 12:08:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517256526; cv=none; d=google.com; s=arc-20160816; b=nBjUQyeq9HeFTzaDhG6rDsu/ICt3upY2Ioekevat8bIcAwhIyV2F9j4iV2J4y496cU h9mKqPLkQnv7hIjLMHWdCuThnSBDWfLPvUbLBI7rJXaEu1R3Ivq6AbS7YAbC7r7jNO0q aeflvoA/wZ52ZdPjHUfb5NhYH4CFccNH6gFWBs3dLZYPAuIF2GY78zEchu9EjQSjvdZ0 nUXURl/B4tYCW+1bRBmNXtkwJqFHbhTJvc4rce5Jx10IR+AamLTj367YapQyn0Hz7IAr EZleZV3eStB7OXaG6a9fad79yBX6YQyWb+8zcVcifWy3qm6qmJ0+1OCIC2hP3uCzGmXq 0tJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender: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=QXNa7aNGroyJkjZ9SbJZ0SeVoPbCey2Vy99MpZiuKYroQZ9xEaNLfKIkYCPApEP7gD k3WNmaUsBk8j5JIDzF/IYQ+4N6HCAn6efojgsXf90eHh/aYn0+h1OsIsuwxP3Jelp6cH wmI+qvBZZnMcHUEu12358w3kaj7vNE8s67BjmZi7LMtsxPiLnuosyjZXDCRjiarRDePP xCU8SlnFlVxQ5YvK4Qz7p7iOg32dWNWgThmPK9QG1pzq6z204oaLbDQGx9eRU5zJaACL q1ro9UgpyLk8ohiX8Dxz6pXHPLbYXKB61sMBwnzSo1TKS6rSFD8+GJlCq1eHVgA3+Lka pDjQ== 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 s64si1981204pfk.33.2018.01.29.12.08.31; Mon, 29 Jan 2018 12:08:46 -0800 (PST) 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 S1752949AbeA2UHm (ORCPT + 99 others); Mon, 29 Jan 2018 15:07:42 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:51228 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752587AbeA2UHi (ORCPT ); Mon, 29 Jan 2018 15:07:38 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 84B32304A; Mon, 29 Jan 2018 13:11:16 +0000 (UTC) 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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;