Skip to contentSkip to conversation

Fixes for SOF module unload/reload

PATCH Superseded Ranjani Sridharan 2 participants 5 messages Jun 26, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Fixes for SOF module unload/reload

A recent commit "ALSA: hdac: fix memory release for SST and SOF drivers" removed the kfree call for the hdac device in snd_hdac_ext_bus_device_exit(). This requires that the SOF driver also make the hdac_device and hdac_hda_priv device-managed so that they can be freed when the SOF module in unloaded. The first patch takes care of this change.

Additionally, because of the above change, the hda_codec is device-managed and freeing it in snd_hda_codec_dev_release() leads to kernel panic with module unload/reload stress tests. The second patch includes the change to avoid freeing hda_codec for ASoC driver.

More details for the module unload/reload test failures can be found
here: https://github.com/thesofproject/linux/issues/966

Ranjani Sridharan (2):
ASoC: SOF: Intel: hda: Make hdac_device device-managed
ASoC: hda: don't free hda_codec for HDA_DEV_ASOC type

 sound/pci/hda/hda_codec.c       | 8 +++++++-
 sound/soc/sof/intel/hda-codec.c | 6 ++----
 2 files changed, 9 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 ASoC: SOF: Intel: hda: Make hdac_device device-managed

snd_hdac_ext_bus_device_exit() has been recently modified to no longer free the hdac device. SOF allocates memory for hdac_device and hda_hda_priv with kzalloc. Make them device-managed instead so that they will be freed when the SOF driver is unloaded.

---
 sound/soc/sof/intel/hda-codec.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
sound/soc/sof/intel/hda-codec.c +2 -4
index b8b37f082309..0d8437b080bf 100644
@@ -62,8 +62,7 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address)
 		address, resp);
 
 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
-	/* snd_hdac_ext_bus_device_exit will use kfree to free hdev */
-	hda_priv = kzalloc(sizeof(*hda_priv), GFP_KERNEL);
+	hda_priv = devm_kzalloc(sdev->dev, sizeof(*hda_priv), GFP_KERNEL);
 	if (!hda_priv)
 		return -ENOMEM;
 
@@ -82,8 +81,7 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address)
 
 	return 0;
 #else
-	/* snd_hdac_ext_bus_device_exit will use kfree to free hdev */
-	hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
+	hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL);
 	if (!hdev)
 		return -ENOMEM;
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/2 ASoC: hda: don't free hda_codec for HDA_DEV_ASOC type

In reply to Ranjani Sridharan

In the case of ASoC driver, the hdac_hda_priv pointer containing the hda_codec is device-managed. It will be freed when the ASoC device is removed during driver unloading. Freeing the codec in snd_hda_codec_dev_release() leads to kernel panics while unloading and reloading the ASoC driver.

---
 sound/pci/hda/hda_codec.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
sound/pci/hda/hda_codec.c +7 -1
index 6c51b8363f8b..a2e23d7e768f 100644
@@ -846,7 +846,13 @@ static void snd_hda_codec_dev_release(struct device *dev)
 	snd_hda_sysfs_clear(codec);
 	kfree(codec->modelname);
 	kfree(codec->wcaps);
-	kfree(codec);
+
+	/*
+	 * In the case of ASoC HD-audio, hda_codec is device managed.
+	 * It will be freed when the ASoC device is removed.
+	 */
+	if (codec->core.type == HDA_DEV_LEGACY)
+		kfree(codec);
 }
 
 #define DEV_NAME_LEN 31
Signature · 1 line
2.17.1
#3 lore raw
In reply to Ranjani Sridharan
Quoted 8 lines · Ranjani Sridharan

A recent commit "ALSA: hdac: fix memory release for SST and SOF drivers" removed the kfree call for the hdac device in snd_hdac_ext_bus_device_exit(). This requires that the SOF driver also make the hdac_device and hdac_hda_priv device-managed so that they can be freed when the SOF module in unloaded. The first patch takes care of this change.

Quoted 4 lines

Additionally, because of the above change, the hda_codec is device-managed and freeing it in snd_hda_codec_dev_release() leads to kernel panic with module unload/reload stress tests. The second patch includes the change to avoid freeing hda_codec for ASoC driver.

In such a case, both patch need to be put into a single patch. Otherwise it leads to a bisection failure.

thanks,

Takashi

Quoted 15 lines

More details for the module unload/reload test failures can be found
here: https://github.com/thesofproject/linux/issues/966

Ranjani Sridharan (2):
ASoC: SOF: Intel: hda: Make hdac_device device-managed
ASoC: hda: don't free hda_codec for HDA_DEV_ASOC type

 sound/pci/hda/hda_codec.c       | 8 +++++++-
 sound/soc/sof/intel/hda-codec.c | 6 ++----
 2 files changed, 9 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1
#4 lore raw
Quoted 11 lines · Takashi Iwai
Quoted 9 lines · Ranjani Sridharan

A recent commit "ALSA: hdac: fix memory release for SST and SOF drivers"
removed the kfree call for the hdac device in snd_hdac_ext_bus_device_exit(). This requires that the SOF driver also make the hdac_device and hdac_hda_priv device-managed so that they can be freed when the SOF module in unloaded. The first patch takes care of this change.

Quoted 8 lines
Quoted 5 lines

Additionally, because of the above change, the hda_codec is device-managed and freeing it in snd_hda_codec_dev_release() leads to kernel panic with module unload/reload stress tests. The second patch includes the change to avoid freeing hda_codec for ASoC driver.

In such a case, both patch need to be put into a single patch. Otherwise it leads to a bisection failure.

Thanks, Takashi. Just sent a v2 combining both the changes.

Thanks,
Ranjani

Quoted 27 lines

thanks,

Takashi

Quoted 5 lines

More details for the module unload/reload test failures can be found
here: https://github.com/thesofproject/linux/issues/966

Quoted 11 lines

Ranjani Sridharan (2):
ASoC: SOF: Intel: hda: Make hdac_device device-managed
ASoC: hda: don't free hda_codec for HDA_DEV_ASOC type

 sound/pci/hda/hda_codec.c       | 8 +++++++-
 sound/soc/sof/intel/hda-codec.c | 6 ++----
 2 files changed, 9 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel