Skip to content

Commit f4611f6

Browse files
jxsteltersoftwarecki
authored andcommitted
module_adapter: Allocate data buffers from MMU shared heap
Allocates audio data buffer from shared memory heap. The security reqirements assume that the non-privileged modules data and code should be protected from other non-privileged modules access. The audio data could be accessible. This change is effective only when CONFIG_USERSPACE=y. Signed-off-by: Jaroslaw Stelter <Jaroslaw.Stelter@intel.com> Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent 420e804 commit f4611f6

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/audio/module_adapter/module_adapter.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ int module_adapter_prepare(struct comp_dev *dev)
210210
struct list_item *blist, *_blist;
211211
uint32_t buff_periods;
212212
uint32_t buff_size; /* size of local buffer */
213+
int memory_flags;
213214
int i = 0;
214215

215216
comp_dbg(dev, "module_adapter_prepare() start");
@@ -342,11 +343,11 @@ int module_adapter_prepare(struct comp_dev *dev)
342343

343344
module_adapter_check_data(mod, dev, sink);
344345

346+
memory_flags = user_get_buffer_memory_region(dev->drv);
345347
/* allocate memory for input buffers */
346348
if (mod->max_sources) {
347349
mod->input_buffers =
348-
rzalloc(SOF_MEM_FLAG_USER,
349-
sizeof(*mod->input_buffers) * mod->max_sources);
350+
rzalloc(memory_flags, sizeof(*mod->input_buffers) * mod->max_sources);
350351
if (!mod->input_buffers) {
351352
comp_err(dev, "failed to allocate input buffers");
352353
return -ENOMEM;
@@ -358,8 +359,7 @@ int module_adapter_prepare(struct comp_dev *dev)
358359
/* allocate memory for output buffers */
359360
if (mod->max_sinks) {
360361
mod->output_buffers =
361-
rzalloc(SOF_MEM_FLAG_USER,
362-
sizeof(*mod->output_buffers) * mod->max_sinks);
362+
rzalloc(memory_flags, sizeof(*mod->output_buffers) * mod->max_sinks);
363363
if (!mod->output_buffers) {
364364
comp_err(dev, "failed to allocate output buffers");
365365
ret = -ENOMEM;
@@ -425,7 +425,7 @@ int module_adapter_prepare(struct comp_dev *dev)
425425
list_for_item(blist, &dev->bsource_list) {
426426
size_t size = MAX(mod->deep_buff_bytes, mod->period_bytes);
427427

428-
mod->input_buffers[i].data = rballoc(SOF_MEM_FLAG_USER, size);
428+
mod->input_buffers[i].data = rballoc(memory_flags, size);
429429
if (!mod->input_buffers[i].data) {
430430
comp_err(mod->dev, "Failed to alloc input buffer data");
431431
ret = -ENOMEM;
@@ -437,7 +437,7 @@ int module_adapter_prepare(struct comp_dev *dev)
437437
/* allocate memory for output buffer data */
438438
i = 0;
439439
list_for_item(blist, &dev->bsink_list) {
440-
mod->output_buffers[i].data = rballoc(SOF_MEM_FLAG_USER, md->mpd.out_buff_size);
440+
mod->output_buffers[i].data = rballoc(memory_flags, md->mpd.out_buff_size);
441441
if (!mod->output_buffers[i].data) {
442442
comp_err(mod->dev, "Failed to alloc output buffer data");
443443
ret = -ENOMEM;
@@ -450,7 +450,7 @@ int module_adapter_prepare(struct comp_dev *dev)
450450
if (list_is_empty(&mod->raw_data_buffers_list)) {
451451
for (i = 0; i < mod->num_of_sinks; i++) {
452452
/* allocate not shared buffer */
453-
struct comp_buffer *buffer = buffer_alloc(buff_size, SOF_MEM_FLAG_USER,
453+
struct comp_buffer *buffer = buffer_alloc(buff_size, memory_flags,
454454
PLATFORM_DCACHE_ALIGN, false);
455455
uint32_t flags;
456456

src/include/sof/audio/component.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,4 +1194,12 @@ void comp_init_performance_data(struct comp_dev *dev);
11941194
*/
11951195
bool comp_update_performance_data(struct comp_dev *dev, uint32_t cycles_used);
11961196

1197+
static inline int user_get_buffer_memory_region(const struct comp_driver* drv)
1198+
{
1199+
#if CONFIG_USERSPACE
1200+
return drv->user_heap ? SOF_MEM_FLAG_USER_SHARED_BUFFER : SOF_MEM_FLAG_USER;
1201+
#else
1202+
return SOF_MEM_FLAG_USER;
1203+
#endif
1204+
}
11971205
#endif /* __SOF_AUDIO_COMPONENT_H__ */

0 commit comments

Comments
 (0)