From patchwork Thu Feb 19 11:32:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 44826 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f199.google.com (mail-we0-f199.google.com [74.125.82.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E4BAC21554 for ; Thu, 19 Feb 2015 11:34:23 +0000 (UTC) Received: by wesq59 with SMTP id q59sf4671746wes.2 for ; Thu, 19 Feb 2015 03:34:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=BTq8AbLCE77nkkKjGaobyunjVuKaWsq1qpTEVUya8bk=; b=FaOdcjjKkG2ZSa1bXPfru4+AdnWIoFo7bj/tJRYkUEgGyWYgL+b4hkACcEpE2KgCPX Yzt/BGmIP3YrewF9gH42kpLsmFCm1UV9cZWA5CHl5V90b3iwqdS3pWptQ9H9EnHZLZrM axYO+zeEEfW8RgpBIO0L+PFrquWZGLMKOcRe7r+O1CbXbHIOrjY0M1uhglf7WxagMF/0 fDalWpofhmD0STVCemxlTcuuXaenDW35zxIKSiCIxGh0kX53OeiBaSXiTRqaR8Q/nDFE vcp5T7937+x+YzD6gMraa/KU1nEPaxQ74GdXqdH94Woh6b/wQlKyqTJIgM9/Z0Y/ThK8 C2iw== X-Gm-Message-State: ALoCoQlaOTPer6767x0qXv2elFQ/qeM1580y3oLcpHiNCGYEYxWFhHuGKAXRM0pRo0IywV8XLfAR X-Received: by 10.180.89.194 with SMTP id bq2mr639846wib.4.1424345663271; Thu, 19 Feb 2015 03:34:23 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.4 with SMTP id u4ls132860laj.88.gmail; Thu, 19 Feb 2015 03:34:23 -0800 (PST) X-Received: by 10.152.170.233 with SMTP id ap9mr3365498lac.47.1424345663096; Thu, 19 Feb 2015 03:34:23 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id bl1si8047088lbc.11.2015.02.19.03.34.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Feb 2015 03:34:23 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by labgd6 with SMTP id gd6so6986320lab.7 for ; Thu, 19 Feb 2015 03:34:23 -0800 (PST) X-Received: by 10.112.167.36 with SMTP id zl4mr3779155lbb.32.1424345663015; Thu, 19 Feb 2015 03:34:23 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp431841lbj; Thu, 19 Feb 2015 03:34:22 -0800 (PST) X-Received: by 10.70.50.10 with SMTP id y10mr6827521pdn.142.1424345661220; Thu, 19 Feb 2015 03:34:21 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m4si12171655pdm.252.2015.02.19.03.34.20; Thu, 19 Feb 2015 03:34:21 -0800 (PST) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753451AbbBSLeQ (ORCPT + 11 others); Thu, 19 Feb 2015 06:34:16 -0500 Received: from mail-pd0-f169.google.com ([209.85.192.169]:45633 "EHLO mail-pd0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753419AbbBSLeM (ORCPT ); Thu, 19 Feb 2015 06:34:12 -0500 Received: by pdjz10 with SMTP id z10so8225331pdj.12 for ; Thu, 19 Feb 2015 03:34:12 -0800 (PST) X-Received: by 10.70.92.3 with SMTP id ci3mr6652954pdb.147.1424345651925; Thu, 19 Feb 2015 03:34:11 -0800 (PST) Received: from localhost ([122.172.249.58]) by mx.google.com with ESMTPSA id nd5sm23402243pbc.64.2015.02.19.03.34.10 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 19 Feb 2015 03:34:11 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, sboyd@codeaurora.org, prarit@redhat.com, skannan@codeaurora.org, Viresh Kumar Subject: [PATCH V2 13/20] cpufreq: Don't allow updating inactive-policies from sysfs Date: Thu, 19 Feb 2015 17:02:15 +0530 Message-Id: <3e0a483f7c559534409bc303a410b7e7fd64dc82.1424345053.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.3.0.rc0.44.ga94655d In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Later commits would change the way policies are managed today. Policies wouldn't be freed on cpu hotplug (currently they aren't freed only for suspend), and while the CPU is offline, the sysfs cpufreq files would still be present. User may accidentally try to update the sysfs files in following directory: '/sys/devices/system/cpu/cpuX/cpufreq/'. And that would result in undefined behavior as policy wouldn't be active then. Apart from updating the store() routine, we also update __cpufreq_get() which can call cpufreq_out_of_sync(). The later routine tries to update policy->cur and starts notifying kernel about it. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index cab4cfdd3ebb..155e6ff2fa85 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -886,11 +886,22 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr, down_write(&policy->rwsem); + /* + * Policy might not be active currently, and so we shouldn't try + * updating any values here. policy->cpus is cleared for inactive policy + * and so cpufreq_cpu_get_raw() should fail. + */ + if (unlikely(policy_is_inactive(policy))) { + ret = -EPERM; + goto unlock_policy_rwsem; + } + if (fattr->store) ret = fattr->store(policy, buf, count); else ret = -EIO; +unlock_policy_rwsem: up_write(&policy->rwsem); up_read(&cpufreq_rwsem); @@ -1620,6 +1631,14 @@ static unsigned int __cpufreq_get(struct cpufreq_policy *policy) ret_freq = cpufreq_driver->get(policy->cpu); + /* + * Policy might not be active currently, and so we shouldn't try + * updating any values here. policy->cpus is cleared for inactive policy + * and so cpufreq_cpu_get_raw() should fail. + */ + if (unlikely(policy_is_inactive(policy))) + return ret_freq; + if (ret_freq && policy->cur && !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { /* verify no discrepancy between actual and