8000 Fix kernel stack pointer save on LoongArch64 (again) by AsakuraMizu · Pull Request #14 · arceos-org/axcpu · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix kernel stack pointer save on LoongArch64 (again) #14

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

Merged
merged 1 commit into from
Jul 15, 2025

Conversation

AsakuraMizu
Copy link
Contributor

Description

The fix proposed previously at 7152ea5 is wrong. next_ctx.sp, which is saved in the previous context_switch, is never the top of kernel stack.

This PR fixs this by porting oscomp/arceos#18.

Comparison

As said in arceos-org/arceos#229, the previous fix tried to take a similar approach to x86_64. But x86_64's TaskContext has a fixed kstack_top field, so this is correct.

I believe there is no need to reduce the times to save kernel sp on LoongArch64 since on x86_64 each save and load involves a memory operation but here we just read and write registers, which is the same way sscratch is used on RISC-V.

@equation314
Copy link
Member

next_ctx.sp, which is saved in the previous context_switch, is never the top of kernel stack.

What does this mean? The sp field in TaskContext is set to the top of kernel stack during initialization and will not be modified.

TaskContext has a fixed kstack_top field, so this is correct.

You mean the sp field in TaskContext is not fixed?

@AsakuraMizu
Copy link
Contributor Author

The sp field in TaskContext is set to the top of kernel stack during initialization and will not be modified.

It will be modified here:

mov x19, sp
mrs x20, tpidr_el0
stp x19, x20, [x0]

@equation314
Copy link
Member

You are right, I confused sp with the top of kernel stack.

@equation314 equation314 merged commit d2544fe into arceos-org:main Jul 15, 2025
6 checks passed
@AsakuraMizu AsakuraMizu deleted the fix/la-ksp branch July 16, 2025 06:48
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.

2 participants
0