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

fix: modify the maintenance of host sp_el0 #15

Merged
merged 4 commits into from
Sep 20, 2024
Merged

fix: modify the maintenance of host sp_el0 #15

merged 4 commits into from
Sep 20, 2024

Conversation

hky1999
Copy link
Contributor

@hky1999 hky1999 commented Sep 13, 2024

BUG decription

There is a bug in current solution of the maintenance of SP_EL0 belonging to host ArceOS, which is used to store the current task pointer.

That is, we save the host's sp_el0 in a wrong place: after restore_vm_system_regs, where guest's sp_el0 is already write to sp_el0 register.

As a result, host save a polluted sp_el0, which is already modified by restore_vm_system_regs.

It will cause a panic when you try to get current task’s pointer during VM-Exit handling.

[  0.467056 0 axruntime::lang_items:5] panicked at /home/hky/.cargo/git/checkouts/arceos-8d7257a02b016867/d4cf00a/modules/axtask/src/task.rs:385:25:
current task is uninitialized

Solution

use percpu region to maintain the correct SP_EL0 belonging to host ArceOS.

#[percpu::def_percpu]
static HOST_SP_EL0: u64 = 0;

fn save_host_sp_el0() {
    unsafe { HOST_SP_EL0.write_current_raw(SP_EL0.get()) }
}

fn restore_host_sp_el0() {
    SP_EL0.set(unsafe { HOST_SP_EL0.read_current_raw() });
}

@hky1999 hky1999 requested a review from aarkegz September 13, 2024 15:51
@hky1999
Copy link
Contributor Author

hky1999 commented Sep 14, 2024

@aarkegz Please check this PR.
@guoweikang I think its more proper to store current SP_EL0 in percpu area.

aarkegz
aarkegz previously approved these changes Sep 20, 2024
@hky1999
Copy link
Contributor Author

hky1999 commented Sep 20, 2024

@hky1999 hky1999 merged commit ac0a9e9 into master Sep 20, 2024
4 checks passed
@aarkegz aarkegz deleted the fix_sp_el0 branch October 15, 2024 11:16
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