cpufreq, store_scaling_governor requires policy->rwsem to be held for duration of changing governors [v2]
Subsystems (2)
PATCH 1/1 cpufreq, store_scaling_governor requires policy->rwsem to be held for duration of changing governors [v2]
[v2]: Fixed wording of commit, and added additional testing information.
A while ago we added a test to mimic some of our users' userspace governor programs which monitor system behaviour and will switch governors on the fly. The decision process for this includes looking at time of day, expected system load, etc. For some time now we have had reports of system panics in the cpufreq code when using the userspace governor utility.
The userspace utility writes /sys/devices/system/cpu/cpuX/cpufreq/scaling_governor and sets the governor. In some cases this can happen rapidly, and under heavy load there are occasions where the changes are delayed. This can mean that several governor changes may occur within a short period of time.
This has exposed a bug in the store_scaling_governor path. When the sysfs file is written to,
store()
->down_write(&policy->rwsem); ->store_scaling_governor() -> cpufreq_set_policy() up_write(&policy->rwsem); __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); down_write(&policy->rwsem);
The release of the policy->rwsem results in a situation where another write to the scaling_governor file can now start and overwrite pointers and cause corruption.
ex)
Oops: 0000 [#1] SMP Modules linked in: sg e1000e igb iTCO_wdt iTCO_vendor_support coretemp kvm_intel ptp kvm pps_core i7300_edac edac_core ses lpc_ich enclosure ioatdma mfd_core shpchp dca i2c_i801 serio_raw acpi_cpufreq pcspkr mperf nfsd auth_rpcgss nfs_acl lockd sunrpc xfs libcrc32c sr_mod cdrom sd_mod ata_generic crc_t10dif crct10dif_common pata_acpi radeon i2c_algo_bit drm_kms_helper ttm drm ata_piix libata i2c_core megaraid_sas dm_mirror dm_region_hash dm_log dm_mod CPU: 7 PID: 565 Comm: kworker/7:2 Not tainted 3.10.0-121.el7.x86_64 #1 Hardware name: Intel MP Server/S7000FC4UR, BIOS SFC4UR.86B.01.00.0031.021820102042 02/18/2010 Workqueue: events od_dbs_timer task: ffff88046544cfa0 ti: ffff880465438000 task.ti: ffff880465438000 RIP: 0010:[<ffffffff81489bed>] [<ffffffff81489bed>] od_dbs_timer+0x2d/0x160 RSP: 0018:ffff880465439de0 EFLAGS: 00010282 RAX: ffff88007f03d500 RBX: 0000000000010de0 RCX: 0000000000000006 RDX: 0000000000000006 RSI: 7040000000000000 RDI: ffff88046f2f0e08 e1000e 0000:06:00.0: irq 79 for MSI/MSI-X IPv6: ADDRCONF(NETDEV_UP): enp6s0f0: link is not ready RBP: ffff880465439e18 R08: ffff88046f2f0e10 R09: dfedcb48370f0e08 R10: dfedcb48370f0e08 R11: 0000000000000000 R12: ffff880465a69200 R13: 0000000000000000 R14: ffff88046f2f0e08 R15: 00000000000001c0 e1000e 0000:06:00.1: irq 80 for MSI/MSI-X FS: 0000000000000000(0000) GS:ffff88046f2e0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b CR2: 0000000000000010 CR3: 0000000466be5000 CR4: 00000000000007e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Stack: ffff88045ef8d140 ffff880468e1ad80 ffff88046f2f0e08 ffff880465a69200 ffff88046f2f3e00 ffff88046f2f7f00 00000000000001c0 ffff880465439e60 ffffffff8107e02b 000000006f2f3e18 0000000000000000 ffff88046f2f3e18 Call Trace: [<ffffffff8107e02b>] process_one_work+0x17b/0x460 [<ffffffff8107edfb>] worker_thread+0x11b/0x400 [<ffffffff8107ece0>] ? rescuer_thread+0x400/0x400 [<ffffffff81085aef>] kthread+0xcf/0xe0 [<ffffffff81085a20>] ? kthread_create_on_node+0x140/0x140 e1000e 0000:06:00.1: irq 80 for MSI/MSI-X IPv6: ADDRCONF(NETDEV_UP): enp6s0f1: link is not ready [<ffffffff815fc76c>] ret_from_fork+0x7c/0xb0 [<ffffffff81085a20>] ? kthread_create_on_node+0x140/0x140 Code: 66 66 90 55 48 89 e5 41 57 41 56 49 89 fe 41 55 41 54 53 48 c7 c3 e0 0d 01 00 48 83 ec 10 48 8b 47 f8 8b 50 14 4c 8b 68 40 89 d1 <4d> 8b 7d 10 89 55 cc 48 03 1c cd 80 78 9e 81 48 8d 83 a8 00 00 RIP [<ffffffff81489bed>] od_dbs_timer+0x2d/0x160 RSP <ffff880465439de0> CR2: 0000000000000010 BUG: unable to handle kernel ---[ end trace c9a1ca82e01a4294 ]--- Kernel panic - not syncing: Fatal exception NULL pointer dereference at 0000000000000014 IP: [<ffffffff81489be4>] od_dbs_timer+0x24/0x160 PGD 46661d067 PUD 465540067 PMD 0 Oops: 0000 [#2] SMP Modules linked in: sg e1000e igb iTCO_wdt iTCO_vendor_support coretemp kvm_intel ptp kvm pps_core i7300_edac edac_core ses lpc_ich enclosure ioatdma mfd_core shpchp dca i2c_i801 serio_raw acpi_cpufreq pcspkr mperf nfsd auth_rpcgss nfs_acl lockd sunrpc xfs libcrc32c sr_mod cdrom sd_mod ata_generic crc_t10dif crct10dif_common pata_acpi radeon i2c_algo_bit drm_kms_helper ttm drm ata_piix libata i2c_core megaraid_sas dm_mirror dm_region_hash dm_log dm_mod CPU: 6 PID: 506 Comm: kworker/6:2 Tainted: G D -------------- 3.10.0-121.el7.x86_64 #1 Hardware name: Intel MP Server/S7000FC4UR, BIOS SFC4UR.86B.01.00.0031.021820102042 02/18/2010 Workqueue: events od_dbs_timer task: ffff880465448b60 ti: ffff880463730000 task.ti: ffff880463730000 RIP: 0010:[<ffffffff81489be4>] [<ffffffff81489be4>] od_dbs_timer+0x24/0x160 RSP: 0018:ffff880463731de0 EFLAGS: 00010282 RAX: 0000000000000000 RBX: 0000000000010de0 RCX: dead000000200200 RDX: 0000000000000001 RSI: 7040000000000000 RDI: ffff88046f2d0e08 RBP: ffff880463731e18 R08: ffff88046f2d0e10 R09: dfedcb50370d0e08 R10: dfedcb50370d0e08 R11: 0000000000000000 R12: ffff880465bd2b80 R13: ffff88046f2d3e00 R14: ffff88046f2d0e08 R15: 0000000000000180 FS: 0000000000000000(0000) GS:ffff88046f2c0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b CR2: 0000000000000014 CR3: 0000000466be5000 CR4: 00000000000007e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Stack: ffff88045ef8d140 ffff880468dcf1c0 ffff88046f2d0e08 ffff880465bd2b80 ffff88046f2d3e00 ffff88046f2d7f00 0000000000000180 ffff880463731e60 ffffffff8107e02b 000000006f2d3e18 0000000000000000 ffff88046f2d3e18 Call Trace: [<ffffffff8107e02b>] process_one_work+0x17b/0x460 [<ffffffff8107edfb>] worker_thread+0x11b/0x400 [<ffffffff8107ece0>] ? rescuer_thread+0x400/0x400 [<ffffffff81085aef>] kthread+0xcf/0xe0 [<ffffffff81085a20>] ? kthread_create_on_node+0x140/0x140 [<ffffffff815fc76c>] ret_from_fork+0x7c/0xb0 [<ffffffff81085a20>] ? kthread_create_on_node+0x140/0x140 Code: 1f 84 00 00 00 00 00 66 66 66 66 90 55 48 89 e5 41 57 41 56 49 89 fe 41 55 41 54 53 48 c7 c3 e0 0d 01 00 48 83 ec 10 48 8b 47 f8 <8b> 50 14 4c 8b 68 40 89 d1 4d 8b 7d 10 89 55 cc 48 03 1c cd 80 RIP [<ffffffff81489be4>] od_dbs_timer+0x24/0x160 RSP <ffff880463731de0> CR2: 0000000000000014 drm_kms_helper: panic occurred, switching back to text console
There are other panics associated with this, including list corruption and various flavors of panics in the od_dbs_timer & work code.
As a test I introduced a separate mutex around the cpufreq_set_policy() call. After doing so system behaves as expected, and the panics no longer happen. I narrowed the mutex down to the "governor switch" code in cpufreq_set_policy() and saw that everything stabilized.
I then reverted commit 955ef4833574636819cd269cfbae12f79cbde63a, cpufreq: Drop rwsem lock around CPUFREQ_GOV_POLICY_EXIT, which added the dropping of the policy->rwsem and again, the panics no longer occurred.
The closer I looked at commit 955ef483, the more questions I have. The first thing is that it appears that the stacktrace includes function calls that are not, and never have been, part of the linux.git tree, ie) the call trace shows
[<c0055a79>] lock_acquire+0x61/0xbc
[<c00fabf1>] sysfs_addrm_finish+0xc1/0x128
[<c00f9819>] sysfs_hash_and_remove+0x35/0x64
[<c00fbe6f>] remove_files.isra.0+0x1b/0x24
[<c00fbea5>] sysfs_remove_group+0x2d/0xa8
[<c02f9a0b>] cpufreq_governor_interactive+0x13b/0x35c
[<c02f61df>] __cpufreq_governor+0x2b/0x8c
[<c02f6579>] __cpufreq_set_policy+0xa9/0xf8
[<c02f6b75>] store_scaling_governor+0x61/0x100
[<c02f6f4d>] store+0x39/0x60
[<c00f9b81>] sysfs_write_file+0xed/0x114
[<c00b3fd1>] vfs_write+0x65/0xd8
[<c00b424b>] sys_write+0x2f/0x50
[<c000cdc1>] ret_fast_syscall+0x1/0x52and the top part of the stack from cpufreq_governor_interactive() appear to be for a driver that is not in the linux.git tree. Google search does show that it exists in various android trees, however, my concern is that the "core" scaling governors are now broken because of an out tree driver.
It seems like the patch fixed this problem incorrectly by breaking the existing locking. The whole point of the policy->rwsem is to single thread updates to the policy struct; this is no longer the case after that commit as we are breaking the locking right in the middle of a policy->governor update. The fix should have been to the cpufreq_governor_interactive out-of-tree driver and fix the locking there in its release code. In any case, the current linux.git code no longer can reproduce the original failure; the locking in the sysfs release code has changed.
In case anyone is interested in reproducing, the reproducer I used was
i=0
while [ True ]; do
i=$((i+1))
echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor & echo "performance" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor & echo "ondemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor & echo "performance" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor & if [ $((i % 100)) = 0 ]; then
num_ps=$(ps aux | grep doit | wc -l)
echo "$i running, $num_ps outstanding"
fi
done
and the system usually panics within 500 iterations.
I have tested this extensively across 15 systems of various configurations. In the unpatched kernel I see oopses usually within 500 iterations. In the patched kernel which fixes the broken locking, I can go several hours without any issues.
This patch effectively reverts commit 955ef483.
--- drivers/cpufreq/cpufreq.c | 8 +------- include/linux/cpufreq.h | 4 ---- 2 files changed, 1 insertion(+), 11 deletions(-)
drivers/cpufreq/cpufreq.c +1 -7
@@ -2198,12 +2198,8 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,/* save old, working values */ old_gov = policy->governor;/* end old governor */ -if (old_gov) { -__cpufreq_governor (policy,CPUFREQ_GOV_STOP ); -up_write (&policy->rwsem); +if (old_gov)__cpufreq_governor (policy,CPUFREQ_GOV_POLICY_EXIT ); -down_write (&policy->rwsem); - }/* start new governor */ policy->governor = new_policy->governor;
@@ -2211,9 +2207,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 */
include/linux/cpufreq.h +0 -4
@@ -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;
Signature · 1 line
1.7.9.3
Quoted 173 lines · Prarit Bhargava
[v2]: Fixed wording of commit, and added additional testing information.
A while ago we added a test to mimic some of our users' userspace governor programs which monitor system behaviour and will switch governors on the fly. The decision process for this includes looking at time of day, expected system load, etc. For some time now we have had reports of system panics in the cpufreq code when using the userspace governor utility.
The userspace utility writes
/sys/devices/system/cpu/cpuX/cpufreq/scaling_governorand sets the governor. In some cases this can happen rapidly, and under heavy load there are occasions where the changes are delayed. This can mean that several governor changes may occur within a short period of time.This has exposed a bug in the
store_scaling_governorpath. When the sysfs file is written to,
store()->down_write(&policy->rwsem); ->store_scaling_governor() -> cpufreq_set_policy() up_write(&policy->rwsem); __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); down_write(&policy->rwsem);The release of the
policy->rwsemresults in a situation where another write to thescaling_governorfile can now start and overwrite pointers and cause corruption.ex)
Oops: 0000 [#1] SMP Modules linked in: sg e1000e igb iTCO_wdt iTCO_vendor_support coretemp kvm_intel ptp kvm pps_core i7300_edac edac_core ses lpc_ich enclosure ioatdma mfd_core shpchp dca i2c_i801 serio_raw acpi_cpufreq pcspkr mperf nfsd auth_rpcgss nfs_acl lockd sunrpc xfs libcrc32c sr_mod cdrom sd_mod ata_generic crc_t10dif crct10dif_common pata_acpi radeon i2c_algo_bit drm_kms_helper ttm drm ata_piix libata i2c_core megaraid_sas dm_mirror dm_region_hash dm_log dm_mod CPU: 7 PID: 565 Comm: kworker/7:2 Not tainted 3.10.0-121.el7.x86_64 #1 Hardware name: Intel MP Server/S7000FC4UR, BIOS SFC4UR.86B.01.00.0031.021820102042 02/18/2010 Workqueue: events od_dbs_timer task: ffff88046544cfa0 ti: ffff880465438000 task.ti: ffff880465438000 RIP: 0010:[<ffffffff81489bed>] [<ffffffff81489bed>] od_dbs_timer+0x2d/0x160 RSP: 0018:ffff880465439de0 EFLAGS: 00010282 RAX: ffff88007f03d500 RBX: 0000000000010de0 RCX: 0000000000000006 RDX: 0000000000000006 RSI: 7040000000000000 RDI: ffff88046f2f0e08 e1000e 0000:06:00.0: irq 79 for MSI/MSI-X IPv6: ADDRCONF(NETDEV_UP): enp6s0f0: link is not ready RBP: ffff880465439e18 R08: ffff88046f2f0e10 R09: dfedcb48370f0e08 R10: dfedcb48370f0e08 R11: 0000000000000000 R12: ffff880465a69200 R13: 0000000000000000 R14: ffff88046f2f0e08 R15: 00000000000001c0 e1000e 0000:06:00.1: irq 80 for MSI/MSI-X FS: 0000000000000000(0000) GS:ffff88046f2e0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b CR2: 0000000000000010 CR3: 0000000466be5000 CR4: 00000000000007e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Stack: ffff88045ef8d140 ffff880468e1ad80 ffff88046f2f0e08 ffff880465a69200 ffff88046f2f3e00 ffff88046f2f7f00 00000000000001c0 ffff880465439e60 ffffffff8107e02b 000000006f2f3e18 0000000000000000 ffff88046f2f3e18 Call Trace: [<ffffffff8107e02b>] process_one_work+0x17b/0x460 [<ffffffff8107edfb>] worker_thread+0x11b/0x400 [<ffffffff8107ece0>] ? rescuer_thread+0x400/0x400 [<ffffffff81085aef>] kthread+0xcf/0xe0 [<ffffffff81085a20>] ? kthread_create_on_node+0x140/0x140 e1000e 0000:06:00.1: irq 80 for MSI/MSI-X IPv6: ADDRCONF(NETDEV_UP): enp6s0f1: link is not ready [<ffffffff815fc76c>] ret_from_fork+0x7c/0xb0 [<ffffffff81085a20>] ? kthread_create_on_node+0x140/0x140 Code: 66 66 90 55 48 89 e5 41 57 41 56 49 89 fe 41 55 41 54 53 48 c7 c3 e0 0d 01 00 48 83 ec 10 48 8b 47 f8 8b 50 14 4c 8b 68 40 89 d1 <4d> 8b 7d 10 89 55 cc 48 03 1c cd 80 78 9e 81 48 8d 83 a8 00 00 RIP [<ffffffff81489bed>] od_dbs_timer+0x2d/0x160 RSP <ffff880465439de0> CR2: 0000000000000010 BUG: unable to handle kernel ---[ end trace c9a1ca82e01a4294 ]--- Kernel panic - not syncing: Fatal exception NULL pointer dereference at 0000000000000014 IP: [<ffffffff81489be4>] od_dbs_timer+0x24/0x160 PGD 46661d067 PUD 465540067 PMD 0 Oops: 0000 [#2] SMP Modules linked in: sg e1000e igb iTCO_wdt iTCO_vendor_support coretemp kvm_intel ptp kvm pps_core i7300_edac edac_core ses lpc_ich enclosure ioatdma mfd_core shpchp dca i2c_i801 serio_raw acpi_cpufreq pcspkr mperf nfsd auth_rpcgss nfs_acl lockd sunrpc xfs libcrc32c sr_mod cdrom sd_mod ata_generic crc_t10dif crct10dif_common pata_acpi radeon i2c_algo_bit drm_kms_helper ttm drm ata_piix libata i2c_core megaraid_sas dm_mirror dm_region_hash dm_log dm_mod CPU: 6 PID: 506 Comm: kworker/6:2 Tainted: G D -------------- 3.10.0-121.el7.x86_64 #1 Hardware name: Intel MP Server/S7000FC4UR, BIOS SFC4UR.86B.01.00.0031.021820102042 02/18/2010 Workqueue: events od_dbs_timer task: ffff880465448b60 ti: ffff880463730000 task.ti: ffff880463730000 RIP: 0010:[<ffffffff81489be4>] [<ffffffff81489be4>] od_dbs_timer+0x24/0x160 RSP: 0018:ffff880463731de0 EFLAGS: 00010282 RAX: 0000000000000000 RBX: 0000000000010de0 RCX: dead000000200200 RDX: 0000000000000001 RSI: 7040000000000000 RDI: ffff88046f2d0e08 RBP: ffff880463731e18 R08: ffff88046f2d0e10 R09: dfedcb50370d0e08 R10: dfedcb50370d0e08 R11: 0000000000000000 R12: ffff880465bd2b80 R13: ffff88046f2d3e00 R14: ffff88046f2d0e08 R15: 0000000000000180 FS: 0000000000000000(0000) GS:ffff88046f2c0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b CR2: 0000000000000014 CR3: 0000000466be5000 CR4: 00000000000007e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Stack: ffff88045ef8d140 ffff880468dcf1c0 ffff88046f2d0e08 ffff880465bd2b80 ffff88046f2d3e00 ffff88046f2d7f00 0000000000000180 ffff880463731e60 ffffffff8107e02b 000000006f2d3e18 0000000000000000 ffff88046f2d3e18 Call Trace: [<ffffffff8107e02b>] process_one_work+0x17b/0x460 [<ffffffff8107edfb>] worker_thread+0x11b/0x400 [<ffffffff8107ece0>] ? rescuer_thread+0x400/0x400 [<ffffffff81085aef>] kthread+0xcf/0xe0 [<ffffffff81085a20>] ? kthread_create_on_node+0x140/0x140 [<ffffffff815fc76c>] ret_from_fork+0x7c/0xb0 [<ffffffff81085a20>] ? kthread_create_on_node+0x140/0x140 Code: 1f 84 00 00 00 00 00 66 66 66 66 90 55 48 89 e5 41 57 41 56 49 89 fe 41 55 41 54 53 48 c7 c3 e0 0d 01 00 48 83 ec 10 48 8b 47 f8 <8b> 50 14 4c 8b 68 40 89 d1 4d 8b 7d 10 89 55 cc 48 03 1c cd 80 RIP [<ffffffff81489be4>] od_dbs_timer+0x24/0x160 RSP <ffff880463731de0> CR2: 0000000000000014 drm_kms_helper: panic occurred, switching back to text consoleThere are other panics associated with this, including list corruption and various flavors of panics in the
od_dbs_timer& work code.As a test I introduced a separate mutex around the
cpufreq_set_policy()call. After doing so system behaves as expected, and the panics no longer happen. I narrowed the mutex down to the "governor switch" code incpufreq_set_policy()and saw that everything stabilized.I then reverted commit
955ef4833574636819cd269cfbae12f79cbde63a, cpufreq: Drop rwsem lock aroundCPUFREQ_GOV_POLICY_EXIT, which added the dropping of thepolicy->rwsemand again, the panics no longer occurred.The closer I looked at commit
955ef483, the more questions I have. The first thing is that it appears that the stacktrace includes function calls that are not, and never have been, part of the linux.git tree, ie) the call trace shows[<c0055a79>] lock_acquire+0x61/0xbc [<c00fabf1>] sysfs_addrm_finish+0xc1/0x128 [<c00f9819>] sysfs_hash_and_remove+0x35/0x64 [<c00fbe6f>] remove_files.isra.0+0x1b/0x24 [<c00fbea5>] sysfs_remove_group+0x2d/0xa8 [<c02f9a0b>] cpufreq_governor_interactive+0x13b/0x35c [<c02f61df>] __cpufreq_governor+0x2b/0x8c [<c02f6579>] __cpufreq_set_policy+0xa9/0xf8 [<c02f6b75>] store_scaling_governor+0x61/0x100 [<c02f6f4d>] store+0x39/0x60 [<c00f9b81>] sysfs_write_file+0xed/0x114 [<c00b3fd1>] vfs_write+0x65/0xd8 [<c00b424b>] sys_write+0x2f/0x50 [<c000cdc1>] ret_fast_syscall+0x1/0x52and the top part of the stack from
cpufreq_governor_interactive()appear to be for a driver that is not in the linux.git tree. Google search does show that it exists in various android trees, however, my concern is that the "core" scaling governors are now broken because of an out tree driver.It seems like the patch fixed this problem incorrectly by breaking the existing locking. The whole point of the
policy->rwsemis to single thread updates to the policy struct; this is no longer the case after that commit as we are breaking the locking right in the middle of apolicy->governorupdate. The fix should have been to thecpufreq_governor_interactiveout-of-tree driver and fix the locking there in its release code. In any case, the current linux.git code no longer can reproduce the original failure; the locking in the sysfs release code has changed.In case anyone is interested in reproducing, the reproducer I used was
i=0
while [ True ]; do
i=$((i+1))
echo "ondemand" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor& echo "performance" >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor& echo "ondemand" >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor& echo "performance" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor& if [ $((i % 100)) = 0 ]; then
num_ps=$(ps aux | grep doit | wc -l)
echo "$i running, $num_ps outstanding"
fi
done
Quoted 8 lines
and the system usually panics within 500 iterations.
I have tested this extensively across 15 systems of various configurations. In the unpatched kernel I see oopses usually within 500 iterations. In the patched kernel which fixes the broken locking, I can go several hours without any issues.
This patch effectively reverts commit
955ef483.
OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Quoted 54 lines
Cc "Rafael J. Wysocki" <[email protected]>Cc Viresh Kumar <[email protected]>Cc Lenny Szubowicz <[email protected]>Signed-off-by Prarit Bhargava <[email protected]>--- drivers/cpufreq/cpufreq.c | 8 +------- include/linux/cpufreq.h | 4 ---- 2 files changed, 1 insertion(+), 11 deletions(-)drivers/cpufreq/cpufreq.c +1
-7@@ -2198,12 +2198,8 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,/* save old, working values */ old_gov = policy->governor;/* end old governor */ -if (old_gov) { -__cpufreq_governor (policy,CPUFREQ_GOV_STOP ); -up_write (&policy->rwsem); +if (old_gov)__cpufreq_governor (policy,CPUFREQ_GOV_POLICY_EXIT ); -down_write (&policy->rwsem); - }/* start new governor */ policy->governor = new_policy->governor;@@ -2211,9 +2207,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 */ include/linux/cpufreq.h +0
-4@@ -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;
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Quoted 181 lines · Rafael J. Wysocki
Quoted 180 lines · Prarit Bhargava
[v2]: Fixed wording of commit, and added additional testing information.
A while ago we added a test to mimic some of our users' userspace governor programs which monitor system behaviour and will switch governors on the fly. The decision process for this includes looking at time of day, expected system load, etc. For some time now we have had reports of system panics in the cpufreq code when using the userspace governor utility.
The userspace utility writes
/sys/devices/system/cpu/cpuX/cpufreq/scaling_governorand sets the governor. In some cases this can happen rapidly, and under heavy load there are occasions where the changes are delayed. This can mean that several governor changes may occur within a short period of time.This has exposed a bug in the
store_scaling_governorpath. When the sysfs file is written to,
store()->down_write(&policy->rwsem); ->store_scaling_governor() -> cpufreq_set_policy() up_write(&policy->rwsem); __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); down_write(&policy->rwsem);The release of the
policy->rwsemresults in a situation where another write to thescaling_governorfile can now start and overwrite pointers and cause corruption.ex)
Oops: 0000 [#1] SMP Modules linked in: sg e1000e igb iTCO_wdt iTCO_vendor_support coretemp kvm_intel ptp kvm pps_core i7300_edac edac_core ses lpc_ich enclosure ioatdma mfd_core shpchp dca i2c_i801 serio_raw acpi_cpufreq pcspkr mperf nfsd auth_rpcgss nfs_acl lockd sunrpc xfs libcrc32c sr_mod cdrom sd_mod ata_generic crc_t10dif crct10dif_common pata_acpi radeon i2c_algo_bit drm_kms_helper ttm drm ata_piix libata i2c_core megaraid_sas dm_mirror dm_region_hash dm_log dm_mod CPU: 7 PID: 565 Comm: kworker/7:2 Not tainted 3.10.0-121.el7.x86_64 #1 Hardware name: Intel MP Server/S7000FC4UR, BIOS SFC4UR.86B.01.00.0031.021820102042 02/18/2010 Workqueue: events od_dbs_timer task: ffff88046544cfa0 ti: ffff880465438000 task.ti: ffff880465438000 RIP: 0010:[<ffffffff81489bed>] [<ffffffff81489bed>] od_dbs_timer+0x2d/0x160 RSP: 0018:ffff880465439de0 EFLAGS: 00010282 RAX: ffff88007f03d500 RBX: 0000000000010de0 RCX: 0000000000000006 RDX: 0000000000000006 RSI: 7040000000000000 RDI: ffff88046f2f0e08 e1000e 0000:06:00.0: irq 79 for MSI/MSI-X IPv6: ADDRCONF(NETDEV_UP): enp6s0f0: link is not ready RBP: ffff880465439e18 R08: ffff88046f2f0e10 R09: dfedcb48370f0e08 R10: dfedcb48370f0e08 R11: 0000000000000000 R12: ffff880465a69200 R13: 0000000000000000 R14: ffff88046f2f0e08 R15: 00000000000001c0 e1000e 0000:06:00.1: irq 80 for MSI/MSI-X FS: 0000000000000000(0000) GS:ffff88046f2e0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b CR2: 0000000000000010 CR3: 0000000466be5000 CR4: 00000000000007e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Stack: ffff88045ef8d140 ffff880468e1ad80 ffff88046f2f0e08 ffff880465a69200 ffff88046f2f3e00 ffff88046f2f7f00 00000000000001c0 ffff880465439e60 ffffffff8107e02b 000000006f2f3e18 0000000000000000 ffff88046f2f3e18 Call Trace: [<ffffffff8107e02b>] process_one_work+0x17b/0x460 [<ffffffff8107edfb>] worker_thread+0x11b/0x400 [<ffffffff8107ece0>] ? rescuer_thread+0x400/0x400 [<ffffffff81085aef>] kthread+0xcf/0xe0 [<ffffffff81085a20>] ? kthread_create_on_node+0x140/0x140 e1000e 0000:06:00.1: irq 80 for MSI/MSI-X IPv6: ADDRCONF(NETDEV_UP): enp6s0f1: link is not ready [<ffffffff815fc76c>] ret_from_fork+0x7c/0xb0 [<ffffffff81085a20>] ? kthread_create_on_node+0x140/0x140 Code: 66 66 90 55 48 89 e5 41 57 41 56 49 89 fe 41 55 41 54 53 48 c7 c3 e0 0d 01 00 48 83 ec 10 48 8b 47 f8 8b 50 14 4c 8b 68 40 89 d1 <4d> 8b 7d 10 89 55 cc 48 03 1c cd 80 78 9e 81 48 8d 83 a8 00 00 RIP [<ffffffff81489bed>] od_dbs_timer+0x2d/0x160 RSP <ffff880465439de0> CR2: 0000000000000010 BUG: unable to handle kernel ---[ end trace c9a1ca82e01a4294 ]--- Kernel panic - not syncing: Fatal exception NULL pointer dereference at 0000000000000014 IP: [<ffffffff81489be4>] od_dbs_timer+0x24/0x160 PGD 46661d067 PUD 465540067 PMD 0 Oops: 0000 [#2] SMP Modules linked in: sg e1000e igb iTCO_wdt iTCO_vendor_support coretemp kvm_intel ptp kvm pps_core i7300_edac edac_core ses lpc_ich enclosure ioatdma mfd_core shpchp dca i2c_i801 serio_raw acpi_cpufreq pcspkr mperf nfsd auth_rpcgss nfs_acl lockd sunrpc xfs libcrc32c sr_mod cdrom sd_mod ata_generic crc_t10dif crct10dif_common pata_acpi radeon i2c_algo_bit drm_kms_helper ttm drm ata_piix libata i2c_core megaraid_sas dm_mirror dm_region_hash dm_log dm_mod CPU: 6 PID: 506 Comm: kworker/6:2 Tainted: G D -------------- 3.10.0-121.el7.x86_64 #1 Hardware name: Intel MP Server/S7000FC4UR, BIOS SFC4UR.86B.01.00.0031.021820102042 02/18/2010 Workqueue: events od_dbs_timer task: ffff880465448b60 ti: ffff880463730000 task.ti: ffff880463730000 RIP: 0010:[<ffffffff81489be4>] [<ffffffff81489be4>] od_dbs_timer+0x24/0x160 RSP: 0018:ffff880463731de0 EFLAGS: 00010282 RAX: 0000000000000000 RBX: 0000000000010de0 RCX: dead000000200200 RDX: 0000000000000001 RSI: 7040000000000000 RDI: ffff88046f2d0e08 RBP: ffff880463731e18 R08: ffff88046f2d0e10 R09: dfedcb50370d0e08 R10: dfedcb50370d0e08 R11: 0000000000000000 R12: ffff880465bd2b80 R13: ffff88046f2d3e00 R14: ffff88046f2d0e08 R15: 0000000000000180 FS: 0000000000000000(0000) GS:ffff88046f2c0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b CR2: 0000000000000014 CR3: 0000000466be5000 CR4: 00000000000007e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Stack: ffff88045ef8d140 ffff880468dcf1c0 ffff88046f2d0e08 ffff880465bd2b80 ffff88046f2d3e00 ffff88046f2d7f00 0000000000000180 ffff880463731e60 ffffffff8107e02b 000000006f2d3e18 0000000000000000 ffff88046f2d3e18 Call Trace: [<ffffffff8107e02b>] process_one_work+0x17b/0x460 [<ffffffff8107edfb>] worker_thread+0x11b/0x400 [<ffffffff8107ece0>] ? rescuer_thread+0x400/0x400 [<ffffffff81085aef>] kthread+0xcf/0xe0 [<ffffffff81085a20>] ? kthread_create_on_node+0x140/0x140 [<ffffffff815fc76c>] ret_from_fork+0x7c/0xb0 [<ffffffff81085a20>] ? kthread_create_on_node+0x140/0x140 Code: 1f 84 00 00 00 00 00 66 66 66 66 90 55 48 89 e5 41 57 41 56 49 89 fe 41 55 41 54 53 48 c7 c3 e0 0d 01 00 48 83 ec 10 48 8b 47 f8 <8b> 50 14 4c 8b 68 40 89 d1 4d 8b 7d 10 89 55 cc 48 03 1c cd 80 RIP [<ffffffff81489be4>] od_dbs_timer+0x24/0x160 RSP <ffff880463731de0> CR2: 0000000000000014 drm_kms_helper: panic occurred, switching back to text consoleThere are other panics associated with this, including list corruption and various flavors of panics in the
od_dbs_timer& work code.As a test I introduced a separate mutex around the
cpufreq_set_policy()call. After doing so system behaves as expected, and the panics no longer happen. I narrowed the mutex down to the "governor switch" code incpufreq_set_policy()and saw that everything stabilized.I then reverted commit
955ef4833574636819cd269cfbae12f79cbde63a, cpufreq: Drop rwsem lock aroundCPUFREQ_GOV_POLICY_EXIT, which added the dropping of thepolicy->rwsemand again, the panics no longer occurred.The closer I looked at commit
955ef483, the more questions I have. The first thing is that it appears that the stacktrace includes function calls that are not, and never have been, part of the linux.git tree, ie) the call trace shows[<c0055a79>] lock_acquire+0x61/0xbc [<c00fabf1>] sysfs_addrm_finish+0xc1/0x128 [<c00f9819>] sysfs_hash_and_remove+0x35/0x64 [<c00fbe6f>] remove_files.isra.0+0x1b/0x24 [<c00fbea5>] sysfs_remove_group+0x2d/0xa8 [<c02f9a0b>] cpufreq_governor_interactive+0x13b/0x35c [<c02f61df>] __cpufreq_governor+0x2b/0x8c [<c02f6579>] __cpufreq_set_policy+0xa9/0xf8 [<c02f6b75>] store_scaling_governor+0x61/0x100 [<c02f6f4d>] store+0x39/0x60 [<c00f9b81>] sysfs_write_file+0xed/0x114 [<c00b3fd1>] vfs_write+0x65/0xd8 [<c00b424b>] sys_write+0x2f/0x50 [<c000cdc1>] ret_fast_syscall+0x1/0x52and the top part of the stack from
cpufreq_governor_interactive()appear to be for a driver that is not in the linux.git tree. Google search does show that it exists in various android trees, however, my concern is that the "core" scaling governors are now broken because of an out tree driver.It seems like the patch fixed this problem incorrectly by breaking the existing locking. The whole point of the
policy->rwsemis to single thread updates to the policy struct; this is no longer the case after that commit as we are breaking the locking right in the middle of apolicy->governorupdate. The fix should have been to thecpufreq_governor_interactiveout-of-tree driver and fix the locking there in its release code. In any case, the current linux.git code no longer can reproduce the original failure; the locking in the sysfs release code has changed.In case anyone is interested in reproducing, the reproducer I used was
i=0
while [ True ]; do
i=$((i+1))
echo "ondemand" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor& echo "performance" >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor& echo "ondemand" >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor& echo "performance" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor& if [ $((i % 100)) = 0 ]; then
num_ps=$(ps aux | grep doit | wc -l)
echo "$i running, $num_ps outstanding"
fi
doneand the system usually panics within 500 iterations.
I have tested this extensively across 15 systems of various configurations. In the unpatched kernel I see oopses usually within 500 iterations. In the patched kernel which fixes the broken locking, I can go several hours without any issues.
Quoted 5 lines
Quoted 1 line
This patch effectively reverts commit
955ef483.OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Rafael, I think that is a good idea. I'm not sure what the protocol is for adding [email protected] though ...
P.
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
This patch effectively reverts commit
955ef483.OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Rafael, I think that is a good idea. I'm not sure what the protocol is for adding [email protected] though ...
I'll take care of this, thanks!
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch effectively reverts commit
955ef483.
The issue reported in this patch is valid. We are seeing that internally too. I believe I reported it in another thread (within the past month).
However, the original patch fixes a real deadlock issue (I'm too tired to look it up now). We can revet the original, but it's going to bring back the original issue. I just want to make sure Prarit and Raphael realize this before proceeding.
I do have plans for a proper fix for the mainline (not stable branches), but plan to do that after the current set of suspend/hotplug patches go through. The fix would be easier to make after that.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Rafael, I think that is a good idea. I'm not sure what the protocol is for adding [email protected] though ...
I'll take care of this, thanks!
But you aren't going to pull the in for the next release, right?
-Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Quoted 27 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch effectively reverts commit
955ef483.The issue reported in this patch is valid. We are seeing that internally too. I believe I reported it in another thread (within the past month).
However, the original patch fixes a real deadlock issue (I'm too tired to look it up now). We can revet the original, but it's going to bring back the original issue. I just want to make sure Prarit and Raphael realize this before proceeding.
I do have plans for a proper fix for the mainline (not stable branches), but plan to do that after the current set of suspend/hotplug patches go through. The fix would be easier to make after that.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Rafael, I think that is a good idea. I'm not sure what the protocol is for adding [email protected] though ...
I'll take care of this, thanks!
But you aren't going to pull the in for the next release, right?
What do you mean?
Rafael
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch effectively reverts commit
955ef483.The issue reported in this patch is valid. We are seeing that internally too. I believe I reported it in another thread (within the past month).
However, the original patch fixes a real deadlock issue (I'm too tired to look it up now). We can revet the original, but it's going to bring back the original issue. I just want to make sure Prarit and Raphael realize this before proceeding.
I do have plans for a proper fix for the mainline (not stable branches), but plan to do that after the current set of suspend/hotplug patches go through. The fix would be easier to make after that.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Rafael, I think that is a good idea. I'm not sure what the protocol is for adding [email protected] though ...
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I'll take care of this, thanks!
But you aren't going to pull the in for the next release, right?
What do you mean?
Reverting the commit will bring back another dead lock issue. So, you don't want to revert it on mainline. Do I still not make sense because I'm not using the right terms?
-Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch effectively reverts commit
955ef483.
Quoted 7 lines
Quoted 7 lines
The issue reported in this patch is valid. We are seeing that internally too. I believe I reported it in another thread (within the past month).
However, the original patch fixes a real deadlock issue (I'm too tired to look it up now). We can revet the original, but it's going to bring back the original issue. I just want to make sure Prarit and Raphael realize this before proceeding.
Hi Saravana,
Thanks for your input. I went back to the code and confirmed my original statement about this patch.
Note: in a previous email I erroneously wrote "buffer->mutex" when I should have identified the lock as sysfs_mutex. Sorry 'bout that, and apologies for any confusion that may have caused.
Quoted 1 line
From my commit message:
"In any case, the current linux.git code no longer can reproduce the original failure; the locking in the sysfs release code has changed."
The original patch attempted to fix this deadlock:
A cpufreq driver on a file read did:
-> #0 (&per_cpu(cpu_policy_rwsem, cpu)){+++++.}:
[<c0055253>] __lock_acquire+0xef3/0x13dc
[<c0055a79>] lock_acquire+0x61/0xbc
[<c03ee1f5>] down_read+0x25/0x30
[<c02f6179>] lock_policy_rwsem_read+0x25/0x34
[<c02f6edd>] show+0x21/0x58
[<c00f9c0f>] sysfs_read_file+0x67/0xcc
[<c00b40a7>] vfs_read+0x63/0xd8
[<c00b41fb>] sys_read+0x2f/0x50
[<c000cdc1>] ret_fast_syscall+0x1/0x52lock(s_active#41) [ which is actually the acquisition of sysfs_mutex ] lock(&per_cpu(cpu_policy_rwsem, cpu));
and on the governor switch (notably the EXIT of the existing governor), the opposite occurs
-> #1 (s_active#41){++++.+}:
[<c0055a79>] lock_acquire+0x61/0xbc
[<c00fabf1>] sysfs_addrm_finish+0xc1/0x128
[<c00f9819>] sysfs_hash_and_remove+0x35/0x64
[<c00fbe6f>] remove_files.isra.0+0x1b/0x24
[<c00fbea5>] sysfs_remove_group+0x2d/0xa8
[<c02f9a0b>] cpufreq_governor_interactive+0x13b/0x35c
[<c02f61df>] __cpufreq_governor+0x2b/0x8c
[<c02f6579>] __cpufreq_set_policy+0xa9/0xf8
[<c02f6b75>] store_scaling_governor+0x61/0x100
[<c02f6f4d>] store+0x39/0x60
[<c00f9b81>] sysfs_write_file+0xed/0x114
[<c00b3fd1>] vfs_write+0x65/0xd8
[<c00b424b>] sys_write+0x2f/0x50
[<c000cdc1>] ret_fast_syscall+0x1/0x52lock(&per_cpu(cpu_policy_rwsem, cpu));lock(s_active#41) [ which is actually the acquisition of sysfs_mutex ]
The sysfs_mutex no longer blocks in the sysfs path, and I have built with LOCKDEP on and off to confirm that I do not see any tracebacks or hangs. I tested this by doing a few reads of the current governor, and then doing a governor switch (to at least initiate the LOCKDEP warning). IIUC the traceback above that is the way to reproduce this LOCKDEP warning.
IOW ... this deadlock situation no longer exists in the code (at least AFAICT).
Secondly, restoring the locking (and keeping in mind the semantic of the read-write semaphore, specifically that all reads must be done before the write lock is acquired by a thread) modifies the code such that the above situation (a read and a write) can no longer occur in this code.
P.
Quoted 74 lines · Prarit Bhargava
Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch effectively reverts commit
955ef483.Quoted 7 lines
Quoted 7 lines
The issue reported in this patch is valid. We are seeing that internally too. I believe I reported it in another thread (within the past month).
However, the original patch fixes a real deadlock issue (I'm too tired to look it up now). We can revet the original, but it's going to bring back the original issue. I just want to make sure Prarit and Raphael realize this before proceeding.
Hi Saravana,
Thanks for your input. I went back to the code and confirmed my original statement about this patch.
Note: in a previous email I erroneously wrote "
buffer->mutex" when I should have identified the lock assysfs_mutex. Sorry 'bout that, and apologies for any confusion that may have caused.From my commit message:
"In any case, the current linux.git code no longer can reproduce the original failure; the locking in the sysfs release code has changed."
The original patch attempted to fix this deadlock:
A cpufreq driver on a file read did:
-> #0 (&per_cpu(cpu_policy_rwsem, cpu)){+++++.}: [<c0055253>] __lock_acquire+0xef3/0x13dc [<c0055a79>] lock_acquire+0x61/0xbc [<c03ee1f5>] down_read+0x25/0x30 [<c02f6179>] lock_policy_rwsem_read+0x25/0x34 [<c02f6edd>] show+0x21/0x58 [<c00f9c0f>] sysfs_read_file+0x67/0xcc [<c00b40a7>] vfs_read+0x63/0xd8 [<c00b41fb>] sys_read+0x2f/0x50 [<c000cdc1>] ret_fast_syscall+0x1/0x52
lock(s_active#41)[ which is actually the acquisition ofsysfs_mutex]lock(&per_cpu(cpu_policy_rwsem, cpu));and on the governor switch (notably the EXIT of the existing governor), the opposite occurs
-> #1 (s_active#41){++++.+}: [<c0055a79>] lock_acquire+0x61/0xbc [<c00fabf1>] sysfs_addrm_finish+0xc1/0x128 [<c00f9819>] sysfs_hash_and_remove+0x35/0x64 [<c00fbe6f>] remove_files.isra.0+0x1b/0x24 [<c00fbea5>] sysfs_remove_group+0x2d/0xa8 [<c02f9a0b>] cpufreq_governor_interactive+0x13b/0x35c [<c02f61df>] __cpufreq_governor+0x2b/0x8c [<c02f6579>] __cpufreq_set_policy+0xa9/0xf8 [<c02f6b75>] store_scaling_governor+0x61/0x100 [<c02f6f4d>] store+0x39/0x60 [<c00f9b81>] sysfs_write_file+0xed/0x114 [<c00b3fd1>] vfs_write+0x65/0xd8 [<c00b424b>] sys_write+0x2f/0x50 [<c000cdc1>] ret_fast_syscall+0x1/0x52
Quoted 8 lines
lock(&per_cpu(cpu_policy_rwsem, cpu));lock(s_active#41)[ which is actually the acquisition ofsysfs_mutex]The
sysfs_mutexno longer blocks in the sysfs path, and I have built with LOCKDEP on and off to confirm that I do not see any tracebacks or hangs. I tested this by doing a few reads of the current governor, and then doing a governor switch (to at least initiate the LOCKDEP warning). IIUC the traceback above that is the way to reproduce this LOCKDEP warning.
^^^ this should not be taken as 'I did only a few reads ...'. I tested quite extensively across 15 different systems and added a read of the scaling_governor files in my little reproducer.
P.
Quoted 24 lines · Rafael J. Wysocki
Quoted 23 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch effectively reverts commit
955ef483.The issue reported in this patch is valid. We are seeing that internally too. I believe I reported it in another thread (within the past month).
However, the original patch fixes a real deadlock issue (I'm too tired to look it up now). We can revet the original, but it's going to bring back the original issue. I just want to make sure Prarit and Raphael realize this before proceeding.
I do have plans for a proper fix for the mainline (not stable branches), but plan to do that after the current set of suspend/hotplug patches go through. The fix would be easier to make after that.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Rafael, I think that is a good idea. I'm not sure what the protocol is for adding [email protected] though ...
Rafael, let me (again) re-write the patch description. I think Saravana has raised an important issue that I have not clearly identified why it is safe to remove this code in my patch description. Also, I want to clearly identify the appropriate -stable releases to push this out to.
I'll submit a [v3] later today or tomorrow.
P.
Quoted 3 lines
Rafael
Quoted 33 lines · Prarit Bhargava
Quoted 24 lines · Rafael J. Wysocki
Quoted 23 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch effectively reverts commit
955ef483.The issue reported in this patch is valid. We are seeing that internally too. I believe I reported it in another thread (within the past month).
However, the original patch fixes a real deadlock issue (I'm too tired to look it up now). We can revet the original, but it's going to bring back the original issue. I just want to make sure Prarit and Raphael realize this before proceeding.
I do have plans for a proper fix for the mainline (not stable branches), but plan to do that after the current set of suspend/hotplug patches go through. The fix would be easier to make after that.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Rafael, I think that is a good idea. I'm not sure what the protocol is for adding [email protected] though ...
Quoted 6 lines
Rafael, let me (again) re-write the patch description. I think Saravana has raised an important issue that I have not clearly identified why it is safe to remove this code in my patch description. Also, I want to clearly identify the appropriate -stable releases to push this out to.
I'll submit a [v3] later today or tomorrow.
In any case that's too late for 3.16 final, unless there's an -rc8.
Thanks for doing that work!
Rafael
Quoted 39 lines · Rafael J. Wysocki
Quoted 38 lines · Prarit Bhargava
Quoted 24 lines · Rafael J. Wysocki
Quoted 23 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch effectively reverts commit
955ef483.The issue reported in this patch is valid. We are seeing that internally too. I believe I reported it in another thread (within the past month).
However, the original patch fixes a real deadlock issue (I'm too tired to look it up now). We can revet the original, but it's going to bring back the original issue. I just want to make sure Prarit and Raphael realize this before proceeding.
I do have plans for a proper fix for the mainline (not stable branches), but plan to do that after the current set of suspend/hotplug patches go through. The fix would be easier to make after that.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Rafael, I think that is a good idea. I'm not sure what the protocol is for adding [email protected] though ...
Rafael, let me (again) re-write the patch description. I think Saravana has raised an important issue that I have not clearly identified why it is safe to remove this code in my patch description. Also, I want to clearly identify the appropriate -stable releases to push this out to.
Quoted 5 lines
Quoted 1 line
I'll submit a [v3] later today or tomorrow.
In any case that's too late for 3.16 final, unless there's an -rc8.
Thanks for doing that work!
Ugh ... I tried this (yet another) large system and hit another panic :(.
I'm investigating now, and I'm hoping this is just something "new".
P.
Quoted 3 lines
Rafael
Quoted 43 lines · Prarit Bhargava
Quoted 41 lines · Rafael J. Wysocki
Quoted 39 lines · Prarit Bhargava
Quoted 24 lines · Rafael J. Wysocki
Quoted 23 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch effectively reverts commit
955ef483.The issue reported in this patch is valid. We are seeing that internally too. I believe I reported it in another thread (within the past month).
However, the original patch fixes a real deadlock issue (I'm too tired to look it up now). We can revet the original, but it's going to bring back the original issue. I just want to make sure Prarit and Raphael realize this before proceeding.
I do have plans for a proper fix for the mainline (not stable branches), but plan to do that after the current set of suspend/hotplug patches go through. The fix would be easier to make after that.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Rafael, I think that is a good idea. I'm not sure what the protocol is for adding [email protected] though ...
Rafael, let me (again) re-write the patch description. I think Saravana has raised an important issue that I have not clearly identified why it is safe to remove this code in my patch description. Also, I want to clearly identify the appropriate -stable releases to push this out to.
I'll submit a [v3] later today or tomorrow.
Quoted 7 lines
Quoted 3 lines
In any case that's too late for 3.16 final, unless there's an -rc8.
Thanks for doing that work!
Ugh ... I tried this (yet another) large system and hit another panic :(.
I'm investigating now, and I'm hoping this is just something "new".
Well, I've applied your patch as is and I can push it to Linus.
However, if you want to update the changelog, I'll not do that, but in that case the patch will have to wait for the next week.
Rafael
Quoted 48 lines · Rafael J. Wysocki
Quoted 47 lines · Prarit Bhargava
Quoted 44 lines · Rafael J. Wysocki
Quoted 33 lines · Prarit Bhargava
Quoted 24 lines · Rafael J. Wysocki
Quoted 23 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch effectively reverts commit
955ef483.The issue reported in this patch is valid. We are seeing that internally too. I believe I reported it in another thread (within the past month).
However, the original patch fixes a real deadlock issue (I'm too tired to look it up now). We can revet the original, but it's going to bring back the original issue. I just want to make sure Prarit and Raphael realize this before proceeding.
I do have plans for a proper fix for the mainline (not stable branches), but plan to do that after the current set of suspend/hotplug patches go through. The fix would be easier to make after that.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Rafael, I think that is a good idea. I'm not sure what the protocol is for adding [email protected] though ...
Quoted 6 lines
Rafael, let me (again) re-write the patch description. I think Saravana has raised an important issue that I have not clearly identified why it is safe to remove this code in my patch description. Also, I want to clearly identify the appropriate -stable releases to push this out to.
I'll submit a [v3] later today or tomorrow.
In any case that's too late for 3.16 final, unless there's an -rc8.
Thanks for doing that work!
Quoted 8 lines
Quoted 3 lines
Ugh ... I tried this (yet another) large system and hit another panic :(.
I'm investigating now, and I'm hoping this is just something "new".
Well, I've applied your patch as is and I can push it to Linus.
However, if you want to update the changelog, I'll not do that, but in that case the patch will have to wait for the next week.
Rafael, please let it wait for next week. I _need_ to make sure this is correct and I'd rather not pushed something half-done.
Thanks,
P.
Quoted 3 lines
Rafael
Quoted 55 lines · Prarit Bhargava
Quoted 52 lines · Rafael J. Wysocki
Quoted 50 lines · Prarit Bhargava
Quoted 39 lines · Rafael J. Wysocki
Quoted 38 lines · Prarit Bhargava
Quoted 24 lines · Rafael J. Wysocki
Quoted 23 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch effectively reverts commit
955ef483.The issue reported in this patch is valid. We are seeing that internally too. I believe I reported it in another thread (within the past month).
However, the original patch fixes a real deadlock issue (I'm too tired to look it up now). We can revet the original, but it's going to bring back the original issue. I just want to make sure Prarit and Raphael realize this before proceeding.
I do have plans for a proper fix for the mainline (not stable branches), but plan to do that after the current set of suspend/hotplug patches go through. The fix would be easier to make after that.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Rafael, I think that is a good idea. I'm not sure what the protocol is for adding [email protected] though ...
Rafael, let me (again) re-write the patch description. I think Saravana has raised an important issue that I have not clearly identified why it is safe to remove this code in my patch description. Also, I want to clearly identify the appropriate -stable releases to push this out to.
Quoted 5 lines
Quoted 1 line
I'll submit a [v3] later today or tomorrow.
In any case that's too late for 3.16 final, unless there's an -rc8.
Thanks for doing that work!
Ugh ... I tried this (yet another) large system and hit another panic :(.
I'm investigating now, and I'm hoping this is just something "new".
Quoted 8 lines
Quoted 4 lines
Well, I've applied your patch as is and I can push it to Linus.
However, if you want to update the changelog, I'll not do that, but in that case the patch will have to wait for the next week.
Rafael, please let it wait for next week. I _need_ to make sure this is correct and I'd rather not pushed something half-done.
Prarit,
I'm not an expert on sysfs locking, but I would think the specific sysfs lock would depend on the file/attribute group. So, can you please try to hotplug a core in/out (to trigger the POLICY_EXIT) and then read a sysfs file exported by the governor? scaling_governor doesn't cut it since that file is not removed on policy exit event to governor. If it's ondemand, try reading/write it's sampling rate file.
The main problem here is upon POLICY_EXIT to the governor, the governor tries to remove its sysfs file. So, if you have the policy lock held while sending POLICY_EXIT to the governor, you'll cause the:
lock policy
lock sysfs
But trying to read the same file would cause:
lock sysfs
lock policy
-Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Quoted 68 lines · Saravana Kannan
Quoted 58 lines · Prarit Bhargava
Quoted 55 lines · Rafael J. Wysocki
Quoted 53 lines · Prarit Bhargava
Quoted 42 lines · Rafael J. Wysocki
Quoted 41 lines · Prarit Bhargava
Quoted 24 lines · Rafael J. Wysocki
Quoted 23 lines · Saravana Kannan
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Prarit Bhargava
Quoted 1 line · Rafael J. Wysocki
On Tuesday, July 29, 2014 07:46:02 AM Prarit Bhargava wrote:
[cut]
Quoted 1 line
Quoted 1 line
Quoted 1 line
This patch effectively reverts commit
955ef483.The issue reported in this patch is valid. We are seeing that internally too. I believe I reported it in another thread (within the past month).
However, the original patch fixes a real deadlock issue (I'm too tired to look it up now). We can revet the original, but it's going to bring back the original issue. I just want to make sure Prarit and Raphael realize this before proceeding.
I do have plans for a proper fix for the mainline (not stable branches), but plan to do that after the current set of suspend/hotplug patches go through. The fix would be easier to make after that.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
OK, I'm convinced by this.
I suppose we should push it for -stable from 3.10 through 3.15.x, right?
Rafael, I think that is a good idea. I'm not sure what the protocol is for
adding [email protected] though ...Rafael, let me (again) re-write the patch description. I think Saravana has raised an important issue that I have not clearly identified why it is safe to
remove this code in my patch description. Also, I want to clearly identify the
appropriate -stable releases to push this out to.Quoted 5 lines
Quoted 1 line
I'll submit a [v3] later today or tomorrow.
In any case that's too late for 3.16 final, unless there's an -rc8.
Thanks for doing that work!
Ugh ... I tried this (yet another) large system and hit another panic :(.
I'm investigating now, and I'm hoping this is just something "new".
Quoted 8 lines
Quoted 4 lines
Well, I've applied your patch as is and I can push it to Linus.
However, if you want to update the changelog, I'll not do that, but in that case the patch will have to wait for the next week.
Rafael, please let it wait for next week. I _need_ to make sure this is correct and I'd rather not pushed something half-done.
Quoted 8 lines
Prarit,
I'm not an expert on sysfs locking, but I would think the specific sysfs lock would depend on the file/attribute group. So, can you please try to hotplug a core in/out (to trigger the
POLICY_EXIT) and then read a sysfs file exported by the governor?scaling_governordoesn't cut it since that file is not removed on policy exit event to governor. If it's ondemand, try reading/write it's sampling rate file.
Thanks Saravana -- will do. I will get back to you shortly on this.
P.
Quoted 3 lines
-Saravana
Quoted 6 lines · Prarit Bhargava
Quoted 3 lines · Saravana Kannan
Prarit,
Quoted 9 lines
Quoted 6 lines
I'm not an expert on sysfs locking, but I would think the specific sysfs lock would depend on the file/attribute group. So, can you please try to hotplug a core in/out (to trigger the
POLICY_EXIT) and then read a sysfs file exported by the governor?scaling_governordoesn't cut it since that file is not removed on policy exit event to governor. If it's ondemand, try reading/write it's sampling rate file.Thanks Saravana -- will do. I will get back to you shortly on this.
Thanks. Btw, in case you weren't already aware of it. You'll have to hoplug out all the CPUs in a cluster to trigger a POLICY_EXIT for that cluster/policy.
-Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Quoted 14 lines · Saravana Kannan
Quoted 13 lines · Prarit Bhargava
Quoted 9 lines · Saravana Kannan
Prarit,
I'm not an expert on sysfs locking, but I would think the specific sysfs lock would depend on the file/attribute group. So, can you please try to hotplug a core in/out (to trigger the
POLICY_EXIT) and then read a sysfs file exported by the governor?scaling_governordoesn't cut it since that file is not removed on policy exit event to governor. If it's ondemand, try reading/write it's sampling rate file.
Quoted 5 lines
Quoted 2 lines
Thanks Saravana -- will do. I will get back to you shortly on this.
Thanks. Btw, in case you weren't already aware of it. You'll have to hoplug out all the CPUs in a cluster to trigger a
POLICY_EXITfor that cluster/policy.
Yep -- the affected_cpus file should show all the cpus in the policy IIRC. One of the systems I have has 1 cpu/policy and has 48 threads so the POLICY_EXIT is called.
I'll put something like
while [1];
do
echo ondemand > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor cat /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate echo 20000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate cat /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate echo 0 > /sys/devices/system/cpu/cpu1/online
sleep 1
echo 1 > /sys/devices/system/cpu/cpu1/online
sleep 1
done
and let it run unless you can think of something else. FWIW, manually trying that yields no problems AFAICT. The sleeps are just me being paranoid and keeping things in sequence.
P.
Quoted 3 lines
-Saravana
Quoted 29 lines · Prarit Bhargava
Quoted 14 lines · Saravana Kannan
Quoted 13 lines · Prarit Bhargava
Quoted 9 lines · Saravana Kannan
Prarit,
I'm not an expert on sysfs locking, but I would think the specific sysfs lock would depend on the file/attribute group. So, can you please try to hotplug a core in/out (to trigger the
POLICY_EXIT) and then read a sysfs file exported by the governor?scaling_governordoesn't cut it since that file is not removed on policy exit event to governor. If it's ondemand, try reading/write it's sampling rate file.Quoted 5 lines
Quoted 2 lines
Thanks Saravana -- will do. I will get back to you shortly on this.
Thanks. Btw, in case you weren't already aware of it. You'll have to hoplug out all the CPUs in a cluster to trigger a
POLICY_EXITfor that cluster/policy.Yep -- the
affected_cpusfile should show all the cpus in the policy IIRC. One of the systems I have has 1 cpu/policy and has 48 threads so thePOLICY_EXITis called.I'll put something like
Quoted 12 lines
while [1];
do
echo ondemand >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governorcat/sys/devices/system/cpu/cpufreq/ondemand/sampling_rateecho 20000 >/sys/devices/system/cpu/cpufreq/ondemand/sampling_ratecat/sys/devices/system/cpu/cpufreq/ondemand/sampling_rateecho 0 >/sys/devices/system/cpu/cpu1/online
sleep 1
echo 1 >/sys/devices/system/cpu/cpu1/online
sleep 1
done
The actual race can only happen with 2 threads. I'm just trying to trigger a lockdep warning here.
-Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Quoted 46 lines · Saravana Kannan
Quoted 32 lines · Prarit Bhargava
Quoted 17 lines · Saravana Kannan
Quoted 16 lines · Prarit Bhargava
Quoted 12 lines · Saravana Kannan
Prarit,
I'm not an expert on sysfs locking, but I would think the specific sysfs lock would depend on the file/attribute group. So, can you please try to hotplug a core in/out (to trigger the
POLICY_EXIT) and then read a sysfs file exported by
the governor?scaling_governordoesn't cut it since that file is not removed on
policy exit event to governor. If it's ondemand, try reading/write it's sampling
rate file.Quoted 5 lines
Quoted 2 lines
Thanks Saravana -- will do. I will get back to you shortly on this.
Thanks. Btw, in case you weren't already aware of it. You'll have to hoplug out all the CPUs in a cluster to trigger a
POLICY_EXITfor that cluster/policy.Yep -- the
affected_cpusfile should show all the cpus in the policy IIRC. One of the systems I have has 1 cpu/policy and has 48 threads so thePOLICY_EXITis called.I'll put something like
Quoted 12 lines
while [1];
do
echo ondemand >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governorcat/sys/devices/system/cpu/cpufreq/ondemand/sampling_rateecho 20000 >/sys/devices/system/cpu/cpufreq/ondemand/sampling_ratecat/sys/devices/system/cpu/cpufreq/ondemand/sampling_rateecho 0 >/sys/devices/system/cpu/cpu1/online
sleep 1
echo 1 >/sys/devices/system/cpu/cpu1/online
sleep 1
done
Quoted 2 lines
The actual race can only happen with 2 threads. I'm just trying to trigger a lockdep warning here.
I ran the above in two separate terminals with cpuset -c 0 and cpuset -c 1 to multi-thread it all. No deadlock or LOCKDEP trace after about 1/2 hour, so I think we're in the clear on that concern.
P.
Quoted 49 lines · Prarit Bhargava
Quoted 46 lines · Saravana Kannan
Quoted 44 lines · Prarit Bhargava
Quoted 17 lines · Saravana Kannan
Quoted 16 lines · Prarit Bhargava
Quoted 12 lines · Saravana Kannan
Prarit,
I'm not an expert on sysfs locking, but I would think the specific sysfs lock would depend on the file/attribute group. So, can you please try to hotplug a core in/out (to trigger the
POLICY_EXIT) and then read a sysfs file exported by
the governor?scaling_governordoesn't cut it since that file is not removed on
policy exit event to governor. If it's ondemand, try reading/write it's sampling
rate file.Quoted 5 lines
Quoted 2 lines
Thanks Saravana -- will do. I will get back to you shortly on this.
Thanks. Btw, in case you weren't already aware of it. You'll have to hoplug out all the CPUs in a cluster to trigger a
POLICY_EXITfor that cluster/policy.Yep -- the
affected_cpusfile should show all the cpus in the policy IIRC. One of the systems I have has 1 cpu/policy and has 48 threads so thePOLICY_EXITis called.I'll put something like
while [1];
do
echo ondemand >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governorcat/sys/devices/system/cpu/cpufreq/ondemand/sampling_rateecho 20000 >/sys/devices/system/cpu/cpufreq/ondemand/sampling_ratecat/sys/devices/system/cpu/cpufreq/ondemand/sampling_rateecho 0 >/sys/devices/system/cpu/cpu1/online
sleep 1
echo 1 >/sys/devices/system/cpu/cpu1/online
sleep 1
done
Quoted 7 lines
Quoted 2 lines
The actual race can only happen with 2 threads. I'm just trying to trigger a lockdep warning here.
I ran the above in two separate terminals with cpuset -c 0 and cpuset -c 1 to multi-thread it all. No deadlock or LOCKDEP trace after about 1/2 hour, so I think we're in the clear on that concern.
I wasn't convinced. So, I took some help from Stephen to test it.
It's been a while, so I didn't remember the original issue clearly when I gave you some test suggestions. Now that I looked at the code more closely, I have a proper way to reproduce the original issue.
Nack for this patch for 2 reasons:
1. You seem to have accidentally removed a GOV_STOP in your patch. We definitely can't do that. This broke changing governors and that's why your patch didn't cause any issues. Because all your governor echos were failing.
2. When we fixed that and actually tried a proper test (not the one I gave you), we reproduced the original issue.
To reproduce original issue:
Preconditions:
* lockdep is enabled
* governor per policy is enabled
Steps:
1. Set governor to ondemand.
2. Cat one of the ondemand sysfs files.
3. Change governor to conservative.
When you do that, there's an AB, BA dead lock issue with one thread trying to cat a governor sysfs file and another thread trying to change governors.
-Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Quoted 63 lines · Saravana Kannan
Quoted 52 lines · Prarit Bhargava
Quoted 49 lines · Saravana Kannan
Quoted 47 lines · Prarit Bhargava
Quoted 19 lines · Saravana Kannan
Quoted 18 lines · Prarit Bhargava
Quoted 14 lines · Saravana Kannan
Prarit,
I'm not an expert on sysfs locking, but I would think the specific sysfs lock
would depend on the file/attribute group. So, can you please try to hotplug a
core in/out (to trigger thePOLICY_EXIT) and then read a sysfs file exported by
the governor?scaling_governordoesn't cut it since that file is not removed on
policy exit event to governor. If it's ondemand, try reading/write it's sampling
rate file.Quoted 6 lines
Quoted 2 lines
Thanks Saravana -- will do. I will get back to you shortly on this.
Thanks. Btw, in case you weren't already aware of it. You'll have to hoplug out
all the CPUs in a cluster to trigger aPOLICY_EXITfor that cluster/policy.Yep -- the
affected_cpusfile should show all the cpus in the policy IIRC. One of the systems I have has 1 cpu/policy and has 48 threads so thePOLICY_EXITis called.I'll put something like
while [1];
do
echo ondemand >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governorcat/sys/devices/system/cpu/cpufreq/ondemand/sampling_rateecho 20000 >/sys/devices/system/cpu/cpufreq/ondemand/sampling_ratecat/sys/devices/system/cpu/cpufreq/ondemand/sampling_rateecho 0 >/sys/devices/system/cpu/cpu1/online
sleep 1
echo 1 >/sys/devices/system/cpu/cpu1/online
sleep 1
doneQuoted 7 lines
Quoted 2 lines
The actual race can only happen with 2 threads. I'm just trying to trigger a lockdep warning here.
I ran the above in two separate terminals with cpuset -c 0 and cpuset -c 1 to multi-thread it all. No deadlock or LOCKDEP trace after about 1/2 hour, so I think we're in the clear on that concern.
I wasn't convinced. So, I took some help from Stephen to test it.
Quoted 8 lines
It's been a while, so I didn't remember the original issue clearly when I gave you some test suggestions. Now that I looked at the code more closely, I have a proper way to reproduce the original issue.
Nack for this patch for 2 reasons:
1. You seem to have accidentally removed aGOV_STOPin your patch. We definitely can't do that. This broke changing governors and that's why your patch didn't cause any issues. Because all your governor echos were failing.
Yes, I mentioned that yesterday in the thread.
Quoted 7 lines
2. When we fixed that and actually tried a proper test (not the one I gave you), we reproduced the original issue.
To reproduce original issue:
Preconditions:
* lockdep is enabled
* governor per policy is enabled
Okay. I have that ...
Quoted 8 lines
Steps:
1. Set governor to ondemand.
2. Cat one of the ondemand sysfs files.
3. Change governor to conservative.When you do that, there's an AB, BA dead lock issue with one thread trying to cat a governor sysfs file and another thread trying to change governors.
Okay, I'm going to try this too...
P.
Quoted 3 lines
-Saravana
Quoted 79 lines · Saravana Kannan
Quoted 52 lines · Prarit Bhargava
Quoted 49 lines · Saravana Kannan
Quoted 47 lines · Prarit Bhargava
Quoted 19 lines · Saravana Kannan
Quoted 18 lines · Prarit Bhargava
Quoted 14 lines · Saravana Kannan
Prarit,
I'm not an expert on sysfs locking, but I would think the specific sysfs lock
would depend on the file/attribute group. So, can you please try to hotplug a
core in/out (to trigger thePOLICY_EXIT) and then read a sysfs file exported by
the governor?scaling_governordoesn't cut it since that file is not removed on
policy exit event to governor. If it's ondemand, try reading/write it's sampling
rate file.Quoted 6 lines
Quoted 2 lines
Thanks Saravana -- will do. I will get back to you shortly on this.
Thanks. Btw, in case you weren't already aware of it. You'll have to hoplug out
all the CPUs in a cluster to trigger aPOLICY_EXITfor that cluster/policy.Yep -- the
affected_cpusfile should show all the cpus in the policy IIRC. One of the systems I have has 1 cpu/policy and has 48 threads so thePOLICY_EXITis called.I'll put something like
while [1];
do
echo ondemand >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governorcat/sys/devices/system/cpu/cpufreq/ondemand/sampling_rateecho 20000 >/sys/devices/system/cpu/cpufreq/ondemand/sampling_ratecat/sys/devices/system/cpu/cpufreq/ondemand/sampling_rateecho 0 >/sys/devices/system/cpu/cpu1/online
sleep 1
echo 1 >/sys/devices/system/cpu/cpu1/online
sleep 1
doneQuoted 7 lines
Quoted 2 lines
The actual race can only happen with 2 threads. I'm just trying to trigger a lockdep warning here.
I ran the above in two separate terminals with cpuset -c 0 and cpuset -c 1 to multi-thread it all. No deadlock or LOCKDEP trace after about 1/2 hour, so I think we're in the clear on that concern.
I wasn't convinced. So, I took some help from Stephen to test it.
It's been a while, so I didn't remember the original issue clearly when I gave you some test suggestions. Now that I looked at the code more closely, I have a proper way to reproduce the original issue.
Nack for this patch for 2 reasons:
1. You seem to have accidentally removed aGOV_STOPin your patch. We definitely can't do that. This broke changing governors and that's why your patch didn't cause any issues. Because all your governor echos were failing.
2. When we fixed that and actually tried a proper test (not the one I gave you), we reproduced the original issue.To reproduce original issue:
Preconditions:
* lockdep is enabled
* governor per policy is enabled
Quoted 4 lines
Steps:
1. Set governor to ondemand.
2. Cat one of the ondemand sysfs files.
3. Change governor to conservative.
Can you send me the test and the trace of the deadlock? I'm not creating it with:
drivers/cpufreq/cpufreq.c +0 -4
@@ -2200,9 +2200,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *polic/* 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 */
@@ -2211,9 +2209,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policif (!__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 */
Quoted 9 lines
When you do that, there's an AB, BA dead lock issue with one thread trying to cat a governor sysfs file and another thread trying to change governors.
-Saravana
Quoted 3 lines · Prarit Bhargava
Can you send me the test and the trace of the deadlock? I'm not creating it with:
This was with conservative as the default, and switching to ondemand
# cd /sys/devices/system/cpu/cpu2/cpufreq # ls affected_cpus scaling_available_governors conservative scaling_cur_freq cpuinfo_cur_freq scaling_driver cpuinfo_max_freq scaling_governor cpuinfo_min_freq scaling_max_freq cpuinfo_transition_latency scaling_min_freq related_cpus scaling_setspeed scaling_available_frequencies stats # cat conservative/down_threshold 20 # echo ondemand > scaling_governor
======================================================
[ INFO: possible circular locking dependency detected ] 3.16.0-rc3-00039-ge1e38f124d87 #47 Not tainted
-------------------------------------------------------
sh/75 is trying to acquire lock:
(s_active#9){++++..}, at: [<c0358a94>] kernfs_remove_by_name_ns+0x3c/0x84
but task is already holding lock:
(&policy->rwsem){+++++.}, at: [<c05ab1f0>] store+0x68/0xb8
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (&policy->rwsem){+++++.}:
[<c0359234>] kernfs_fop_open+0x138/0x298
[<c02fa3f4>] do_dentry_open.isra.12+0x1b0/0x2f0
[<c02fa604>] finish_open+0x20/0x38
[<c0308d34>] do_last.isra.37+0x5ac/0xb68
[<c03093a4>] path_openat+0xb4/0x5d8
[<c0309bcc>] do_filp_open+0x2c/0x80
[<c02fb558>] do_sys_open+0x10c/0x1c8
[<c020f0a0>] ret_fast_syscall+0x0/0x48-> #0 (s_active#9){++++..}:
[<c0357d18>] __kernfs_remove+0x250/0x300
[<c0358a94>] kernfs_remove_by_name_ns+0x3c/0x84
[<c035aa78>] remove_files+0x34/0x78
[<c035aee0>] sysfs_remove_group+0x40/0x98
[<c05b0560>] cpufreq_governor_dbs+0x4c0/0x6ec
[<c05abebc>] __cpufreq_governor+0x118/0x200
[<c05ac0fc>] cpufreq_set_policy+0x158/0x2ac
[<c05ad5e4>] store_scaling_governor+0x6c/0x94
[<c05ab210>] store+0x88/0xb8
[<c035a00c>] sysfs_kf_write+0x4c/0x50
[<c03594d4>] kernfs_fop_write+0xc0/0x180
[<c02fc5c8>] vfs_write+0xa0/0x1a8
[<c02fc9d4>] SyS_write+0x40/0x8c
[<c020f0a0>] ret_fast_syscall+0x0/0x48other info that might help us debug this:
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&policy->rwsem);
lock(s_active#9);
lock(&policy->rwsem); lock(s_active#9);
*** DEADLOCK ***
6 locks held by sh/75:
#0: (sb_writers#4){.+.+..}, at: [<c02fc6a8>] vfs_write+0x180/0x1a8
#1: (&of->mutex){+.+...}, at: [<c0359498>] kernfs_fop_write+0x84/0x180
#2: (s_active#10){.+.+..}, at: [<c03594a0>] kernfs_fop_write+0x8c/0x180
#3: (cpu_hotplug.lock){++++++}, at: [<c0221ef8>] get_online_cpus+0x38/0x9c
#4: (cpufreq_rwsem){.+.+.+}, at: [<c05ab1d8>] store+0x50/0xb8
#5: (&policy->rwsem){+++++.}, at: [<c05ab1f0>] store+0x68/0xb8stack backtrace: CPU: 0 PID: 75 Comm: sh Not tainted 3.16.0-rc3-00039-ge1e38f124d87 #47 [<c0214de8>] (unwind_backtrace) from [<c02123f8>] (show_stack+0x10/0x14) [<c02123f8>] (show_stack) from [<c0709e5c>] (dump_stack+0x70/0xbc) [<c0709e5c>] (dump_stack) from [<c070722c>] (print_circular_bug+0x280/0x2d4) [<c070722c>] (print_circular_bug) from [<c02629cc>] (__lock_acquire+0x18d0/0x1abc) [<c02629cc>] (__lock_acquire) from [<c026310c>] (lock_acquire+0x9c/0x138) [<c026310c>] (lock_acquire) from [<c0357d18>] (__kernfs_remove+0x250/0x300) [<c0357d18>] (__kernfs_remove) from [<c0358a94>] (kernfs_remove_by_name_ns+0x3c/0x84) [<c0358a94>] (kernfs_remove_by_name_ns) from [<c035aa78>] (remove_files+0x34/0x78) [<c035aa78>] (remove_files) from [<c035aee0>] (sysfs_remove_group+0x40/0x98) [<c035aee0>] (sysfs_remove_group) from [<c05b0560>] (cpufreq_governor_dbs+0x4c0/0x6ec) [<c05b0560>] (cpufreq_governor_dbs) from [<c05abebc>] (__cpufreq_governor+0x118/0x200) [<c05abebc>] (__cpufreq_governor) from [<c05ac0fc>] (cpufreq_set_policy+0x158/0x2ac) [<c05ac0fc>] (cpufreq_set_policy) from [<c05ad5e4>] (store_scaling_governor+0x6c/0x94) [<c05ad5e4>] (store_scaling_governor) from [<c05ab210>] (store+0x88/0xb8) [<c05ab210>] (store) from [<c035a00c>] (sysfs_kf_write+0x4c/0x50) [<c035a00c>] (sysfs_kf_write) from [<c03594d4>] (kernfs_fop_write+0xc0/0x180) [<c03594d4>] (kernfs_fop_write) from [<c02fc5c8>] (vfs_write+0xa0/0x1a8) [<c02fc5c8>] (vfs_write) from [<c02fc9d4>] (SyS_write+0x40/0x8c) [<c02fc9d4>] (SyS_write) from [<c020f0a0>] (ret_fast_syscall+0x0/0x48)
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 7 lines · Stephen Boyd
Quoted 3 lines · Prarit Bhargava
Can you send me the test and the trace of the deadlock? I'm not creating it with:
This was with conservative as the default, and switching to ondemand
Quoted 13 lines
# cd /sys/devices/system/cpu/cpu2/cpufreq # ls affected_cpus scaling_available_governors conservative scaling_cur_freq cpuinfo_cur_freq scaling_driver cpuinfo_max_freq scaling_governor cpuinfo_min_freq scaling_max_freq cpuinfo_transition_latency scaling_min_freq related_cpus scaling_setspeed scaling_available_frequencies stats # cat conservative/down_threshold 20 # echo ondemand > scaling_governor
Thanks Stephen,
There's obviously a difference in our .configs. I have a global conservative directory, ie) /sys/devices/system/cpu/cpufreq/conservative instead of a per-cpu governor file.
ie) what are your .config options for CPUFREQ?
Mine are:
#
# CPU Frequency scaling
#CONFIG_CPU_FREQ=y CONFIG_CPU_FREQ_GOV_COMMON=y CONFIG_CPU_FREQ_STAT=m CONFIG_CPU_FREQ_STAT_DETAILS=y
# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set # CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set # CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE=y CONFIG_CPU_FREQ_GOV_PERFORMANCE=y CONFIG_CPU_FREQ_GOV_POWERSAVE=y CONFIG_CPU_FREQ_GOV_USERSPACE=y CONFIG_CPU_FREQ_GOV_ONDEMAND=y CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
Is there some other config option I have to set?
P.
Quoted 86 lines
======================================================
[ INFO: possible circular locking dependency detected ] 3.16.0-rc3-00039-ge1e38f124d87 #47 Not tainted
-------------------------------------------------------
sh/75 is trying to acquire lock:
(s_active#9){++++..}, at: [<c0358a94>]kernfs_remove_by_name_ns+0x3c/0x84but task is already holding lock:
(&policy->rwsem){+++++.}, at: [<c05ab1f0>]store+0x68/0xb8which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (&policy->rwsem){+++++.}:
[<c0359234>] kernfs_fop_open+0x138/0x298 [<c02fa3f4>] do_dentry_open.isra.12+0x1b0/0x2f0 [<c02fa604>] finish_open+0x20/0x38 [<c0308d34>] do_last.isra.37+0x5ac/0xb68 [<c03093a4>] path_openat+0xb4/0x5d8 [<c0309bcc>] do_filp_open+0x2c/0x80 [<c02fb558>] do_sys_open+0x10c/0x1c8 [<c020f0a0>] ret_fast_syscall+0x0/0x48-> #0 (s_active#9){++++..}:
[<c0357d18>] __kernfs_remove+0x250/0x300 [<c0358a94>] kernfs_remove_by_name_ns+0x3c/0x84 [<c035aa78>] remove_files+0x34/0x78 [<c035aee0>] sysfs_remove_group+0x40/0x98 [<c05b0560>] cpufreq_governor_dbs+0x4c0/0x6ec [<c05abebc>] __cpufreq_governor+0x118/0x200 [<c05ac0fc>] cpufreq_set_policy+0x158/0x2ac [<c05ad5e4>] store_scaling_governor+0x6c/0x94 [<c05ab210>] store+0x88/0xb8 [<c035a00c>] sysfs_kf_write+0x4c/0x50 [<c03594d4>] kernfs_fop_write+0xc0/0x180 [<c02fc5c8>] vfs_write+0xa0/0x1a8 [<c02fc9d4>] SyS_write+0x40/0x8c [<c020f0a0>] ret_fast_syscall+0x0/0x48other info that might help us debug this:
Possible unsafe locking scenario:CPU0 CPU1 ---- ---- lock(&policy->rwsem); lock(s_active#9); lock(&policy->rwsem);
lock(s_active#9);*** DEADLOCK ***
6 locks held by sh/75:
#0: (sb_writers#4){.+.+..}, at: [<c02fc6a8>] vfs_write+0x180/0x1a8 #1: (&of->mutex){+.+...}, at: [<c0359498>] kernfs_fop_write+0x84/0x180 #2: (s_active#10){.+.+..}, at: [<c03594a0>] kernfs_fop_write+0x8c/0x180 #3: (cpu_hotplug.lock){++++++}, at: [<c0221ef8>] get_online_cpus+0x38/0x9c #4: (cpufreq_rwsem){.+.+.+}, at: [<c05ab1d8>] store+0x50/0xb8 #5: (&policy->rwsem){+++++.}, at: [<c05ab1f0>] store+0x68/0xb8stack backtrace: CPU: 0 PID: 75 Comm: sh Not tainted 3.16.0-rc3-00039-ge1e38f124d87 #47 [<c0214de8>] (unwind_backtrace) from [<c02123f8>] (show_stack+0x10/0x14) [<c02123f8>] (show_stack) from [<c0709e5c>] (dump_stack+0x70/0xbc) [<c0709e5c>] (dump_stack) from [<c070722c>] (print_circular_bug+0x280/0x2d4) [<c070722c>] (print_circular_bug) from [<c02629cc>] (__lock_acquire+0x18d0/0x1abc) [<c02629cc>] (__lock_acquire) from [<c026310c>] (lock_acquire+0x9c/0x138) [<c026310c>] (lock_acquire) from [<c0357d18>] (__kernfs_remove+0x250/0x300) [<c0357d18>] (__kernfs_remove) from [<c0358a94>] (kernfs_remove_by_name_ns+0x3c/0x84) [<c0358a94>] (kernfs_remove_by_name_ns) from [<c035aa78>] (remove_files+0x34/0x78) [<c035aa78>] (remove_files) from [<c035aee0>] (sysfs_remove_group+0x40/0x98) [<c035aee0>] (sysfs_remove_group) from [<c05b0560>] (cpufreq_governor_dbs+0x4c0/0x6ec) [<c05b0560>] (cpufreq_governor_dbs) from [<c05abebc>] (__cpufreq_governor+0x118/0x200) [<c05abebc>] (__cpufreq_governor) from [<c05ac0fc>] (cpufreq_set_policy+0x158/0x2ac) [<c05ac0fc>] (cpufreq_set_policy) from [<c05ad5e4>] (store_scaling_governor+0x6c/0x94) [<c05ad5e4>] (store_scaling_governor) from [<c05ab210>] (store+0x88/0xb8) [<c05ab210>] (store) from [<c035a00c>] (sysfs_kf_write+0x4c/0x50) [<c035a00c>] (sysfs_kf_write) from [<c03594d4>] (kernfs_fop_write+0xc0/0x180) [<c03594d4>] (kernfs_fop_write) from [<c02fc5c8>] (vfs_write+0xa0/0x1a8) [<c02fc5c8>] (vfs_write) from [<c02fc9d4>] (SyS_write+0x40/0x8c) [<c02fc9d4>] (SyS_write) from [<c020f0a0>] (ret_fast_syscall+0x0/0x48)
Quoted 47 lines · Prarit Bhargava
Quoted 5 lines · Stephen Boyd
Quoted 2 lines · Prarit Bhargava
Can you send me the test and the trace of the deadlock? I'm not creating it with:
This was with conservative as the default, and switching to ondemand
Quoted 13 lines
# cd /sys/devices/system/cpu/cpu2/cpufreq # ls affected_cpus scaling_available_governors conservative scaling_cur_freq cpuinfo_cur_freq scaling_driver cpuinfo_max_freq scaling_governor cpuinfo_min_freq scaling_max_freq cpuinfo_transition_latency scaling_min_freq related_cpus scaling_setspeed scaling_available_frequencies stats # cat conservative/down_threshold 20 # echo ondemand > scaling_governorThanks Stephen,
There's obviously a difference in our .configs. I have a global conservative directory, ie)
/sys/devices/system/cpu/cpufreq/conservativeinstead of a per-cpu governor file.ie) what are your .config options for CPUFREQ?
Mine are:
#
# CPU Frequency scaling
#CONFIG_CPU_FREQ=yCONFIG_CPU_FREQ_GOV_COMMON=yCONFIG_CPU_FREQ_STAT=mCONFIG_CPU_FREQ_STAT_DETAILS=y
#CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMANDis not setCONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE=yCONFIG_CPU_FREQ_GOV_PERFORMANCE=yCONFIG_CPU_FREQ_GOV_POWERSAVE=yCONFIG_CPU_FREQ_GOV_USERSPACE=yCONFIG_CPU_FREQ_GOV_ONDEMAND=yCONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
Quoted 1 line
Is there some other config option I have to set?
I have the same options. The difference is that my driver has a governor per policy. That's set with the CPUFREQ_HAVE_GOVERNOR_PER_POLICY flag. If I remove that flag I can't trigger the lockdep splat anymore with this sequence and your patch.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 48 lines · Stephen Boyd
Quoted 47 lines · Prarit Bhargava
Quoted 5 lines · Stephen Boyd
Quoted 2 lines · Prarit Bhargava
Can you send me the test and the trace of the deadlock? I'm not creating it with:
This was with conservative as the default, and switching to ondemand
Quoted 13 lines
# cd /sys/devices/system/cpu/cpu2/cpufreq # ls affected_cpus scaling_available_governors conservative scaling_cur_freq cpuinfo_cur_freq scaling_driver cpuinfo_max_freq scaling_governor cpuinfo_min_freq scaling_max_freq cpuinfo_transition_latency scaling_min_freq related_cpus scaling_setspeed scaling_available_frequencies stats # cat conservative/down_threshold 20 # echo ondemand > scaling_governorThanks Stephen,
There's obviously a difference in our .configs. I have a global conservative directory, ie)
/sys/devices/system/cpu/cpufreq/conservativeinstead of a per-cpu governor file.ie) what are your .config options for CPUFREQ?
Mine are:
#
# CPU Frequency scaling
#CONFIG_CPU_FREQ=yCONFIG_CPU_FREQ_GOV_COMMON=yCONFIG_CPU_FREQ_STAT=mCONFIG_CPU_FREQ_STAT_DETAILS=y
#CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMANDis not setCONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE=yCONFIG_CPU_FREQ_GOV_PERFORMANCE=yCONFIG_CPU_FREQ_GOV_POWERSAVE=yCONFIG_CPU_FREQ_GOV_USERSPACE=yCONFIG_CPU_FREQ_GOV_ONDEMAND=yCONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
Quoted 6 lines
Quoted 1 line
Is there some other config option I have to set?
I have the same options. The difference is that my driver has a governor per policy. That's set with the
CPUFREQ_HAVE_GOVERNOR_PER_POLICYflag. If I remove that flag I can't trigger the lockdep splat anymore with this sequence and your patch.
I see -- so you're seeing this on arm then? If so, let me know so I can reserve one to work on :)
Thanks!
P.
Quoted 1 line
Quoted 49 lines · Prarit Bhargava
Quoted 47 lines · Stephen Boyd
Quoted 46 lines · Prarit Bhargava
Quoted 5 lines · Stephen Boyd
Quoted 2 lines · Prarit Bhargava
Can you send me the test and the trace of the deadlock? I'm not creating it with:
This was with conservative as the default, and switching to ondemand
Quoted 13 lines
# cd /sys/devices/system/cpu/cpu2/cpufreq # ls affected_cpus scaling_available_governors conservative scaling_cur_freq cpuinfo_cur_freq scaling_driver cpuinfo_max_freq scaling_governor cpuinfo_min_freq scaling_max_freq cpuinfo_transition_latency scaling_min_freq related_cpus scaling_setspeed scaling_available_frequencies stats # cat conservative/down_threshold 20 # echo ondemand > scaling_governorThanks Stephen,
There's obviously a difference in our .configs. I have a global conservative directory, ie)
/sys/devices/system/cpu/cpufreq/conservativeinstead of a per-cpu governor file.ie) what are your .config options for CPUFREQ?
Mine are:
#
# CPU Frequency scaling
#CONFIG_CPU_FREQ=yCONFIG_CPU_FREQ_GOV_COMMON=yCONFIG_CPU_FREQ_STAT=mCONFIG_CPU_FREQ_STAT_DETAILS=y
#CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMANDis not setCONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE=yCONFIG_CPU_FREQ_GOV_PERFORMANCE=yCONFIG_CPU_FREQ_GOV_POWERSAVE=yCONFIG_CPU_FREQ_GOV_USERSPACE=yCONFIG_CPU_FREQ_GOV_ONDEMAND=yCONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Is there some other config option I have to set?
I have the same options. The difference is that my driver has a governor per policy. That's set with the
CPUFREQ_HAVE_GOVERNOR_PER_POLICYflag. If I remove that flag I can't trigger the lockdep splat anymore with this sequence and your patch.I see -- so you're seeing this on arm then? If so, let me know so I can reserve one to work on :)
I only have ARM to test on. You can set this flag in your cpufreq driver if you have independently scaling CPU frequencies, so it isn't necessarily an ARM thing.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 55 lines · Stephen Boyd
Quoted 54 lines · Prarit Bhargava
Quoted 52 lines · Stephen Boyd
Quoted 46 lines · Prarit Bhargava
Quoted 5 lines · Stephen Boyd
Quoted 2 lines · Prarit Bhargava
Can you send me the test and the trace of the deadlock? I'm not creating it with:
This was with conservative as the default, and switching to ondemand
Quoted 13 lines
# cd /sys/devices/system/cpu/cpu2/cpufreq # ls affected_cpus scaling_available_governors conservative scaling_cur_freq cpuinfo_cur_freq scaling_driver cpuinfo_max_freq scaling_governor cpuinfo_min_freq scaling_max_freq cpuinfo_transition_latency scaling_min_freq related_cpus scaling_setspeed scaling_available_frequencies stats # cat conservative/down_threshold 20 # echo ondemand > scaling_governorThanks Stephen,
There's obviously a difference in our .configs. I have a global conservative directory, ie)
/sys/devices/system/cpu/cpufreq/conservativeinstead of a per-cpu governor file.ie) what are your .config options for CPUFREQ?
Mine are:
#
# CPU Frequency scaling
#CONFIG_CPU_FREQ=yCONFIG_CPU_FREQ_GOV_COMMON=yCONFIG_CPU_FREQ_STAT=mCONFIG_CPU_FREQ_STAT_DETAILS=y
#CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMANDis not setCONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE=yCONFIG_CPU_FREQ_GOV_PERFORMANCE=yCONFIG_CPU_FREQ_GOV_POWERSAVE=yCONFIG_CPU_FREQ_GOV_USERSPACE=yCONFIG_CPU_FREQ_GOV_ONDEMAND=yCONFIG_CPU_FREQ_GOV_CONSERVATIVE=yQuoted 1 line
Is there some other config option I have to set?
I have the same options. The difference is that my driver has a governor per policy. That's set with the
CPUFREQ_HAVE_GOVERNOR_PER_POLICYflag. If I remove that flag I can't trigger the lockdep splat anymore with this sequence and your patch.
Quoted 8 lines
Quoted 3 lines
I see -- so you're seeing this on arm then? If so, let me know so I can reserve one to work on :)
I only have ARM to test on. You can set this flag in your cpufreq driver if you have independently scaling CPU frequencies, so it isn't necessarily an ARM thing.
Sorry, forgot to mention this in the earlier email. But yeah, this is a totally SW feature. You should be able to enable this flag in your driver.
-Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Quoted 62 lines · Saravana Kannan
Quoted 61 lines · Stephen Boyd
Quoted 59 lines · Prarit Bhargava
Quoted 49 lines · Stephen Boyd
Quoted 48 lines · Prarit Bhargava
Quoted 6 lines · Stephen Boyd
Quoted 3 lines · Prarit Bhargava
Can you send me the test and the trace of the deadlock? I'm not creating it with:
This was with conservative as the default, and switching to ondemand
Quoted 13 lines
# cd /sys/devices/system/cpu/cpu2/cpufreq # ls affected_cpus scaling_available_governors conservative scaling_cur_freq cpuinfo_cur_freq scaling_driver cpuinfo_max_freq scaling_governor cpuinfo_min_freq scaling_max_freq cpuinfo_transition_latency scaling_min_freq related_cpus scaling_setspeed scaling_available_frequencies stats # cat conservative/down_threshold 20 # echo ondemand > scaling_governorThanks Stephen,
There's obviously a difference in our .configs. I have a global conservative directory, ie)
/sys/devices/system/cpu/cpufreq/conservativeinstead of a per-cpu
governor file.ie) what are your .config options for CPUFREQ?
Mine are:
#
# CPU Frequency scaling
#CONFIG_CPU_FREQ=yCONFIG_CPU_FREQ_GOV_COMMON=yCONFIG_CPU_FREQ_STAT=mCONFIG_CPU_FREQ_STAT_DETAILS=y
#CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMANDis not setCONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE=yCONFIG_CPU_FREQ_GOV_PERFORMANCE=yCONFIG_CPU_FREQ_GOV_POWERSAVE=yCONFIG_CPU_FREQ_GOV_USERSPACE=yCONFIG_CPU_FREQ_GOV_ONDEMAND=yCONFIG_CPU_FREQ_GOV_CONSERVATIVE=yQuoted 5 lines
Quoted 1 line
Is there some other config option I have to set?
I have the same options. The difference is that my driver has a governor per policy. That's set with the
CPUFREQ_HAVE_GOVERNOR_PER_POLICYflag. If I remove that flag I can't trigger the lockdep splat anymore with this sequence and your patch.I see -- so you're seeing this on arm then? If so, let me know so I can reserve one to work on :)
Quoted 7 lines
Quoted 4 lines
I only have ARM to test on. You can set this flag in your cpufreq driver if you have independently scaling CPU frequencies, so it isn't necessarily an ARM thing.
Sorry, forgot to mention this in the earlier email. But yeah, this is a totally SW feature. You should be able to enable this flag in your driver.
Thanks Saravana, I'll get back to this today. I'm also going to try to track down an ARM server as well.
I'll get back to everyone in a bit.
P.
Quoted 3 lines
-Saravana
Viresh Kumar
maintainerSorry for the delay guys, was away :(
Adding Robert as well, he reported something similar so better discuss here.
Quoted 91 lines · Stephen Boyd
This was with conservative as the default, and switching to ondemand
# cd /sys/devices/system/cpu/cpu2/cpufreq # ls affected_cpus scaling_available_governors conservative scaling_cur_freq cpuinfo_cur_freq scaling_driver cpuinfo_max_freq scaling_governor cpuinfo_min_freq scaling_max_freq cpuinfo_transition_latency scaling_min_freq related_cpus scaling_setspeed scaling_available_frequencies stats # cat conservative/down_threshold 20 # echo ondemand > scaling_governor======================================================
[ INFO: possible circular locking dependency detected ] 3.16.0-rc3-00039-ge1e38f124d87 #47 Not tainted
-------------------------------------------------------
sh/75 is trying to acquire lock:
(s_active#9){++++..}, at: [<c0358a94>]kernfs_remove_by_name_ns+0x3c/0x84but task is already holding lock:
(&policy->rwsem){+++++.}, at: [<c05ab1f0>]store+0x68/0xb8which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (&policy->rwsem){+++++.}:
[<c0359234>] kernfs_fop_open+0x138/0x298 [<c02fa3f4>] do_dentry_open.isra.12+0x1b0/0x2f0 [<c02fa604>] finish_open+0x20/0x38 [<c0308d34>] do_last.isra.37+0x5ac/0xb68 [<c03093a4>] path_openat+0xb4/0x5d8 [<c0309bcc>] do_filp_open+0x2c/0x80 [<c02fb558>] do_sys_open+0x10c/0x1c8 [<c020f0a0>] ret_fast_syscall+0x0/0x48-> #0 (s_active#9){++++..}:
[<c0357d18>] __kernfs_remove+0x250/0x300 [<c0358a94>] kernfs_remove_by_name_ns+0x3c/0x84 [<c035aa78>] remove_files+0x34/0x78 [<c035aee0>] sysfs_remove_group+0x40/0x98 [<c05b0560>] cpufreq_governor_dbs+0x4c0/0x6ec [<c05abebc>] __cpufreq_governor+0x118/0x200 [<c05ac0fc>] cpufreq_set_policy+0x158/0x2ac [<c05ad5e4>] store_scaling_governor+0x6c/0x94 [<c05ab210>] store+0x88/0xb8 [<c035a00c>] sysfs_kf_write+0x4c/0x50 [<c03594d4>] kernfs_fop_write+0xc0/0x180 [<c02fc5c8>] vfs_write+0xa0/0x1a8 [<c02fc9d4>] SyS_write+0x40/0x8c [<c020f0a0>] ret_fast_syscall+0x0/0x48other info that might help us debug this:
Possible unsafe locking scenario:CPU0 CPU1 ---- ---- lock(&policy->rwsem); lock(s_active#9); lock(&policy->rwsem);
lock(s_active#9);*** DEADLOCK ***
6 locks held by sh/75:
#0: (sb_writers#4){.+.+..}, at: [<c02fc6a8>] vfs_write+0x180/0x1a8 #1: (&of->mutex){+.+...}, at: [<c0359498>] kernfs_fop_write+0x84/0x180 #2: (s_active#10){.+.+..}, at: [<c03594a0>] kernfs_fop_write+0x8c/0x180 #3: (cpu_hotplug.lock){++++++}, at: [<c0221ef8>] get_online_cpus+0x38/0x9c #4: (cpufreq_rwsem){.+.+.+}, at: [<c05ab1d8>] store+0x50/0xb8 #5: (&policy->rwsem){+++++.}, at: [<c05ab1f0>] store+0x68/0xb8stack backtrace: CPU: 0 PID: 75 Comm: sh Not tainted 3.16.0-rc3-00039-ge1e38f124d87 #47 [<c0214de8>] (unwind_backtrace) from [<c02123f8>] (show_stack+0x10/0x14) [<c02123f8>] (show_stack) from [<c0709e5c>] (dump_stack+0x70/0xbc) [<c0709e5c>] (dump_stack) from [<c070722c>] (print_circular_bug+0x280/0x2d4) [<c070722c>] (print_circular_bug) from [<c02629cc>] (__lock_acquire+0x18d0/0x1abc) [<c02629cc>] (__lock_acquire) from [<c026310c>] (lock_acquire+0x9c/0x138) [<c026310c>] (lock_acquire) from [<c0357d18>] (__kernfs_remove+0x250/0x300) [<c0357d18>] (__kernfs_remove) from [<c0358a94>] (kernfs_remove_by_name_ns+0x3c/0x84) [<c0358a94>] (kernfs_remove_by_name_ns) from [<c035aa78>] (remove_files+0x34/0x78) [<c035aa78>] (remove_files) from [<c035aee0>] (sysfs_remove_group+0x40/0x98) [<c035aee0>] (sysfs_remove_group) from [<c05b0560>] (cpufreq_governor_dbs+0x4c0/0x6ec) [<c05b0560>] (cpufreq_governor_dbs) from [<c05abebc>] (__cpufreq_governor+0x118/0x200)
Quoted 8 lines
[<c05abebc>] (__cpufreq_governor) from [<c05ac0fc>] (cpufreq_set_policy+0x158/0x2ac) [<c05ac0fc>] (cpufreq_set_policy) from [<c05ad5e4>] (store_scaling_governor+0x6c/0x94) [<c05ad5e4>] (store_scaling_governor) from [<c05ab210>] (store+0x88/0xb8) [<c05ab210>] (store) from [<c035a00c>] (sysfs_kf_write+0x4c/0x50) [<c035a00c>] (sysfs_kf_write) from [<c03594d4>] (kernfs_fop_write+0xc0/0x180) [<c03594d4>] (kernfs_fop_write) from [<c02fc5c8>] (vfs_write+0xa0/0x1a8) [<c02fc5c8>] (vfs_write) from [<c02fc9d4>] (SyS_write+0x40/0x8c) [<c02fc9d4>] (SyS_write) from [<c020f0a0>] (ret_fast_syscall+0x0/0x48)
Thanks for coming to my rescue Stephen :), I was quite sure I got this with ondemand
as well..
I will be looking very closely at the code now to see what's going wrong. And btw, does anybody here has the exact understanding of why this lockdep does happen? I mean what was the real problem for which we just dropped the rwsems.. I understood that earlier but couldn't get that again :)
Thanks all for you work on getting this fixed.
--
viresh
Quoted 13 lines · Viresh Kumar
Sorry for the delay guys, was away :(
Quoted 10 lines
Possible unsafe locking scenario:CPU0 CPU1 ---- ---- lock(&policy->rwsem); lock(s_active#9); lock(&policy->rwsem);
lock(s_active#9);
Quoted 3 lines
Thanks for coming to my rescue Stephen :), I was quite sure I got this with ondemand
as well..
Yeah, I'm confused by it a bit because I wasn't able to reproduce it. But I've got some pretty clear instructions on how to do it.
Quoted 4 lines
I will be looking very closely at the code now to see what's going wrong. And btw, does anybody here has the exact understanding of why this lockdep does happen? I mean what was the real problem for which we
The issue is the collision between the setup & teardown of the policy's governor sysfs files.
On creation the kernel does:
down_write(&policy->rwsem)mutex_lock(kernfs_mutex) <- note this is similar to the "old" sysfs_mutex.
The opposite happens on a governor switch, specifically the existing governor's exit, and then we get a lockdep warning.
I tried to reproduce with the instructions but was unable to ... ut that was on Friday ;) and I'm going to try again this morning. I've also ping'd some of the engineers here in the office who are working on ARM to get access to a system to do further analysis and testing.
I'll ping back later in the day with some results.
Sorry I don't have a better answer or solution yet, Viresh.
P.
Viresh Kumar
maintainerQuoted 10 lines · Prarit Bhargava
The issue is the collision between the setup & teardown of the policy's governor sysfs files.
On creation the kernel does:
down_write(&policy->rwsem)mutex_lock(kernfs_mutex)<- note this is similar to the "old"sysfs_mutex.The opposite happens on a governor switch, specifically the existing governor's exit, and then we get a lockdep warning.
Okay, probably a bit more clarity is what I was looking for. Suppose we try to change governor, now tell me what will happen.
Quoted 4 lines
I tried to reproduce with the instructions but was unable to ... ut that was on Friday ;) and I'm going to try again this morning. I've also ping'd some of the engineers here in the office who are working on ARM to get access to a system to do further analysis and testing.
You DON'T need an ARM for that, just try that on any x86 machine which has multiple groups of CPUs sharing clock line. Or in other terms there are multiple policy structures there..
You just need to enable the flag we were discussing about, it just decided the location where governor's directory will get created. Nothing else.
Quoted 15 lines · Viresh Kumar
Quoted 10 lines · Prarit Bhargava
The issue is the collision between the setup & teardown of the policy's governor sysfs files.
On creation the kernel does:
down_write(&policy->rwsem)mutex_lock(kernfs_mutex)<- note this is similar to the "old"sysfs_mutex.The opposite happens on a governor switch, specifically the existing governor's exit, and then we get a lockdep warning.
Okay, probably a bit more clarity is what I was looking for. Suppose we try to change governor, now tell me what will happen.
Quoted 8 lines
Quoted 4 lines
I tried to reproduce with the instructions but was unable to ... ut that was on Friday ;) and I'm going to try again this morning. I've also ping'd some of the engineers here in the office who are working on ARM to get access to a system to do further analysis and testing.
You DON'T need an ARM for that, just try that on any x86 machine which has multiple groups of CPUs sharing clock line. Or in other terms there are multiple policy structures there..
I do ... I really think I do. Because this is all working on x86 AFAICT.
Quoted 4 lines
You just need to enable the flag we were discussing about, it just decided the location where governor's directory will get created. Nothing else.
That doesn't appear to be correct. I'm testing with the patch that removes the locking workaround and:
drivers/cpufreq/acpi-cpufreq.c +2 -0
@@ -884,6 +884,8 @@ static struct freq_attr *acpi_cpufreq_attr[] = { };static struct cpufreq_driver acpi_cpufreq_driver = { + .name ="acpi_cpufreq" , + .flags =CPUFREQ_HAVE_GOVERNOR_PER_POLICY , .verify = cpufreq_generic_frequency_table_verify, .target_index = acpi_cpufreq_target, .bios_limit = acpi_processor_get_bios_limit,
as well as few printk statement sprinkled in the code. I'm doing the following and on *15* different x86 systems I do not see a problem:
My cpufreq related config is
#
# CPU Frequency scaling
#CONFIG_CPU_FREQ=y CONFIG_CPU_FREQ_GOV_COMMON=y CONFIG_CPU_FREQ_STAT=m CONFIG_CPU_FREQ_STAT_DETAILS=y
# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set # CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set # CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE=y CONFIG_CPU_FREQ_GOV_PERFORMANCE=y CONFIG_CPU_FREQ_GOV_POWERSAVE=y CONFIG_CPU_FREQ_GOV_USERSPACE=y CONFIG_CPU_FREQ_GOV_ONDEMAND=y CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
I am doing (from boot)
[root@intel-canoepass-05 cpufreq]# cd /sys/devices/system/cpu/cpu2/cpufreq/ [root@intel-canoepass-05 cpufreq]# ls
affected_cpus cpuinfo_transition_latency scaling_driver bios_limit freqdomain_cpus scaling_governor conservative related_cpus scaling_max_freq cpuinfo_cur_freq scaling_available_frequencies scaling_min_freq cpuinfo_max_freq scaling_available_governors scaling_setspeed cpuinfo_min_freq scaling_cur_freq [root@intel-canoepass-05 cpufreq]# cat conservative/ down_threshold sampling_down_factor up_threshold freq_step sampling_rate ignore_nice_load sampling_rate_min
[root@intel-canoepass-05 cpufreq]# cat conservative/down_threshold 20
[root@intel-canoepass-05 cpufreq]# echo ondemand > scaling_governor [root@intel-canoepass-05 cpufreq]# cat ondemand/up_threshold 95
[root@intel-canoepass-05 cpufreq]# echo conservative > scaling_governor [root@intel-canoepass-05 cpufreq]#
without any issue. My dmesg (with the printk's) shows
[ 55.331058] cpufreq_set_policy: stopping governor conservative [ 55.337652] cpufreq_governor_dbs: removing sysfs files for governor conservative [ 55.346028] cpufreq_set_policy: starting governor ondemand [ 55.352167] cpufreq_governor_dbs: creating sysfs files for governor ondemand [ 76.818989] cpufreq_set_policy: stopping governor ondemand [ 76.825202] cpufreq_governor_dbs: removing sysfs files for governor ondemand [ 76.833131] cpufreq_set_policy: starting governor conservative [ 76.839667] cpufreq_governor_dbs: creating sysfs files for governor conservative
There is an already reported LOCKDEP warning in the xfs code that fires at login so I know LOCKDEP is functional.
Stephen's report as well as the lockup report implies that I should open a file,
-> #1 (&policy->rwsem){+++++.}:
[<c0359234>] kernfs_fop_open+0x138/0x298
[<c02fa3f4>] do_dentry_open.isra.12+0x1b0/0x2f0
[<c02fa604>] finish_open+0x20/0x38
[<c0308d34>] do_last.isra.37+0x5ac/0xb68
[<c03093a4>] path_openat+0xb4/0x5d8
[<c0309bcc>] do_filp_open+0x2c/0x80
[<c02fb558>] do_sys_open+0x10c/0x1c8
[<c020f0a0>] ret_fast_syscall+0x0/0x48and then switch the governor ...
-> #0 (s_active#9){++++..}:
[<c0357d18>] __kernfs_remove+0x250/0x300
[<c0358a94>] kernfs_remove_by_name_ns+0x3c/0x84
[<c035aa78>] remove_files+0x34/0x78
[<c035aee0>] sysfs_remove_group+0x40/0x98
[<c05b0560>] cpufreq_governor_dbs+0x4c0/0x6ec
[<c05abebc>] __cpufreq_governor+0x118/0x200
[<c05ac0fc>] cpufreq_set_policy+0x158/0x2ac
[<c05ad5e4>] store_scaling_governor+0x6c/0x94
[<c05ab210>] store+0x88/0xb8
[<c035a00c>] sysfs_kf_write+0x4c/0x50
[<c03594d4>] kernfs_fop_write+0xc0/0x180
[<c02fc5c8>] vfs_write+0xa0/0x1a8
[<c02fc9d4>] SyS_write+0x40/0x8c
[<c020f0a0>] ret_fast_syscall+0x0/0x48... right?
P.
Quoted 3 lines · Prarit Bhargava
There is an already reported LOCKDEP warning in the xfs code that fires at login so I know LOCKDEP is functional.
It turns out that the above was the problem. I didn't realize that LOCKDEP will only report a single warning :(
[Aside: Is there a way to "re-arm" LOCKDEP?]
Reproduced on x86 and taking a further look:
[root@intel-canoepass-05 ~]# cd /sys/devices/system/cpu/cpu2/cpufreq/ [root@intel-canoepass-05 cpufreq]# cat conservative/*
20
5
0
1
20000
20000
80
[root@intel-canoepass-05 cpufreq]# echo ondemand > scaling_governor
[ 75.163583] cpufreq_set_policy: stopping governor conservative
[ 75.170348] cpufreq_governor_dbs: removing sysfs files for governor conservative
[ 75.178698]
[ 75.180364] ======================================================
[ 75.187271] [ INFO: possible circular locking dependency detected ]
[ 75.194278] 3.16.0-rc7+ #22 Not tainted
[ 75.198561] -------------------------------------------------------
[ 75.205564] bash/3131 is trying to acquire lock:
[ 75.210726] (s_active#219){++++.+}, at: [<ffffffff8126ce55>]
kernfs_remove_by_name_ns+0x45/0xa0
[ 75.220623]
[ 75.220623] but task is already holding lock:
[ 75.227141] (&policy->rwsem){+++++.}, at: [<ffffffff814ecab0>] store+0x60/0xc0
[ 75.235370]
[ 75.235370] which lock already depends on the new lock.
[ 75.235370]
[ 75.244509]
[ 75.244509] the existing dependency chain (in reverse order) is:
[ 75.252874]
-> #1 (&policy->rwsem){+++++.}:
[ 75.257785] [<ffffffff810cc892>] lock_acquire+0xa2/0x120
[ 75.264429] [<ffffffff8166ed40>] mutex_lock_nested+0x60/0x4d0
[ 75.271558] [<ffffffff8126de2e>] kernfs_fop_open+0x16e/0x340
[ 75.278579] [<ffffffff811efaef>] do_dentry_open+0x1ff/0x350
[ 75.285510] [<ffffffff811efe11>] finish_open+0x31/0x40
[ 75.291948] [<ffffffff81202e26>] do_last+0xc16/0x1350
[ 75.298298] [<ffffffff8120362d>] path_openat+0xcd/0x640
[ 75.304821] [<ffffffff8120442d>] do_filp_open+0x4d/0xb0
[ 75.311353] [<ffffffff811f18a7>] do_sys_open+0x137/0x240
[ 75.317989] [<ffffffff811f19ce>] SyS_open+0x1e/0x20
[ 75.324122] [<ffffffff81672ca9>] system_call_fastpath+0x16/0x1b
[ 75.331437]
-> #0 (s_active#219){++++.+}:
[ 75.336174] [<ffffffff810cba76>] __lock_acquire+0x14e6/0x1b40
[ 75.343293] [<ffffffff810cc892>] lock_acquire+0xa2/0x120
[ 75.349923] [<ffffffff8126bc48>] __kernfs_remove+0x248/0x330
[ 75.356950] [<ffffffff8126ce55>] kernfs_remove_by_name_ns+0x45/0xa0
[ 75.364638] [<ffffffff8126f739>] remove_files.isra.1+0x39/0x70
[ 75.371850] [<ffffffff8126fa44>] sysfs_remove_group+0x44/0xa0
[ 75.378965] [<ffffffff814f280a>] cpufreq_governor_dbs+0x6da/0x770
[ 75.386478] [<ffffffff814f1277>] cs_cpufreq_governor_dbs+0x17/0x20
[ 75.394088] [<ffffffff814ed1bd>] __cpufreq_governor+0x11d/0x230
[ 75.401395] [<ffffffff814ed435>] cpufreq_set_policy+0x165/0x2c0
[ 75.408706] [<ffffffff814ee16d>] store_scaling_governor+0xad/0xf0
[ 75.416211] [<ffffffff814ecacc>] store+0x7c/0xc0
[ 75.422062] [<ffffffff8126e7e4>] sysfs_kf_write+0x44/0x60
[ 75.428790] [<ffffffff8126e0e7>] kernfs_fop_write+0xe7/0x170
[ 75.435806] [<ffffffff811f2857>] vfs_write+0xb7/0x1f0
[ 75.442146] [<ffffffff811f3488>] SyS_write+0x58/0xd0
[ 75.448390] [<ffffffff81672ca9>] system_call_fastpath+0x16/0x1b
[ 75.455706]
[ 75.455706] other info that might help us debug this:
[ 75.455706]
[ 75.464649] Possible unsafe locking scenario:
[ 75.464649]
[ 75.471265] CPU0 CPU1
[ 75.476327] ---- ----
[ 75.481385] lock(&policy->rwsem);
[ 75.485307] lock(s_active#219);
[ 75.491857] lock(&policy->rwsem);
[ 75.498592] lock(s_active#219);
[ 75.502331]
[ 75.502331] *** DEADLOCK ***
[ 75.502331]
[ 75.508948] 6 locks held by bash/3131:
[ 75.513136] #0: (sb_writers#3){.+.+.+}, at: [<ffffffff811f2953>]
vfs_write+0x1b3/0x1f0
[ 75.522259] #1: (&of->mutex){+.+.+.}, at: [<ffffffff8126e0bb>]
kernfs_fop_write+0xbb/0x170
[ 75.531751] #2: (s_active#221){.+.+.+}, at: [<ffffffff8126e0c3>]
kernfs_fop_write+0xc3/0x170
[ 75.541448] #3: (cpu_hotplug.lock){++++++}, at: [<ffffffff810752d4>]
get_online_cpus+0x24/0x70
[ 75.551339] #4: (cpufreq_rwsem){.+.+.+}, at: [<ffffffff814eca96>]
store+0x46/0xc0
[ 75.559957] #5: (&policy->rwsem){+++++.}, at: [<ffffffff814ecab0>]
store+0x60/0xc0
[ 75.568671]
[ 75.568671] stack backtrace:
[ 75.573544] CPU: 14 PID: 3131 Comm: bash Not tainted 3.16.0-rc7+ #22
[ 75.580647] Hardware name: Intel Corporation S2600CP/S2600CP, BIOS
RMLSDP.86I.R2.21.D636.1301031557 01/03/2013
[ 75.591824] 0000000000000000 000000000264b511 ffff881001837868 ffffffff816696a7
[ 75.600137] ffffffff8254dd40 ffff8810018378a8 ffffffff81662be3 ffff881001837900
[ 75.608451] ffff88100a6fba68 0000000000000005 ffff88100a6fba68 ffff88100a6fadc0
[ 75.616764] Call Trace:
[ 75.619505] [<ffffffff816696a7>] dump_stack+0x45/0x56
[ 75.625253] [<ffffffff81662be3>] print_circular_bug+0x1f9/0x207
[ 75.631966] [<ffffffff810cba76>] __lock_acquire+0x14e6/0x1b40
[ 75.638478] [<ffffffff810cb284>] ? __lock_acquire+0xcf4/0x1b40
[ 75.645095] [<ffffffff810c9f7a>] ? mark_held_locks+0x6a/0x90
[ 75.651522] [<ffffffff810cc892>] lock_acquire+0xa2/0x120
[ 75.657557] [<ffffffff8126ce55>] ? kernfs_remove_by_name_ns+0x45/0xa0
[ 75.664854] [<ffffffff8126bc48>] __kernfs_remove+0x248/0x330
[ 75.671279] [<ffffffff8126ce55>] ? kernfs_remove_by_name_ns+0x45/0xa0
[ 75.678577] [<ffffffff8126b117>] ? kernfs_name_hash+0x17/0xd0
[ 75.685097] [<ffffffff8126bdec>] ? kernfs_find_ns+0xbc/0x160
[ 75.691523] [<ffffffff8126ce55>] kernfs_remove_by_name_ns+0x45/0xa0
[ 75.698627] [<ffffffff8126f739>] remove_files.isra.1+0x39/0x70
[ 75.705242] [<ffffffff8126fa44>] sysfs_remove_group+0x44/0xa0
[ 75.711753] [<ffffffff814f280a>] cpufreq_governor_dbs+0x6da/0x770
[ 75.718661] [<ffffffff810ca0a5>] ? trace_hardirqs_on_caller+0x105/0x1d0
[ 75.726152] [<ffffffff810ca17d>] ? trace_hardirqs_on+0xd/0x10
[ 75.732672] [<ffffffff814f1277>] cs_cpufreq_governor_dbs+0x17/0x20
[ 75.739675] [<ffffffff814ed1bd>] __cpufreq_governor+0x11d/0x230
[ 75.746387] [<ffffffff814ed435>] cpufreq_set_policy+0x165/0x2c0
[ 75.753099] [<ffffffff814ee16d>] store_scaling_governor+0xad/0xf0
[ 75.760007] [<ffffffff814ed780>] ? cpufreq_update_policy+0x1f0/0x1f0
[ 75.767207] [<ffffffff814ecacc>] store+0x7c/0xc0
[ 75.772464] [<ffffffff8126e7e4>] sysfs_kf_write+0x44/0x60
[ 75.778586] [<ffffffff8126e0e7>] kernfs_fop_write+0xe7/0x170
[ 75.785000] [<ffffffff811f2857>] vfs_write+0xb7/0x1f0
[ 75.790741] [<ffffffff811f3488>] SyS_write+0x58/0xd0
[ 75.796386] [<ffffffff81672ca9>] system_call_fastpath+0x16/0x1b
[ 75.803172] cpufreq_set_policy: starting governor ondemand
[ 75.809341] cpufreq_governor_dbs: creating sysfs files for governor ondemandP.
Quoted 6 lines · Viresh Kumar
Quoted 5 lines · Prarit Bhargava
The issue is the collision between the setup & teardown of the policy's governor sysfs files.
On creation the kernel does:
Quoted 9 lines
Quoted 5 lines
down_write(&policy->rwsem)mutex_lock(kernfs_mutex)<- note this is similar to the "old"sysfs_mutex.The opposite happens on a governor switch, specifically the existing governor's exit, and then we get a lockdep warning.
Okay, probably a bit more clarity is what I was looking for. Suppose we try to change governor, now tell me what will happen.
Viresh, I have a good understanding of what's going on. I was planning to fix this after the rest of my patches are done. Didn't want to keep too many outstanding unaccepted patches.
The problem is when between one thread trying to cat a governor's file (say, sampling_rate) vs the governor getting a POLICY_EXIT.
In the read thread, the sysfs lock is grabbed first and then the policy lock is grabbed next. When the governor gets the POLICY_EXIT, we call it with the policy lock held and the governor tries to do sysfs remove which tries to grab the sysfs lock. Classic deadlock.
Could you please look at my policy free/remove patches? If you can do that, I can work on a fix for this. It might also be simpler to fix after my patch series (not sure, might be).
Thanks,
Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Viresh Kumar
maintainerQuoted 2 lines · Saravana Kannan
The problem is when between one thread trying to cat a governor's file (say,
sampling_rate) vs the governor getting aPOLICY_EXIT.
I don't see two threads racing against each other here. Simply changing the governor from conservative->ondemand creates this.
Or is it that the kernel is detecting two different orders of taking lock?
But during governor change, isn't the sysfs lock taken first as we are storing a value to "scaling_governor"? So, isn't this a sysfs lock first in all cases?
In short, I am still unclear about the *exact* problem here.
Quoted 3 lines
Could you please look at my policy free/remove patches? If you can do that, I can work on a fix for this. It might also be simpler to fix after my patch series (not sure, might be).
I had an overall look of those on the day you posted them, but haven't commented yet as was going away..
There is no way those can land in 3.17-rc1 atleast and so we still have some time to get them pushed..
Anyway, they are my number two priority and the number one is this bug, which we have to fix in stable kernels as well. So, a dependency on your series wouldn't work..
Let me see if I can get some solution to this problem first.
Quoted 25 lines · Viresh Kumar
Quoted 3 lines · Saravana Kannan
The problem is when between one thread trying to cat a governor's file (say,
sampling_rate) vs the governor getting aPOLICY_EXIT.I don't see two threads racing against each other here. Simply changing the governor from
conservative->ondemandcreates this.Or is it that the kernel is detecting two different orders of taking lock?
But during governor change, isn't the sysfs lock taken first as we are storing a value to "
scaling_governor"? So, isn't this a sysfs lock first in all cases?In short, I am still unclear about the *exact* problem here.
Quoted 5 lines
Could you please look at my policy free/remove patches? If you can do that,
I can work on a fix for this. It might also be simpler to fix after my patch
series (not sure, might be).I had an overall look of those on the day you posted them, but haven't commented yet as was going away..
Quoted 6 lines
There is no way those can land in 3.17-rc1 atleast and so we still have some time to get them pushed..
Anyway, they are my number two priority and the number one is this bug, which we have to fix in stable kernels as well. So, a dependency on your series wouldn't work..
Sigh... ok. I too will try to fix this one. I already have something in mind for this.
Looks like Srivatsa has gone off the grid too. I'm hoping at least one of you can do a review of my series. Come on guys, not everyone has to work on the same patch/issue. :-(
-Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Viresh Kumar
maintainerQuoted 3 lines · On 5 August 2014 11:59, <[email protected]> wrote:
Looks like Srivatsa has gone off the grid too. I'm hoping at least one of you can do a review of my series. Come on guys, not everyone has to work on the same patch/issue. :-(
Srivatsa is currently going through some personal stuff. He is joining MIT for his Masters/Phd and so would be moving to US soon :)
Viresh Kumar
maintainerQuoted 2 lines · Stephen Boyd
I have the same options. The difference is that my driver has a governor per policy. That's set with the
CPUFREQ_HAVE_GOVERNOR_PER_POLICYflag.
You may call me stupid but I got a bit confused after looking into the code again. Why does the crash dump depends on this flag?
We *always* remove the governor specific directory while switching governors (Ofcourse only if its updated for All CPUs). And so on a dual core platform, where both CPU 0 & 1 share a clock line, switching of governors should result in this crash dump?
I may know the answer to the stupid question I had, but not sure why that is a problem. The only (and quite significant) difference that this flag makes is the location of governor-specific directory:
- w/o this flag: /sys/devices/system/cpu/cpufreq/<here>
- w/ this flag: /sys/devices/system/cpu/cpu*/cpufreq/<here>
So, is there some issue with the sysfs lock for <cpu*/cpufreq/> node as while switching governor we change <cpu*/cpufreq/scaling_governor> at the same location?
--
viresh
--
viresh
Quoted 6 lines · Viresh Kumar
Quoted 2 lines · Stephen Boyd
I have the same options. The difference is that my driver has a governor per policy. That's set with the
CPUFREQ_HAVE_GOVERNOR_PER_POLICYflag.You may call me stupid but I got a bit confused after looking into the code again. Why does the crash dump depends on this flag?
Nope, not a stupid question. After reproducing (finally!) yesterday I've been wondering the same thing.
Quoted 5 lines
We *always* remove the governor specific directory while switching governors (Ofcourse only if its updated for All CPUs). And so on a dual core platform, where both CPU 0 & 1 share a clock line, switching of governors should result in this crash dump?
I've been looking into *exactly* this. On any platform where cpu_weight(affected_cpus) == 1 for a particular cpu this lockdep trace should happen.
Quoted 7 lines
I may know the answer to the stupid question I had, but not sure why that is a problem. The only (and quite significant) difference that this flag makes is the location of governor-specific directory:
- w/o this flag: /sys/devices/system/cpu/cpufreq/<here>
- w/ this flag: /sys/devices/system/cpu/cpu*/cpufreq/<here>
cpufreq_global_kobject vs the policy's kobject.
Quoted 3 lines
So, is there some issue with the sysfs lock for <cpu*/cpufreq/> node as while switching governor we change <cpu*/cpufreq/scaling_governor> at the same location?
That's what I'm wondering too. I'm going to instrument the code to find out this morning. I'm wondering if this comes down to a lockdep class issue (perhaps lockdep puts globally defined locks like cpufreq_global_kobject in a different class?).
P.
Viresh Kumar
maintainerQuoted 2 lines · Prarit Bhargava
Nope, not a stupid question. After reproducing (finally!) yesterday I've been wondering the same thing.
Good to know that :)
Quoted 8 lines
I've been looking into *exactly* this. On any platform where
cpu_weight(affected_cpus)== 1 for a particular cpu this lockdep trace should happen.That's what I'm wondering too. I'm going to instrument the code to find out this morning. I'm wondering if this comes down to a lockdep class issue (perhaps lockdep puts globally defined locks like
cpufreq_global_kobjectin a different class?).
Maybe, I tried this Hack to make this somewhat similar to the other case on my platform with just two CPUs:
drivers/cpufreq/cpufreq.c +1 -1
@@ -98,7 +98,7 @@ static DEFINE_MUTEX(cpufreq_governor_mutex);bool have_governor_per_policy (void ) { -return !!(cpufreq_driver->flags &CPUFREQ_HAVE_GOVERNOR_PER_POLICY ); +return !(cpufreq_driver->flags &CPUFREQ_HAVE_GOVERNOR_PER_POLICY ); }EXPORT_SYMBOL_GPL (have_governor_per_policy);
This should result in something similar to setting that per-policy-governor flag (Actually I could have done that too :)), and I couldn't see that crash :(
That needs more investigation now, probably we can get some champ of sysfs stuff like Tejun/Greg into discussion now..
--
viresh
Quoted 32 lines · Viresh Kumar
Quoted 2 lines · Prarit Bhargava
Nope, not a stupid question. After reproducing (finally!) yesterday I've been wondering the same thing.
Good to know that :)
Quoted 8 lines
I've been looking into *exactly* this. On any platform where
cpu_weight(affected_cpus)== 1 for a particular cpu this lockdep trace should happen.That's what I'm wondering too. I'm going to instrument the code to find out this morning. I'm wondering if this comes down to a lockdep class issue (perhaps lockdep puts globally defined locks like
cpufreq_global_kobjectin a different class?).Maybe, I tried this Hack to make this somewhat similar to the other case on my platform with just two CPUs:
drivers/cpufreq/cpufreq.c +1
-1@@ -98,7 +98,7 @@ static DEFINE_MUTEX(cpufreq_governor_mutex);bool have_governor_per_policy (void ) { -return !!(cpufreq_driver->flags &CPUFREQ_HAVE_GOVERNOR_PER_POLICY ); +return !(cpufreq_driver->flags &CPUFREQ_HAVE_GOVERNOR_PER_POLICY ); }EXPORT_SYMBOL_GPL (have_governor_per_policy);
Quoted 5 lines
This should result in something similar to setting that per-policy-governor flag (Actually I could have done that too :)), and I couldn't see that crash :(
That needs more investigation now, probably we can get some champ of sysfs stuff like Tejun/Greg into discussion now..
Stephen and I looked into this. This is not a sysfs framework difference. The reason we don't have this issue when we use global tunables is because we add the attribute group to the cpufreq_global_kobject and that kobject doesn't have a kobj_type ops similar to the per policy kobject. So, read/write to those attributes do NOT go through the generic show/store ops that wrap every other cpufreq framework attribute read/writes.
So, none of those read/write do any kind of locking. They don't race with POLICY_EXIT (because we remove the sysfs group first thing in POLICY_EXIT) but might still race with START/STOPs (not sure, haven't looked closely yet).
For example, writing to sampling_rate of ondemand governor might cause a race in update_sampling_rate(). It could race and happen between a STOP and POLICY_EXIT (triggered by hotplug, gov change, etc).
So, this might be a completely separate bug that needs fixing when we don't use per policy govs.
-Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Quoted 50 lines · Saravana Kannan
Quoted 32 lines · Viresh Kumar
Quoted 2 lines · Prarit Bhargava
Nope, not a stupid question. After reproducing (finally!) yesterday I've been wondering the same thing.
Good to know that :)
Quoted 8 lines
I've been looking into *exactly* this. On any platform where
cpu_weight(affected_cpus)== 1 for a particular cpu this lockdep trace should happen.That's what I'm wondering too. I'm going to instrument the code to find out this morning. I'm wondering if this comes down to a lockdep class issue (perhaps lockdep puts globally defined locks like
cpufreq_global_kobjectin a different class?).Maybe, I tried this Hack to make this somewhat similar to the other case on my platform with just two CPUs:
drivers/cpufreq/cpufreq.c +1
-1@@ -98,7 +98,7 @@ static DEFINE_MUTEX(cpufreq_governor_mutex);bool have_governor_per_policy (void ) { -return !!(cpufreq_driver->flags &CPUFREQ_HAVE_GOVERNOR_PER_POLICY ); +return !(cpufreq_driver->flags &CPUFREQ_HAVE_GOVERNOR_PER_POLICY ); }EXPORT_SYMBOL_GPL (have_governor_per_policy);Quoted 5 lines
This should result in something similar to setting that per-policy-governor flag (Actually I could have done that too :)), and I couldn't see that crash :(
That needs more investigation now, probably we can get some champ of sysfs stuff like Tejun/Greg into discussion now..
Stephen and I looked into this. This is not a sysfs framework difference. The reason we don't have this issue when we use global tunables is because we add the attribute group to the
cpufreq_global_kobjectand that kobject doesn't have akobj_typeops similar to the per policy kobject. So, read/write to those attributes do NOT go through the generic show/store ops that wrap every other cpufreq framework attribute read/writes.So, none of those read/write do any kind of locking. They don't race with
POLICY_EXIT(because we remove the sysfs group first thing inPOLICY_EXIT) but might still race with START/STOPs (not sure, haven't looked closely yet).
Quoted 6 lines
For example, writing to
sampling_rateof ondemand governor might cause a race inupdate_sampling_rate(). It could race and happen between a STOP andPOLICY_EXIT(triggered by hotplug, gov change, etc).So, this might be a completely separate bug that needs fixing when we don't use per policy govs.
Yeah, the show_one & store_one macros don't have any locking in them :/.
Okay ... at least that isn't the issue. I spent 1/2 the day trying to figure out why
drivers/cpufreq/cpufreq.c +2 -0
@@ -745,12 +745,14 @@ static struct attribute *default_attrs[] = {#define to_policy (k) container_of(k, struct cpufreq_policy, kobj)#define to_attr (a) container_of(a, struct freq_attr, attr) +/* PRARIT - in the CPUFREQ_HAVE_GOVERNOR_PER_POLICY, this is used */ static ssize_t show (struct kobject *kobj,struct attribute *attr,char *buf) {struct cpufreq_policy *policy =to_policy (kobj);struct freq_attr *fattr =to_attr (attr);ssize_t ret; +printk ("%s: kobject %p\n" , __FUNCTION__, kobj);if (!down_read_trylock (&cpufreq_rwsem))return -EINVAL ;
wasn't printing the kobject line when acpi-cpufreq didn't have the CPUFREQ_HAVE_GOVERNOR_PER_POLICY flag. And I agree ... it is a bug.
P.
Quoted 84 lines · Prarit Bhargava
Quoted 50 lines · Saravana Kannan
Quoted 32 lines · Viresh Kumar
Quoted 2 lines · Prarit Bhargava
Nope, not a stupid question. After reproducing (finally!) yesterday I've been wondering the same thing.
Good to know that :)
Quoted 8 lines
I've been looking into *exactly* this. On any platform where
cpu_weight(affected_cpus)== 1 for a particular cpu this lockdep trace should happen.That's what I'm wondering too. I'm going to instrument the code to find out this morning. I'm wondering if this comes down to a lockdep class issue (perhaps lockdep puts globally defined locks like
cpufreq_global_kobjectin a different class?).Maybe, I tried this Hack to make this somewhat similar to the other case on my platform with just two CPUs:
drivers/cpufreq/cpufreq.c +1
-1@@ -98,7 +98,7 @@ static DEFINE_MUTEX(cpufreq_governor_mutex);bool have_governor_per_policy (void ) { -return !!(cpufreq_driver->flags &CPUFREQ_HAVE_GOVERNOR_PER_POLICY ); +return !(cpufreq_driver->flags &CPUFREQ_HAVE_GOVERNOR_PER_POLICY ); }EXPORT_SYMBOL_GPL (have_governor_per_policy);Quoted 5 lines
This should result in something similar to setting that per-policy-governor flag (Actually I could have done that too :)), and I couldn't see that crash :(
That needs more investigation now, probably we can get some champ of sysfs stuff like Tejun/Greg into discussion now..
Stephen and I looked into this. This is not a sysfs framework difference. The reason we don't have this issue when we use global tunables is because we add the attribute group to the
cpufreq_global_kobjectand that kobject doesn't have akobj_typeops similar to the per policy kobject. So, read/write to those attributes do NOT go through the generic show/store ops that wrap every other cpufreq framework attribute read/writes.So, none of those read/write do any kind of locking. They don't race with
POLICY_EXIT(because we remove the sysfs group first thing inPOLICY_EXIT) but might still race with START/STOPs (not sure, haven't looked closely yet).Quoted 6 lines
For example, writing to
sampling_rateof ondemand governor might cause a race inupdate_sampling_rate(). It could race and happen between a STOP andPOLICY_EXIT(triggered by hotplug, gov change, etc).So, this might be a completely separate bug that needs fixing when we don't use per policy govs.
Yeah, the
show_one&store_onemacros don't have any locking in them :/.Okay ... at least that isn't the issue. I spent 1/2 the day trying to figure out why
drivers/cpufreq/cpufreq.c +2
-0@@ -745,12 +745,14 @@ static struct attribute *default_attrs[] = {#define to_policy (k) container_of(k, struct cpufreq_policy, kobj)#define to_attr (a) container_of(a, struct freq_attr, attr) +/* PRARIT - in the CPUFREQ_HAVE_GOVERNOR_PER_POLICY, this is used */ static ssize_t show (struct kobject *kobj,struct attribute *attr,char *buf) {struct cpufreq_policy *policy =to_policy (kobj);struct freq_attr *fattr =to_attr (attr);ssize_t ret; +printk ("%s: kobject %p\n" , __FUNCTION__, kobj);if (!down_read_trylock (&cpufreq_rwsem))return -EINVAL ;
Quoted 3 lines
wasn't printing the kobject line when acpi-cpufreq didn't have the
CPUFREQ_HAVE_GOVERNOR_PER_POLICYflag. And I agree ... it is a bug.
Wait, should I stop reporting bugs so that my patch series gets reviewed? :P
-Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
So back to the original problem, which in short, revolves around these two functions (with comments included by me):
/* called with kernfs rwsem for this kobj held */
static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
{
struct cpufreq_policy *policy = to_policy(kobj);
struct freq_attr *fattr = to_attr(attr);
ssize_t ret;
if (!down_read_trylock(&cpufreq_rwsem))
return -EINVAL;
down_read(&policy->rwsem);and
static ssize_t store(struct kobject *kobj, struct attribute *attr,
const char *buf, size_t count)
{
struct cpufreq_policy *policy = to_policy(kobj);
struct freq_attr *fattr = to_attr(attr);
ssize_t ret = -EINVAL;
get_online_cpus();
if (!cpu_online(policy->cpu))
goto unlock;
if (!down_read_trylock(&cpufreq_rwsem))
goto unlock;
down_write(&policy->rwsem);
/* if governor switch, calls sysfs_remove_group
* and acquires kernfs rwsem for this kobj */There's another bug here which I haven't had a chance to discuss. There's the possibility that we have multiple threads waiting at the store's down_write(&policy->rwsem) when another thread does a governor switch. When the policy->rwsem is released by the governor switch thread, all the other threads will enter this code path and race through while looking at stale data.
We hit some NULL pointers (very similar to the ones originally reported in this thread) and, of course, the system dies.
I wonder if the show() down_read(&policy->rwsem) needs to be a down_read_trylock(), and similarily in the store the down_write(&policy->rwsem) needs to be a down_write_trylock() ?
We would also have to do a check on policy->governor_enabled to verify that the data was still valid after taking the lock.
*If* we were to make this change, does that also happen to fix the risk of a deadlock in this code?
That might be too hacky ... gotta be a better way :/ ...
Anyway, just a thought.
P.
Quoted 44 lines · Prarit Bhargava
So back to the original problem, which in short, revolves around these two functions (with comments included by me):
/* called with kernfs rwsem for this kobj held */
staticssize_tshow(struct kobject *kobj, struct attribute *attr, char *buf){ struct cpufreq_policy *policy = to_policy(kobj); struct freq_attr *fattr = to_attr(attr); ssize_t ret; if (!down_read_trylock(&cpufreq_rwsem)) return -EINVAL; down_read(&policy->rwsem);and
static
ssize_tstore(struct kobject *kobj, struct attribute *attr,
const char *buf,size_tcount){ struct cpufreq_policy *policy = to_policy(kobj); struct freq_attr *fattr = to_attr(attr); ssize_t ret = -EINVAL; get_online_cpus(); if (!cpu_online(policy->cpu)) goto unlock; if (!down_read_trylock(&cpufreq_rwsem)) goto unlock; down_write(&policy->rwsem); /* if governor switch, calls sysfs_remove_group * and acquires kernfs rwsem for this kobj */There's another bug here which I haven't had a chance to discuss. There's the possibility that we have multiple threads waiting at the store's
down_write(&policy->rwsem)when another thread does a governor switch. When thepolicy->rwsemis released by the governor switch thread, all the other threads will enter this code path and race through while looking at stale data.
Quoted 6 lines
We hit some NULL pointers (very similar to the ones originally reported in this thread) and, of course, the system dies.
I wonder if the
show()down_read(&policy->rwsem)needs to be adown_read_trylock(), and similarily in the store thedown_write(&policy->rwsem)needs to be adown_write_trylock()?
This will create bigger issues if you make this change to the generic show/store. The writes would no longer be reliable even if the race could have been handled properly in the kernel (say, a race between a call to cpufreq_update_policy() and user space reading/writing something). This would be a serious userspace ABI change.
Quoted 5 lines
We would also have to do a check on
policy->governor_enabledto verify that the data was still valid after taking the lock.*If* we were to make this change, does that also happen to fix the risk of a deadlock in this code?
We should not do the change you are referring to.
Quoted 5 lines
That might be too hacky ... gotta be a better way :/ ...
Anyway, just a thought.
I definitely have a fix for this and the original race you reported. It's basically reverting that commit you reverted + a fix for the deadlock. That's the only way to fix the scaling_governor issue.
You fix the deadlock by moving the governor attribute group removing to the framework code and doing it before STOP+EXIT to governor without holding the policy lock. And the reverse for INIT+STOP.
I'll try to get to it if no one else does.
-Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Viresh Kumar
maintainerQuoted 7 lines · Saravana Kannan
Stephen and I looked into this. This is not a sysfs framework difference. The reason we don't have this issue when we use global tunables is because we add the attribute group to the
cpufreq_global_kobjectand that kobject doesn't have akobj_typeops similar to the per policy kobject. So, read/write to those attributes do NOT go through the generic show/store ops that wrap every other cpufreq framework attribute read/writes.
Quoted 8 lines
So, none of those read/write do any kind of locking. They don't race with
POLICY_EXIT(because we remove the sysfs group first thing inPOLICY_EXIT) but might still race with START/STOPs (not sure, haven't looked closely yet).For example, writing to
sampling_rateof ondemand governor might cause a race inupdate_sampling_rate(). It could race and happen between a STOP andPOLICY_EXIT(triggered by hotplug, gov change, etc).
This sounds good but I couldn't prove it. Doing this on my dual core exynos doesn't give me that crash report and it should?
drivers/cpufreq/exynos-cpufreq.c +0 -0
@@ -139,7 +139,7 @@ static int exynos_cpufreq_cpu_init(struct
cpufreq_policy *policy)
}
static struct cpufreq_driver exynos_driver = {
- .flags = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK,
+ .flags = CPUFREQ_STICKY |
CPUFREQ_NEED_INITIAL_FREQ_CHECK | CPUFREQ_HAVE_GOVERNOR_PER_POLICY,
.verify = cpufreq_generic_frequency_table_verify,
.target_index = exynos_target,
.get = cpufreq_generic_get,Quoted 13 lines · Viresh Kumar
Quoted 12 lines · Saravana Kannan
Stephen and I looked into this. This is not a sysfs framework difference. The reason we don't have this issue when we use global tunables is because we add the attribute group to the
cpufreq_global_kobjectand that kobject doesn't have akobj_typeops similar to the per policy kobject. So, read/write to those attributes do NOT go through the generic show/store ops that wrap every other cpufreq framework attribute read/writes.So, none of those read/write do any kind of locking. They don't race with
POLICY_EXIT(because we remove the sysfs group first thing inPOLICY_EXIT) but might still race with START/STOPs (not sure, haven't looked closely yet).
Quoted 6 lines
Quoted 3 lines
For example, writing to
sampling_rateof ondemand governor might cause a race inupdate_sampling_rate(). It could race and happen between a STOP andPOLICY_EXIT(triggered by hotplug, gov change, etc).This sounds good but I couldn't prove it. Doing this on my dual core exynos doesn't give me that crash report and it should?
Are you sure you're not seeing another lockdep warning? That was my problem -- there was an xfs related lockdep warning which then resulted in lockdep being disabled from that point on.
P.
Quoted 17 lines
drivers/cpufreq/exynos-cpufreq.c +1
-1@@ -139,7 +139,7 @@ static int exynos_cpufreq_cpu_init(struct cpufreq_policy *policy) }static struct cpufreq_driver exynos_driver = { - .flags =CPUFREQ_STICKY |CPUFREQ_NEED_INITIAL_FREQ_CHECK , + .flags =CPUFREQ_STICKY |CPUFREQ_NEED_INITIAL_FREQ_CHECK |CPUFREQ_HAVE_GOVERNOR_PER_POLICY , .verify = cpufreq_generic_frequency_table_verify,.target_index =
exynos_target,
.get =cpufreq_generic_get,
Quoted 20 lines · Prarit Bhargava
Quoted 17 lines · Viresh Kumar
Quoted 15 lines · Saravana Kannan
Stephen and I looked into this. This is not a sysfs framework difference. The reason we don't have this issue when we use global tunables is because we add the attribute group to the
cpufreq_global_kobjectand that kobject doesn't have akobj_typeops similar to the per policy kobject. So, read/write to those attributes do NOT go through the generic show/store ops that wrap every other cpufreq framework attribute read/writes.So, none of those read/write do any kind of locking. They don't race with
POLICY_EXIT(because we remove the sysfs group first thing inPOLICY_EXIT) but might still race with START/STOPs (not sure, haven't looked closely yet).For example, writing to
sampling_rateof ondemand governor might cause a race inupdate_sampling_rate(). It could race and happen between a STOP andPOLICY_EXIT(triggered by hotplug, gov change, etc).
Quoted 7 lines
Quoted 2 lines
This sounds good but I couldn't prove it. Doing this on my dual core exynos doesn't give me that crash report and it should?
Are you sure you're not seeing another lockdep warning? That was my problem -- there was an xfs related lockdep warning which then resulted in lockdep being disabled from that point on.
Are we talking about the lockdep splat or the crash that started this thread or something else? For the lockdep splat you need the corrected patch in this thread and the per policy governor flag. I'm not sure how to recreate the crash that started this thread.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Viresh Kumar
maintainerQuoted 4 lines · Stephen Boyd
Quoted 3 lines · Prarit Bhargava
Are you sure you're not seeing another lockdep warning? That was my problem -- there was an xfs related lockdep warning which then resulted in lockdep being disabled from that point on.
There is a fair chance that I might be doing something really really stupid, but I couldn't get the lockdep warning..
Quoted 4 lines
Are we talking about the lockdep splat or the crash that started this thread or something else? For the lockdep splat you need the corrected patch in this thread and the per policy governor flag. I'm not sure how to recreate the crash that started this thread.
We are talking about the lockdep splat that would happen if we don't drop locking around EXIT..
This is my full diff over mainline and my .config is attached. Please enlighten me on what am I missing :)
drivers/cpufreq/cpufreq.c +0 -0
@@ -2200,9 +2200,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 */@@ -2211,9 +2209,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 */drivers/cpufreq/exynos-cpufreq.c +0 -0
@@ -139,7 +139,7 @@ static int exynos_cpufreq_cpu_init(struct
cpufreq_policy *policy)
}
static struct cpufreq_driver exynos_driver = {
- .flags = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK,
+ .flags = CPUFREQ_STICKY |
CPUFREQ_NEED_INITIAL_FREQ_CHECK | CPUFREQ_HAVE_GOVERNOR_PER_POLICY,
.verify = cpufreq_generic_frequency_table_verify,
.target_index = exynos_target,
.get = cpufreq_generic_get,Quoted 14 lines · Viresh Kumar
Quoted 4 lines · Stephen Boyd
Quoted 3 lines · Prarit Bhargava
Are you sure you're not seeing another lockdep warning? That was my problem -- there was an xfs related lockdep warning which then resulted in lockdep being disabled from that point on.
There is a fair chance that I might be doing something really really stupid, but I couldn't get the lockdep warning..
Quoted 4 lines
Are we talking about the lockdep splat or the crash that started this thread or something else? For the lockdep splat you need the corrected patch in this thread and the per policy governor flag. I'm not sure how to recreate the crash that started this thread.
Quoted 5 lines
We are talking about the lockdep splat that would happen if we don't drop locking around EXIT..
This is my full diff over mainline and my .config is attached. Please enlighten me on what am I missing :)
That should have done it. What are your CPUFREQ configs?
P.
Quoted 43 lines
drivers/cpufreq/cpufreq.c +0
-2@@ -2200,9 +2200,7 @@ static int cpufreq_set_policy(structcpufreq_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 */drivers/cpufreq/cpufreq.c +0
-2@@ -2211,9 +2209,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 */drivers/cpufreq/exynos-cpufreq.c +1
-1@@ -139,7 +139,7 @@ static int exynos_cpufreq_cpu_init(struct cpufreq_policy *policy) }static struct cpufreq_driver exynos_driver = { - .flags =CPUFREQ_STICKY |CPUFREQ_NEED_INITIAL_FREQ_CHECK , + .flags =CPUFREQ_STICKY |CPUFREQ_NEED_INITIAL_FREQ_CHECK |CPUFREQ_HAVE_GOVERNOR_PER_POLICY , .verify = cpufreq_generic_frequency_table_verify,.target_index =
exynos_target,
.get =cpufreq_generic_get,
Viresh Kumar
maintainerQuoted 1 line · Prarit Bhargava
That should have done it. What are your CPUFREQ configs?
You can check the same .config I attached last time for that :)
CONFIG_CPU_FREQ=y CONFIG_CPU_FREQ_GOV_COMMON=y CONFIG_CPU_FREQ_STAT=y CONFIG_CPU_FREQ_STAT_DETAILS=y
# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set # CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set # CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE=y CONFIG_CPU_FREQ_GOV_PERFORMANCE=y CONFIG_CPU_FREQ_GOV_POWERSAVE=y CONFIG_CPU_FREQ_GOV_USERSPACE=y CONFIG_CPU_FREQ_GOV_ONDEMAND=y CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
Anyway, has anybody tried to test what I have been trying now? @Prarit: You can try that on your x86 box as well, which has a single cluster or group of CPUs sharing clock line.
Viresh Kumar
maintainerQuoted 20 lines · Viresh Kumar
Quoted 1 line · Prarit Bhargava
That should have done it. What are your CPUFREQ configs?
You can check the same .config I attached last time for that :)
CONFIG_CPU_FREQ=yCONFIG_CPU_FREQ_GOV_COMMON=yCONFIG_CPU_FREQ_STAT=yCONFIG_CPU_FREQ_STAT_DETAILS=y
#CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMANDis not setCONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE=yCONFIG_CPU_FREQ_GOV_PERFORMANCE=yCONFIG_CPU_FREQ_GOV_POWERSAVE=yCONFIG_CPU_FREQ_GOV_USERSPACE=yCONFIG_CPU_FREQ_GOV_ONDEMAND=yCONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
Quoted 3 lines
Anyway, has anybody tried to test what I have been trying now? @Prarit: You can try that on your x86 box as well, which has a single cluster or group of CPUs sharing clock line.
Ping!!
Quoted 6 lines · Viresh Kumar
Quoted 5 lines · Viresh Kumar
Quoted 1 line · Prarit Bhargava
That should have done it. What are your CPUFREQ configs?
You can check the same .config I attached last time for that :)
Quoted 13 lines
Quoted 5 lines
CONFIG_CPU_FREQ=yCONFIG_CPU_FREQ_GOV_COMMON=yCONFIG_CPU_FREQ_STAT=yCONFIG_CPU_FREQ_STAT_DETAILS=y
#CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCEis not setQuoted 8 lines
#
CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACEis not set #CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMANDis not setCONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE=yCONFIG_CPU_FREQ_GOV_PERFORMANCE=yCONFIG_CPU_FREQ_GOV_POWERSAVE=yCONFIG_CPU_FREQ_GOV_USERSPACE=yCONFIG_CPU_FREQ_GOV_ONDEMAND=yCONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
Viresh, sorry for my late reply -- I got distracted by another issue.
Quoted 6 lines
Quoted 5 lines
Anyway, has anybody tried to test what I have been trying now? @Prarit: You can try that on your x86 box as well, which has a single cluster or group of CPUs sharing clock line.
Okay, this is what I have and I can reproduce this *easily* 100% of the time.
I've used your above config options and have enabled LOCKDEP.
In order to restore the locking, I've applied the following patch to the cpufreq core (sorry for the cut-and-paste):
drivers/cpufreq/cpufreq.c +0 -4
@@ -2192,9 +2192,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *polic/* 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 */
@@ -2203,9 +2201,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policif (!__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 */
I've modified the acpi-cpufreq driver to include (sorry for the cut-and-paste)
drivers/cpufreq/acpi-cpufreq.c +3 -0
@@ -884,6 +884,9 @@ static struct freq_attr *acpi_cpufreq_attr[] = { };static struct cpufreq_driver acpi_cpufreq_driver = { + .flags =CPUFREQ_STICKY | +CPUFREQ_HAVE_GOVERNOR_PER_POLICY | +CPUFREQ_NEED_INITIAL_FREQ_CHECK , .verify = cpufreq_generic_frequency_table_verify, .target_index = acpi_cpufreq_target, .bios_limit = acpi_processor_get_bios_limit,
I do a
cat /sys/devices/system/cpu/cpu2/cpufreq/conservative/* echo ondemand > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
and then I immediately see the stack trace.
P.
Quoted 2 lines
Ping!!
Viresh Kumar
maintainerQuoted 50 lines · Prarit Bhargava
Okay, this is what I have and I can reproduce this *easily* 100% of the time.
I've used your above config options and have enabled LOCKDEP.
In order to restore the locking, I've applied the following patch to the cpufreq core (sorry for the cut-and-paste):
drivers/cpufreq/cpufreq.c +0
-4@@ -2192,9 +2192,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *polic/* 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 */ @@ -2203,9 +2201,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policif (!__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 */ I've modified the acpi-cpufreq driver to include (sorry for the cut-and-paste)
drivers/cpufreq/acpi-cpufreq.c +3
-0@@ -884,6 +884,9 @@ static struct freq_attr *acpi_cpufreq_attr[] = { };static struct cpufreq_driver acpi_cpufreq_driver = { + .flags =CPUFREQ_STICKY | +CPUFREQ_HAVE_GOVERNOR_PER_POLICY | +CPUFREQ_NEED_INITIAL_FREQ_CHECK , .verify = cpufreq_generic_frequency_table_verify, .target_index = acpi_cpufreq_target, .bios_limit = acpi_processor_get_bios_limit,
Quoted 6 lines
I do a
cat
/sys/devices/system/cpu/cpu2/cpufreq/conservative/*echo ondemand >/sys/devices/system/cpu/cpu2/cpufreq/scaling_governorand then I immediately see the stack trace.
What's your system configuration? How many clusters/cpus/etc..
Quoted 51 lines · Viresh Kumar
Quoted 50 lines · Prarit Bhargava
Okay, this is what I have and I can reproduce this *easily* 100% of the time.
I've used your above config options and have enabled LOCKDEP.
In order to restore the locking, I've applied the following patch to the cpufreq core (sorry for the cut-and-paste):
drivers/cpufreq/cpufreq.c +0
-4@@ -2192,9 +2192,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *polic/* 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 */ @@ -2203,9 +2201,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policif (!__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 */ I've modified the acpi-cpufreq driver to include (sorry for the cut-and-paste)
drivers/cpufreq/acpi-cpufreq.c +3
-0@@ -884,6 +884,9 @@ static struct freq_attr *acpi_cpufreq_attr[] = { };static struct cpufreq_driver acpi_cpufreq_driver = { + .flags =CPUFREQ_STICKY | +CPUFREQ_HAVE_GOVERNOR_PER_POLICY | +CPUFREQ_NEED_INITIAL_FREQ_CHECK , .verify = cpufreq_generic_frequency_table_verify, .target_index = acpi_cpufreq_target, .bios_limit = acpi_processor_get_bios_limit,
Quoted 8 lines
Quoted 6 lines
I do a
cat
/sys/devices/system/cpu/cpu2/cpufreq/conservative/*echo ondemand >/sys/devices/system/cpu/cpu2/cpufreq/scaling_governorand then I immediately see the stack trace.
What's your system configuration? How many clusters/cpus/etc..
Anywhere from 2-4 sockets, 8 - 240 cpus (depending on # of sockets), x86 arch.
P.
Quoted 1 line
Quoted 9 lines · Saravana Kannan
I definitely have a fix for this and the original race you reported. It's basically reverting that commit you reverted + a fix for the deadlock. That's the only way to fix the
scaling_governorissue.You fix the deadlock by moving the governor attribute group removing to the framework code and doing it before STOP+EXIT to governor without holding the policy lock. And the reverse for INIT+STOP.
I'm still not convinced of the deadlock so I did a bit of additional research and am pretty close to saying that this is a false positive from the lockdep code in the kernfs area.
A few things that have caused me concern about the lockdep splat we're seeing:
1. The splat occurs when we hit __kernfs_remove+0x25b/0x360 which resolves to
if (kernfs_lockdep(kn)) {
rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_); <<< RIGHT HERE
if (atomic_read(&kn->active) != KN_DEACTIVATED_BIAS)
lock_contended(&kn->dep_map, _RET_IP_);
}ie) the *ONLY* way we hit a "deadlock" in this code is if we have LOCKDEP configured in the kernfs.
It should be noted, that having kernfs_lockdep() always return 0 [1], results in NO additional lockdep warnings.
Additionally the splat contains
[ 107.428421] CPU0 CPU1 [ 107.433482] ---- ---- [ 107.438544] lock(&policy->rwsem); [ 107.442459] lock(s_active#98); [ 107.448916] lock(&policy->rwsem); [ 107.455650] lock(s_active#98);
which also points to the situation above (s_active is the default naming used in the kernfs lockdep code).
In short -- there is no deadlock here. It only happens in the lockdep code itself, not because lockdep has identified a real problem.
2. I then started asking myself why this was occurring. The reason appears to be that the attribute for scaling_governor is deleting other sysfs attributes and that got me to wondering if there were other areas where this occurred and I remembered it does! In the USB code writing and reading to the bConfiguration of a device may lead to the removal of "down stream" attributes. The reading and writing of bConfiguration occurs indrivers/usb/core/sysfs.c:79
/* configuration value is always present, and r/w */ usb_actconfig_show(bConfigurationValue, "%u\n");
static ssize_t bConfigurationValue_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct usb_device *udev = to_usb_device(dev);
int config, value;
if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255)
return -EINVAL;
usb_lock_device(udev);
value = usb_set_configuration(udev, config);
usb_unlock_device(udev);
return (value < 0) ? value : count;
}... and the next lines are IMO important here:
static DEVICE_ATTR_IGNORE_LOCKDEP(bConfigurationValue, S_IRUGO | S_IWUSR,
bConfigurationValue_show, bConfigurationValue_store);
FWIW, it isn't *exactly* the same ... but commit 356c05d58af05d582e634b54b40050c73609617b explains a similarity between what is happening with our lockdep splat and the lockdep issues seen in USB.
3. I came across this from an earlier discussion ...
https://lkml.org/lkml/2010/1/29/306
"We get false positives when the code of a sysfs attribute synchronously removes other sysfs attributes. In general that is not safe due to hotplug etc, but there are specific instances of static sysfs entries like the pm_core where it appears to be safe."
...
So ... the question that I have is: is this lockdep splat "real"? It seems to only occur because we enable the lockdep code in kernfs, that is it occurs as a side-effect and doesn't appear to be "real" to me.
I only offer this in an effort to keep work to a minimum ;)
P.
[1] It wasn't that simple. There are some other changes that have to be made. But you get the idea ...
Viresh Kumar
maintainerQuoted 1 line · Prarit Bhargava
Anywhere from 2-4 sockets, 8 - 240 cpus (depending on # of sockets), x86 arch.
That's what. We know that it does happen on multi cluster systems and I was reproducing it on a single cluster one. i.e. all CPUs share clock line.
Quoted 76 lines · Prarit Bhargava
Quoted 9 lines · Saravana Kannan
I definitely have a fix for this and the original race you reported. It's basically reverting that commit you reverted + a fix for the deadlock. That's the only way to fix the
scaling_governorissue.You fix the deadlock by moving the governor attribute group removing to the framework code and doing it before STOP+EXIT to governor without holding the policy lock. And the reverse for INIT+STOP.
I'm still not convinced of the deadlock so I did a bit of additional research and am pretty close to saying that this is a false positive from the lockdep code in the kernfs area.
A few things that have caused me concern about the lockdep splat we're seeing:
1. The splat occurs when we hit
__kernfs_remove+0x25b/0x360which resolves toif (kernfs_lockdep(kn)) { rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_); <<< RIGHT HERE if (atomic_read(&kn->active) != KN_DEACTIVATED_BIAS) lock_contended(&kn->dep_map, _RET_IP_); }ie) the *ONLY* way we hit a "deadlock" in this code is if we have LOCKDEP configured in the kernfs.
It should be noted, that having
kernfs_lockdep()always return 0 [1], results in NO additional lockdep warnings.Additionally the splat contains
[ 107.428421] CPU0 CPU1 [ 107.433482] ---- ---- [ 107.438544] lock(&policy->rwsem); [ 107.442459] lock(s_active#98); [ 107.448916] lock(&policy->rwsem); [ 107.455650] lock(s_active#98);which also points to the situation above (
s_activeis the default naming used in the kernfs lockdep code).In short -- there is no deadlock here. It only happens in the lockdep code itself, not because lockdep has identified a real problem.
2. I then started asking myself why this was occurring. The reason appears to be that the attribute for
scaling_governoris deleting other sysfs attributes and that got me to wondering if there were other areas where this occurred and I remembered it does! In the USB code writing and reading to the bConfiguration of a device may lead to the removal of "down stream" attributes. The reading and writing of bConfiguration occurs indrivers/usb/core/sysfs.c:79/* configuration value is always present, and r/w */
usb_actconfig_show(bConfigurationValue, "%u\n");static
ssize_tbConfigurationValue_store(struct device *dev,
structdevice_attribute*attr, const char *buf,size_tcount){ struct usb_device *udev = to_usb_device(dev); int config, value; if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255) return -EINVAL; usb_lock_device(udev); value = usb_set_configuration(udev, config); usb_unlock_device(udev); return (value < 0) ? value : count; }
Quoted 8 lines
... and the next lines are IMO important here:
static DEVICE_ATTR_IGNORE_LOCKDEP(bConfigurationValue,
S_IRUGO|S_IWUSR,bConfigurationValue_show, bConfigurationValue_store);FWIW, it isn't *exactly* the same ... but commit
356c05d58af05d582e634b54b40050c73609617bexplains a similarity between what is happening with our lockdep splat and the lockdep issues seen in USB.
This seems VERY different from our situation. I don't see an equivalent of a policy lock that's grabbed from both threads, but in opposite order.
If I'm not mistaken, the sysfs entry here uses some wait/complete pair to wait for something. But that's an equivalent of a semaphore with max count of 1. Lockdep just seems to be making it obvious by adding semaphore calls.
So, a semaphore equivalent deadlock with another semaphore. I believe this is a read deadlock.
-Saravana
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Viresh Kumar
maintainerQuoted 21 lines · Stephen Boyd
Quoted 3 lines · Prarit Bhargava
Can you send me the test and the trace of the deadlock? I'm not creating it with:
This was with conservative as the default, and switching to ondemand
# cd /sys/devices/system/cpu/cpu2/cpufreq # ls affected_cpus scaling_available_governors conservative scaling_cur_freq cpuinfo_cur_freq scaling_driver cpuinfo_max_freq scaling_governor cpuinfo_min_freq scaling_max_freq cpuinfo_transition_latency scaling_min_freq related_cpus scaling_setspeed scaling_available_frequencies stats # cat conservative/down_threshold 20 # echo ondemand > scaling_governor
Quoted 6 lines
======================================================
[ INFO: possible circular locking dependency detected ] 3.16.0-rc3-00039-ge1e38f124d87 #47 Not tainted
-------------------------------------------------------
sh/75 is trying to acquire lock:
(s_active#9){++++..}, at: [<c0358a94>]kernfs_remove_by_name_ns+0x3c/0x84
Can you please retry this on mainline? I wasn't able to reproduce it now over 3.17.
I am trying this on Exynos b.L implementation..
Quoted 29 lines · Viresh Kumar
Quoted 21 lines · Stephen Boyd
Quoted 3 lines · Prarit Bhargava
Can you send me the test and the trace of the deadlock? I'm not creating it with:
This was with conservative as the default, and switching to ondemand
# cd /sys/devices/system/cpu/cpu2/cpufreq # ls affected_cpus scaling_available_governors conservative scaling_cur_freq cpuinfo_cur_freq scaling_driver cpuinfo_max_freq scaling_governor cpuinfo_min_freq scaling_max_freq cpuinfo_transition_latency scaling_min_freq related_cpus scaling_setspeed scaling_available_frequencies stats # cat conservative/down_threshold 20 # echo ondemand > scaling_governorQuoted 6 lines
======================================================
[ INFO: possible circular locking dependency detected ] 3.16.0-rc3-00039-ge1e38f124d87 #47 Not tainted
-------------------------------------------------------
sh/75 is trying to acquire lock:
(s_active#9){++++..}, at: [<c0358a94>]kernfs_remove_by_name_ns+0x3c/0x84
Quoted 3 lines
Can you please retry this on mainline? I wasn't able to reproduce it now over 3.17.
I am trying this on Exynos b.L implementation..
I have 100% reproducibility on latest mainline.
Viresh, please see my next post on the locking issues in cpufreq.
P.