Skip to content

ASoC: SOF: Intel: hda-dsp: Make sure that no irq handler is pending b… - #4617

Merged
plbossart merged 1 commit into
thesofproject:topic/sof-devfrom
ujfalusi:peter/sof/pr/hda-dsp-wait-for-irq-01
Oct 9, 2023
Merged

plbossart merged 1 commit into
thesofproject:topic/sof-devfrom
ujfalusi:peter/sof/pr/hda-dsp-wait-for-irq-01

Conversation

@ujfalusi

@ujfalusi ujfalusi commented Oct 5, 2023

Copy link
Copy Markdown
Collaborator

…efore suspend

It has been observed on an experimental (iow, buggy) kernel that the irq thread got delayed by several seconds after the primary handler returned with IRQ_WAKE_THREAD when sending the last IPC message before powering down the DSP.

While the bug which causes the delay is not in the audio stack, we must handle such cases nevertheless without a risk of crashing the kernel due to access to registers of a powered down IP.

Call synchronize_irq() before proceeding to power down the DSP to make sure that no irq thread is pending execution.

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @ujfalusi, exactly what we needed.

I only have a couple of comments on the commit message to make the upstream part easier.


/* make sure that no irq handler is pending before shutdown */
synchronize_irq(sdev->ipc_irq);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-picks on commit message

  • no mention of a crash
  • double negative "nevertheless without"
  • Need "Closes" tag

suggested edit:

In the existing IPC support, the reply to each IPC message is handled in an IRQ thread. The assumption is that the IRQ thread is scheduled without significant delays.

On an experimental (iow, buggy) kernel, the IRQ thread dealing with the reply to the last IPC message before powering-down the DSP can be delayed by several seconds. The IRQ thread will proceed with register accesses after the DSP is powered-down which results in a kernel crash.

While the bug which causes the delay is not in the audio stack, we must
handle such cases with defensive programming to avoid such crashes.

Call synchronize_irq() before proceeding to power down the DSP to make
sure that no irq thread is pending execution.

Closes: #4608 (check this is the relevant issue).

…efore suspend

In the existing IPC support, the reply to each IPC message is handled in
an IRQ thread. The assumption is that the IRQ thread is scheduled without
significant delays.

On an experimental (iow, buggy) kernel, the IRQ thread dealing with the
reply to the last IPC message before powering-down the DSP can be delayed
by several seconds. The IRQ thread will proceed with register accesses
after the DSP is powered-down which results in a kernel crash.

While the bug which causes the delay is not in the audio stack, we must
handle such cases with defensive programming to avoid such crashes.

Call synchronize_irq() before proceeding to power down the DSP to make
sure that no irq thread is pending execution.

Closes: thesofproject#4608
Signed-off-by: Peter Ujfalusi <[email protected]>
@ujfalusi
ujfalusi force-pushed the peter/sof/pr/hda-dsp-wait-for-irq-01 branch from b786eb2 to e375efc Compare October 5, 2023 15:57
@ujfalusi

ujfalusi commented Oct 5, 2023

Copy link
Copy Markdown
Collaborator Author

Changes since v1:

  • commit message updated as per @plbossart suggestion, thank you.

@plbossart

Copy link
Copy Markdown
Member

@macchian

macchian commented Oct 6, 2023

Copy link
Copy Markdown

the patch has ran overnight test. I don't see "ipc timed out" in logs. It could be no irq pending or synchronize_irq clean up correctly. @ujfalusi, could you check the device. I chould stop it for your remote access.

@ujfalusi

ujfalusi commented Oct 6, 2023

Copy link
Copy Markdown
Collaborator Author

need to verify if https://sof-ci.01.org/linuxpr/PR4617/build6896/devicetest/index.html?model=GLK_BOB_DA7219&testcase=check-kmod-load-unload is reproducible, this looks suspicious.

This patch is not affecting the module removal, the hda_suspend() is not called.
but suspicious, I''l check on up2 locally

@ujfalusi

ujfalusi commented Oct 6, 2023

Copy link
Copy Markdown
Collaborator Author

the patch has ran overnight test. I don't see "ipc timed out" in logs. It could be no irq pending or synchronize_irq clean up correctly. @ujfalusi, could you check the device. I chould stop it for your remote access.

@macchian, no show of "IPC timeout" is a sign that the very thing this workaround is fixing is not happening, the irq thread is called in time and thus we don't have timeout, this when we enter hda_suspend() there is no pending interrupts to wait for.

Thank you for testing!

@marc-hb

marc-hb commented Oct 9, 2023 •

Copy link
Copy Markdown
Collaborator

While the bug which causes the delay is not in the audio stack, we must
handle such cases with defensive programming to avoid such crashes.

I'm curious whether synchronize_irq(sdev->ipc_irq); notices the extraordinary delay and logs it with an ERROR message or just hides the bug.

EDIT: also, is it easy to locally delay a specific IRQ for testing?

@ujfalusi

ujfalusi commented Oct 9, 2023

Copy link
Copy Markdown
Collaborator Author

While the bug which causes the delay is not in the audio stack, we must
handle such cases with defensive programming to avoid such crashes.

I'm curious whether synchronize_irq(sdev->ipc_irq); notices the extraordinary delay and logs it with an ERROR message or just hides the bug.

No, it is lot logging 'extraordinary delays' but we are going to see the IPC timeout printed in the kernel log.
This patch is to fix the page fault by handling of the improbable.
I have patches to handle the last or all IPC replies in primary handler, that will fix the IPC timeout but it is intrusive to say the least. The question is: do we want to have extensive changes to tackle a broken kernel? I mean, that bug has to be fixed, it is not acceptable under any circumstances that the irq thread is blocked for ages.

EDIT: also, is it easy to locally delay a specific IRQ for testing?

Yes and I did lot of testing like that to test out different timing and execution orders.

@plbossart
plbossart merged commit 876835f into thesofproject:topic/sof-dev Oct 9, 2023
@marc-hb

marc-hb commented Oct 9, 2023

Copy link
Copy Markdown
Collaborator

The question is: do we want to have extensive changes to tackle a broken kernel?

"Extensive" changes, no. I was hoping an ERROR message would already be there or not require much change.

I mean, that bug has to be fixed, it is not acceptable under any circumstances that the irq thread is blocked for ages.

Yes of course but it'll never be fixed if it's never caught.

but we are going to see the IPC timeout printed in the kernel log.

As long as this is at the ERROR level then it will be caught and reported and everything is fine.

@ujfalusi
ujfalusi deleted the peter/sof/pr/hda-dsp-wait-for-irq-01 branch December 13, 2024 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants