From patchwork Mon Jun 8 12:55:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 49614 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8EF1A21419 for ; Mon, 8 Jun 2015 12:56:40 +0000 (UTC) Received: by wifx6 with SMTP id x6sf20898880wif.1 for ; Mon, 08 Jun 2015 05:56:39 -0700 (PDT) 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=S8HTWvKi2X6H7WWTVXLzV7sTukJZ9jpsYeIRkIpffLk=; b=m3qhJvje166jybLBYG7BqCB5da0JdiISKK6xafzFSLEPZ4N19pcUAzr55nABGU7+nQ uv61rFCAwjqkWaszeZMumVHWhTJk3NQiRwIEoTdkNjCLUYFmZR32XRgSnvq+s+Fys5Az Cs/EeQwp3kDcj6XdFpPEvbgvs/AmXp1f+Ks6oUV4pSDeTKB0ISvswJao17F7E/tWDE3p 6FXm/qgrRpFA/FOlpbNtIp9TOV6NBVXLgyd6/ucabHuyRoDcFSl5doQ/qjG78GoNIaHe nSDUuZ/17+LTcKKIfxCXuSW4FZjnltarbBINoBfa0NWWAon47upI0xUgZFdeP46eGT0f Rb1g== X-Gm-Message-State: ALoCoQmUp2D6b6eZcoXU553IUXwrqhFJ9eoSvXasTHsZNs3lDx6dUYvxH1z0Vwem1iH9uVWoYIol X-Received: by 10.112.14.101 with SMTP id o5mr17006402lbc.3.1433768199865; Mon, 08 Jun 2015 05:56:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.178.195 with SMTP id da3ls670449lac.43.gmail; Mon, 08 Jun 2015 05:56:39 -0700 (PDT) X-Received: by 10.112.242.40 with SMTP id wn8mr16626279lbc.57.1433768199725; Mon, 08 Jun 2015 05:56:39 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id am2si2674182lac.0.2015.06.08.05.56.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jun 2015 05:56:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by laew7 with SMTP id w7so96295076lae.1 for ; Mon, 08 Jun 2015 05:56:39 -0700 (PDT) X-Received: by 10.112.140.231 with SMTP id rj7mr16543073lbb.76.1433768199617; Mon, 08 Jun 2015 05:56:39 -0700 (PDT) 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.108.230 with SMTP id hn6csp1845129lbb; Mon, 8 Jun 2015 05:56:38 -0700 (PDT) X-Received: by 10.68.114.131 with SMTP id jg3mr29700163pbb.54.1433768197774; Mon, 08 Jun 2015 05:56:37 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id df1si4029496pad.84.2015.06.08.05.56.36; Mon, 08 Jun 2015 05:56:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753178AbbFHM4K (ORCPT + 11 others); Mon, 8 Jun 2015 08:56:10 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:36509 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752248AbbFHMzx (ORCPT ); Mon, 8 Jun 2015 08:55:53 -0400 Received: by pabqy3 with SMTP id qy3so96980650pab.3 for ; Mon, 08 Jun 2015 05:55:53 -0700 (PDT) X-Received: by 10.70.29.4 with SMTP id f4mr29886292pdh.23.1433768152951; Mon, 08 Jun 2015 05:55:52 -0700 (PDT) Received: from localhost ([122.167.219.251]) by mx.google.com with ESMTPSA id cd10sm2597970pac.7.2015.06.08.05.55.51 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 08 Jun 2015 05:55:52 -0700 (PDT) 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, Srivatsa Bhat , Viresh Kumar Subject: [PATCH V7 1/6] cpufreq: Don't allow updating inactive policies from sysfs Date: Mon, 8 Jun 2015 18:25:27 +0530 Message-Id: <243ddd967eebe1cafeda824a5ab5c67885d3653d.1433767914.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 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.44 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 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 5d780ff5a10a..7eeff892c0a6 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -875,11 +875,18 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr, down_write(&policy->rwsem); + /* Updating inactive policies is invalid, so avoid doing that. */ + 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); @@ -1610,6 +1617,10 @@ static unsigned int __cpufreq_get(struct cpufreq_policy *policy) ret_freq = cpufreq_driver->get(policy->cpu); + /* Updating inactive policies is invalid, so avoid doing that. */ + 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