From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14FB9FEC0FC for ; Tue, 24 Mar 2026 20:49:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w58gp-0000od-Ba; Tue, 24 Mar 2026 16:49:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w58gl-0000mT-Se for qemu-devel@nongnu.org; Tue, 24 Mar 2026 16:49:23 -0400 Received: from p-west2-cluster5-host3-snip4-1.eps.apple.com ([57.103.71.84] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w58gk-0004dk-2p for qemu-devel@nongnu.org; Tue, 24 Mar 2026 16:49:23 -0400 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-10-percent-0 (Postfix) with ESMTPS id 7D8F31800143; Tue, 24 Mar 2026 20:49:19 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1774385360; x=1776977360; bh=FBH3qmZPf7N3qFdetPUWzmKqQjMulIkpLcLbzIqxLeM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=atUXs/6l64vYCN8ggJ0bjQtvkYbvgyohXuLNByvnySILtHliY/+Jfphi1AmKuBQVUth+HM0rVqhFT2gEA9tcop1iFRegr9DWeaUhK3lMiMjzNsappCRk9iF7S6aHveof2FsOYgq2V2q4No5rHY7gfAXkw173p3JeplsAGDMzFyuS/wBMC7y4tRW5HjEzMNfDMuyZLHXVY/JUCKoCKIzeauHC5kEiPio8q1ZxWciFHSM3XNTOmIkMPC8a6iYFqmNeSAOLbowd3XmaU+RDtH2lsVIW1uwNdPAOSmqIc0xYdpNbV84nEUYP5zq9EqSxOOqH4AZXJXA2JcAUhVhLGK6+pA== mail-alias-created-date: 1752046281608 Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-10-percent-0 (Postfix) with ESMTPSA id 2473C1800462; Tue, 24 Mar 2026 20:49:13 +0000 (UTC) From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Akihiko Odaki , qemu-arm@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , Phil Dennis-Jordan , Peter Xu , Mads Ynddal , Roman Bolshakov , Alexander Graf , Mohamed Mediouni Subject: [RFC PATCH v7 1/7] vmapple: apple-gfx: make it work on the latest macOS release Date: Tue, 24 Mar 2026 21:48:49 +0100 Message-ID: <20260324204855.29759-2-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260324204855.29759-1-mohamed@unpredictable.fr> References: <20260324204855.29759-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: RNBHlEtrobwsmRWf6n1c7nr2-x4BYAUV X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzI0MDE2MSBTYWx0ZWRfX7eYvnjC+1YBR yq8FGl8bkeUFMNdv0PndBycSkbKyDL4g6k6kjRJ2NqTk96N3tuNjlrkSgZ6kiYNLJp/YRWSe3D1 RTp8NVrg1qf6fbje/7r5Tygo+kO5R9adZ2bZHUHsJ72Xw35NPcMqOj8kepDtdKxk10VLxwWemNI xcmLQncNVgR9pj9Vw8nrfl9xkLeOp2JJQCvQ5Kgbd0NfetjagEOjUTIYbpJzrB9vLuU32U65j4m WFb7KeqdXsmjSDcXlJoDJAzdsmPcDjgRkG/hi+C8dwA4zpioU/lESDdJAHYgRlu1rchRA0PYf3q K2RsF9oJ6j/S5Vpkx7Rm0/pBYDt557QFlJm/53qddhjtVAUeAOfm+gIJV4qFG4= X-Authority-Info-Out: v=2.4 cv=Kt5AGGWN c=1 sm=1 tr=0 ts=69c2f8d0 cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=XaNHVGzJZ3ayr3Wv:21 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=2lQx5wYd1WNrG3klcQkA:9 X-Proofpoint-ORIG-GUID: RNBHlEtrobwsmRWf6n1c7nr2-x4BYAUV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-24_03,2026-03-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 clxscore=1030 adultscore=0 spamscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2603240161 Received-SPF: pass client-ip=57.103.71.84; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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. Signed-off-by: Mohamed Mediouni --- hw/display/apple-gfx-mmio.m | 59 ++++++++++++++++++++++++++++--------- hw/display/apple-gfx.h | 16 ++++++++++ hw/display/apple-gfx.m | 41 +++++++++++++++++++++++++- 3 files changed, 101 insertions(+), 15 deletions(-) diff --git a/hw/display/apple-gfx-mmio.m b/hw/display/apple-gfx-mmio.m index 58beaadd1f..cc1f8cfcad 100644 --- a/hw/display/apple-gfx-mmio.m +++ b/hw/display/apple-gfx-mmio.m @@ -19,6 +19,7 @@ #include "hw/core/irq.h" #include "apple-gfx.h" #include "trace.h" +#include "system/address-spaces.h" #import @@ -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; } diff --git a/hw/display/apple-gfx.h b/hw/display/apple-gfx.h index 3197bd853d..384aee0c5f 100644 --- a/hw/display/apple-gfx.h +++ b/hw/display/apple-gfx.h @@ -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 diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m index e0a765fcb1..213233084d 100644 --- a/hw/display/apple-gfx.m +++ b/hw/display/apple-gfx.m @@ -21,6 +21,7 @@ #include "system/address-spaces.h" #include "system/dma.h" #include "migration/blocker.h" +#include "system/memory.h" #include "ui/console.h" #include "apple-gfx.h" #include "trace.h" @@ -596,6 +597,35 @@ void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_name) /* TODO: PVG framework supports serialising device state: integrate it! */ } +@interface PGDeviceDescriptor (IOSurfaceMapper) +@property (readwrite, nonatomic, copy, nullable) PGMemoryMapDescriptor* memoryMapDescriptor; +@end + +bool apple_gfx_register_memory_cb(Int128 start, Int128 len, + const MemoryRegion *mr, + hwaddr offset_in_region, void *opaque) { + PGGuestPhysicalRange_t range; + PGMemoryMapDescriptor *memory_map_descriptor = opaque; + if (memory_access_is_direct(mr, true, MEMTXATTRS_UNSPECIFIED)) { + range.physicalAddress = start; + range.physicalLength = len; + range.hostAddress = memory_region_get_ram_ptr(mr); + [memory_map_descriptor addRange:range]; + } + return false; +} + +static void apple_gfx_register_memory(AppleGFXState *s, + PGDeviceDescriptor *desc) +{ + PGMemoryMapDescriptor* memoryMapDescriptor = [PGMemoryMapDescriptor new]; + + FlatView* fv = address_space_to_flatview(&address_space_memory); + flatview_for_each_range(fv, apple_gfx_register_memory_cb, memoryMapDescriptor); + + desc.memoryMapDescriptor = memoryMapDescriptor; +} + static void apple_gfx_register_task_mapping_handlers(AppleGFXState *s, PGDeviceDescriptor *desc) { @@ -763,7 +793,16 @@ bool apple_gfx_common_realize(AppleGFXState *s, DeviceState *dev, desc.device = s->mtl; - apple_gfx_register_task_mapping_handlers(s, desc); + /* + * The legacy memory management interface doesn't allow for + * vGPU sandboxing. As such, always use the new interface + * on macOS 15.4 onwards. + */ + if (@available(macOS 15.4, *)) { + apple_gfx_register_memory(s, desc); + } else { + apple_gfx_register_task_mapping_handlers(s, desc); + } s->cursor_show = true; -- 2.50.1 (Apple Git-155)