linux-stable/drivers/regulator
Chen-Yu Tsai 21e39809fd
regulator: vctrl: Avoid lockdep warning in enable/disable ops
vctrl_enable() and vctrl_disable() call regulator_enable() and
regulator_disable(), respectively. However, vctrl_* are regulator ops
and should not be calling the locked regulator APIs. Doing so results in
a lockdep warning.

Instead of exporting more internal regulator ops, model the ctrl supply
as an actual supply to vctrl-regulator. At probe time this driver still
needs to use the consumer API to fetch its constraints, but otherwise
lets the regulator core handle the upstream supply for it.

The enable/disable/is_enabled ops are not removed, but now only track
state internally. This preserves the original behavior with the ops
being available, but one could argue that the original behavior was
already incorrect: the internal state would not match the upstream
supply if that supply had another consumer that enabled the supply,
while vctrl-regulator was not enabled.

The lockdep warning is as follows:

	WARNING: possible circular locking dependency detected
	5.14.0-rc6 #2 Not tainted
	------------------------------------------------------
	swapper/0/1 is trying to acquire lock:
	ffffffc011306d00 (regulator_list_mutex){+.+.}-{3:3}, at:
		regulator_lock_dependent (arch/arm64/include/asm/current.h:19
					  include/linux/ww_mutex.h:111
					  drivers/regulator/core.c:329)

	but task is already holding lock:
	ffffff8004a77160 (regulator_ww_class_mutex){+.+.}-{3:3}, at:
		regulator_lock_recursive (drivers/regulator/core.c:156
					  drivers/regulator/core.c:263)

	which lock already depends on the new lock.

	the existing dependency chain (in reverse order) is:

	-> #2 (regulator_ww_class_mutex){+.+.}-{3:3}:
	__mutex_lock_common (include/asm-generic/atomic-instrumented.h:606
			     include/asm-generic/atomic-long.h:29
			     kernel/locking/mutex.c:103
			     kernel/locking/mutex.c:144
			     kernel/locking/mutex.c:963)
	ww_mutex_lock (kernel/locking/mutex.c:1199)
	regulator_lock_recursive (drivers/regulator/core.c:156
				  drivers/regulator/core.c:263)
	regulator_lock_dependent (drivers/regulator/core.c:343)
	regulator_enable (drivers/regulator/core.c:2808)
	set_machine_constraints (drivers/regulator/core.c:1536)
	regulator_register (drivers/regulator/core.c:5486)
	devm_regulator_register (drivers/regulator/devres.c:196)
	reg_fixed_voltage_probe (drivers/regulator/fixed.c:289)
	platform_probe (drivers/base/platform.c:1427)
	[...]

	-> #1 (regulator_ww_class_acquire){+.+.}-{0:0}:
	regulator_lock_dependent (include/linux/ww_mutex.h:129
				  drivers/regulator/core.c:329)
	regulator_enable (drivers/regulator/core.c:2808)
	set_machine_constraints (drivers/regulator/core.c:1536)
	regulator_register (drivers/regulator/core.c:5486)
	devm_regulator_register (drivers/regulator/devres.c:196)
	reg_fixed_voltage_probe (drivers/regulator/fixed.c:289)
	[...]

	-> #0 (regulator_list_mutex){+.+.}-{3:3}:
	__lock_acquire (kernel/locking/lockdep.c:3052 (discriminator 4)
			kernel/locking/lockdep.c:3174 (discriminator 4)
			kernel/locking/lockdep.c:3789 (discriminator 4)
			kernel/locking/lockdep.c:5015 (discriminator 4))
	lock_acquire (arch/arm64/include/asm/percpu.h:39
		      kernel/locking/lockdep.c:438
		      kernel/locking/lockdep.c:5627)
	__mutex_lock_common (include/asm-generic/atomic-instrumented.h:606
			     include/asm-generic/atomic-long.h:29
			     kernel/locking/mutex.c:103
			     kernel/locking/mutex.c:144
			     kernel/locking/mutex.c:963)
	mutex_lock_nested (kernel/locking/mutex.c:1125)
	regulator_lock_dependent (arch/arm64/include/asm/current.h:19
				  include/linux/ww_mutex.h:111
				  drivers/regulator/core.c:329)
	regulator_enable (drivers/regulator/core.c:2808)
	vctrl_enable (drivers/regulator/vctrl-regulator.c:400)
	_regulator_do_enable (drivers/regulator/core.c:2617)
	_regulator_enable (drivers/regulator/core.c:2764)
	regulator_enable (drivers/regulator/core.c:308
			  drivers/regulator/core.c:2809)
	_set_opp (drivers/opp/core.c:819 drivers/opp/core.c:1072)
	dev_pm_opp_set_rate (drivers/opp/core.c:1164)
	set_target (drivers/cpufreq/cpufreq-dt.c:62)
	__cpufreq_driver_target (drivers/cpufreq/cpufreq.c:2216
				 drivers/cpufreq/cpufreq.c:2271)
	cpufreq_online (drivers/cpufreq/cpufreq.c:1488 (discriminator 2))
	cpufreq_add_dev (drivers/cpufreq/cpufreq.c:1563)
	subsys_interface_register (drivers/base/bus.c:?)
	cpufreq_register_driver (drivers/cpufreq/cpufreq.c:2819)
	dt_cpufreq_probe (drivers/cpufreq/cpufreq-dt.c:344)
	[...]

	other info that might help us debug this:

	Chain exists of:
	  regulator_list_mutex --> regulator_ww_class_acquire --> regulator_ww_class_mutex

	 Possible unsafe locking scenario:

	       CPU0                    CPU1
	       ----                    ----
	  lock(regulator_ww_class_mutex);
				       lock(regulator_ww_class_acquire);
				       lock(regulator_ww_class_mutex);
	  lock(regulator_list_mutex);

	 *** DEADLOCK ***

	6 locks held by swapper/0/1:
	#0: ffffff8002d32188 (&dev->mutex){....}-{3:3}, at:
		__device_driver_lock (drivers/base/dd.c:1030)
	#1: ffffffc0111a0520 (cpu_hotplug_lock){++++}-{0:0}, at:
		cpufreq_register_driver (drivers/cpufreq/cpufreq.c:2792 (discriminator 2))
	#2: ffffff8002a8d918 (subsys mutex#9){+.+.}-{3:3}, at:
		subsys_interface_register (drivers/base/bus.c:1033)
	#3: ffffff800341bb90 (&policy->rwsem){+.+.}-{3:3}, at:
		cpufreq_online (include/linux/bitmap.h:285
				include/linux/cpumask.h:405
				drivers/cpufreq/cpufreq.c:1399)
	#4: ffffffc011f0b7b8 (regulator_ww_class_acquire){+.+.}-{0:0}, at:
		regulator_enable (drivers/regulator/core.c:2808)
	#5: ffffff8004a77160 (regulator_ww_class_mutex){+.+.}-{3:3}, at:
		regulator_lock_recursive (drivers/regulator/core.c:156
		drivers/regulator/core.c:263)

	stack backtrace:
	CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.14.0-rc6 #2 7c8f8996d021ed0f65271e6aeebf7999de74a9fa
	Hardware name: Google Scarlet (DT)
	Call trace:
	dump_backtrace (arch/arm64/kernel/stacktrace.c:161)
	show_stack (arch/arm64/kernel/stacktrace.c:218)
	dump_stack_lvl (lib/dump_stack.c:106 (discriminator 2))
	dump_stack (lib/dump_stack.c:113)
	print_circular_bug (kernel/locking/lockdep.c:?)
	check_noncircular (kernel/locking/lockdep.c:?)
	__lock_acquire (kernel/locking/lockdep.c:3052 (discriminator 4)
			kernel/locking/lockdep.c:3174 (discriminator 4)
			kernel/locking/lockdep.c:3789 (discriminator 4)
			kernel/locking/lockdep.c:5015 (discriminator 4))
	lock_acquire (arch/arm64/include/asm/percpu.h:39
		      kernel/locking/lockdep.c:438
		      kernel/locking/lockdep.c:5627)
	__mutex_lock_common (include/asm-generic/atomic-instrumented.h:606
			     include/asm-generic/atomic-long.h:29
			     kernel/locking/mutex.c:103
			     kernel/locking/mutex.c:144
			     kernel/locking/mutex.c:963)
	mutex_lock_nested (kernel/locking/mutex.c:1125)
	regulator_lock_dependent (arch/arm64/include/asm/current.h:19
				  include/linux/ww_mutex.h:111
				  drivers/regulator/core.c:329)
	regulator_enable (drivers/regulator/core.c:2808)
	vctrl_enable (drivers/regulator/vctrl-regulator.c:400)
	_regulator_do_enable (drivers/regulator/core.c:2617)
	_regulator_enable (drivers/regulator/core.c:2764)
	regulator_enable (drivers/regulator/core.c:308
			  drivers/regulator/core.c:2809)
	_set_opp (drivers/opp/core.c:819 drivers/opp/core.c:1072)
	dev_pm_opp_set_rate (drivers/opp/core.c:1164)
	set_target (drivers/cpufreq/cpufreq-dt.c:62)
	__cpufreq_driver_target (drivers/cpufreq/cpufreq.c:2216
				 drivers/cpufreq/cpufreq.c:2271)
	cpufreq_online (drivers/cpufreq/cpufreq.c:1488 (discriminator 2))
	cpufreq_add_dev (drivers/cpufreq/cpufreq.c:1563)
	subsys_interface_register (drivers/base/bus.c:?)
	cpufreq_register_driver (drivers/cpufreq/cpufreq.c:2819)
	dt_cpufreq_probe (drivers/cpufreq/cpufreq-dt.c:344)
	[...]

Reported-by: Brian Norris <briannorris@chromium.org>
Fixes: f8702f9e4a ("regulator: core: Use ww_mutex for regulators locking")
Fixes: e915331149 ("regulator: vctrl-regulator: Avoid deadlock getting and setting the voltage")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Link: https://lore.kernel.org/r/20210825033704.3307263-3-wenst@chromium.org
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-08-25 14:17:53 +01:00
..
88pg86x.c
88pm800-regulator.c
88pm8607.c
aat2870-regulator.c
ab8500-ext.c
ab8500.c
act8865-regulator.c
act8945a-regulator.c
ad5398.c
anatop-regulator.c
arizona-ldo1.c
arizona-micsupp.c
as3711-regulator.c
as3722-regulator.c
atc260x-regulator.c regulator: atc260x: Fix n_voltages and min_sel for pickable linear ranges 2021-06-01 14:03:06 +01:00
axp20x-regulator.c
bcm590xx-regulator.c
bd718x7-regulator.c regulator: bd718x7: Suopport configuring UVP/OVP state 2021-07-11 23:50:44 +01:00
bd9571mwv-regulator.c
bd9576-regulator.c regulator: bd9576: Fix testing wrong flag in check_temp_flag_mismatch 2021-07-01 14:50:30 +01:00
bd71815-regulator.c regulator: bd71815: Get rid of struct bd71815_pmic 2021-06-08 13:37:46 +01:00
bd71828-regulator.c
core.c Merge remote-tracking branch 'regulator/for-5.14' into regulator-next 2021-06-23 16:56:31 +01:00
cpcap-regulator.c
cros-ec-regulator.c regulator: cros-ec: Fix error code in dev_err message 2021-05-12 13:01:41 +01:00
da903x-regulator.c
da9052-regulator.c regulator: da9052: Ensure enough delay time for .set_voltage_time_sel 2021-06-23 12:34:40 +01:00
da9055-regulator.c
da9062-regulator.c
da9063-regulator.c regulator: da9063: Add support for full-current mode. 2021-07-15 17:24:50 +01:00
da9121-regulator.c regulator: da9121: Return REGULATOR_MODE_INVALID for invalid mode 2021-05-18 14:04:21 +01:00
da9121-regulator.h
da9210-regulator.c
da9210-regulator.h
da9211-regulator.c
da9211-regulator.h
db8500-prcmu.c
dbx500-prcmu.c regulator: Replace symbolic permissions with octal permissions 2021-07-11 23:50:43 +01:00
dbx500-prcmu.h
devres.c regulator: devres: unexport devm_regulator_unregister_supply_alias() 2021-07-11 23:50:34 +01:00
dummy.c
dummy.h
fan53555.c regulator: fan53555: add tcs4526 2021-06-04 15:27:10 +01:00
fan53880.c Merge remote-tracking branch 'regulator/for-5.14' into regulator-next 2021-06-23 16:56:31 +01:00
fixed-helper.c
fixed.c regulator: fixed: use dev_err_probe for register 2021-07-22 12:40:12 +01:00
gpio-regulator.c
helpers.c regulator: Check ramp_delay_table for regulator_set_ramp_delay_regmap 2021-05-19 14:31:43 +01:00
hi655x-regulator.c regulator: hi655x: Fix pass wrong pointer to config.driver_data 2021-06-21 13:02:05 +01:00
hi6421-regulator.c regulator: hi6421: Fix getting wrong drvdata 2021-07-11 23:44:37 +01:00
hi6421v530-regulator.c
hi6421v600-regulator.c regulator: hi6421v600: rename voltage range arrays 2021-07-26 02:16:49 +01:00
internal.h regulator: move rdev_print helpers to internal.h 2021-06-21 13:08:39 +01:00
irq_helpers.c regulator: Documentation fix for regulator error notification helper 2021-08-23 11:06:28 +01:00
isl6271a-regulator.c
isl9305.c
Kconfig regulator: rtq2134: Add support for Richtek RTQ2134 SubPMIC 2021-07-20 13:37:29 +01:00
lm363x-regulator.c
lochnagar-regulator.c
lp872x.c
lp873x-regulator.c
lp3971.c
lp3972.c
lp8755.c regulator: lp8755: Convert to use regulator_set_ramp_delay_regmap 2021-06-01 14:05:23 +01:00
lp8788-buck.c
lp8788-ldo.c
lp87565-regulator.c mfd: lp87565: Move LP87565_regulator_id to .c file 2021-05-19 13:34:00 +01:00
ltc3589.c regulator: ltc3589: Convert to use regulator_set_ramp_delay_regmap 2021-06-08 13:37:45 +01:00
ltc3676.c
Makefile regulator: rtq2134: Add support for Richtek RTQ2134 SubPMIC 2021-07-20 13:37:29 +01:00
max1586.c
max8649.c
max8660.c
max8893.c regulator: max8893: add regulator driver 2021-06-21 13:07:44 +01:00
max8907-regulator.c
max8925-regulator.c
max8952.c
max8973-regulator.c regulator: max8973: Convert to use regulator_set_ramp_delay_regmap 2021-05-24 09:51:34 +01:00
max8997-regulator.c
max8998.c
max14577-regulator.c
max77620-regulator.c regulator: max77620: Silence deferred probe error 2021-05-24 09:50:20 +01:00
max77650-regulator.c
max77686-regulator.c regulator: max77686: Convert to use regulator_set_ramp_delay_regmap 2021-06-07 16:24:07 +01:00
max77693-regulator.c
max77802-regulator.c regulator: max77802: Convert to use regulator_set_ramp_delay_regmap 2021-06-03 14:04:51 +01:00
max77826-regulator.c
mc13xxx-regulator-core.c
mc13xxx.h
mc13783-regulator.c
mc13892-regulator.c
mcp16502.c regulator: mcp16502: Convert to use regulator_set_ramp_delay_regmap 2021-06-01 14:05:26 +01:00
mp886x.c regulator: mp886x: Convert to use regulator_set_ramp_delay_regmap 2021-05-25 16:45:09 +01:00
mp5416.c regulator: mp5416: Convert to use regulator_set_ramp_delay_regmap 2021-05-25 16:45:10 +01:00
mp8859.c
mpq7920.c
mpq7920.h
mt6311-regulator.c
mt6311-regulator.h
mt6315-regulator.c Merge remote-tracking branch 'regulator/for-5.14' into regulator-next 2021-06-23 16:56:31 +01:00
mt6323-regulator.c
mt6358-regulator.c regulator: mt6358: Remove shift fields from struct mt6358_regulator_info 2021-07-11 23:50:35 +01:00
mt6359-regulator.c regulator: mt6359: Remove shift fields from struct mt6359_regulator_info 2021-07-11 23:50:36 +01:00
mt6360-regulator.c
mt6380-regulator.c
mt6397-regulator.c regulator: mt6397: Remove modeset_shift from struct mt6397_regulator_info 2021-07-11 23:50:37 +01:00
mtk-dvfsrc-regulator.c regulator: mtk-dvfsrc: Fix wrong dev pointer for devm_regulator_register 2021-07-07 12:01:32 +01:00
of_regulator.c regulator: add property parsing and callbacks to set protection limits 2021-06-21 13:08:41 +01:00
palmas-regulator.c
pbias-regulator.c
pca9450-regulator.c regulator: pca9450: Convert to use regulator_set_ramp_delay_regmap 2021-06-01 14:05:21 +01:00
pcap-regulator.c
pcf50633-regulator.c
pf8x00-regulator.c
pfuze100-regulator.c
pv88060-regulator.c
pv88060-regulator.h
pv88080-regulator.c
pv88080-regulator.h
pv88090-regulator.c
pv88090-regulator.h
pwm-regulator.c
qcom-labibb-regulator.c regulator: add property parsing and callbacks to set protection limits 2021-06-21 13:08:41 +01:00
qcom-rpmh-regulator.c regulator: qcom-rpmh: Add new regulator found on SA8155p adp board 2021-06-21 13:07:27 +01:00
qcom_rpm-regulator.c
qcom_smd-regulator.c regulator: qcom_smd: Make pm8953_lnldo linear_ranges entries properly sorted 2021-05-25 16:45:08 +01:00
qcom_spmi-regulator.c regulator: add property parsing and callbacks to set protection limits 2021-06-21 13:08:41 +01:00
qcom_usb_vbus-regulator.c regulator: Add a routine to set the current limit for QCOM PMIC VBUS 2021-05-10 13:06:50 +01:00
rc5t583-regulator.c
rk808-regulator.c regulator: rk808: Convert to use regulator_set_ramp_delay_regmap 2021-05-26 19:22:09 +01:00
rn5t618-regulator.c
rohm-regulator.c
rpi-panel-attiny-regulator.c
rt4801-regulator.c regulator: rt4801: Fix NULL pointer dereference if priv->enable_gpios is NULL 2021-06-03 19:35:48 +01:00
rt4831-regulator.c regulator: rt4831: Add missing .owner field in regulator_desc 2021-05-25 16:45:11 +01:00
rt5033-regulator.c regulator: rt5033: Use linear ranges to map all voltage selection 2021-07-11 23:50:39 +01:00
rt6160-regulator.c regulator: rt6160: Fix setting suspend voltage 2021-06-16 15:41:16 +01:00
rt6245-regulator.c regulator: rt6245: make a const array func_base static, makes object smaller 2021-07-15 17:24:49 +01:00
rtmv20-regulator.c Merge existing fixes from regulator/for-5.14 2021-07-11 23:45:15 +01:00
rtq2134-regulator.c regulator: rtq2134: Fix coding style 2021-07-30 16:04:42 +01:00
rtq6752-regulator.c regulator: rtq6752: fix reg reset behavior 2021-07-16 13:55:34 +01:00
s2mpa01.c
s2mps11.c
s5m8767.c
sc2731-regulator.c
scmi-regulator.c regulator: Fixes for v5.14 2021-06-08 09:41:16 -07:00
sky81452-regulator.c
slg51000-regulator.c
slg51000-regulator.h
stm32-booster.c
stm32-pwr.c
stm32-vrefbuf.c
stpmic1_regulator.c regulator: add property parsing and callbacks to set protection limits 2021-06-21 13:08:41 +01:00
stw481x-vmmc.c
sy7636a-regulator.c regulator: sy7636a: Use the regmap directly 2021-08-09 12:40:26 +01:00
sy8106a-regulator.c
sy8824x.c regulator: sy8824x: Enable REGCACHE_FLAT 2021-08-03 18:27:18 +01:00
sy8827n.c regulator: sy8827n: Enable REGCACHE_FLAT 2021-08-03 18:27:19 +01:00
ti-abb-regulator.c
tps6105x-regulator.c
tps6507x-regulator.c
tps6524x-regulator.c
tps6586x-regulator.c
tps51632-regulator.c
tps62360-regulator.c
tps65023-regulator.c
tps65086-regulator.c
tps65090-regulator.c
tps65132-regulator.c
tps65217-regulator.c
tps65218-regulator.c
tps65910-regulator.c regulator: tps65910: Silence deferred probe error 2021-07-11 23:50:38 +01:00
tps65912-regulator.c
tps80031-regulator.c
twl-regulator.c
twl6030-regulator.c
uniphier-regulator.c regulator: uniphier: Add missing MODULE_DEVICE_TABLE 2021-05-11 10:05:48 +01:00
userspace-consumer.c regulator: userspace-consumer: use DEVICE_ATTR_RO/RW macro 2021-06-02 12:03:37 +01:00
vctrl-regulator.c regulator: vctrl: Avoid lockdep warning in enable/disable ops 2021-08-25 14:17:53 +01:00
vexpress-regulator.c
virtual.c
vqmmc-ipq4019-regulator.c
wm831x-dcdc.c
wm831x-isink.c
wm831x-ldo.c
wm8350-regulator.c
wm8400-regulator.c
wm8994-regulator.c