Skip to content

Commit

Permalink
Merge branch 'DragonOS-Community:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
laokengwt authored Apr 22, 2024
2 parents 48850e5 + e32effb commit a193330
Show file tree
Hide file tree
Showing 40 changed files with 2,886 additions and 461 deletions.
62 changes: 62 additions & 0 deletions .github/issue-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
default-mode:
add:
remove: [pull_request_target, issues]
labels:
# skips and removes
- name: skip all
content:
regexes: '[Ss]kip (?:[Aa]ll |)[Ll]abels?'
- name: remove all
content:
regexes: '[Rr]emove (?:[Aa]ll |)[Ll]abels?'
- name: skip ambiguous
content:
regexes: '[Ss]kip (?:[Ll]abels? |)(?:`|)ambiguous(?:`|)'
- name: remove ambiguous
content:
regexes: '[Rr]emove (?:[Ll]abels? |)(?:`|)ambiguous(?:`|)'
# `feature`
- name: enhance
content: enhancement
regexes: '[Ff]eat(?:\([a-zA-Z]*\))?[\:\.\,]'
skip-if:
- skip all
remove-if:
- remove all
# `Bug fix`
- name: bug-fix
content: Bug fix
regexes: '[Ff]ix(?:\([a-zA-Z]*\))?[\:\.\,]'
skip-if:
- skip all
remove-if:
- remove all
# `document`
- name: doc
content: documentation
regexes: '[Dd]ocs(?:\([a-zA-Z]*\))?[\:\.\,]'
skip-if:
- skip all
remove-if:
- remove all
# `test`
- name: test
content: test
regexes: '[Tt]est(?:\([a-zA-Z]*\))?[\:\.\,]'
skip-if:
- skip all
remove-if:
- remove all
# `ambiguous`
- name: pr-ambiguous
# 不符合 commitizen 的 PR
content: ambiguous
regexes: '^(?!(?:build|chore|ci|docs?|feat|fix|perf|refactor|rft|style|test)(?:\([a-zA-Z]*\))?[\:\.\(\,]|[Rr]evert|[Rr]elease)'
mode:
pull_request_target:
skip-if:
- skip all
- skip ambiguous
remove-if:
- remove all
- remove ambiguous
24 changes: 24 additions & 0 deletions .github/workflows/issue-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "Issue Checker"
on:
issues:
types: [opened, edited]
pull_request_target:
types: [opened, edited]
issue_comment:
types: [created, edited]

permissions:
contents: read
issues: write
pull-requests: write

jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: zzyyyl/[email protected]
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: .github/issue-checker.yml
not-before: 2024-04-20T00:00:00Z
include-title: 1
1 change: 1 addition & 0 deletions kernel/crates/klog_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ pub enum AllocatorLogType {
Alloc(AllocLogItem),
AllocZeroed(AllocLogItem),
Free(AllocLogItem),
LazyAlloc(AllocLogItem),
}

#[repr(C)]
Expand Down
17 changes: 15 additions & 2 deletions kernel/src/arch/riscv64/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ pub(self) static INNER_ALLOCATOR: SpinLock<Option<BuddyAllocator<MMArch>>> = Spi
pub struct RiscV64MMArch;

impl RiscV64MMArch {
pub const ENTRY_FLAG_GLOBAL: usize = 1 << 5;

/// 使远程cpu的TLB中,指定地址范围的页失效
pub fn remote_invalidate_page(
cpu: ProcessorId,
Expand Down Expand Up @@ -85,6 +83,9 @@ const KERNEL_TOP_PAGE_ENTRY_NO: usize = (RiscV64MMArch::PHYS_OFFSET
>> (RiscV64MMArch::ENTRY_ADDRESS_SHIFT - RiscV64MMArch::PAGE_ENTRY_SHIFT);

impl MemoryManagementArch for RiscV64MMArch {
/// riscv64暂不支持缺页中断
const PAGE_FAULT_ENABLED: bool = false;

const PAGE_SHIFT: usize = 12;

const PAGE_ENTRY_SHIFT: usize = 9;
Expand Down Expand Up @@ -119,6 +120,7 @@ impl MemoryManagementArch for RiscV64MMArch {
const ENTRY_FLAG_EXEC: usize = (1 << 3);
const ENTRY_FLAG_ACCESSED: usize = (1 << 6);
const ENTRY_FLAG_DIRTY: usize = (1 << 7);
const ENTRY_FLAG_GLOBAL: usize = (1 << 5);

const PHYS_OFFSET: usize = 0xffff_ffc0_0000_0000;
const KERNEL_LINK_OFFSET: usize = 0x1000000;
Expand All @@ -139,6 +141,8 @@ impl MemoryManagementArch for RiscV64MMArch {
/// 设置1g的MMIO空间
const MMIO_SIZE: usize = 1 << PAGE_1G_SHIFT;

const ENTRY_FLAG_HUGE_PAGE: usize = Self::ENTRY_FLAG_PRESENT | Self::ENTRY_FLAG_READWRITE;

#[inline(never)]
unsafe fn init() {
riscv_mm_init().expect("init kernel memory management architecture failed");
Expand Down Expand Up @@ -239,6 +243,15 @@ impl MemoryManagementArch for RiscV64MMArch {
let r = ((ppn & ((1 << 54) - 1)) << 10) | page_flags;
return r;
}

fn vma_access_permitted(
_vma: alloc::sync::Arc<crate::mm::ucontext::LockedVMA>,
_write: bool,
_execute: bool,
_foreign: bool,
) -> bool {
true
}
}

impl VirtAddr {
Expand Down
6 changes: 3 additions & 3 deletions kernel/src/arch/x86_64/driver/apic/x2apic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use x86::msr::{
IA32_X2APIC_VERSION,
};

use crate::{kdebug, kinfo};
use crate::kinfo;

use super::{hw_irq::ApicId, LVTRegister, LocalAPIC, LVT};

Expand Down Expand Up @@ -55,9 +55,9 @@ impl LocalAPIC for X2Apic {
kinfo!("x2APIC EOI broadcast suppression enabled.");
}
}
kdebug!("x2apic: to mask all lvt");
// kdebug!("x2apic: to mask all lvt");
self.mask_all_lvt();
kdebug!("x2apic: all lvt masked");
// kdebug!("x2apic: all lvt masked");
}
true
}
Expand Down
131 changes: 96 additions & 35 deletions kernel/src/arch/x86_64/interrupt/trap.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use system_error::SystemError;

use crate::{
arch::CurrentIrqArch, exception::InterruptArch, kerror, kwarn, mm::VirtAddr, print,
process::ProcessManager, smp::core::smp_get_processor_id,
arch::{CurrentIrqArch, MMArch},
exception::InterruptArch,
kerror, kwarn,
mm::VirtAddr,
process::ProcessManager,
smp::core::smp_get_processor_id,
};

use super::{
Expand Down Expand Up @@ -33,6 +37,46 @@ extern "C" {
fn trap_virtualization_exception();
}

bitflags! {
pub struct TrapNr: u64 {
const X86_TRAP_DE = 0;
const X86_TRAP_DB = 1;
const X86_TRAP_NMI = 2;
const X86_TRAP_BP = 3;
const X86_TRAP_OF = 4;
const X86_TRAP_BR = 5;
const X86_TRAP_UD = 6;
const X86_TRAP_NM = 7;
const X86_TRAP_DF = 8;
const X86_TRAP_OLD_MF = 9;
const X86_TRAP_TS = 10;
const X86_TRAP_NP = 11;
const X86_TRAP_SS = 12;
const X86_TRAP_GP = 13;
const X86_TRAP_PF = 14;
const X86_TRAP_SPURIOUS = 15;
const X86_TRAP_MF = 16;
const X86_TRAP_AC = 17;
const X86_TRAP_MC = 18;
const X86_TRAP_XF = 19;
const X86_TRAP_VE = 20;
const X86_TRAP_CP = 21;
const X86_TRAP_VC = 29;
const X86_TRAP_IRET = 32;
}

pub struct X86PfErrorCode : u32{
const X86_PF_PROT = 1 << 0;
const X86_PF_WRITE = 1 << 1;
const X86_PF_USER = 1 << 2;
const X86_PF_RSVD = 1 << 3;
const X86_PF_INSTR = 1 << 4;
const X86_PF_PK = 1 << 5;
const X86_PF_SHSTK = 1 << 6;
const X86_PF_SGX = 1 << 15;
}
}

#[inline(never)]
pub fn arch_trap_init() -> Result<(), SystemError> {
unsafe {
Expand Down Expand Up @@ -319,42 +363,59 @@ Segment Selector Index: {:#x}\n
/// 处理页错误 14 #PF
#[no_mangle]
unsafe extern "C" fn do_page_fault(regs: &'static TrapFrame, error_code: u64) {
kerror!(
"do_page_fault(14), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}, \nFault Address: {:#x}",
error_code,
regs.rsp,
regs.rip,
smp_get_processor_id().data(),
ProcessManager::current_pid(),
x86::controlregs::cr2()
);

if (error_code & 0x01) == 0 {
print!("Page Not Present,\t");
}
if (error_code & 0x02) != 0 {
print!("Write Access,\t");
} else {
print!("Read Access,\t");
}

if (error_code & 0x04) != 0 {
print!("Fault in user(3),\t");
// kerror!(
// "do_page_fault(14), \tError code: {:#x},\trsp: {:#x},\trip: {:#x},\t CPU: {}, \tpid: {:?}, \nFault Address: {:#x}",
// error_code,
// regs.rsp,
// regs.rip,
// smp_get_processor_id().data(),
// ProcessManager::current_pid(),
// x86::controlregs::cr2()
// );

// if (error_code & 0x01) == 0 {
// print!("Page Not Present,\t");
// }
// if (error_code & 0x02) != 0 {
// print!("Write Access,\t");
// } else {
// print!("Read Access,\t");
// }

// if (error_code & 0x04) != 0 {
// print!("Fault in user(3),\t");
// } else {
// print!("Fault in supervisor(0,1,2),\t");
// }

// if (error_code & 0x08) != 0 {
// print!("Reserved bit violation cause fault,\t");
// }

// if (error_code & 0x10) != 0 {
// print!("Instruction fetch cause fault,\t");
// }
// print!("\n");

// CurrentIrqArch::interrupt_enable();
// panic!("Page Fault");
CurrentIrqArch::interrupt_disable();
let address = x86::controlregs::cr2();
// crate::kinfo!(
// "fault address: {:#x}, error_code: {:#b}, pid: {}\n",
// address,
// error_code,
// ProcessManager::current_pid().data()
// );

let address = VirtAddr::new(address);
let error_code = X86PfErrorCode::from_bits_truncate(error_code as u32);
if address.check_user() {
MMArch::do_user_addr_fault(regs, error_code, address);
} else {
print!("Fault in supervisor(0,1,2),\t");
MMArch::do_kern_addr_fault(regs, error_code, address);
}

if (error_code & 0x08) != 0 {
print!("Reserved bit violation cause fault,\t");
}

if (error_code & 0x10) != 0 {
print!("Instruction fetch cause fault,\t");
}
print!("\n");

CurrentIrqArch::interrupt_enable();
panic!("Page Fault");
}

/// 处理x87 FPU错误 16 #MF
Expand Down
Loading

0 comments on commit a193330

Please sign in to comment.