rcore-os / zCore

Zircon microkernel reimplemented in Rust.
MIT License
1.71k stars 208 forks source link

Encounter errors at dtb-walker when using Qemu-7.0 on Ubuntu 20.04.1 LTS #357

Closed elliott10 closed 2 years ago

elliott10 commented 2 years ago

Encounter errors below at dtb-walker when using Qemu-7.0 on Ubuntu 20.04.1 LTS

panic cpu=0

panicked at 'called `Result::unwrap()` on an `Err` value: LastCompVersion(2)', zCore/src/platform/riscv/entry.rs:60:15

See also: https://github.com/rcore-os/zCore/pull/312#issuecomment-1151045189

elliott10 commented 2 years ago

env log:

$ make run LINUX=1 ARCH=riscv64 PLATFORM=qemu  MODE=release
Building zCore kernel
SMP=1 cargo build --features "linux" --no-default-features --target riscv64.json -Z build-std=core,alloc -Z build-std-features=compiler-builtins-mem --release
    Finished release [optimized + debuginfo] target(s) in 0.17s
rust-objcopy --binary-architecture=riscv64 ../target/riscv64/release/zcore --strip-all -O binary ../target/riscv64/release/zcore.bin
qemu-system-riscv64 -smp 1 -machine virt -bios default -m 512M -no-reboot -serial mon:stdio -serial file:/tmp/serial.out -kernel ../target/riscv64/release/zcore.bin -initrd /home/xly/rust/tmp/udp-zcore/zCore/riscv64.img -append "LOG=warn" -netdev user,id=net1,hostfwd=tcp::8000-:80,hostfwd=tcp::2222-:2222,hostfwd=udp::6969-:6969 -device e1000e,netdev=net1 -display none

OpenSBI v1.0
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : riscv-virtio,qemu
Platform Features         : medeleg
Platform HART Count       : 1
Platform IPI Device       : aclint-mswi
Platform Timer Device     : aclint-mtimer @ 10000000Hz
Platform Console Device   : uart8250
Platform HSM Device       : ---
Platform Reboot Device    : sifive_test
Platform Shutdown Device  : sifive_test
Firmware Base             : 0x80000000
Firmware Size             : 252 KB
Runtime SBI Version       : 0.3

Domain0 Name              : root
Domain0 Boot HART         : 0
Domain0 HARTs             : 0*
Domain0 Region00          : 0x0000000002000000-0x000000000200ffff (I)
Domain0 Region01          : 0x0000000080000000-0x000000008003ffff ()
Domain0 Region02          : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address      : 0x0000000080200000
Domain0 Next Arg1         : 0x000000009f000000
Domain0 Next Mode         : S-mode
Domain0 SysReset          : yes

Boot HART ID              : 0
Boot HART Domain          : root
Boot HART ISA             : rv64imafdcsuh
Boot HART Features        : scounteren,mcounteren,time
Boot HART PMP Count       : 16
Boot HART PMP Granularity : 4
Boot HART PMP Address Bits: 54
Boot HART MHPM Count      : 0
Boot HART MIDELEG         : 0x0000000000001666
Boot HART MEDELEG         : 0x0000000000f0b509

panic cpu=0

panicked at 'called `Result::unwrap()` on an `Err` value: LastCompVersion(2)', zCore/src/platform/riscv/entry.rs:60:15
QEMU: Terminated
$ qemu-system-riscv64 --version
QEMU emulator version 7.0.0
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
xly@xly-SVE151100C:~/rust/tmp/udp-zcore/zCore$ lsb_release  -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:    20.04
Codename:   focal
YdrMaster commented 2 years ago

这个要怎么复现啊?我这用 make run 也是正常的

make run LINUX=1 ARCH=riscv64 PLATFORM=qemu  MODE=release
Building zCore kernel
SMP=1 cargo build --features "linux" --no-default-features --target riscv64.json -Z build-std=core,alloc -Z build-std-features=compiler-builtins-mem --release
   Compiling zcore v0.1.0 (/home/mechdancer/repos/zCore/zCore)
    Finished release [optimized + debuginfo] target(s) in 17.12s
rust-objcopy --binary-architecture=riscv64 ../target/riscv64/release/zcore --strip-all -O binary ../target/riscv64/release/zcore.bin
Generating riscv64 sfsimg
Image resized.
qemu-system-riscv64 -smp 1 -machine virt -bios default -m 512M -no-reboot -serial mon:stdio -serial file:/tmp/serial.out -kernel ../target/riscv64/release/zcore.bin -initrd /home/mechdancer/repos/zCore/zCore/riscv64.img -append "LOG=warn" -netdev user,id=net1,hostfwd=tcp::8000-:80,hostfwd=tcp::2222-:2222,hostfwd=udp::6969-:6969 -device e1000e,netdev=net1 -display none

OpenSBI v1.0
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : riscv-virtio,qemu
Platform Features         : medeleg
Platform HART Count       : 1
Platform IPI Device       : aclint-mswi
Platform Timer Device     : aclint-mtimer @ 10000000Hz
Platform Console Device   : uart8250
Platform HSM Device       : ---
Platform Reboot Device    : sifive_test
Platform Shutdown Device  : sifive_test
Firmware Base             : 0x80000000
Firmware Size             : 252 KB
Runtime SBI Version       : 0.3

Domain0 Name              : root
Domain0 Boot HART         : 0
Domain0 HARTs             : 0*
Domain0 Region00          : 0x0000000002000000-0x000000000200ffff (I)
Domain0 Region01          : 0x0000000080000000-0x000000008003ffff ()
Domain0 Region02          : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address      : 0x0000000080200000
Domain0 Next Arg1         : 0x000000009f000000
Domain0 Next Mode         : S-mode
Domain0 SysReset          : yes

Boot HART ID              : 0
Boot HART Domain          : root
Boot HART ISA             : rv64imafdcsuh
Boot HART Features        : scounteren,mcounteren,time
Boot HART PMP Count       : 16
Boot HART PMP Granularity : 4
Boot HART PMP Address Bits: 54
Boot HART MHPM Count      : 0
Boot HART MIDELEG         : 0x0000000000001666
Boot HART MEDELEG         : 0x0000000000f0b509

boot page table launched, sstatus = 0x8000000200046000
kernel (physical): 0000000080200000..000000008542a0b8
kernel (remapped): ffffffffc0000000..ffffffffc522a0b8
device tree:       000000009f000000..000000009f00135e

hart0 is the primary hart.

[  0.070038 WARN  0 0:0 zcore_drivers::bus::pci] NoResources, failed to initialize PCI device: 1b36:0008
[  0.130639 WARN  0 0:0 linux_syscall] brk: unimplemented
[  0.131148 WARN  0 0:0 linux_syscall] brk: unimplemented
[  0.131569 WARN  0 0:0 linux_syscall::vm] mprotect: unimplemented
[  0.132843 WARN  0 0:0 linux_syscall::vm] mprotect: unimplemented
[  0.133671 WARN  0 0:0 linux_syscall] getuid: unimplemented
[  0.139162 WARN  0 0:0 linux_syscall] getpgid: unimplemented
[  0.139612 WARN  0 0:0 linux_syscall] setpgid: unimplemented
[  0.139804 WARN  0 0:0 linux_object::fs::stdio] stdout TCGETS | TIOCSPGRP, pretend to be tty.
[  0.143670 WARN  0 0:0 linux_object::fs::stdio] stdin TCGETS | TIOCSPGRP, pretend to be tty.
[  0.145643 WARN  0 0:0 linux_syscall] geteuid: unimplemented
[  0.146424 WARN  0 0:0 linux_syscall] geteuid: unimplemented
/ # 
YdrMaster commented 2 years ago

感觉还有别的因素在影响?CI 也是 7.0.0,应该都是正常的

YdrMaster commented 2 years ago

注意到你这个 make run 使用了不同的参数,试了一下,也没问题

mechdancer@DESKTOP-4F2L3I4:~/repos/zCore/zCore$ SMP=1 cargo build --features "linux" --no-default-features --target riscv64.json -Z build-std=core,alloc -Z build-std-features=compiler-builtins-mem --release
    Finished release [optimized + debuginfo] target(s) in 0.07s
mechdancer@DESKTOP-4F2L3I4:~/repos/zCore/zCore$ rust-objcopy --binary-architecture=riscv64 ../target/riscv64/release/zcore --strip-all -O binary ../target/riscv64/release/zcore.bin
mechdancer@DESKTOP-4F2L3I4:~/repos/zCore/zCore$ qemu-system-riscv64 -smp 1 -machine virt -bios default -m 512M -no-reboot -serial mon:stdio -serial file:/tmp/serial.out -kernel ../target/riscv64/release/zcore.bin -initrd riscv64.img -append "LOG=warn" -netdev user,id=net1,hostfwd=tcp::8000-:80,hostfwd=tcp::2222-:2222,hostfwd=udp::6969-:6969 -device e1000e,netdev=net1 -display none

OpenSBI v1.0
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : riscv-virtio,qemu
Platform Features         : medeleg
Platform HART Count       : 1
Platform IPI Device       : aclint-mswi
Platform Timer Device     : aclint-mtimer @ 10000000Hz
Platform Console Device   : uart8250
Platform HSM Device       : ---
Platform Reboot Device    : sifive_test
Platform Shutdown Device  : sifive_test
Firmware Base             : 0x80000000
Firmware Size             : 252 KB
Runtime SBI Version       : 0.3

Domain0 Name              : root
Domain0 Boot HART         : 0
Domain0 HARTs             : 0*
Domain0 Region00          : 0x0000000002000000-0x000000000200ffff (I)
Domain0 Region01          : 0x0000000080000000-0x000000008003ffff ()
Domain0 Region02          : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address      : 0x0000000080200000
Domain0 Next Arg1         : 0x000000009f000000
Domain0 Next Mode         : S-mode
Domain0 SysReset          : yes

Boot HART ID              : 0
Boot HART Domain          : root
Boot HART ISA             : rv64imafdcsuh
Boot HART Features        : scounteren,mcounteren,time
Boot HART PMP Count       : 16
Boot HART PMP Granularity : 4
Boot HART PMP Address Bits: 54
Boot HART MHPM Count      : 0
Boot HART MIDELEG         : 0x0000000000001666
Boot HART MEDELEG         : 0x0000000000f0b509

boot page table launched, sstatus = 0x8000000200046000
kernel (physical): 0000000080200000..000000008542a0b8
kernel (remapped): ffffffffc0000000..ffffffffc522a0b8
device tree:       000000009f000000..000000009f00135e

hart0 is the primary hart.

[  0.079404 WARN  0 0:0 zcore_drivers::bus::pci] NoResources, failed to initialize PCI device: 1b36:0008
[  0.143843 WARN  0 0:0 linux_syscall] brk: unimplemented
[  0.144099 WARN  0 0:0 linux_syscall] brk: unimplemented
[  0.144483 WARN  0 0:0 linux_syscall::vm] mprotect: unimplemented
[  0.145725 WARN  0 0:0 linux_syscall::vm] mprotect: unimplemented
[  0.146527 WARN  0 0:0 linux_syscall] getuid: unimplemented
[  0.153256 WARN  0 0:0 linux_syscall] getpgid: unimplemented
[  0.153530 WARN  0 0:0 linux_syscall] setpgid: unimplemented
[  0.153748 WARN  0 0:0 linux_object::fs::stdio] stdout TCGETS | TIOCSPGRP, pretend to be tty.
[  0.155834 WARN  0 0:0 linux_object::fs::stdio] stdin TCGETS | TIOCSPGRP, pretend to be tty.
[  0.157013 WARN  0 0:0 linux_syscall] geteuid: unimplemented
[  0.157645 WARN  0 0:0 linux_syscall] geteuid: unimplemented
/ # 
YdrMaster commented 2 years ago

还有一个不同点是我没有你的脚本里提到的 riscv64.img,用的是我自己构造的

elliott10 commented 2 years ago

再次试验了另外一台Ubuntu 20.04.4的机器,发现还是与Qemu有关。 某个版本的qemu-7可以运行,另外一个版本的qemu-7(应该是更加新的版本)却出了错。 对于出现的这个问题,也可作为检验dtb设备树解析库兼容性的一种方式。兼容尽量多的dtb设备树是必要的,以再更多不同版本的系统上运行好zCore。 甚至我认为能兼容到2020年发布的qemu-4/5就最好了,在于新的ubuntu-20长期发行版,默认apt安装的Qemu版本会在v4,这会是许多人的默认运行环境。

szx@server:~/Code-os/zCore/zCore$ make run LINUX=1 MODE=release ARCH=riscv64 -n
echo Building zCore kernel
SMP=1 cargo build --features "linux board-qemu" --no-default-features --target riscv64.json -Z build-std=core,alloc -Z build-std-features=compiler-builtins-mem --release
rust-objcopy --binary-architecture=riscv64 ../target/riscv64/release/zcore --strip-all -O binary ../target/riscv64/release/zcore.bin
qemu-system-riscv64 -smp 1 -machine virt -bios default -m 512M -no-reboot -serial mon:stdio -serial file:/tmp/serial.out -kernel ../target/riscv64/release/zcore.bin -initrd /data/home/szx/Code-OS/zCore/zCore/riscv64.img -append "LOG=warn" -netdev user,id=net1,hostfwd=tcp::8000-:80,hostfwd=tcp::2222-:2222,hostfwd=udp::6969-:6969 -device e1000e,netdev=net1 -display none
szx@server:~/Code-os/zCore/zCore$ qemu-system-riscv64 --version
QEMU emulator version 7.0.0
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
szx@server:~/Code-os/zCore/zCore$ qemu-system-riscv64 -smp 1 -machine virt -bios default -m 512M -no-reboot -serial mon:stdio -serial file:/tmp/serial.out -kernel ../target/riscv64/release/zcore.bin -initrd /data/home/szx/Code-OS/zCore/zCore/riscv64.img -append "LOG=warn" -netdev user,id=net1,hostfwd=tcp::8000-:80,hostfwd=tcp::2222-:2222,hostfwd=udp::6969-:6969 -device e1000e,netdev=net1 -display none

OpenSBI v1.0
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : riscv-virtio,qemu
Platform Features         : medeleg
Platform HART Count       : 1
Platform IPI Device       : aclint-mswi
Platform Timer Device     : aclint-mtimer @ 10000000Hz
Platform Console Device   : uart8250
Platform HSM Device       : ---
Platform Reboot Device    : sifive_test
Platform Shutdown Device  : sifive_test
Firmware Base             : 0x80000000
Firmware Size             : 252 KB
Runtime SBI Version       : 0.3

Domain0 Name              : root
Domain0 Boot HART         : 0
Domain0 HARTs             : 0*
Domain0 Region00          : 0x0000000002000000-0x000000000200ffff (I)
Domain0 Region01          : 0x0000000080000000-0x000000008003ffff ()
Domain0 Region02          : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address      : 0x0000000080200000
Domain0 Next Arg1         : 0x000000009f000000
Domain0 Next Mode         : S-mode
Domain0 SysReset          : yes

Boot HART ID              : 0
Boot HART Domain          : root
Boot HART ISA             : rv64imafdcsuh
Boot HART Features        : scounteren,mcounteren,time
Boot HART PMP Count       : 16
Boot HART PMP Granularity : 4
Boot HART PMP Address Bits: 54
Boot HART MHPM Count      : 0
Boot HART MIDELEG         : 0x0000000000001666
Boot HART MEDELEG         : 0x0000000000f0b509

boot page table launched, sstatus = 0x8000000200046000
parse device tree from 0x9f000000

hart0 is the primary hart.

[  0.134298 WARN  0 0:0 zcore_drivers::bus::pci] NoResources, failed to initialize PCI device: 1b36:0008
[  0.218919 WARN  0 0:0 linux_syscall] brk: unimplemented
[  0.219352 WARN  0 0:0 linux_syscall] brk: unimplemented
[  0.220081 WARN  0 0:0 linux_syscall::vm] mprotect: unimplemented
[  0.222116 WARN  0 0:0 linux_syscall::vm] mprotect: unimplemented
[  0.223483 WARN  0 0:0 linux_syscall] getuid: unimplemented
[  0.230715 WARN  0 0:0 linux_syscall] getpgid: unimplemented
[  0.231248 WARN  0 0:0 linux_syscall] setpgid: unimplemented
[  0.231703 WARN  0 0:0 linux_object::fs::stdio] stdout TCGETS | TIOCSPGRP, pretend to be tty.
[  0.234567 WARN  0 0:0 linux_object::fs::stdio] stdin TCGETS | TIOCSPGRP, pretend to be tty.
[  0.236233 WARN  0 0:0 linux_syscall] geteuid: unimplemented
[  0.237053 WARN  0 0:0 linux_syscall] geteuid: unimplemented
/ # 

szx@server:~/Code-os/zCore/zCore$ /home/szx/Downloads/qemu/usr/bin/qemu-system-riscv64 -smp 1 -machine virt -bios default -m 512M -no-reboot -serial mon:stdio -serial file:/tmp/serial.out -kernel ../target/riscv64/release/zcore.bin -initrd /data/home/szx/Code-OS/zCore/zCore/riscv64.img -append "LOG=warn" -netdev user,id=net1,hostfwd=tcp::8000-:80,hostfwd=tcp::2222-:2222,hostfwd=udp::6969-:6969 -device e1000e,netdev=net1 -display none

OpenSBI v1.0
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : riscv-virtio,qemu
Platform Features         : medeleg
Platform HART Count       : 1
Platform IPI Device       : aclint-mswi
Platform Timer Device     : aclint-mtimer @ 10000000Hz
Platform Console Device   : uart8250
Platform HSM Device       : ---
Platform Reboot Device    : sifive_test
Platform Shutdown Device  : sifive_test
Firmware Base             : 0x80000000
Firmware Size             : 252 KB
Runtime SBI Version       : 0.3

Domain0 Name              : root
Domain0 Boot HART         : 0
Domain0 HARTs             : 0*
Domain0 Region00          : 0x0000000002000000-0x000000000200ffff (I)
Domain0 Region01          : 0x0000000080000000-0x000000008003ffff ()
Domain0 Region02          : 0x0000000000000000-0xffffffffffffffff (R,W,X)
Domain0 Next Address      : 0x0000000080200000
Domain0 Next Arg1         : 0x000000009f000000
Domain0 Next Mode         : S-mode
Domain0 SysReset          : yes

Boot HART ID              : 0
Boot HART Domain          : root
Boot HART ISA             : rv64imafdcsuh
Boot HART Features        : scounteren,mcounteren,time
Boot HART PMP Count       : 16
Boot HART PMP Granularity : 4
Boot HART PMP Address Bits: 54
Boot HART MHPM Count      : 0
Boot HART MIDELEG         : 0x0000000000001666
Boot HART MEDELEG         : 0x0000000000f0b509

boot page table launched, sstatus = 0x8000000200046000
parse device tree from 0x9f000000

panic cpu=0

panicked at 'called `Result::unwrap()` on an `Err` value: LastCompVersion(2)', zCore/src/platform/riscv/entry.rs:132:15
szx@server:~/Code-os/zCore/zCore$ /home/szx/Downloads/qemu/usr/bin/qemu-system-riscv64 --version
QEMU emulator version 7.0.0
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
szx@server:~/Code-os/zCore/zCore$ uname -a
Linux server 5.15.0-41-generic #44~20.04.1-Ubuntu SMP Fri Jun 24 13:27:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
szx@server:~/Code-os/zCore/zCore$ lsb_release  -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:    20.04
Codename:   focal