1
0
Fork 0
alistair23-linux/sound/hda
Takashi Iwai 69d5dc286d ALSA: hda: Manage concurrent reg access more properly
[ Upstream commit 1a462be52f ]

In the commit 8e85def572 ("ALSA: hda: enable regmap internal
locking"), we re-enabled the regmap lock due to the reported
regression that showed the possible concurrent accesses.  It was a
temporary workaround, and there are still a few opened races even
after the revert.  In this patch, we cover those still opened windows
with a proper mutex lock and disable the regmap internal lock again.

First off, the patch introduces a new snd_hdac_device.regmap_lock
mutex that is applied for each snd_hdac_regmap_*() call, including
read, write and update helpers.  The mutex is applied carefully so
that it won't block the self-power-up procedure in the helper
function.  Also, this assures the protection for the accesses without
regmap, too.

The snd_hdac_regmap_update_raw() is refactored to use the standard
regmap_update_bits_check() function instead of the open-code.  The
non-regmap case is still open-coded but it's an easy part.  The all
read and write operations are in the single mutex protection, so it's
now race-free.

In addition, a couple of new helper functions are added:
snd_hdac_regmap_update_raw_once() and snd_hdac_regmap_sync().  Both
are called from HD-audio legacy driver.  The former is to initialize
the given verb bits but only once when it's not initialized yet.  Due
to this condition, the function invokes regcache_cache_only(), and
it's now performed inside the regmap_lock (formerly it was racy) too.
The latter function is for simply invoking regcache_sync() inside the
regmap_lock, which is called from the codec resume call path.
Along with that, the HD-audio codec driver code is slightly modified /
simplified to adapt those new functions.

And finally, snd_hdac_regmap_read_raw(), *_write_raw(), etc are
rewritten with the helper macro.  It's just for simplification because
the code logic is identical among all those functions.

Tested-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Link: https://lore.kernel.org/r/20200109090104.26073-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-05-27 17:46:37 +02:00
..
ext ALSA: hda: do not override bus codec_mask in link_get() 2020-03-12 13:00:10 +01:00
Kconfig Merge branch 'topic/hda-bus-ops-cleanup' into for-next 2019-08-08 22:35:44 +02:00
Makefile ALSA: hda: move parts of NHLT code to new module 2019-07-31 15:45:59 +02:00
array.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
hda_bus_type.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
hdac_bus.c ALSA: hda: Unexport a few more stuff 2019-08-14 20:00:56 +02:00
hdac_component.c Linux 5.1-rc5 2019-04-15 15:51:49 +10:00
hdac_controller.c Revert "ALSA: hda: Flush interrupts on disabling" 2019-10-28 11:47:59 +01:00
hdac_device.c ALSA: hda: Manage concurrent reg access more properly 2020-05-27 17:46:37 +02:00
hdac_i915.c ALSA: hda: Fix 1-minute detection delay when i915 module is not available 2019-07-27 08:31:46 +02:00
hdac_regmap.c ALSA: hda: Manage concurrent reg access more properly 2020-05-27 17:46:37 +02:00
hdac_stream.c ALSA: hda: Fix regression by strip mask fix 2019-12-21 11:05:23 +01:00
hdac_sysfs.c ALSA: hda: Simplify snd_hdac_refresh_widgets() 2019-07-05 12:01:06 +02:00
hdmi_chmap.c ALSA: hda: Use scnprintf() for printing texts for sysfs/procfs 2020-02-28 17:22:12 +01:00
intel-nhlt.c ALSA: hda: intel-nhlt: handle NHLT VENDOR_DEFINED DMIC geometry 2019-07-31 15:46:00 +02:00
local.h ALSA: hda: Unexport a few more stuff 2019-08-14 20:00:56 +02:00
trace.c ALSA: hda - Re-add tracepoints to HD-audio core driver 2015-03-23 13:17:58 +01:00
trace.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00