vmapple: making it work on the latest macOS releaases and Apple M4
cover vmapple: making it work on the latest macOS releaases and Apple M4
RFC as it's hacky code, especially for the Apple M4 support workaround part. Support for newer guest OSes isn't part of this series.
Mohamed Mediouni (4):
hw: vmapple: include missing headers
hvf: arm64: add workaround for Apple M4 to run older macOS versions
vmapple: apple-gfx: make it work on the latest macOS release Revert "hw/arm: Do not build VMapple machine by default"
accel/hvf/hvf-accel-ops.c | 4 +- configs/devices/aarch64-softmmu/default.mak | 1 - hw/display/apple-gfx-mmio.m | 56 +++++++++++----- hw/display/apple-gfx.h | 13 ++++ hw/display/apple-gfx.m | 42 +++++++++++- hw/vmapple/vmapple.c | 2 + include/system/hvf_int.h | 4 ++ target/arm/hvf/hvf.c | 71 +++++++++++++++++++++ 8 files changed, 174 insertions(+), 19 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
RFC 1/4 hw: vmapple: include missing headers
Disablement by default led to:
../hw/vmapple/vmapple.c:276:39: error: use of undeclared identifier 'GTIMER_VIRT'
276 | qdev_connect_gpio_out(cpudev, GTIMER_VIRT,
| ^../hw/vmapple/vmapple.c:479:54: error: use of undeclared identifier 'QEMU_PSCI_CONDUIT_HVC'
479 | object_property_set_int(cpu, "psci-conduit", QEMU_PSCI_CONDUIT_HVC,
| ^../hw/vmapple/vmapple.c:556:13: error: call to undeclared function 'arm_build_mp_affinity'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
556 | arm_build_mp_affinity(n, GICV3_TARGETLIST_BITS);
| ^3 errors generated.
pretty quickly.
--- hw/vmapple/vmapple.c | 2 ++ 1 file changed, 2 insertions(+)
hw/vmapple/vmapple.c +2 -0
@@ -51,6 +51,8 @@#include "system/reset.h" #include "system/runstate.h" #include "system/system.h" +#include "gtimer.h" +#include "cpu.h" struct VMAppleMachineState {MachineState parent;
Signature · 1 line
2.50.1 (Apple Git-155)
RFC 2/4 hvf: arm64: add workaround for Apple M4 to run older macOS versions
In reply to Mohamed MediouniApple M4 removes FEAT_SSBS. However, older macOS releases do misbehave in such a configuration and do not boot.
Use private API to trap SCTLR_EL1 accesses through FGT.
--- accel/hvf/hvf-accel-ops.c | 4 +-- include/system/hvf_int.h | 4 +++ target/arm/hvf/hvf.c | 71 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-)
accel/hvf/hvf-accel-ops.c +2 -2
@@ -152,8 +152,8 @@ static int hvf_init_vcpu(CPUState *cpu)sigdelset (&cpu->accel->unblock_ipi_mask,SIG_IPI );#ifdef __aarch64__ - r =hv_vcpu_create (&cpu->accel->fd, - (hv_vcpu_exit_t **)&cpu->accel->exit,NULL ); + r =hvf_vcpu_create (&cpu->accel->fd, + (hv_vcpu_exit_t **)&cpu->accel->exit);#else r =hv_vcpu_create (&cpu->accel->fd,HV_VCPU_DEFAULT );#endif
include/system/hvf_int.h +4 -0
@@ -111,4 +111,8 @@ void hvf_arch_update_guest_debug(CPUState *cpu);*/ bool hvf_arch_supports_guest_debug (void ); +#ifdef __aarch64__ +hv_return_t hvf_vcpu_create (hv_vcpu_t * vcpu_ptr,hv_vcpu_exit_t ** exit); +#endif +#endif
target/arm/hvf/hvf.c +71 -0
109 lines not on this page · raw message
Signature · 1 line
2.50.1 (Apple Git-155)
RFC 3/4 vmapple: apple-gfx: make it work on the latest macOS release
In reply to Mohamed MediouniFollow changes in memory management, and enable process isolation for a sandboxed GPU process when on a new OS.
--- hw/display/apple-gfx-mmio.m | 56 +++++++++++++++++++++++++++---------- hw/display/apple-gfx.h | 13 +++++++++ hw/display/apple-gfx.m | 42 +++++++++++++++++++++++++++- 3 files changed, 95 insertions(+), 16 deletions(-)
hw/display/apple-gfx-mmio.m +41 -15
@@ -19,6 +19,7 @@ #include "hw/irq.h" #include "apple-gfx.h" #include "trace.h" +#include "system/address-spaces.h" #import <ParavirtualizedGraphics/ParavirtualizedGraphics.h>
@@ -34,14 +35,25 @@ typedef bool(^IOSFCMapMemory)(uint64_t phys, uint64_t len, bool ro, void **va, void *, void *); +@interface PGMemoryMapDescriptor : NSObject +-(void)addRange:(struct PGGuestPhysicalRange_s) range; +@end + @interface PGDeviceDescriptor (IOSurfaceMapper) @property (readwrite, nonatomic) bool usingIOSurfaceMapper; +@property (readwrite, nonatomic) bool enableArgumentBuffers; +@property (readwrite, nonatomic) bool enableProcessIsolation; +@property (readwrite, nonatomic) bool enableProtectedContent; + +@property (readwrite, nonatomic, copy, nullable) PGMemoryMapDescriptor* memoryMapDescriptor; @end @interface PGIOSurfaceHostDeviceDescriptor : NSObject -(PGIOSurfaceHostDeviceDescriptor *)init; @property (readwrite, nonatomic, copy, nullable) IOSFCMapMemory mapMemory; @property (readwrite, nonatomic, copy, nullable) IOSFCUnmapMemory unmapMemory; +@property (readwrite, nonatomic, copy, nullable) PGMemoryMapDescriptor* memoryMapDescriptor; +@property (readwrite, nonatomic) unsigned long long mmioLength; @property (readwrite, nonatomic, copy, nullable) IOSFCRaiseInterrupt raiseInterrupt; @end
@@ -182,20 +194,28 @@ static bool apple_gfx_mmio_unmap_surface_memory(void *ptr) PGIOSurfaceHostDeviceDescriptor *iosfc_desc = [PGIOSurfaceHostDeviceDescriptor new]; PGIOSurfaceHostDevice *iosfc_host_dev; - - iosfc_desc.mapMemory = - ^bool(uint64_t phys, uint64_t len, bool ro, void **va, void *e, void *f) { - *va = apple_gfx_mmio_map_surface_memory(phys, len, ro); - - trace_apple_gfx_iosfc_map_memory(phys, len, ro, va, e, f, *va); - - return *va != NULL; - }; - - iosfc_desc.unmapMemory = - ^bool(void *va, void *b, void *c, void *d, void *e, void *f) { - return apple_gfx_mmio_unmap_surface_memory(va); - }; + PGMemoryMapDescriptor* memoryMapDescriptor = [PGMemoryMapDescriptor new]; + + if (@available(macOS 15.4, *)) { + FlatView* fv = address_space_to_flatview(&address_space_memory); + flatview_for_each_range(fv, apple_gfx_register_memory_cb, memoryMapDescriptor); + iosfc_desc.mmioLength = 0x10000; + iosfc_desc.memoryMapDescriptor = memoryMapDescriptor; + } else { + iosfc_desc.mapMemory = + ^bool(uint64_t phys, uint64_t len, bool ro, void **va, void *e, void *f) { + *va = apple_gfx_mmio_map_surface_memory(phys, len, ro); + + trace_apple_gfx_iosfc_map_memory(phys, len, ro, va, e, f, *va); + + return *va != NULL; + }; + + iosfc_desc.unmapMemory = + ^bool(void *va, void *b, void *c, void *d, void *e, void *f) { + return apple_gfx_mmio_unmap_surface_memory(va); + }; + } iosfc_desc.raiseInterrupt = ^bool(uint32_t vector) { trace_apple_gfx_iosfc_raise_irq(vector);
@@ -223,13 +243,19 @@ static void apple_gfx_mmio_realize(DeviceState *dev, Error **errp) }; desc.usingIOSurfaceMapper = true; - s->pgiosfc = apple_gfx_prepare_iosurface_host_device(s); + desc.enableArgumentBuffers = true; + // Process isolation needs to go through PGMemoryMapDescriptor + if (@available(macOS 15.4, *)) { + desc.enableProcessIsolation = true; + } if (!apple_gfx_common_realize(&s->common, dev, desc, errp)) { [s->pgiosfc release]; s->pgiosfc = nil; } + s->pgiosfc = apple_gfx_prepare_iosurface_host_device(s); + [desc release]; desc = nil; }
hw/display/apple-gfx.h +13 -0
@@ -23,6 +23,13 @@ @protocol MTLTexture; @protocol MTLCommandQueue; +typedef struct PGGuestPhysicalRange_s +{ +uint64_t physicalAddress; +uint64_t physicalLength; +void *hostAddress; +}PGGuestPhysicalRange_t ; + typedef QTAILQ_HEAD(, PGTask_s) PGTaskList; typedef struct AppleGFXDisplayMode {
@@ -68,6 +75,12 @@ void *apple_gfx_host_ptr_for_gpa_range(uint64_t guest_physical, uint64_t length, bool read_only, MemoryRegion **mapping_in_region); +bool apple_gfx_register_memory_cb (Int128 start, +Int128 len, +const MemoryRegion *mr, +hwaddr offset_in_region, +void *opaque); +extern const PropertyInfo qdev_prop_apple_gfx_display_mode;#endif
hw/display/apple-gfx.m +41 -1
60 lines not on this page · raw message
Signature · 1 line
2.50.1 (Apple Git-155)
RFC 4/4 Revert "hw/arm: Do not build VMapple machine by default"
In reply to Mohamed MediouniThis reverts commit 49551752e860f5e403cdacac11ee1d218141fd3d.
--- configs/devices/aarch64-softmmu/default.mak | 1 - 1 file changed, 1 deletion(-)
configs/devices/aarch64-softmmu/default.mak +0 -1
@@ -9,4 +9,3 @@ include ../arm-softmmu/default.mak # CONFIG_XLNX_VERSAL=n # CONFIG_SBSA_REF=n # CONFIG_NPCM8XX=n -CONFIG_VMAPPLE=n
Signature · 1 line
2.50.1 (Apple Git-155)