vmapple: making it work on the latest macOS host releases
v6 cover vmapple: making it work on the latest macOS host releases
Support for newer guest OSes isn't part of this series.
v6:
Rework the patches a bit, with making sure that there's no compiler warnings
v5:
Address review comments and rebase.
v4:
Rebase and resend without the RFC tag as I didn't get feedback.
Drop patch 1 (version I posted was incomplete anyways). Last patch isn't worth it too tbh.
v2->v3:
Remove the Apple M4 support workaround part for now, to be part of another patchset perhaps Address comments
v1->v2:
Remove some lines that shouldn't have been present...
Mohamed Mediouni (4):
system: memory: convert some helpers to const
vmapple: apple-gfx: make it work on the latest macOS release hw/vmapple: aes: convert MAX_LEN to a #define Revert "hw/arm: Do not build VMapple machine by default"
configs/devices/aarch64-softmmu/default.mak | 1 - hw/display/apple-gfx-mmio.m | 59 ++++++++++++++++----- hw/display/apple-gfx.h | 16 ++++++ hw/display/apple-gfx.m | 42 ++++++++++++++- hw/vmapple/aes.c | 3 +- include/system/memory.h | 14 ++--- system/memory.c | 6 +-- 7 files changed, 114 insertions(+), 27 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v6 2/4 vmapple: apple-gfx: make it work on the latest macOS release
Follow changes in memory management introduced on macOS 15.4.
The legacy memory management API has been removed for the IOSurface mapper on that macOS version.
Also enable process isolation for a sandboxed GPU process when on a new OS.
--- hw/display/apple-gfx-mmio.m | 59 ++++++++++++++++++++++++++++--------- hw/display/apple-gfx.h | 16 ++++++++++ hw/display/apple-gfx.m | 42 +++++++++++++++++++++++++- 3 files changed, 102 insertions(+), 15 deletions(-)
hw/display/apple-gfx-mmio.m +45 -14
@@ -19,6 +19,7 @@ #include "hw/core/irq.h" #include "apple-gfx.h" #include "trace.h" +#include "system/address-spaces.h" #import <ParavirtualizedGraphics/ParavirtualizedGraphics.h>
@@ -36,12 +37,19 @@ typedef bool(^IOSFCMapMemory)(uint64_t phys, uint64_t len, bool ro, void **va, @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
@@ -183,19 +191,32 @@ static bool apple_gfx_mmio_unmap_surface_memory(void *ptr) [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); - }; + /* + * The legacy memory management API is no longer present + * for the IOSurface mapper as of macOS 15.4. + */ + if (@available(macOS 15.4, *)) { + PGMemoryMapDescriptor *memory_map_descriptor = [PGMemoryMapDescriptor new]; + FlatView* fv = address_space_to_flatview(&address_space_memory); + flatview_for_each_range(fv, apple_gfx_register_memory_cb, memory_map_descriptor); + /* the device model defines this as a single-page MMIO region, hence 16KB */ + iosfc_desc.mmioLength = 0x10000; + iosfc_desc.memoryMapDescriptor = memory_map_descriptor; + } 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 +244,23 @@ 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 PGMemoryMapDescriptor instead of + * the legacy memory management interface present in releases + * older than macOS 15.4. + */ + 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 +16 -0
@@ -12,6 +12,7 @@#include "system/memory.h" #include "hw/core/qdev-properties.h" #include "ui/surface.h" +#include "objc/NSObject.h" #define TYPE_APPLE_GFX_MMIO "apple-gfx-mmio"#define TYPE_APPLE_GFX_PCI "apple-gfx-pci"
@@ -23,6 +24,17 @@ @protocol MTLTexture; @protocol MTLCommandQueue; +typedef struct PGGuestPhysicalRange_s +{ +uint64_t physicalAddress; +uint64_t physicalLength; +void *hostAddress; +}PGGuestPhysicalRange_t ; + +@interface PGMemoryMapDescriptor : NSObject +-(void)addRange:(PGGuestPhysicalRange_t) range; +@end + typedef QTAILQ_HEAD(, PGTask_s) PGTaskList; typedef struct AppleGFXDisplayMode {
@@ -68,6 +80,10 @@ 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)
PATCH v6 4/4 Revert "hw/arm: Do not build VMapple machine by default"
In reply to Mohamed MediouniThe vmapple virtual machine is now functional on newer macOS host releases. Revert 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)
PATCH v6 3/4 hw/vmapple: aes: convert MAX_LEN to a #define
In reply to Mohamed MediouniWorking around this compiler warning:
../hw/vmapple/aes.c:257:14: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
257 | char hex[MAX_LEN * 2 + 1] = "";
| ^~~~~~~~~~~~~~~1 warning generated.
--- hw/vmapple/aes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/vmapple/aes.c +2 -1
@@ -253,7 +253,7 @@ static bool cmd_iv(AESState *s)static void dump_data (const char *desc,const void *p,size_t len) { -static const size_t MAX_LEN =0x1000 ; +#define MAX_LEN 0x1000char hex[MAX_LEN *2 +1 ] ="" ;if (len >MAX_LEN ) {
@@ -262,6 +262,7 @@ static void dump_data(const char *desc, const void *p, size_t len)qemu_hexdump_to_buffer (hex,sizeof (hex), p, len);trace_aes_dump_data (desc, hex); +#undef MAX_LEN }static bool cmd_data (AESState *s)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v6 1/4 system: memory: convert some helpers to const
In reply to Mohamed MediouniSeemed to be a better alternative than making flatview_for_each_range pass non-const pointers.
--- include/system/memory.h | 14 +++++++------- system/memory.c | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-)
include/system/memory.h +7 -7
@@ -1339,7 +1339,7 @@ void memory_region_init(MemoryRegion *mr,* * @mr: the #MemoryRegion */ -void memory_region_ref (MemoryRegion *mr); +void memory_region_ref (const MemoryRegion *mr);/** * memory_region_unref: Remove 1 to a memory region's reference count
@@ -1765,7 +1765,7 @@ uint64_t memory_region_size(MemoryRegion *mr);* * @mr: the memory region being queried */ -static inline bool memory_region_is_ram (MemoryRegion *mr) +static inline bool memory_region_is_ram (const MemoryRegion *mr) {return mr->ram; }
@@ -1777,7 +1777,7 @@ static inline bool memory_region_is_ram(MemoryRegion *mr)* * @mr: the memory region being queried */ -bool memory_region_is_ram_device (MemoryRegion *mr); +bool memory_region_is_ram_device (const MemoryRegion *mr);/** * memory_region_is_romd: check whether a memory region is in ROMD mode
@@ -1787,7 +1787,7 @@ bool memory_region_is_ram_device(MemoryRegion *mr);* * @mr: the memory region being queried */ -static inline bool memory_region_is_romd (MemoryRegion *mr) +static inline bool memory_region_is_romd (const MemoryRegion *mr) {return mr->rom_device && mr->romd_mode; }
@@ -2071,7 +2071,7 @@ MemoryRegion *memory_region_from_host(void *ptr, ram_addr_t *offset);* * @mr: the memory region being queried. */ -void *memory_region_get_ram_ptr (MemoryRegion *mr); +void *memory_region_get_ram_ptr (const MemoryRegion *mr);/* memory_region_ram_resize: Resize a RAM region. *
@@ -2967,7 +2967,7 @@ void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr);int memory_access_size (MemoryRegion *mr,unsigned l,hwaddr addr);bool prepare_mmio_access (MemoryRegion *mr); -static inline bool memory_region_supports_direct_access (MemoryRegion *mr) +static inline bool memory_region_supports_direct_access (const MemoryRegion *mr) {/* ROM DEVICE regions only allow direct access if in ROMD mode. */ if (memory_region_is_romd (mr)) {
@@ -2984,7 +2984,7 @@ static inline bool memory_region_supports_direct_access(MemoryRegion *mr)return !memory_region_is_ram_device (mr); } -static inline bool memory_access_is_direct (MemoryRegion *mr,bool is_write, +static inline bool memory_access_is_direct (const MemoryRegion *mr,bool is_write,MemTxAttrs attrs) {if (!memory_region_supports_direct_access (mr)) {
system/memory.c +3 -3
@@ -1825,7 +1825,7 @@ Object *memory_region_owner(MemoryRegion *mr)return obj->parent; } -void memory_region_ref (MemoryRegion *mr) +void memory_region_ref (const MemoryRegion *mr) {/* MMIO callbacks most likely will access data that belongs * to the owner, hence the need to ref/unref the owner whenever
@@ -1866,7 +1866,7 @@ const char *memory_region_name(const MemoryRegion *mr)return mr->name; } -bool memory_region_is_ram_device (MemoryRegion *mr) +bool memory_region_is_ram_device (const MemoryRegion *mr) {return mr->ram_device; }
@@ -2415,7 +2415,7 @@ int memory_region_get_fd(MemoryRegion *mr)return mr->ram_block->fd; } -void *memory_region_get_ram_ptr (MemoryRegion *mr) +void *memory_region_get_ram_ptr (const MemoryRegion *mr) {uint64_t offset =0 ;
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH v6 1/4] system: memory: convert some helpers to const
Quoted 14 lines · Mohamed Mediouni
Seemed to be a better alternative than making
flatview_for_each_rangepass non-const pointers.Signed-off-by Mohamed Mediouni <[email protected]>--- include/system/memory.h | 14 +++++++------- system/memory.c | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-)include/system/memory.h +0
-0
include/system/memory.h void memory_region_init(MemoryRegion *mr, · line 1342
Quoted 5 lines
include/system/memory.h +1
-1@@ -1339,7 +1339,7 @@ void memory_region_init(MemoryRegion *mr,* * @mr: the #MemoryRegion */ -void memory_region_ref (MemoryRegion *mr); +void memory_region_ref (const MemoryRegion *mr);
I don't firmly oppose this, but I feel a bit uneasy about this change.
You are right that this should be const in principle: this function does not modify mr in any way.
However, we can also consider the current implement as "abusing" the const qualifier to express that we are not going to ref/unref. It is an abuse, but I think it is practically makes sense.
Regards,
Akihiko Odaki
Quoted 88 lines
include/system/memory.h +6
-6/** * memory_region_unref: Remove 1 to a memory region's reference count @@ -1765,7 +1765,7 @@ uint64_t memory_region_size(MemoryRegion *mr);* * @mr: the memory region being queried */ -static inline bool memory_region_is_ram (MemoryRegion *mr) +static inline bool memory_region_is_ram (const MemoryRegion *mr) {return mr->ram; }@@ -1777,7 +1777,7 @@ static inline bool memory_region_is_ram(MemoryRegion *mr)* * @mr: the memory region being queried */ -bool memory_region_is_ram_device (MemoryRegion *mr); +bool memory_region_is_ram_device (const MemoryRegion *mr);/** * memory_region_is_romd: check whether a memory region is in ROMD mode @@ -1787,7 +1787,7 @@ bool memory_region_is_ram_device(MemoryRegion *mr);* * @mr: the memory region being queried */ -static inline bool memory_region_is_romd (MemoryRegion *mr) +static inline bool memory_region_is_romd (const MemoryRegion *mr) {return mr->rom_device && mr->romd_mode; }@@ -2071,7 +2071,7 @@ MemoryRegion *memory_region_from_host(void *ptr, ram_addr_t *offset);* * @mr: the memory region being queried. */ -void *memory_region_get_ram_ptr (MemoryRegion *mr); +void *memory_region_get_ram_ptr (const MemoryRegion *mr);/* memory_region_ram_resize: Resize a RAM region. * @@ -2967,7 +2967,7 @@ void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr);int memory_access_size (MemoryRegion *mr,unsigned l,hwaddr addr);bool prepare_mmio_access (MemoryRegion *mr); -static inline bool memory_region_supports_direct_access (MemoryRegion *mr) +static inline bool memory_region_supports_direct_access (const MemoryRegion *mr) {/* ROM DEVICE regions only allow direct access if in ROMD mode. */ if (memory_region_is_romd (mr)) {@@ -2984,7 +2984,7 @@ static inline bool memory_region_supports_direct_access(MemoryRegion *mr)return !memory_region_is_ram_device (mr); } -static inline bool memory_access_is_direct (MemoryRegion *mr,bool is_write, +static inline bool memory_access_is_direct (const MemoryRegion *mr,bool is_write,MemTxAttrs attrs) {if (!memory_region_supports_direct_access (mr)) {system/memory.c +3
-3@@ -1825,7 +1825,7 @@ Object *memory_region_owner(MemoryRegion *mr)return obj->parent; } -void memory_region_ref (MemoryRegion *mr) +void memory_region_ref (const MemoryRegion *mr) {/* MMIO callbacks most likely will access data that belongs * to the owner, hence the need to ref/unref the owner whenever @@ -1866,7 +1866,7 @@ const char *memory_region_name(const MemoryRegion *mr)return mr->name; } -bool memory_region_is_ram_device (MemoryRegion *mr) +bool memory_region_is_ram_device (const MemoryRegion *mr) {return mr->ram_device; }@@ -2415,7 +2415,7 @@ int memory_region_get_fd(MemoryRegion *mr)return mr->ram_block->fd; } -void *memory_region_get_ram_ptr (MemoryRegion *mr) +void *memory_region_get_ram_ptr (const MemoryRegion *mr) {uint64_t offset =0 ;