copy / v86

x86 PC emulator and x86-to-wasm JIT, running in the browser
https://copy.sh/v86/
BSD 2-Clause "Simplified" License
19.76k stars 1.39k forks source link

"Invalid argument" on creating file in 9p filesystem (Linux) #996

Closed SuperMaxusa closed 6 months ago

SuperMaxusa commented 8 months ago

Linux (from 6.6.x) can't create file on mounted host9p by mount -t 9p host9p /mnt, returning an error Invalid argument (-1 EINVAL), also this error showing on ls.

error

strace (ls) ``` execve("/bin/ls", ["ls", "/mnt"], 0xbfdeff4c /* 12 vars */) = 0 set_thread_area({entry_number=-1, base_addr=0xb7f7bc64, limit=0x0fffff, seg_32bit=1, contents=0, read_exec_only=0, limit_in_pages=1, seg_not_present=0, useable=1}) = 0 (entry_number=6) set_tid_address(0xb7f7bcfc) = 1930 brk(NULL) = 0x13d4000 brk(0x13d6000) = 0x13d6000 mmap2(0x13d4000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x13d4000 mprotect(0xb7f79000, 4096, PROT_READ) = 0 mprotect(0x551000, 8192, PROT_READ) = 0 getuid32() = 0 ioctl(0, TIOCGWINSZ, {ws_row=48, ws_col=128, ws_xpixel=0, ws_ypixel=400}) = 0 ioctl(1, TIOCGWINSZ, {ws_row=48, ws_col=128, ws_xpixel=0, ws_ypixel=400}) = 0 ioctl(1, TIOCGWINSZ, {ws_row=48, ws_col=128, ws_xpixel=0, ws_ypixel=400}) = 0 statx(AT_FDCWD, "/mnt", AT_STATX_SYNC_AS_STAT, STATX_BASIC_STATS, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=STATX_ATTR_MOUNT_ROOT, stx_mode=S_IFDIR|0777, stx_size=0, ...}) = 0 open("/mnt", O_RDONLY|O_LARGEFILE|O_CLOEXEC|O_DIRECTORY) = 3 fcntl64(3, F_SETFD, FD_CLOEXEC) = 0 mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7ed1000 getdents64(3, 0xb7ed1038 /* 4 entries */, 2048) = 120 statx(AT_FDCWD, "/mnt/testfile", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW, STATX_BASIC_STATS, 0xbf8d56c0) = -1 EINVAL (Invalid argument) write(2, "ls: /mnt/testfile: Invalid argum"..., 36) = 36 statx(AT_FDCWD, "/mnt/file_from_host.txt", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW, STATX_BASIC_STATS, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0666, stx_size=0, ...}) = 0 getdents64(3, 0xb7ed1038 /* 0 entries */, 2048) = 0 close(3) = 0 munmap(0xb7ed1000, 8192) = 0 ioctl(1, TIOCGWINSZ, {ws_row=48, ws_col=128, ws_xpixel=0, ws_ypixel=400}) = 0 writev(1, [{iov_base="\33[0;0mfile_from_host.txt\33[m", iov_len=27}, {iov_base="\n", iov_len=1}], 2) = 28 exit_group(1) = ? +++ exited with 1 +++ ```
strace (touch) ``` execve("/bin/touch", ["touch", "/mnt/testfile"], 0xbf92b1bc /* 12 vars */) = 0 set_thread_area({entry_number=-1, base_addr=0xb7f7cc64, limit=0x0fffff, seg_32bit=1, contents=0, read_exec_only=0, limit_in_pages=1, seg_not_present=0, useable=1}) = 0 (entry_number=6) set_tid_address(0xb7f7ccfc) = 1923 brk(NULL) = 0x1723000 brk(0x1725000) = 0x1725000 mmap2(0x1723000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x1723000 mprotect(0xb7f7a000, 4096, PROT_READ) = 0 mprotect(0x546000, 8192, PROT_READ) = 0 getuid32() = 0 utimensat(AT_FDCWD, "/mnt/testfile", NULL, 0) = -1 ENOENT (No such file or directory) open("/mnt/testfile", O_RDWR|O_CREAT|O_LARGEFILE, 0666) = -1 EINVAL (Invalid argument) write(2, "touch: /mnt/testfile: Invalid ar"..., 39) = 39 exit_group(1) = ? +++ exited with 1 +++ ```

Note for Alpine Linux: the bug is only on v3.19 (from 3.19.0 RC2 and above, this does not apply to previous versions):

Alpine's version Kernel version Have a bug?
3.18.6 6.1.75 no
3.19.0 RC1 6.1.62 no
3.19.0 RC2 6.6.3 yes
3.19.1 6.6.14 yes
farhan-ct commented 8 months ago

I have a similar issue when trying to open node console on alpine. It gives me an error saying 'x' invalid argument found or something. Will add more details later. Please ignore if this is irrelevant.

SuperMaxusa commented 8 months ago

trying to open node console on alpine.

did you tried run node with script without repl (or node -e "console.log('hello')") or this is also not working?

farhan-ct commented 8 months ago

did you tried run node with script without repl (or node -e "console.log('hello')") or this is also not working?

Am able to run node scripts without issues. issue was for node console only. Will try node -e "console.log('hello')" too and update here.

farhan-ct commented 7 months ago

@SuperMaxusa regarding the node issue I mentioned earlier, nothing to worry about, it's #875 . I noticed it earlier but just confirming the same here.

SuperMaxusa commented 7 months ago

This also reproduces in Void Linux 2024-03-14, so it's problem of Linux kernel 6.6.x (or earlier), not just Alpine

void

farhan-ct commented 7 months ago

Issue in debian too :( with 9pfs

farhan-ct commented 6 months ago

How do we fix this? I can try but will need some guidance. Issue is reproducable in the provided debian docker build in this repo too.

SuperMaxusa commented 6 months ago

I have some thoughts about this commit in linux repo: https://github.com/torvalds/linux/commit/3866584a1c56a2bbc8c0981deb4476d0b801969e, but I'm not entirely sure. Because of that reason, probably, open() and statx() returns EINVAL about incorrect flags.

Issue is reproducable in the provided debian docker build in this repo too.

Can you provide which kernel version is installed in rootfs? Seems a Dockerfile created on Debian Buster, which linux-image-686 has latest version as 4.19, or it's automatically updates?

farhan-ct commented 6 months ago

Seems a Dockerfile created on Debian Buster, which linux-image-686 has latest version as 4.19

Its auto-updated so the current version in it is 6.6.15-686

However, I downloaded and installed linux-image 5.10.0 (5.10.0-0.deb10.28-686) kernel but trying to figure out where I can change the default kernel version when booting :(

I am trying to see if 9p mounted with 5.10.0 linux-image would resolve the problem if its due to compatibility like you mentioned.

farhan-ct commented 6 months ago

My above reply is wrong, I changed it to trixie earlier. Buster doesn't have the 9p issue, working perfectly fine.

copy commented 6 months ago

Will be fixed in 2ca82a5.

SuperMaxusa commented 6 months ago

Thanks, works for me on Linux 6.6 without any problems. 9p-alpine

@farhan-ct can you try build v86 from wip branch and test on newer Alpine (3.18.6+) or Debian (trixie+) versions?

farhan-ct commented 6 months ago

Yes this issue is fixed and works in debian trixie+ too.

We can close this issue now (or maybe after new release)