From patchwork Thu May 16 05:09:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 16972 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 78CE725E17 for ; Thu, 16 May 2013 05:11:25 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id c10sf1954613qcz.10 for ; Wed, 15 May 2013 22:10:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:in-reply-to:references:x-gm-message-state :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:x-google-group-id:list-post:list-help :list-archive:list-unsubscribe; bh=x/u+OiSwreDJGz6VI4NTWZYnm9VmZJURnSDtu1WuG2s=; b=M71itzX/Aph3podhP2HITGkDquMtThF6QG/fWJUL5tLzdN1epNRPtH8N3UkbtuSpzV sn7iqnMcdGZNciJCzWLztXxV6ZHHdSfWHAI4iwUFcocivzZt7y/Lysm2ZKKnEUdEup9k S3895JuaB1Ip6v+4zO+JU/3e2IrWEG/1tSSWSZEfwECEfaJ7lL2Rzb1RwQh7tWG7mrxC vjTp8ga36xwWf97RPJsDpY+O1nXV0OxTDVZfwoB8ODnEkTHDaI+4LD6Fk3hzOc64AC7s +Wa3k50NNha3lnHnVw7F8zpz7pDp3WX2djHSpaJfZbqiWTTBVnQZ7ui4IN7LQRp+u2gC N0Tg== X-Received: by 10.236.135.65 with SMTP id t41mr20783822yhi.42.1368681047115; Wed, 15 May 2013 22:10:47 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.27.161 with SMTP id u1ls1112726qeg.57.gmail; Wed, 15 May 2013 22:10:47 -0700 (PDT) X-Received: by 10.220.85.66 with SMTP id n2mr27207048vcl.31.1368681046962; Wed, 15 May 2013 22:10:46 -0700 (PDT) Received: from mail-ve0-x233.google.com (mail-ve0-x233.google.com [2607:f8b0:400c:c01::233]) by mx.google.com with ESMTPS id p8si3125985vdv.5.2013.05.15.22.10.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 May 2013 22:10:46 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::233 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::233; Received: by mail-ve0-f179.google.com with SMTP id oz10so2628115veb.24 for ; Wed, 15 May 2013 22:10:46 -0700 (PDT) X-Received: by 10.52.20.210 with SMTP id p18mr22568942vde.42.1368681046762; Wed, 15 May 2013 22:10:46 -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.126.138 with SMTP id c10csp47998vcs; Wed, 15 May 2013 22:10:46 -0700 (PDT) X-Received: by 10.66.14.1 with SMTP id l1mr42798205pac.150.1368681045897; Wed, 15 May 2013 22:10:45 -0700 (PDT) Received: from mail-pd0-f179.google.com (mail-pd0-f179.google.com [209.85.192.179]) by mx.google.com with ESMTPS id pf4si3554818pbc.254.2013.05.15.22.10.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 May 2013 22:10:45 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.179 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=209.85.192.179; Received: by mail-pd0-f179.google.com with SMTP id q10so1976779pdj.24 for ; Wed, 15 May 2013 22:10:45 -0700 (PDT) X-Received: by 10.68.184.100 with SMTP id et4mr41120257pbc.48.1368681045374; Wed, 15 May 2013 22:10:45 -0700 (PDT) Received: from localhost ([106.197.193.133]) by mx.google.com with ESMTPSA id kv2sm5311353pbc.28.2013.05.15.22.10.37 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 15 May 2013 22:10:44 -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, robin.randhawa@arm.com, Steve.Bannister@arm.com, Liviu.Dudau@arm.com, charles.garcia-tobin@arm.com, arvind.chauhan@arm.com, Viresh Kumar Subject: [PATCH 3/3] cpufreq: Drop rwsem lock around CPUFREQ_GOV_POLICY_EXIT Date: Thu, 16 May 2013 10:39:58 +0530 Message-Id: <84fda3b9bd78dbdb8bd062b130365342b4cf202b.1368679353.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQmftymyA9XUuoVw//slmxkEe/TQeghHTynM97QZiltRkcyPa6B5RKDgauJz1LgYnexj7nlA X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::233 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: , With this lock around __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT), we get circular dependency when we call sysfs_remove_group(). [ 195.319079] ====================================================== [ 195.337653] [ INFO: possible circular locking dependency detected ] [ 195.356497] 3.9.0-rc7+ #15 Not tainted [ 195.367758] ------------------------------------------------------- [ 195.386613] cat/2387 is trying to acquire lock: [ 195.400176] (&per_cpu(cpu_policy_rwsem, cpu)){+++++.}, at: [] lock_policy_rwsem_read+0x25/0x34 [ 195.428920] [ 195.428920] but task is already holding lock: [ 195.446393] (s_active#41){++++.+}, at: [] sysfs_read_file+0x4f/0xcc [ 195.468305] [ 195.468305] which lock already depends on the new lock. [ 195.468305] [ 195.492830] [ 195.492830] the existing dependency chain (in reverse order) is: [ 195.515250] -> #1 (s_active#41){++++.+}: [ 195.527647] [] lock_acquire+0x61/0xbc [ 195.543129] [] sysfs_addrm_finish+0xc1/0x128 [ 195.560362] [] sysfs_hash_and_remove+0x35/0x64 [ 195.578119] [] remove_files.isra.0+0x1b/0x24 [ 195.595497] [] sysfs_remove_group+0x2d/0xa8 [ 195.612469] [] cpufreq_governor_interactive+0x13b/0x35c [ 195.632668] [] __cpufreq_governor+0x2b/0x8c [ 195.649644] [] __cpufreq_set_policy+0xa9/0xf8 [ 195.667132] [] store_scaling_governor+0x61/0x100 [ 195.685404] [] store+0x39/0x60 [ 195.698989] [] sysfs_write_file+0xed/0x114 [ 195.715694] [] vfs_write+0x65/0xd8 [ 195.730320] [] sys_write+0x2f/0x50 [ 195.744943] [] ret_fast_syscall+0x1/0x52 [ 195.761135] -> #0 (&per_cpu(cpu_policy_rwsem, cpu)){+++++.}: [ 195.778665] [] __lock_acquire+0xef3/0x13dc [ 195.795371] [] lock_acquire+0x61/0xbc [ 195.810776] [] down_read+0x25/0x30 [ 195.825398] [] lock_policy_rwsem_read+0x25/0x34 [ 195.843410] [] show+0x21/0x58 [ 195.856731] [] sysfs_read_file+0x67/0xcc [ 195.872919] [] vfs_read+0x63/0xd8 [ 195.887282] [] sys_read+0x2f/0x50 [ 195.901645] [] ret_fast_syscall+0x1/0x52 [ 195.917863] [ 195.917863] other info that might help us debug this: [ 195.917863] [ 195.941853] Possible unsafe locking scenario: [ 195.941853] [ 195.959586] CPU0 CPU1 [ 195.973149] ---- ---- [ 195.986712] lock(s_active#41); [ 195.996407] lock(&per_cpu(cpu_policy_rwsem, cpu)); [ 196.018912] lock(s_active#41); [ 196.036161] lock(&per_cpu(cpu_policy_rwsem, cpu)); [ 196.051051] [ 196.051051] *** DEADLOCK *** [ 196.051051] [ 196.068792] 2 locks held by cat/2387: [ 196.079750] #0: (&buffer->mutex){+.+.+.}, at: [] sysfs_read_file+0x25/0xcc [ 196.103546] #1: (s_active#41){++++.+}, at: [] sysfs_read_file+0x4f/0xcc [ 196.126577] [ 196.126577] stack backtrace: [ 196.139644] [] (unwind_backtrace+0x1/0x9c) from [] (print_circular_bug+0x19d/0x1e8) [ 196.167857] [] (print_circular_bug+0x19d/0x1e8) from [] (__lock_acquire+0xef3/0x13dc) [ 196.196542] [] (__lock_acquire+0xef3/0x13dc) from [] (lock_acquire+0x61/0xbc) [ 196.223139] [] (lock_acquire+0x61/0xbc) from [] (down_read+0x25/0x30) [ 196.247722] [] (down_read+0x25/0x30) from [] (lock_policy_rwsem_read+0x25/0x34) [ 196.274905] [] (lock_policy_rwsem_read+0x25/0x34) from [] (show+0x21/0x58) [ 196.300724] [] (show+0x21/0x58) from [] (sysfs_read_file+0x67/0xcc) [ 196.324719] [] (sysfs_read_file+0x67/0xcc) from [] (vfs_read+0x63/0xd8) [ 196.349756] [] (vfs_read+0x63/0xd8) from [] (sys_read+0x2f/0x50) [ 196.372970] [] (sys_read+0x2f/0x50) from [] (ret_fast_syscall+0x1/0x52) This lock isn't required while calling __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT). Remove it. Signed-off-by: Viresh Kumar --- 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 cb0f723..2d5a829 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1739,18 +1739,23 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, /* end old governor */ if (data->governor) { __cpufreq_governor(data, CPUFREQ_GOV_STOP); + unlock_policy_rwsem_write(policy->cpu); __cpufreq_governor(data, CPUFREQ_GOV_POLICY_EXIT); + lock_policy_rwsem_write(policy->cpu); } /* start new governor */ data->governor = policy->governor; if (!__cpufreq_governor(data, CPUFREQ_GOV_POLICY_INIT)) { - if (!__cpufreq_governor(data, CPUFREQ_GOV_START)) + if (!__cpufreq_governor(data, CPUFREQ_GOV_START)) { failed = 0; - else + } else { + unlock_policy_rwsem_write(policy->cpu); __cpufreq_governor(data, CPUFREQ_GOV_POLICY_EXIT); + lock_policy_rwsem_write(policy->cpu); + } } if (failed) {