From patchwork Thu May 16 09:28:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 16988 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 68FD82391B for ; Thu, 16 May 2013 09:32:29 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id a41sf3799165yho.2 for ; Thu, 16 May 2013 02:31:50 -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=v5QlzaiRdVERUBh5/qV5E/bwGKatN93m8YHVm2JMIQU=; b=I//gH8loaAjDNzuTaoF1KsacgGGGyLv9N27RN7rUhlGsrNFxMZDetzneCwFX0CAodl I306Z0slHxidhAeYXNxnMwMmB5uYR1T5k+ABXkIVkeE6uTU2cnw7gZs/oULU95zSpuJd R/FjTJJRXQQoFUT8xlwl2Mh8WSYFcbypxHjvZyw+s6gTIlH5PsHUZ3NjmX6Een/b7Aj4 Hug+LvCWZYKToIVMQHanf5dIOQnREMNIq6HgQ41CsXeCdfxNVwA9N3mNK3V16LSXr510 X1Pb4EkT8tuM3eycD1EjeUtfVrpJkQxiUvQO85vojE5FyDv70GavRn3upuGrBvWmDF5P iwhw== X-Received: by 10.224.215.194 with SMTP id hf2mr25470424qab.0.1368696710591; Thu, 16 May 2013 02:31:50 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.48.233 with SMTP id p9ls1072995qen.60.gmail; Thu, 16 May 2013 02:31:50 -0700 (PDT) X-Received: by 10.220.228.74 with SMTP id jd10mr27270406vcb.65.1368696710443; Thu, 16 May 2013 02:31:50 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id p19si3480136vcw.89.2013.05.16.02.31.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 16 May 2013 02:31:50 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.174 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.174; Received: by mail-vc0-f174.google.com with SMTP id hr11so2617369vcb.33 for ; Thu, 16 May 2013 02:31:50 -0700 (PDT) X-Received: by 10.220.238.4 with SMTP id kq4mr3177552vcb.73.1368696710264; Thu, 16 May 2013 02:31:50 -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 c10csp56042vcs; Thu, 16 May 2013 02:31:49 -0700 (PDT) X-Received: by 10.68.202.7 with SMTP id ke7mr41747165pbc.82.1368696709141; Thu, 16 May 2013 02:31:49 -0700 (PDT) Received: from mail-pb0-x231.google.com (mail-pb0-x231.google.com [2607:f8b0:400e:c01::231]) by mx.google.com with ESMTPS id zq4si4139408pbc.45.2013.05.16.02.31.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 16 May 2013 02:31:49 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400e:c01::231 is neither permitted nor denied by best guess record for domain of viresh.kumar@linaro.org) client-ip=2607:f8b0:400e:c01::231; Received: by mail-pb0-f49.google.com with SMTP id rp8so874806pbb.8 for ; Thu, 16 May 2013 02:31:48 -0700 (PDT) X-Received: by 10.68.56.231 with SMTP id d7mr14736705pbq.49.1368696708664; Thu, 16 May 2013 02:31:48 -0700 (PDT) Received: from localhost ([106.197.193.133]) by mx.google.com with ESMTPSA id lq4sm6833505pab.19.2013.05.16.02.31.42 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 16 May 2013 02:31:48 -0700 (PDT) From: Viresh Kumar To: toddpoynor@google.com Cc: linaro-kernel@lists.linaro.org, patches@linaro.org, robin.randhawa@arm.com, Steve.Bannister@arm.com, Liviu.Dudau@arm.com, charles.garcia-tobin@arm.com, arvind.chauhan@arm.com, android-kernel@googlegroups.com, viresh.kumar@linaro.org Subject: [PATCH 11/16] cpufreq: Drop rwsem lock around CPUFREQ_GOV_POLICY_EXIT Date: Thu, 16 May 2013 14:58:49 +0530 Message-Id: X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQlj0QvYpWJnuYYW0KL3kBc2g2uuzA8bxj3cP+9rLq3qQTruXOy2H2yQ1usxUoWD3WonYyXi X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.174 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 763fc8e1..cdde8cb 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1732,18 +1732,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) {