Rezero
Rezero

Reputation: 168

run `make qemu` got error: `qemu_mprotect__osdep: mprotect failed: Permission denied`

I am trying do mit6.828 lab on mac m1. After installed riscv-tool-chain, I tried to run make qemu which seems to be used start the kernel, but at first I got this error:

mkfs/mkfs fs.img README user/xargstest.sh user/_cat user/_echo user/_forktest user/_grep user/_init user/_kill user/_ln user/_ls user/_mkdir user/_rm user/_sh user/_stressfs user/_usertests user/_wc user/_zombie user/_cowtest user/_uthread user/_call user/_testsh user/_kalloctest user/_bcachetest user/_alloctest user/_bigfile
nmeta 46 (boot, super, log blocks 30 inode blocks 13, bitmap blocks 1) blocks 1954 total 2000
balloc: first 766 blocks have been allocated
balloc: write bitmap block at sector 45
qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 1 -nographic -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
Could not allocate dynamic translator buffer
make: *** [qemu] Error 1

So I clone the qemu reposiroty from the github to get the source code,and check the version to v5.1.0, then I apply the patch from this link pathch which is mentioned by this link

configure run as the belows:

 ./configure --disable-kvm --disable-werror --prefix=/usr/local --target-list="riscv64-softmmu"`

The make and make install seems work well, but when I execute make qemu again in the lab, it appeared another error, I still not found how to solve this problem:

qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 3 -nographic -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
qemu-system-riscv64: qemu_mprotect__osdep: mprotect failed: Permission denied
**
ERROR:/Users/rezero/Desktop/6.828-note/qemus/qemu-5.1.0/tcg/tcg.c:733:tcg_region_init: assertion failed: (!rc)
Bail out! ERROR:/Users/rezero/Desktop/6.828-note/qemus/qemu-5.1.0/tcg/tcg.c:733:tcg_region_init: assertion failed: (!rc)
make: *** [qemu] Abort trap: 6

Upvotes: 2

Views: 1324

Answers (3)

qixiaoliu
qixiaoliu

Reputation: 1

it is macOS 11.2 mprotect bug, you can modify qemu/tcg/tcg.c fix it, view https://gitlab.com/qemu-project/qemu/-/commit/c118881ee607dcac

Upvotes: 0

Liu Charles
Liu Charles

Reputation: 101

@Rezero follow your step, have you encountered such error when compile:

 CC      hw/display/virtio-gpu-3d.o
hw/display/virtio-gpu-3d.c:149:41: error: variable has incomplete type 'struct virgl_renderer_resource_info'
    struct virgl_renderer_resource_info info;
                                        ^
hw/display/virtio-gpu-3d.c:149:12: note: forward declaration of 'struct virgl_renderer_resource_info'
    struct virgl_renderer_resource_info info;
           ^
hw/display/virtio-gpu-3d.c:167:15: error: implicit declaration of function 'virgl_renderer_resource_get_info' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

Upvotes: 0

Rezero
Rezero

Reputation: 168

I tried many times since I not familiar about the qemu and macos. And here I got:

# modify /etc/paths 
/usr/bin
/bin
/usr/local/bin
/usr/sbin
/sbin

# modify .zshrc
export PATH="/opt/homebrew/bin:$PATH"
export PATH="$HOME/bin:/usr/local/bin:$PATH"
export PATH="$PATH:/usr/local/opt/riscv-gnu-toolchain/bin"

Still do not know what happened, but things seems worked after I apply two patches as the below. (Ensure close Rosetta mode on iterm, still using qemu 5.1.0)

patch1 you can just download and cd to the qemu directory then command like this: patch -p1 < ../patch/v2-tcg-Fix-execution-on-Apple-Silicon.patch

patch2 only two lines, just open the osdep.c file and modify it.

And after apply the above patches, run configure with:

./configure --disable-kvm --disable-werror --prefix=/usr/local --target-list="riscv64-softmmu"

and make & make install

Then it worked, and kernal could start.

Upvotes: 1

Related Questions