Repository navigation
buffer: prevent cache corruption #7808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| #include <sof/common.h> | ||
| #include <sof/platform.h> | ||
| #include <sof/ut.h> | ||
| #include <rtos/interrupt.h> | ||
| #include <limits.h> | ||
| #include <stdint.h> | ||
|
|
||
|
|
@@ -357,13 +358,17 @@ int module_adapter_prepare(struct comp_dev *dev) | |
| for (i = 0; i < mod->num_output_buffers; i++) { | ||
| struct comp_buffer *buffer = buffer_alloc(buff_size, SOF_MEM_CAPS_RAM, | ||
| 0, PLATFORM_DCACHE_ALIGN); | ||
| uint32_t flags; | ||
|
|
||
| if (!buffer) { | ||
| comp_err(dev, "module_adapter_prepare(): failed to allocate local buffer"); | ||
| ret = -ENOMEM; | ||
| goto free; | ||
| } | ||
|
|
||
| irq_local_disable(flags); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when turn off irq, means some or one of irq have negative impact with buffer_attach.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is needed because we're processing an IPC here and we might get interrupted by the scheduler, already running a pipeline to which we're attaching an additional source or sink.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does feel out-of-place in module_adapter.c level code. Given both IPC and pipeline are run in regular threads, we should be able to use plain mutex'es for exclusive access here. This would make it also userspace compatible for future-proofing this code. But maybe beyond this PR, especially given pipeline_connect() already does the IRQ enable/disable dance, so the same should be done here to be safe.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@kv2019i maybe mutexes would work too, but would take context switching:
So, this should work, but would involve a bunch of switching. If the protected area is small enough, locking interrupts should be simple enough. But if we shouldn't use priority calls, then we can use a mutex
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lyakh Ack. Let's revisit this when we introduce user-space, this is anyways not the only place where we have explicit irq control in the SOF audio code. |
||
| buffer_attach(buffer, &mod->sink_buffer_list, PPL_DIR_UPSTREAM); | ||
| irq_local_enable(flags); | ||
|
|
||
| buffer_c = buffer_acquire(buffer); | ||
| buffer_set_params(buffer_c, mod->stream_params, BUFFER_UPDATE_FORCE); | ||
|
|
@@ -398,8 +403,11 @@ int module_adapter_prepare(struct comp_dev *dev) | |
| list_for_item_safe(blist, _blist, &mod->sink_buffer_list) { | ||
| struct comp_buffer *buffer = container_of(blist, struct comp_buffer, | ||
| sink_list); | ||
| uint32_t flags; | ||
|
|
||
| irq_local_disable(flags); | ||
| buffer_detach(buffer, &mod->sink_buffer_list, PPL_DIR_UPSTREAM); | ||
| irq_local_enable(flags); | ||
| buffer_free(buffer); | ||
| } | ||
|
|
||
|
|
@@ -1185,8 +1193,11 @@ void module_adapter_free(struct comp_dev *dev) | |
| list_for_item_safe(blist, _blist, &mod->sink_buffer_list) { | ||
| struct comp_buffer *buffer = container_of(blist, struct comp_buffer, | ||
| sink_list); | ||
| uint32_t flags; | ||
|
|
||
| irq_local_disable(flags); | ||
| buffer_detach(buffer, &mod->sink_buffer_list, PPL_DIR_UPSTREAM); | ||
| irq_local_enable(flags); | ||
| buffer_free(buffer); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.