Skip to content

Conversation

@marcinszkudlinski
Copy link
Contributor

@marcinszkudlinski marcinszkudlinski commented Jul 30, 2025

This PR does 2 things:

  • removes MEM_REG_ATTR_SHARED_HEAP, add function stubs and - to allow merging changes to zephyr
  • forces buffers location in the very first memory region. This is required because of conflict of virtual addresses with loadable modules in case the platform has 5 cores

@marcinszkudlinski
Copy link
Contributor Author

Internal CI was green before update

I needed to add a commit allowing SOF to work without and with zephyr changes from zephyrproject-rtos/zephyr#93334

This PR forces buffers location in the very first memory region,
preventing from conflict of  virtual addresses with loadable modules
in case of 5 cores platforms

Signed-off-by: Marcin Szkudlinski <[email protected]>
@marcinszkudlinski
Copy link
Contributor Author

...and incorrect commit description fix

Please review and merge ASAP

@marcinszkudlinski marcinszkudlinski marked this pull request as ready for review July 30, 2025 11:25
Copilot AI review requested due to automatic review settings July 30, 2025 11:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a workaround to resolve virtual address conflicts with loadable modules on 5-core platforms by removing dependency on MEM_REG_ATTR_SHARED_HEAP and forcing buffer allocation in the first memory region.

  • Removes the search for MEM_REG_ATTR_SHARED_HEAP regions and uses the first available virtual memory region instead
  • Adds weak function stubs for future Zephyr integration compatibility
  • Introduces a new configuration option for virtual heap region size

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
zephyr/lib/regions_mm.c Replaces heap region search logic with direct assignment to first virtual memory region
zephyr/lib/alloc.c Adds weak stubs and virtual memory region initialization logic
zephyr/include/sof/lib/regions_mm.h Defines new attribute constant for shared heap regions
zephyr/Kconfig Adds configuration option for virtual heap region size

#include <sof/audio/pipeline.h>
#include <sof/audio/component_ext.h>
#include <sof/trace/trace.h>
#include <zephyr/drivers/mm/mm_drv_intel_adsp_mtl_tlb.h>
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Including a platform-specific driver header in generic allocation code reduces portability. Consider moving this include to a platform-specific file or using a more generic interface.

Suggested change
#include <zephyr/drivers/mm/mm_drv_intel_adsp_mtl_tlb.h>
// Platform-specific header moved to a dedicated file for Intel ADSP MTL-specific logic.

Copilot uses AI. Check for mistakes.
},
};

/* WA Stubs begin
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The abbreviation 'WA' should be spelled out as 'Workaround' for clarity in the comment.

Suggested change
/* WA Stubs begin
/* Workaround Stubs begin

Copilot uses AI. Check for mistakes.
{
return 0;
}
/* WA Stubs end */
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The abbreviation 'WA' should be spelled out as 'Workaround' for clarity in the comment.

Suggested change
/* WA Stubs end */
/* Workaround Stubs end */

Copilot uses AI. Check for mistakes.
Comment on lines +298 to +303

__weak
uintptr_t adsp_mm_get_unused_l2_start_aligned(void)
{
return 0;
}

Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The weak stub function lacks documentation explaining its purpose, expected behavior when the real implementation is available, and return value meaning.

Suggested change
__weak
uintptr_t adsp_mm_get_unused_l2_start_aligned(void)
{
return 0;
}
/**
* @brief Weak stub for retrieving the start address of unused L2 memory, aligned.
*
* This function is a placeholder and should be overridden by a platform-specific
* implementation. It is expected to return the starting address of unused L2 memory,
* aligned to the required boundary.
*
* @return uintptr_t The aligned start address of unused L2 memory. Returns 0 if
* no implementation is provided.
*/
__weak
uintptr_t adsp_mm_get_unused_l2_start_aligned(void)
{
return 0;
}
/**
* @brief Weak stub for adding a virtual memory region.
*
* This function is a placeholder and should be overridden by a platform-specific
* implementation. It is expected to add a virtual memory region with the specified
* address, size, and attributes.
*
* @param region_address The starting address of the virtual memory region.
* @param region_size The size of the virtual memory region in bytes.
* @param attr Attributes for the virtual memory region (e.g., access permissions).
*
* @return int Returns 0 if successful, or an error code if the operation fails.
*/

Copilot uses AI. Check for mistakes.
{
return 0;
}

Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The weak stub function lacks documentation explaining its parameters, return values, and expected behavior when the real implementation becomes available.

Suggested change
/**
* @brief Add a virtual memory region to the system.
*
* This weak stub function is a placeholder for adding a virtual memory region.
* It is expected to be overridden by a real implementation in the future.
*
* @param region_address The starting address of the memory region.
* @param region_size The size of the memory region in bytes.
* @param attr Attributes for the memory region (e.g., access permissions).
*
* @return 0 on success, or an error code indicating failure.
*/

Copilot uses AI. Check for mistakes.
This commit add creation of virtual memory region for heap
Called functions are not yet present in Zephyr (Zephyr is creating
regions by itself now), so the commit also contains weaked aliases
of zephyr functions.

Signed-off-by: Marcin Szkudlinski <[email protected]>
@marcinszkudlinski
Copy link
Contributor Author

fix for compilation when CONFIG_VIRTUAL_HEAP=0 (TGL)

* @retval ptr to a new heap if successful.
* @retval NULL on creation failure.
*/
struct vmh_heap *vmh_init_heap(const struct vmh_heap_config *cfg, bool allocating_continuously)
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you please explain - do you mean that VMH and LLEXT attempt to use the same addresses on PTL? Don't we have enough address space, cannot we just adjust CONFIG_LIBRARY_BASE_ADDRESS?

Copy link
Contributor Author

@marcinszkudlinski marcinszkudlinski Jul 31, 2025

Choose a reason for hiding this comment

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

sure it would work too. Yet I also want to make the whole system more resistant to such problem in a future, and this commit is making 2 steps at the same time - 1) a workaround 2) removing circular dependency from Zephyr.
Both can be done by getting the 1st range from the table with no questions ask, and than - when Zephyr is ready - creating zones by call from SOF (instead of hard-coded zones in Zephyr as it is now) and checking if any mapping fits into dedicated zone.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@marcinszkudlinski well, I was just wondering - why create a somewhat complicated workaround to be later replaced with a proper solution, if we can fix the problem by just changing an address in platform configuration, while also still working on a proper solution

Copy link
Contributor Author

@marcinszkudlinski marcinszkudlinski Jul 31, 2025

Choose a reason for hiding this comment

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

  1. removing circular dependency from Zephyr.

Currently I cannot merge "proper solution" to Zephyr

https://github.com/zephyrproject-rtos/zephyr/actions/runs/16593737908/job/46935880948?pr=93334

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ack @marcinszkudlinski . So it would this is the way to go, this PR removes MEM_REG_ATTR_CORE_HEAP, Marcin can update SOF in Zephyr manifest, then do the change in Zephyr (zephyrproject-rtos/zephyr#93334), and then update Zephyr in SOF. Good to go @lyakh ? We have failures in quickbuild as long as we have this open.

@marcinszkudlinski
Copy link
Contributor Author

can we proceed? This defect is blocking PTL CI

@lgirdwood lgirdwood merged commit 4f1980c into thesofproject:main Jul 31, 2025
36 of 45 checks passed
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