On Tue, 26 Oct 2021 at 09:09, Alexander Graf <ag...@csgraf.de> wrote: > > Apple's Hypervisor.Framework forwards cache operations as MMIO traps > into user space. For MMIO however, these have no meaning: There is no > cache attached to them. > > So let's just treat cache data exits as nops. > > This fixes OpenBSD booting as guest.
I agree that "ignore cache maintenance ops" is the right thing (among other things it's what KVM does in kvm_handle_guest_abort()). But CM=1 isn't only cache maintenance, it is also set for faults for address translation instructions. I think (but have not tested or completely thought through) that before this you also want if (S1PTW is set) { /* * Guest has put its page tables not into RAM. We * can't do anything to retrieve this, so re-inject * the abort back into the guest. */ inject a data abort with suitable fault info; } Compare the sequence in the KVM code: https://elixir.bootlin.com/linux/latest/source/arch/arm64/kvm/mmu.c#L1233 where we check S1PTW, then CM, then go for "let userspace do MMIO emulation". It's possible that Hypervisor.Framework handles the S1PTW case for you; you could test with a stunt guest that sets up the page tables so that the 2nd level page table for a particular VA range is mapped to an IPA that's not in RAM, and then try just using that VA and/or passing that VA to one of the AT instructions, to see whether you get handed the fault or not. (My bet would be that hvf does not handle this for you, because in general it seems to prefer to punt everything.) -- PMM