From patchwork Tue Sep 17 04:52:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 20370 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AC1D028E98 for ; Tue, 17 Sep 2013 04:52:27 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id x20sf5126478qcv.7 for ; Mon, 16 Sep 2013 21:52:27 -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=xMmrKgo/xmCj2ghvPc/9DUytlao7avDavFpMAOFDus4=; b=WwodAfe2jxTMcHtCuxCu9WjIhNlbeIoLxsrjrzLQZ5E/ps8u7OldnjfETYDRE+rU3J 72ecjbTZXMGKyCOPiliGKwLeBp1FG5ZJ7e0XDvmQ3aKxEGRDBj6GiRLLCQGKhj4o0h00 9bBnCl3MpT8Zb/Ra0VIaXfwBFWYZaHKQV4D8KzEeB/SWxIDFfgX2L5UPbdaUyq5bYgF8 ZzyVBPhVFiZKdaSPgh2mZTZ7YxwkZ+nE6aBCAWJg4+9AhgnUfYSFMOaXgcNAQFDGDpXX OWnmpogQLcZgWQr0a4B256FXr93GAcQRh8DaJaiaPKfmazwq9wYGm55IG5T9vZ0Eu6Xh wuIQ== X-Gm-Message-State: ALoCoQk95tI0y576wV4GtnG3bYWp3QJCgJNVn5ogPe7M2LLeYcdJ4G4Zw4bCzEl/HwCfyWFZF87B X-Received: by 10.236.4.69 with SMTP id 45mr11558620yhi.20.1379393547162; Mon, 16 Sep 2013 21:52:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.64.38 with SMTP id l6ls1271219qes.89.gmail; Mon, 16 Sep 2013 21:52:27 -0700 (PDT) X-Received: by 10.58.73.202 with SMTP id n10mr30699394vev.7.1379393547073; Mon, 16 Sep 2013 21:52:27 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id se9si8001277vdc.75.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Sep 2013 21:52:26 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id hf12so3767270vcb.27 for ; Mon, 16 Sep 2013 21:52:26 -0700 (PDT) X-Received: by 10.221.51.206 with SMTP id vj14mr30570567vcb.17.1379393546817; Mon, 16 Sep 2013 21:52:26 -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 u4csp134497vcz; Mon, 16 Sep 2013 21:52:26 -0700 (PDT) X-Received: by 10.66.121.68 with SMTP id li4mr34121867pab.33.1379393545841; Mon, 16 Sep 2013 21:52:25 -0700 (PDT) Received: from mail-pb0-f47.google.com (mail-pb0-f47.google.com [209.85.160.47]) by mx.google.com with ESMTPS id iv2si24086500pac.148.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Sep 2013 21:52:25 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.47 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.160.47; Received: by mail-pb0-f47.google.com with SMTP id rr4so4964888pbb.20 for ; Mon, 16 Sep 2013 21:52:25 -0700 (PDT) X-Received: by 10.68.223.161 with SMTP id qv1mr32886989pbc.79.1379393545269; Mon, 16 Sep 2013 21:52:25 -0700 (PDT) Received: from localhost ([223.178.228.25]) by mx.google.com with ESMTPSA id dw3sm35269817pbc.17.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 16 Sep 2013 21:52:24 -0700 (PDT) From: Viresh Kumar To: rjw@sisk.pl 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, tixy@linaro.org, Viresh Kumar Subject: [PATCH V2 1/2] cpufreq: unlock correct rwsem while updating policy->cpu Date: Tue, 17 Sep 2013 10:22:11 +0530 Message-Id: <63ac1edc637ef2c8cf05579972506ad5365948c1.1379393377.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.220.182 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 release the same lock as was taken earlier. Also update_policy_cpu() was also called from cpufreq_add_dev() without any locks and so its better if we move this locking to inside update_policy_cpu(). Reported-and-Tested-by: Jon Medhurst Signed-off-by: Viresh Kumar --- Hi Rafael, Only one patch is sent now as other one is unchanged. drivers/cpufreq/cpufreq.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 43c24aa..1479522 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -952,9 +952,20 @@ 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. + * Also lock for last cpu is enough here as contention will happen only + * after policy->cpu is changed and after it is changed, other threads + * will try to acquire lock for new cpu. And policy is already updated + * by then. + */ + down_write(&per_cpu(cpu_policy_rwsem, policy->cpu)); + policy->last_cpu = policy->cpu; policy->cpu = cpu; + up_write(&per_cpu(cpu_policy_rwsem, policy->last_cpu)); + #ifdef CONFIG_CPU_FREQ_TABLE cpufreq_frequency_table_update_policy_cpu(policy); #endif @@ -1203,9 +1214,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 "