Skip to content

Conversation

@marcinszkudlinski
Copy link
Contributor

this is a fix for 38c4810

It may happen that virtual_heap_init would be called several times.
This commit prevents the heap for being re-initialized

this is a fix for 38c4810

It may happen that virtual_heap_init would be called
several times.
This commit prevents the heap for being re-initialized

Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
Copilot AI review requested due to automatic review settings July 8, 2025 11:23
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

A fix to avoid re-initializing the virtual heap when virtual_heap_init is called multiple times.

  • Adds a guard to only call vmh_init_heap on the first invocation
  • Ensures no error is reported on subsequent invocations if initialization succeeded

static int virtual_heap_init(void)
{
virtual_buffers_heap = vmh_init_heap(&static_hp_buffers, false);
if (!virtual_buffers_heap)
Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

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

This guard is not thread-safe; concurrent calls may still race and initialize the heap multiple times. Consider using a mutex or atomic compare-and-swap to ensure only one initialization occurs.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

false positive - calls to virtual_heap_init are serialized.

{ 524288, 1} /* buffer for kpb */
},
};

Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding a brief comment above this function explaining the one-time init guard and expected usage to improve maintainability.

Suggested change
/*
* Initializes the virtual heap if it has not already been initialized.
* The one-time initialization guard ensures that the heap is only
* initialized once during the system's lifetime. This function is
* registered as a SYS_INIT hook to run during the POST_KERNEL phase.
*/

Copilot uses AI. Check for mistakes.
static int virtual_heap_init(void)
{
virtual_buffers_heap = vmh_init_heap(&static_hp_buffers, false);
if (!virtual_buffers_heap)
Copy link
Member

Choose a reason for hiding this comment

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

false positive - calls to virtual_heap_init are serialized.

Copy link
Collaborator

@lyakh lyakh left a comment

Choose a reason for hiding this comment

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

sorry, don't understand. virtual_heap_init() is only called on initialisations from a SYS_INIT() abstraction. If such calls can indeed be called more than once, then we're misunderstanding how SYS_INIT() works and we have to review and possibly fix other its uses?

@marcinszkudlinski
Copy link
Contributor Author

@lyakh it is possible that we don't understand something... I did not check why it is called couple of times, just fixed a problem here that was causing regression.

@lgirdwood
Copy link
Member

lgirdwood commented Jul 10, 2025

@lyakh it is possible that we don't understand something... I did not check why it is called couple of times, just fixed a problem here that was causing regression.

Once per core ? So maybe the init flow needs more if (core == 0) in places.

@lyakh
Copy link
Collaborator

lyakh commented Jul 11, 2025

@lyakh it is possible that we don't understand something... I did not check why it is called couple of times, just fixed a problem here that was causing regression.

@marcinszkudlinski sorry, but this seems rather important. I think we should understand this. If it really can happen (be it once per core or anything else), then it's really important to know that to fix our other use-cases. If it cannot happen and you misinterpreted your test results, then we shouldn't add useless code that can only confuse the reader. Can you describe the conditions when you observed this being called multiple times?

@marcinszkudlinski
Copy link
Contributor Author

@lyakh absolutely we need to understand. And we need merge this PR ASAP - this problem is causing crashes in some scenarios

@lgirdwood
Copy link
Member

@lyakh absolutely we need to understand. And we need merge this PR ASAP - this problem is causing crashes in some scenarios

Agree - @marcinszkudlinski are you able to create a BUG to track, we can merge this now to WA issue until root cause is identified.
@lyakh good for you ?

@lgirdwood
Copy link
Member

@lyakh absolutely we need to understand. And we need merge this PR ASAP - this problem is causing crashes in some scenarios

Agree - @marcinszkudlinski are you able to create a BUG to track, we can merge this now to WA issue until root cause is identified. @lyakh good for you ?

Ping @marcinszkudlinski @lyakh do we have a fix or can we go with the WA today (and create a BUG) ?

@marcinszkudlinski
Copy link
Contributor Author

marcinszkudlinski commented Jul 16, 2025

@lgirdwood not really
Looks like I came to this fix because of some issues with incremental building. I double checked and compiled this twice - once as full compilation, second as incremental - and results are different...

We need to take a closer look to a build system

anyway - this PR is NOT fixing and issue. I'm marking it as DNM
And - there's no double call of the init function, so the bug is not needed

@marcinszkudlinski marcinszkudlinski changed the title fix: prevent virtual heap for multiple initialization [DNM] fix: prevent virtual heap for multiple initialization Jul 16, 2025
@lyakh
Copy link
Collaborator

lyakh commented Jul 17, 2025

@marcinszkudlinski should we close this or you want to re-use the PR with a different fix?

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.

4 participants