Skip to content
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

Core: add platform abort handler + stm32 SERC usage #7253

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

GseoC
Copy link
Contributor

@GseoC GseoC commented Jan 30, 2025

Implement a platform abort handler to handle use cases such as data aborts generated by peripherals on the bus.

These kinds of abort could be caused by platform-specific features, hence the weak function.

core/include/kernel/abort.h Show resolved Hide resolved
@@ -555,6 +560,8 @@ void abort_handler(uint32_t abort_type, struct thread_abort_regs *regs)

switch (get_fault_type(&ai)) {
case FAULT_TYPE_IGNORE:
/* Allow platform-specific handling */
plat_abort_handler(regs);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not so keen on adding hooks that the compiler can't optimize away if unused.
How about using a config variable so the function call can be optimized away if not needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok for using a config switch, how about CFG_EXTERNAL_ABORT_PLAT_HANDLER,

/* Print abort info + stack dump to the console */
void abort_print_error(struct abort_info *ai);

void abort_handler(uint32_t abort_type, struct thread_abort_regs *regs);

/* Platform overload, should be implemented in platform code */
void plat_abort_handler(struct thread_abort_regs *regs);
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it only external aborts we care about here? If so, how about plat_external_abort_handler()?
This function should probably take a struct abort_info *ai argument instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is about external aborts. Maybe we can even restrain the call to platform code on external aborts that are not table walks or table updates?
I'm fine with your suggestions

@@ -555,6 +560,8 @@ void abort_handler(uint32_t abort_type, struct thread_abort_regs *regs)

switch (get_fault_type(&ai)) {
case FAULT_TYPE_IGNORE:
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add a FAULT_TYPE_EXTERNAL_ABORT if we need special treatment for external aborts.

Copy link
Contributor Author

@GseoC GseoC Jan 31, 2025

Choose a reason for hiding this comment

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

Ok so that type of fault should be returned when encountering CORE_MMU_FAULT_ASYNC_EXTERNAL if asynchronous and create another CORE_MMU_FAULT_SYNC_EXTERNAL then?

I think we also miss the synchronous external abort cases, looking at the documentation for AARCH64: "Synchronous External abort, not on translation tablewalk or hardware update of translation table." is 0x10 in FSR.

So 0x10 and 0x12->0x17 are all external aborts. We miss these descriptions in core/arch/arm/include/arm64.h

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I suppose it can be useful to tell synchronous and asynchronous extern aborts apart.

@GseoC
Copy link
Contributor Author

GseoC commented Jan 31, 2025

Updated with comments addressed.

I'm having thoughts on the sharing of bindings between AARCH64 ESR_FSC_x and AARCH32 DFSR because it's supposed to to be architecturally mapped. Please let me know what you think of it as it is now.

core/include/drivers/stm32_serc.h Outdated Show resolved Hide resolved
core/include/drivers/stm32_serc.h Outdated Show resolved Hide resolved
core/arch/arm/kernel/abort.c Outdated Show resolved Hide resolved
void __weak plat_abort_handler(struct abort_info *ai __unused)
{
/* Do nothing */
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this weak function needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For whatever reason, if the switch is enabled and the function is not defined? Given that the switch is intended for this purpose, I think there is indeed no need for this weak function.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the switch is enabled, the platform should implement the handler. Having a build error is a nice way to trigger that it's missing IMO.

/* Print abort info + stack dump to the console */
void abort_print_error(struct abort_info *ai);

void abort_handler(uint32_t abort_type, struct thread_abort_regs *regs);

/* Platform overload, should be implemented in platform code */
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explicitly mention CFG_EXTERNAL_ABORT_PLAT_HANDLER must be enabled to have the platform handler be called. I think the function label should explicitly mention _external_abort_ if called only for external aborts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, will change to that

GseoC added 6 commits February 6, 2025 13:11
Platforms may have specific code to handle an abort  when fault type
is FAULT_TYPE_IGNORE. Add plat_abort_handler() that can be overridden
at platform level.

Signed-off-by: Gatien Chevallier <[email protected]>
When a data abort occurs and its fault type is FAULT_TYPE_IGNORE, it
may be an abort generated by the SERC hardware block. Check if a
SERC Illegal Access was caught and print the SERC register and panic()
if that is the case.

Signed-off-by: Gatien Chevallier <[email protected]>
Differentiate Async/Sync external aborts, create a new fault type and
introduce CFG_EXTERNAL_ABORT_PLAT_HANDLER switch.

Signed-off-by: Gatien Chevallier <[email protected]>
Synchronize with the updates of the other patch.

Signed-off-by: Gatien Chevallier <[email protected]>
Type fixes and rename to plat_external_abort_handler

Signed-off-by: Gatien Chevallier <[email protected]>
Copyright fix and use renamed function.

Signed-off-by: Gatien Chevallier <[email protected]>
@GseoC GseoC changed the title (RFC)Core: add platform abort handler + stm32 SERC usage Core: add platform abort handler + stm32 SERC usage Feb 7, 2025
@GseoC
Copy link
Contributor Author

GseoC commented Feb 7, 2025

Removed "RFC" from the P-R title, comments addressed

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