From: Tianhao Wang <shrik3@mailbox.org>
newer arm64 archs add PAN (Privilege Access Never) bit in the pstate
which prevents the kernel (el1) from accessing user (el0) memory. Full
support is WIP. As a temporary workaround we simply clear the PAN in the
qkernel.
Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
---
qkernel/Cargo.toml | 4 ++++
qkernel/aarch64-qkernel.json | 2 +-
qlib/kernel/threadmgr/task_usermem.rs | 12 ++++++++++++
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/qkernel/Cargo.toml b/qkernel/Cargo.toml
index f28c3a0b..4ac8b53c 100644
--- a/qkernel/Cargo.toml
+++ b/qkernel/Cargo.toml
@@ -51,3 +51,7 @@ overflow-checks = false
lto = true
codegen-units = 1
debug-assertions = false
+
+[features]
+default = ["building_qkernel"]
+building_qkernel = []
diff --git a/qkernel/aarch64-qkernel.json b/qkernel/aarch64-qkernel.json
index 90c7a6ba..0f454583 100644
--- a/qkernel/aarch64-qkernel.json
+++ b/qkernel/aarch64-qkernel.json
@@ -10,7 +10,7 @@
"pre-link-args": {
"gcc": ["-m64", "-nostdlib", "-static"]
},
- "features": "+strict-align,-neon,-fp-armv8,+tpidr-el1",
+ "features": "+strict-align,-neon,-fp-armv8,+tpidr-el1,+pan",
"dynamic-linking": false,
"executables": false,
"relocation-model": "pic",
diff --git a/qlib/kernel/threadmgr/task_usermem.rs b/qlib/kernel/threadmgr/task_usermem.rs
index 91139e47..250cb656 100644
--- a/qlib/kernel/threadmgr/task_usermem.rs
+++ b/qlib/kernel/threadmgr/task_usermem.rs
@@ -536,6 +536,18 @@ impl MemoryManager {
}
pub fn Memcpy(dst: u64, src: u64, count: usize) {
+ #[cfg(feature="building_qkernel")]{
+ use crate::kernel_def::*;
+ let ua = enable_access_user();
+ unsafe {
+ let dstPtr = dst as *mut u8;
+ let srcPtr = src as *const u8;
+ debug!("VM: Memcpy - from:{:#x}; to:{:#x}.", src, dst);
+ core::ptr::copy_nonoverlapping(srcPtr, dstPtr, count);
+ }
+ set_access_user(ua);
+ return;
+ }
unsafe {
let dstPtr = dst as *mut u8;
let srcPtr = src as *const u8;
--
2.45.0