News for hackers. Stuff that matters.
Re:Virtualizing iOS on Apple Silicon by grishka on Monday October 07, 2024 @05:45PM (#41771389)
You can't. The term "virtualize" is generally used to mean running an OS via hardware virtualization, where your host CPU natively runs its code but forwards all I/O to a hypervisor. You can only do that with an OS built for the same CPU architecture as your host system.

For everything else, like running ARM software on x86 (and vice versa), you'll have to resort to emulation, which involves either interpreting the code or dynamically recompiling it. By definition, you can emulate anything on anything else (someone recently booted Linux for MIPS on an Intel 4004, the first ever microprocessor), but the performance might be a problem.

Re:Virtualizing iOS on Apple Silicon by amarshall on Monday October 07, 2024 @06:19PM (#41771685)
TL;DR: emulating any ARM binaries on x86_64 via QEMU is so slow that it is unusable for any general use.

This is also less of a QEMU problem and more just that ARM does not emulate well on x86_64 due to their designs.

Re:Virtualizing iOS on Apple Silicon by userbinator on Monday October 07, 2024 @08:06PM (#41772472)
I have tried emulating ARM Windows on x86 with QEMU. It is fast enough to see whether something works and not much more (imagine Windows 11 on a 400MHz equivalent processor to understand what the performance was like --- and the host was a fairly recent Intel i7.)

ARM Linux is close to usable, however.

Re:Virtualizing iOS on Apple Silicon by grishka on Monday October 07, 2024 @09:23PM (#41772906)
It feels like it's just not possible in general to emulate the full instruction set of any CPU with an MMU with an acceptable performance to run modern software. QEMU running Windows for x86 on an M1 isn't very fast either.

Only emulating the portion of the instruction set available from the userspace is another story though. At least the way Apple does it with Rosetta and Microsoft with whatever their thing is called, you don't even notice that an app is running under emulation. The only giveaway is that it takes a noticeable time to start for the first time while the code is being translated. It's truly impressive.

Re:Virtualizing iOS on Apple Silicon by Netch on Tuesday October 08, 2024 @01:42AM (#41774149)
> QEMU running Windows for x86 on an M1 isn't very fast either.

It seems the main obstacle is in paging where x86 4KB clashes with Apple 16KB (ARM/64 supports multiple sizes), so, 2-level paging canʼt aid and an emulator has to shadow-paging which is, definitely, much slower.

> Apple does it with Rosetta and Microsoft with whatever their thing is called, you don't even notice that an app is running under emulation.

But they still use a vendor-specific TSO support in hardware.

Re:Virtualizing iOS on Apple Silicon by amelius on Tuesday October 08, 2024 @06:28AM (#41775747)
Curious, does QEMU use some kind of ahead-of-time translating scheme? Or do they rewrite instructions as they see them?
Re:Virtualizing iOS on Apple Silicon by saagarjha on Tuesday October 08, 2024 @11:49PM (#41784353)
Latter.
Re:Virtualizing iOS on Apple Silicon by amelius on Wednesday October 09, 2024 @07:07AM (#41786511)
Sounds like a huge opportunity for improvements.

A simple approach would identify basic blocks in the code and translate them to an IR for an optimizing compiler back-end like LLVM.

Of course, you have to be careful with self-modifying code.