Skip to content

os/mm/mm_heap: Optimize alloc fail recovery operation. #6749

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ewoodev
Copy link
Contributor

@ewoodev ewoodev commented Apr 1, 2025

If security level is high, we must not print memory address and dumps. Therefore, we added secure state checking in mfdbg and head_dbg.

However, there are many memory dumps. Even if we add secure state checking to mfdbg adn heap_dbg, checking the secure state may cause delays in recovery when outputting every log lines.

Therefore, add to check secure state when the first alloc function is called, and if the secure state is active, do not call any memory printing.

@ewoodev ewoodev force-pushed the WORK-250401_add_check_condition_security_level_in_alloc_fail branch from 6771b56 to e04b96b Compare April 1, 2025 09:13
@@ -97,6 +99,18 @@ void mm_manage_alloc_fail(struct mm_heap_s *heap, int startidx, int endidx, size
{
irqstate_t flags = enter_critical_section();

/* If secure state, do not print memory usage and address infomation */
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need to move this after cpu pause (line 119)?

Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm... little bit duplicated and missing conditional.
How about below?

void mm_manage_alloc_fail(...)
{
    enter_critical_section();
    cpu pause all
    abort_mode = true;
    write reboot reason ();

    if (!IS_SECURE_STATE()) {   <---- only if is added, rest are existed codes.
       heap messages
    }

   cpu resume all
   panic();
   leave_critical_section();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't need to call cpu pause.
the cpu pause is for only log mixing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed duplicated code.

If security level is high, we must not print memory address and dumps.
Therefore, we added secure state checking in mfdbg and head_dbg.

However, there are many memory dumps. Even if we add secure state checking to
mfdbg adn heap_dbg, checking the secure state may cause delays in recovery
when outputting every log lines.

Therefore, add to check secure state when the first alloc function is called,
and if the secure state is active, do not call any memory printing.

Signed-off-by: eunwoo.nam <eunwoo.nam@samsung.com>
@ewoodev ewoodev force-pushed the WORK-250401_add_check_condition_security_level_in_alloc_fail branch from e04b96b to 738fc54 Compare April 2, 2025 06:51
@@ -109,12 +109,6 @@ void mm_manage_alloc_fail(struct mm_heap_s *heap, int startidx, int endidx, size
abort_mode = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

When the secure level is high, this is not called. Is it ok?
@r-prabu @kishore-sn Could you review this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure about it. With the secure state are we restricting only the console logs or log dump as well? If we are only restricting the console logs then will this change wont affect the logdump to these alloc fail logs?

Copy link
Contributor Author

@ewoodev ewoodev Apr 9, 2025

Choose a reason for hiding this comment

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

If security level is high, we don't print alloc fail log, so, we will call PANIC() immediately.
The setting abort_mode is in the up_assert().

Copy link
Contributor

Choose a reason for hiding this comment

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

327e46f

This is conflict with this commit. The variable has too many usages.

@kishore-sn @r-prabu @neel-samsung @ewoodev

Comment on lines +190 to +194
#ifdef CONFIG_DEBUG_MM_HEAPINFO
void mm_manage_alloc_fail(struct mm_heap_s *heap, int startidx, int endidx, size_t size, size_t align, int heap_type, mmaddress_t caller)
#else
void mm_manage_alloc_fail(struct mm_heap_s *heap, int startidx, int endidx, size_t size, size_t align, int heap_type)
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Regardless of this PR, how about using just one api?
When the config is disabled, we can give null or 0 for additional argu.

@r-prabu @kishore-sn How do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is a good suggestion so that maintainability will be easy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about raise new PR about this suggestion?

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.

3 participants