-
Notifications
You must be signed in to change notification settings - Fork 304
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
Fix crash on aarch64 linux. #225
Conversation
No offense. Do you fully understand all 3 addressing mode? But you really need to understand the memory addressing mode in BII before making this drastic change in this PR. What is the addressing mode in your configure? |
I'm using the default which results in "direct". Setting --enable-addressing=real fails and falls back on "memory banks" which also works for me.
Just read TECH. If I understand correctly I broke REAL_ADDRESSING=1? So just check for that? This is just making me further question the fact that linux i386 and FreeBSD set MAP_BASE = 0x10000000 while TECH claims those platforms work with real addressing. :) As an experiment, I tried setting vm.mmap_min_addr="0" and it still fails to allocate at 0x0 on Debian aarch64 and CentOS 8 x86_64 so yeah, the linux world is very determined to make that impossible going forward and any security minded OS is likely to do the same. See https://access.redhat.com/articles/20484 and regarding FreeBSD they're doing it too: https://utcc.utoronto.ca/~cks/space/blog/unix/MunmapPageZero Pushed an update that should preserve real addressing on whatever platforms can even do that anymore. (autoconf appears to test for this directly on unix, and macOS has its own code path I didn't touch) |
I strongly opposed this PR.
Please read the wiki I wrote on addressing. I'd recommend you to use memory bank and kill this PR. |
OK let me explain, the problem here is ALL addressing modes are broken on aarch64 (and every 64bit arch on Linux other than x86_64). This patch fixes all addressing modes. ALL addressing modes are broken without this patch. Basilisk II is completely unusable on aarch64 (and PPC64 and RISC-V) without this patch. x86_64 works because 1) it and ONLY it implements MAP_32BIT, you can confirm this at https://elixir.bootlin.com/linux/latest/ident/MAP_32BIT so when the allocation fails at the requested address it at least falls back to an address low enough to not crash ...and 2) linux x86/x86_64 (and FreeBSD) uses MAP_BASE=0x10000000 so REAL ADDRESSING IS BROKEN THERE ALREADY AND IS UNAFFECTED BY MY PATCH. Read the code. And you can confirm it with my printf debug.
mmap-ing at 0x0 is being disabled in Linux using numerous methods. Not just the sysctl setting, SELinux is being used to disable it as well on CentOS for example. All other unix OS are quickly following suit. "real" addressing is simply not going to be possible on modern unix for the average user going forwards. But with my current revision it should still work if you can convince the OS to let it happen. I have confirmed my patch works correctly on x86_64 and aarch64 Linux, with both "direct" and "memory banks" and with JIT enabled on x86_64. Please merge. |
|
I'm pretty sure you messed up It initializes
So that when it mmap, the kernel chooses the (page-aligned) address.
See mmap doc PS:
|
Yes, I have tried virtual address mode a.k.a memory bank. It is broken without my patch on aarch64. It works with my patch on aarch64. The problem here is the behavior of Linux's mmap. It really doesn't want to give you the behavior you want, for good reasons. YES, this is all an ugly hack. That's the problem. Go ahead, show me how this breaks for some theoretical PPC and ARM7 users and i'll fix it. Until then, it is actually broken on Linux aarch64, a real thing that exists and is currently selling in the millions. https://www.zdnet.com/article/raspberry-pi-now-weve-sold-30-million/ I've read the mmap doc, I've read the implementations of mmap in the source code of Linux and FreeBSD. I have a pretty good handle on mmap behavior on Linux and FreeBSD kernels across all architectures. I've already explained it to you with relevant links in great detail. JIT on x86_64 Linux works just fine for me. Please merge. |
Your first message indicates that you have no ideas of addressing in BII. Also, how many RaPi sells is irrelevant with the correctness of the PR. Please focus on the topic. In ASLR, how can you be so sure that fixing the starting address to I'm not convince that your PR benefits for other architectures. It is more likely causing others to break. The debug message that you printed out the mmap address is NOT related to the PR at all.
I'm not that smart to read mmap source code of Linux or FreeBSD. For a complex subject matter such as memory management, I could never claim that I "have a pretty good handle on mmap behavior on Linux and FreeBSD kernels across all architectures". If you want to continue the discussion in a productive manner -- First thing first, show me the memory mmap debug message in ARM64 under memory bank addressing or direct addressing without your hack. |
You don't have merge permission? You can't read kernel source code? Why am I wasting my time arguing with you then? Please merge. |
Wasn't expecting such weird pushback, making a new PR with this change isolated to a branch so i can move on to other fixes. |
Discussion continuing in emaculation/macemu#141 @rickyzhang82 are there any automated tests that highlight the problems introduced by this patch on the architectures you mentioned (PPC, ARM7, etc)? Or would you have to have that physical hardware to run the tests? |
Invalidate cached ethernet allocation when system is reset
Hi Basilisk II fails to start a VM on Debian aarch64, in my case a Raspi4.
With some printf debugging I discovered it is because MAP_BASE defaults to 0x0 which is unavailable for security reasons on recent kernels thus the memory allocator falls back on a standard allocation way up in 64bit address space, which fails the address sanity test and returns a misleading "not enough memory" error to the user.
Removing the sanity check results in a VM crash so it would seem low addresses are in fact required for now.
The easy fix is to bump MAP_BASE up past the security/debug guard. I've added some comments explaining the issues involved and the choices made.
This is all a bit ugly and flaky and the real fix would be to make Basilisk II not require low addresses, but that's another patch for another day.
I have not touched the linux i386|FreeBSD|HAVE_LINKER_SCRIPT case as i don't know the issues there and i assume that case is working properly.
Resolves #188