From patchwork Wed Nov 5 14:53:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prarit Bhargava X-Patchwork-Id: 5234821 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 98F6D9F295 for ; Wed, 5 Nov 2014 15:00:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 75FA12017A for ; Wed, 5 Nov 2014 15:00:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4E9E9201FA for ; Wed, 5 Nov 2014 15:00:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755265AbaKEO7Z (ORCPT ); Wed, 5 Nov 2014 09:59:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50939 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755347AbaKEOyT (ORCPT ); Wed, 5 Nov 2014 09:54:19 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sA5Es6Cu024671 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 5 Nov 2014 09:54:06 -0500 Received: from praritdesktop.bos.redhat.com (prarit-guest.khw.lab.eng.bos.redhat.com [10.16.186.145]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sA5Es3JB005051; Wed, 5 Nov 2014 09:54:05 -0500 From: Prarit Bhargava To: linux-kernel@vger.kernel.org Cc: robert.schoene@tu-dresden.de, sboyd@codeaurora.org, Prarit Bhargava , "Rafael J. Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org Subject: [PATCH 2/5] cpufreq, fix locking around CPUFREQ_GOV_POLICY_EXIT calls Date: Wed, 5 Nov 2014 09:53:56 -0500 Message-Id: <1415199239-19019-3-git-send-email-prarit@redhat.com> In-Reply-To: <1415199239-19019-1-git-send-email-prarit@redhat.com> References: <1415199239-19019-1-git-send-email-prarit@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP commit 955ef4833574636819cd269cfbae12f79cbde63a (" cpufreq: Drop rwsem lock around CPUFREQ_GOV_POLICY_EXIT") opens up a hole in the locking scheme for cpufreq. Simple tests such as rapidly switching the governor between ondemand and performance or attempting to read policy values while a governor switch occurs now fail with very NULL pointer warnings, sysfs namespace collisions, and system hangs. In short, the locking that policy->rwsem is supposed to provide is currently broken. The identified commit attempts to resolve a lockdep warning by removing a lock around a section of code which does a shutdown of the existing policy. The problem is that this is part of the _critical_ section of code that switches the governors and must be protected by the lock; without locking readers may access now NULL or stale data, and writes may collide with each other. With the previous patch, which now returns -EBUSY during times of contention the deadlock reported in 955ef4833574636819cd269cfbae12f79cbde63a (" cpufreq: Drop rwsem lock around CPUFREQ_GOV_POLICY_EXIT") cannot occur, so adding the locks back into this section of code is possible. Cc: "Rafael J. Wysocki" Cc: Viresh Kumar Cc: linux-pm@vger.kernel.org Signed-off-by: Prarit Bhargava --- drivers/cpufreq/cpufreq.c | 4 ---- include/linux/cpufreq.h | 4 ---- 2 files changed, 8 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 3f09ca9..e33cb15 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2222,9 +2222,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, /* end old governor */ if (old_gov) { __cpufreq_governor(policy, CPUFREQ_GOV_STOP); - up_write(&policy->rwsem); __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); - down_write(&policy->rwsem); } /* start new governor */ @@ -2233,9 +2231,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, if (!__cpufreq_governor(policy, CPUFREQ_GOV_START)) goto out; - up_write(&policy->rwsem); __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); - down_write(&policy->rwsem); } /* new governor failed, so re-start old one */ diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 503b085..43909ad 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -100,10 +100,6 @@ struct cpufreq_policy { * - Any routine that will write to the policy structure and/or may take away * the policy altogether (eg. CPU hotplug), will hold this lock in write * mode before doing so. - * - * Additional rules: - * - Lock should not be held across - * __cpufreq_governor(data, CPUFREQ_GOV_POLICY_EXIT); */ struct rw_semaphore rwsem;