From patchwork Mon Sep 16 15:10:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 20346 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C275D2486B for ; Mon, 16 Sep 2013 15:10:36 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id i72sf4551606yha.1 for ; Mon, 16 Sep 2013 08:10:35 -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:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=eYpuwQ8FNgU9/dnTVXRPOjVlVCa/Ezpqo0KLJjVZWGY=; b=KSFMZ/hF5zC3/OKnNkUIKqu5GoF8yTq3oVk2B604nzr3hk4QvLnZfUnYqO2svTA4WX neL9Noy2jClW0kjjgolmPNMBYagPc+IXslhM1oYYtUyhmNV8YE0tBh2uwbD3TFWrQsz/ J7Q9tZ4tLf26Tzmzvoo9HLWpKqpSCZXjc+iKki64URJYQtDhB1urdhR8vYcgHMnjp7J+ 6MWUERGEzAtRnLwacuizoQ1A+J6GjtUls+WOmLiCTtxtkMKvKX5dDGVOuRwnT2g/miVO 4WnxNjB6N9ZhCNKwgYLG+/D1fB0EqNPF4gP9N3MVq9MHoeg3HattF6m8hCF+GrYzp5Mw Dd4g== X-Gm-Message-State: ALoCoQnaeKIBF8IiOquLRwTuxjEYqdYMRiN3AK8nzpbqJCijhjT6afvDaSA+QYyth/FMCSIxzxcY X-Received: by 10.58.46.1 with SMTP id r1mr192114vem.28.1379344235737; Mon, 16 Sep 2013 08:10:35 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.1.102 with SMTP id 6ls2285190qel.40.gmail; Mon, 16 Sep 2013 08:10:35 -0700 (PDT) X-Received: by 10.220.169.203 with SMTP id a11mr898038vcz.26.1379344235663; Mon, 16 Sep 2013 08:10:35 -0700 (PDT) Received: from mail-vb0-f42.google.com (mail-vb0-f42.google.com [209.85.212.42]) by mx.google.com with ESMTPS id l1si7208144vcl.64.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Sep 2013 08:10:35 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.42 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.42; Received: by mail-vb0-f42.google.com with SMTP id e12so3093499vbg.1 for ; Mon, 16 Sep 2013 08:10:35 -0700 (PDT) X-Received: by 10.58.75.131 with SMTP id c3mr24183540vew.12.1379344235579; Mon, 16 Sep 2013 08:10:35 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp102166vcz; Mon, 16 Sep 2013 08:10:34 -0700 (PDT) X-Received: by 10.68.178.197 with SMTP id da5mr29821365pbc.28.1379344233871; Mon, 16 Sep 2013 08:10:33 -0700 (PDT) Received: from mail-pd0-f182.google.com (mail-pd0-f182.google.com [209.85.192.182]) by mx.google.com with ESMTPS id e5si9324702pba.87.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Sep 2013 08:10:33 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.182 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.192.182; Received: by mail-pd0-f182.google.com with SMTP id r10so4241235pdi.13 for ; Mon, 16 Sep 2013 08:10:29 -0700 (PDT) X-Received: by 10.68.29.36 with SMTP id g4mr3277506pbh.145.1379344229053; Mon, 16 Sep 2013 08:10:29 -0700 (PDT) Received: from localhost ([122.167.152.64]) by mx.google.com with ESMTPSA id mr3sm31813790pbb.27.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 16 Sep 2013 08:10:28 -0700 (PDT) From: Viresh Kumar To: rjw@sisk.pl, tixy@linaro.org Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, srivatsa.bhat@linux.vnet.ibm.com, Viresh Kumar Subject: [PATCH 1/2] cpufreq: unlock correct rwsem while updating policy->cpu Date: Mon, 16 Sep 2013 20:40:16 +0530 Message-Id: <075032be4fd288074b8f699d4f4ba0179518df6f.1379344038.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.42 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Current code looks like this: WARN_ON(lock_policy_rwsem_write(cpu)); update_policy_cpu(policy, new_cpu); unlock_policy_rwsem_write(cpu); {lock|unlock}_policy_rwsem_write(cpu) takes/releases policy->cpu's rwsem. Because cpu is changing with the call to update_policy_cpu(), the unlock_policy_rwsem_write() will release the incorrect lock. The right solution would be to take rwsem lock/unlock for both old and new cpu. This patch fixes this bug by taking both locks directly instead of calling lock_policy_rwsem_write(). Reported-by: Jon Medhurst Signed-off-by: Viresh Kumar Tested-by: Jon Medhurst --- Hi Rafael, Probably we can get this patch in for 3.12? The second one can go in 3.13. These are compile tested only at my end. Tixy reported these and probably can give his tested-by once he is done testing them. drivers/cpufreq/cpufreq.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 43c24aa..c18bf7b 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -952,9 +952,16 @@ static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu) if (cpu == policy->cpu) return; + /* take direct locks as lock_policy_rwsem_write wouldn't work here */ + down_write(&per_cpu(cpu_policy_rwsem, policy->cpu)); + down_write(&per_cpu(cpu_policy_rwsem, cpu)); + policy->last_cpu = policy->cpu; policy->cpu = cpu; + up_write(&per_cpu(cpu_policy_rwsem, cpu)); + up_write(&per_cpu(cpu_policy_rwsem, policy->cpu)); + #ifdef CONFIG_CPU_FREQ_TABLE cpufreq_frequency_table_update_policy_cpu(policy); #endif @@ -1203,9 +1210,7 @@ static int __cpufreq_remove_dev_prepare(struct device *dev, new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu, frozen); if (new_cpu >= 0) { - WARN_ON(lock_policy_rwsem_write(cpu)); update_policy_cpu(policy, new_cpu); - unlock_policy_rwsem_write(cpu); if (!frozen) { pr_debug("%s: policy Kobject moved to cpu: %d "