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

Page Fault during probing PCI device in x86_64 #213

Open
hky1999 opened this issue Dec 13, 2024 · 1 comment
Open

Page Fault during probing PCI device in x86_64 #213

hky1999 opened this issue Dec 13, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@hky1999
Copy link
Contributor

hky1999 commented Dec 13, 2024

in scripts/make/qemu.mk, when you try to set memory provided by QEMU as 4G or bigger

qemu_args-y := -m 4G -smp $(SMP) $(qemu_args-$(ARCH))

page fault will occur at VA:0x378000000014

command: make ARCH=x86_64 A=examples/shell/ LOG=debug BLK=y run

output:

SeaBIOS (version rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org)


iPXE (http://ipxe.org) 00:02.0 CA00 PCI2.10 PnP PMM+7EFD0AA0+7EF30AA0 CA00
                                                                               


Booting from ROM..
Initialize IDT & GDT...

       d8888                            .d88888b.   .d8888b.
      d88888                           d88P" "Y88b d88P  Y88b
     d88P888                           888     888 Y88b.
    d88P 888 888d888  .d8888b  .d88b.  888     888  "Y888b.
   d88P  888 888P"   d88P"    d8P  Y8b 888     888     "Y88b.
  d88P   888 888     888      88888888 888     888       "888
 d8888888888 888     Y88b.    Y8b.     Y88b. .d88P Y88b  d88P
d88P     888 888      "Y8888P  "Y8888   "Y88888P"   "Y8888P"

arch = x86_64
platform = x86_64-qemu-q35
target = x86_64-unknown-none
smp = 1
build_mode = release
log_level = debug

[  0.004204 0 axruntime:130] Logging is enabled.
[  0.004665 0 axruntime:131] Primary CPU 0 started, dtb = 0x0.
[  0.005207 0 axruntime:133] Found physcial memory regions:
[  0.005728 0 axruntime:135]   [PA:0x200000, PA:0x293000) .text (READ | EXECUTE | RESERVED)
[  0.006465 0 axruntime:135]   [PA:0x293000, PA:0x2a6000) .rodata (READ | RESERVED)
[  0.007147 0 axruntime:135]   [PA:0x2a6000, PA:0x2b3000) .data .tdata .tbss .percpu (READ | WRITE | RESERVED)
[  0.008013 0 axruntime:135]   [PA:0x2b3000, PA:0x2f3000) boot stack (READ | WRITE | RESERVED)
[  0.008785 0 axruntime:135]   [PA:0x2f3000, PA:0x519000) .bss (READ | WRITE | RESERVED)
[  0.009509 0 axruntime:135]   [PA:0x1000, PA:0x9f000) low memory (READ | WRITE | RESERVED)
[  0.010245 0 axruntime:135]   [PA:0x519000, PA:0x8000000) free memory (READ | WRITE | FREE)
[  0.010992 0 axruntime:135]   [PA:0xb0000000, PA:0xc0000000) mmio (READ | WRITE | DEVICE | RESERVED)
[  0.011803 0 axruntime:135]   [PA:0xfe000000, PA:0xfec00000) mmio (READ | WRITE | DEVICE | RESERVED)
[  0.012614 0 axruntime:135]   [PA:0xfec00000, PA:0xfec01000) mmio (READ | WRITE | DEVICE | RESERVED)
[  0.013438 0 axruntime:135]   [PA:0xfed00000, PA:0xfed01000) mmio (READ | WRITE | DEVICE | RESERVED)
[  0.014250 0 axruntime:135]   [PA:0xfee00000, PA:0xfee01000) mmio (READ | WRITE | DEVICE | RESERVED)
[  0.015067 0 axruntime:208] Initialize global memory allocator...
[  0.015641 0 axruntime:209]   use TLSF allocator.
[  0.016108 0 axalloc:230] initialize global allocator at: [0xffffff8000519000, 0xffffff8008000000)
[  0.016902 0 axmm:60] Initialize virtual memory management...
[  0.017939 0 axmm:63] kernel address space init OK: AddrSpace {
    va_range: VA:0xffffff8000000000..VA:0xfffffffffffff000,
    page_table_root: PA:0x521000,
}
[  0.019176 0 axruntime:150] Initialize platform devices...
[  0.019654 0 axhal::platform::x86_pc::apic:87] Initialize Local APIC...
[  0.020214 0 axhal::platform::x86_pc::apic:102] Using x2APIC.
[  0.020740 0 axhal::platform::x86_pc::apic:116] Initialize IO APIC...
[  0.021313 0 axtask::api:73] Initialize scheduling...
[  0.021777 0 axtask::task:120] new task: Task(1, "idle")
[  0.022280 0 axtask::task:120] new task: Task(3, "gc")
[  0.022752 0 axalloc:118] expand heap memory: [0xffffff80005ee000, 0xffffff800062e000)
[  0.023817 0 axalloc:118] expand heap memory: [0xffffff800062e000, 0xffffff80006ae000)
[  0.024486 0 axtask::api:79]   use FIFO scheduler.
[  0.024923 0 axdriver:152] Initialize device drivers...
[  0.025391 0 axdriver:153]   device model: static
[  0.025836 0 axdriver::bus::pci:97] PCI 00:00.0: 8086:29c0 (class 06.00, rev 00) Standard
[  0.026842 0 axdriver::bus::pci:97] PCI 00:01.0: 1234:1111 (class 03.00, rev 02) Standard
[  0.028454 0 axdriver::bus::pci:54]   BAR 0: MEM [0xfd000000, 0xfe000000) pref
[  0.029662 0 axdriver::bus::pci:54]   BAR 2: MEM [0xfebd4000, 0xfebd5000)
[  0.030539 0 axdriver::bus::pci:97] PCI 00:02.0: 8086:10d3 (class 02.00, rev 00) Standard
[  0.031783 0 axdriver::bus::pci:54]   BAR 0: MEM [0xfeb80000, 0xfeba0000)
[  0.032882 0 axdriver::bus::pci:54]   BAR 1: MEM [0xfeba0000, 0xfebc0000)
[  0.033878 0 axdriver::bus::pci:44]   BAR 2: IO  [0xc0c0, 0xc0e0)
[  0.034952 0 axdriver::bus::pci:54]   BAR 3: MEM [0xfebd0000, 0xfebd4000)
[  0.035830 0 axdriver::bus::pci:97] PCI 00:03.0: 1af4:1001 (class 01.00, rev 00) Standard
[  0.037517 0 axdriver::bus::pci:44]   BAR 0: IO  [0xc000, 0xc080)
[  0.038436 0 axdriver::bus::pci:54]   BAR 1: MEM [0xfebd5000, 0xfebd6000)
[  0.039948 0 axdriver::bus::pci:54]   BAR 4: MEM [0x380000000000, 0x380000004000) 64bit pref
[  0.043459 0 axhal::arch::x86_64::trap:16] No registered handler for trap PAGE_FAULT
[  0.044186 0 axruntime::lang_items:5] panicked at /home/hky/.cargo/git/checkouts/arceos-8c00e25977aa9a10/b2124ce/modules/axhal/src/arch/x86_64/trap.rs:17:9:
Unhandled kernel #PF @ 0xffffff800021e09b, fault_vaddr=VA:0x378000000014, error_code=0x2 (WRITE):
TrapFrame {
    rax: 0x2,
    rcx: 0x400,
    rdx: 0x800,
    rbx: 0xffffff80002f2550,
    rbp: 0x18000,
    rsi: 0xffffff80002f2878,
    rdi: 0xffffff80002f2550,
    r8: 0x3000,
    r9: 0x18000,
    r10: 0x380000000000,
    r11: 0x2,
    r12: 0x378000000000,
    r13: 0xffffff80b0000000,
    r14: 0xffffff80002f2878,
    r15: 0x378000000000,
    vector: 0xe,
    error_code: 0x2,
    rip: 0xffffff800021e09b,
    cs: 0x10,
    rflags: 0x10086,
    rsp: 0xffffff80002f23c0,
    ss: 0x0,
}
[  0.049730 0 axhal::platform::x86_pc::misc:7] Shutting down...
@hky1999 hky1999 added the bug Something isn't working label Dec 13, 2024
@hky1999
Copy link
Contributor Author

hky1999 commented Dec 13, 2024

fixed by reset the phys-virt-offset to "0xffff_8000_0000_0000"

platforms/x86_64-qemu-q35.toml:

# Architecture identifier.
arch = "x86_64"
# Platform identifier.
platform = "x86_64-qemu-q35"
# Platform family.
family = "x86-pc"

# Base address of the whole physical memory.
phys-memory-base = "0"
# Size of the whole physical memory.
phys-memory-size = "0x800_0000"     # 128M
# Base physical address of the kernel image.
kernel-base-paddr = "0x20_0000"
# Base virtual address of the kernel image.
kernel-base-vaddr = "0xffff_8000_0020_0000"
# Linear mapping offset, for quick conversions between physical and virtual
# addresses.
phys-virt-offset = "0xffff_8000_0000_0000"
# Offset of bus address and phys address. some boards, the bus address is
# different from the physical address.
phys-bus-offset = "0"
# Kernel address space base.
kernel-aspace-base = "0xffff_8000_0000_0000"
# Kernel address space size.
kernel-aspace-size = "0x0000_7fff_ffff_f000"
# MMIO regions with format (`base_paddr`, `size`).
mmio-regions = [
    ["0xb000_0000", "0x1000_0000"], # PCI config space
    ["0xfe00_0000", "0xc0_0000"],   # PCI devices
    ["0xfec0_0000", "0x1000"],      # IO APIC
    ["0xfed0_0000", "0x1000"],      # HPET
    ["0xfee0_0000", "0x1000"],      # Local APIC
    ["0x2_8000_0000", "0x8_0000_0000"], # PCI devices
    ["0x3800_0000_0000", "0x4000"] # PCI devices
]
# VirtIO MMIO regions with format (`base_paddr`, `size`).
virtio-mmio-regions = []
# Base physical address of the PCIe ECAM space (should read from ACPI 'MCFG' table).
pci-ecam-base = "0xb000_0000"
# End PCI bus number.
pci-bus-end = "0xff"
# PCI device memory ranges (not used on x86).
pci-ranges = []

# Timer interrupt frequencyin Hz.
timer-frequency = "4_000_000_000"   # 4.0GHz

modules/axhal/src/platform/x86_pc/multiboot.S:

.balign 4096
.Ltmp_pml4:
    # 0x0000_0000 ~ 0xffff_ffff
    .quad .Ltmp_pdpt_low - {offset} + 0x3   # PRESENT | WRITABLE | paddr(tmp_pdpt)
    .zero 8 * 255
    # 0xffff_8000_0000_0000 ~ 0xffff_8000_ffff_ffff
    .quad .Ltmp_pdpt_high - {offset} + 0x3  # PRESENT | WRITABLE | paddr(tmp_pdpt)
    .zero 8 * 255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants