ASoC: Intel: Skylake: Acquire irq after RIRB allocation
Subsystems (3)
PATCH 1/1 ASoC: Intel: Skylake: Acquire irq after RIRB allocation
Cold reboot stress test found that the hda irq could access rirb ring buffer before its memory gets allocated which resulting in null pointer dereference inside snd_hdac_bus_update_rirb().
Fix it by moving the skl_acquire_irq after ring buffer allocation. While here, also change err return from -EBUSY to actual error code.
--- sound/soc/intel/skylake/skl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
sound/soc/intel/skylake/skl.c +6 -4
@@ -838,11 +838,7 @@ static int skl_first_init(struct hdac_bus *bus)snd_hdac_bus_parse_capabilities (bus); -if (skl_acquire_irq (bus,0 ) <0 ) -return -EBUSY ; -pci_set_master (pci); -synchronize_irq (bus->irq); gcap =snd_hdac_chip_readw (bus,GCAP );dev_dbg (bus->dev,"chipset global capabilities = 0x%x\n" , gcap);
@@ -875,6 +871,12 @@ static int skl_first_init(struct hdac_bus *bus)if (err <0 )return err; + err =skl_acquire_irq (bus,0 ); +if (err <0 ) +return err; + +synchronize_irq (bus->irq); +/* initialize chip */ skl_init_pci (skl);
Signature · 1 line
2.7.4
Quoted 6 lines · Yong Zhi
Cold reboot stress test found that the hda irq could access rirb ring buffer before its memory gets allocated which resulting in null pointer dereference inside
snd_hdac_bus_update_rirb().Fix it by moving the
skl_acquire_irqafter ring buffer allocation. While here, also change err return from-EBUSYto actual error code.
I am not that familiar with PCI gory details but that patch was reviewed internally with no objections raised; there was also an agreement that the SOF driver would follow the same sequence, so
Quoted 36 lines
Signed-off-by Yong Zhi <[email protected]>--- sound/soc/intel/skylake/skl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)sound/soc/intel/skylake/skl.c +6
-4@@ -838,11 +838,7 @@ static int skl_first_init(struct hdac_bus *bus)snd_hdac_bus_parse_capabilities (bus); -if (skl_acquire_irq (bus,0 ) <0 ) -return -EBUSY ; -pci_set_master (pci); -synchronize_irq (bus->irq); gcap =snd_hdac_chip_readw (bus,GCAP );dev_dbg (bus->dev,"chipset global capabilities = 0x%x\n" , gcap);@@ -875,6 +871,12 @@ static int skl_first_init(struct hdac_bus *bus)if (err <0 )return err; + err =skl_acquire_irq (bus,0 ); +if (err <0 ) +return err; + +synchronize_irq (bus->irq); +/* initialize chip */ skl_init_pci (skl);
Quoted 6 lines · Pierre-Louis Bossart
Quoted 4 lines · Yong Zhi
Cold reboot stress test found that the hda irq could access rirb ring buffer before its memory gets allocated which resulting in null pointer dereference inside
snd_hdac_bus_update_rirb().
Quoted 8 lines
Quoted 2 lines
Fix it by moving the
skl_acquire_irqafter ring buffer allocation. While here, also change err return from-EBUSYto actual error code.I am not that familiar with PCI gory details but that patch was reviewed internally with no objections raised; there was also an agreement that the SOF driver would follow the same sequence, so
It's a standard idiom for a driver allocating a shared irq line. Because an irq may be issued by another device on the same line, the registered irq handler may be kicked off before the registers or whatever else is ready for use, eventually leading to some Oops.
The destructor is other way round; first free the irq handler, then release the rest resources.
Takashi
Quoted 39 lines
Quoted 23 lines
Signed-off-by Yong Zhi <[email protected]>--- sound/soc/intel/skylake/skl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)sound/soc/intel/skylake/skl.c +0
-3@@ -838,11 +838,7 @@ static int skl_first_init(struct hdac_bus *bus)snd_hdac_bus_parse_capabilities (bus); - if (skl_acquire_irq(bus, 0) < 0) - return -EBUSY; -pci_set_master (pci); -synchronize_irq (bus->irq); gcap =snd_hdac_chip_readw (bus,GCAP );dev_dbg (bus->dev,"chipset global capabilities = 0x%x\n" , gcap);@@ -875,6 +871,12 @@ static int skl_first_init(struct hdac_bus *bus)if (err <0 )sound/soc/intel/skylake/skl.c static int skl_first_init(struct hdac_bus *bus) · line 881
Quoted 10 lines
sound/soc/intel/skylake/skl.c +5
-0return err; + err =skl_acquire_irq (bus,0 ); +if (err <0 ) +return err; + +synchronize_irq (bus->irq); +/* initialize chip */ skl_init_pci (skl);_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Mark Brown
maintainerQuoted 6 lines · Takashi Iwai
Quoted 3 lines · Pierre-Louis Bossart
I am not that familiar with PCI gory details but that patch was reviewed internally with no objections raised; there was also an agreement that the SOF driver would follow the same sequence, so
Quoted 7 lines
It's a standard idiom for a driver allocating a shared irq line. Because an irq may be issued by another device on the same line, the registered irq handler may be kicked off before the registers or whatever else is ready for use, eventually leading to some Oops.
The destructor is other way round; first free the irq handler, then release the rest resources.
Right, it's nothing to do with PCI specifically. We even have a debug option in the kernel which will simulate the interrupt firing on potentially shared lines immediately on registering to try to catch such bugs.
Mark Brown
maintainerApplied "ASoC: Intel: Skylake: Acquire irq after RIRB allocation" to the asoc tree
In reply to Yong ZhiThe patch
ASoC: Intel: Skylake: Acquire irq after RIRB allocation
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
12eeeb4f4733bbc4481d01df35933fc15beb8b19Mon Sep 17 00:00:00 2001
From: Yong Zhi <[email protected]>
Date: Mon, 13 Aug 2018 18:15:14 -0500
Subject: [PATCH] ASoC: Intel: Skylake: Acquire irq after RIRB allocation
Cold reboot stress test found that the hda irq could access rirb ring buffer before its memory gets allocated which resulting in null pointer dereference inside snd_hdac_bus_update_rirb().
Fix it by moving the skl_acquire_irq after ring buffer allocation. While here, also change err return from -EBUSY to actual error code.
--- sound/soc/intel/skylake/skl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
sound/soc/intel/skylake/skl.c +6 -4
@@ -838,11 +838,7 @@ static int skl_first_init(struct hdac_bus *bus)snd_hdac_bus_parse_capabilities (bus); -if (skl_acquire_irq (bus,0 ) <0 ) -return -EBUSY ; -pci_set_master (pci); -synchronize_irq (bus->irq); gcap =snd_hdac_chip_readw (bus,GCAP );dev_dbg (bus->dev,"chipset global capabilities = 0x%x\n" , gcap);
@@ -875,6 +871,12 @@ static int skl_first_init(struct hdac_bus *bus)if (err <0 )return err; + err =skl_acquire_irq (bus,0 ); +if (err <0 ) +return err; + +synchronize_irq (bus->irq); +/* initialize chip */ skl_init_pci (skl);
Signature · 1 line
2.18.0