From nobody Mon Apr 6 21:33:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1773769843; cv=none; d=zohomail.com; s=zohoarc; b=btzw7RAxtSJl8/dCe+gj6434S+wYwWXYdPjRdo3NOLvbnre6FQmJ6nF49BKBTy9x2t3AWMbVMLzGvkO/oV1JIhIysl/02INcowist7h3Qp3DrY8l2DDim2YpK1D/c2xb7qzMJ8UxbZ3buaJZnjuohTD9crbsRpgQj3jAIa5sHCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773769842; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Okui3+LoiEw6Ead0/iU3+dwFPXpVpxuXn0Pb9e4RdJE=; b=ZtNvO3DlcmpRmAcxEznJd8CgMfnV1SyOEBQ1yYqtEbUOBhuZo1XfICI92btAKkXgBHp2A+Xcs3v6N0b3UiW7E39TZZlMRyIokCHuMdyK9innj1ZfI9BrLGJSyuBHpnLHw5iCud721ivuqPVH//Mb37MBvIudSsYmCehTymmnXoQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773769842991708.8940355376728; Tue, 17 Mar 2026 10:50:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2YXV-0003fi-T6; Tue, 17 Mar 2026 13:49:10 -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 1w2YXN-0003cg-AL for qemu-devel@nongnu.org; Tue, 17 Mar 2026 13:49:01 -0400 Received: from mail-dy1-x1333.google.com ([2607:f8b0:4864:20::1333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w2YXI-00075D-GU for qemu-devel@nongnu.org; Tue, 17 Mar 2026 13:48:58 -0400 Received: by mail-dy1-x1333.google.com with SMTP id 5a478bee46e88-2bd9a485bd6so530993eec.1 for ; Tue, 17 Mar 2026 10:48:55 -0700 (PDT) Received: from localhost.localdomain ([143.54.78.51]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2c0e5583533sm190487eec.18.2026.03.17.10.48.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 17 Mar 2026 10:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773769734; x=1774374534; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Okui3+LoiEw6Ead0/iU3+dwFPXpVpxuXn0Pb9e4RdJE=; b=Srkct72KVBpskW4PenA7z/KmiMedFK3gMmdf1rvjwjDF8dtoTgPVCrMjd/KcL1QxV0 g0nODKKjV7DYV6o3hCZnIuVqTwzPtQ5xARGDGKE5WIGHaAV7fHE1Hrm7ejHjvsACTneB sGsF95WvE7GE/xt4+6Ud6lsCw/C71wlSs6dGCmkBBv3JRllPZSjkh9X9ZtT1AdQ5/MM/ NdC5kpdD3FMFWal+VcGndlhhTRuwNTw087l2beA1q3sn3GH+lB/r1A5+7zy42j3ZDtos 8rp2SL8Wez4PIPM7xtxSB5KDLatezjOGLJZS/npQ3imi3eTZnXMRiWqB4upss+VCDnn+ MXpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773769734; x=1774374534; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Okui3+LoiEw6Ead0/iU3+dwFPXpVpxuXn0Pb9e4RdJE=; b=DKXnfLofE1FrCRRdvXvZZi19gk1CO6pYHBi7kEMRrro1PvN5KCwavWL9lDwjyIool0 ZO+alzqNXD01DAK72YrGVsxeAnnfLr/98TlTA6W2Rh5U1IWiZufbr0bDG82GCelzKX8G vDdWFo0mgYbia4jVrMvAsb/hSgykELcaNR9eRxzSBh/8spDjz0fQ97Ovztd/DGIhmniV aqE+FJyq+Oxt2VEdIbEW6oR6TaiZDgOYIJoKEYLzdFzTIUa87nAODjAq3erhNJr6b6L8 kJrOT+R1MPMCYTUEzzDk+18aToRHCTeiGvuSog+ncUAfa4kR7JylPRaVaDmqPMqif69E AqPg== X-Gm-Message-State: AOJu0YwpOR1Lo/HtCMFHMfMhFJoG4YQsTx+u0pydoyGNI4kwdw+lXrrc VV+Z3rxHy1wR59F/LN6PK1FJ+VQP5LYS2JS44ymQ3q7dtkbLRUaACRrKN65HTW77 X-Gm-Gg: ATEYQzy0hm0Yiq5gydu0Z+GlWrGtntbfRdNpd4x2wqs7Q4Ln/vCmTQ55q470Ya5M5Db itgV+yS4SM2DuiVVS64U6cJ6E9R8m953s76rjWgbuSUOgoU0dWazW+iCE5qCji7U2dgy5CACklU C8Cth7pAoj4g+4mpviPnbKxRYFgO5nUhqt/J6McMOCRbRxFlEz6z4wHvTwaVsZqItdWtQpbq2yy Vu1WGSUnqLr6KRPC7oNGFMQ8qirumNZFSfJm74MUyYPNyl2jVvg9jRo2zhuJSY7op0r9KFGZipM Pjm6OxD+sIFQnRcJocvi3eYz9m4oNN42aEy0389c+XMHcQLFm5b5TOwHuHI+My6rztblkUjMZQb UeW9nqYtuTi0g5Fs6KyaGEsnP5+aAmX3xHYV+436TCImvlSMv9RSDr0Y+20mglXRlSKoCrQd6KY sG8ZHBoKJxQos4pFWUpjbCaJRfnYZCXZyoLMpFeuCpDTK54CmLRdPu X-Received: by 2002:a05:7301:1691:b0:2bd:c8a2:954 with SMTP id 5a478bee46e88-2c0e5041a17mr182287eec.24.1773769734014; Tue, 17 Mar 2026 10:48:54 -0700 (PDT) From: Lucas Amaral To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, agraf@csgraf.de, peter.maydell@linaro.org, mohamed@unpredictable.fr, Lucas Amaral Subject: [PATCH v4 1/3] virtio-gpu: validate host page alignment for MAP_FIXED blobs Date: Tue, 17 Mar 2026 14:48:43 -0300 Message-ID: <20260317174845.31768-2-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260317174845.31768-1-lucaaamaral@gmail.com> References: <20260317174845.31768-1-lucaaamaral@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1333; envelope-from=lucaaamaral@gmail.com; helo=mail-dy1-x1333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1773769845240158500 Content-Type: text/plain; charset="utf-8" Commit 4eb0aace ("virtio-gpu: Support mapping hostmem blobs with map_fixed") uses mmap(MAP_FIXED) to map blob resources into a pre-allocated hostmem region. Both the offset and size passed to mmap must be aligned to the host page size, but the code does not validate this. On hosts where qemu_real_host_page_size() exceeds the guest's page size (e.g. ARM64 with 16KB or 64KB pages, macOS ARM64), the guest may provide blob offsets aligned to its own page size (4KB) but not to the host's. This causes mmap(MAP_FIXED) to fail with EINVAL, and the subsequent unmap (which also uses mmap MAP_FIXED) fails the same way, producing: virtio_gpu_virgl_unmap_resource_blob: failed to unmap(fixed) virgl resource: Invalid argument Add an alignment check before attempting MAP_FIXED. When the offset or blob size is not host-page-aligned, skip the MAP_FIXED path and fall through to the existing subregion method, which handles any alignment. Fixes: 4eb0aace ("virtio-gpu: Support mapping hostmem blobs with map_fixed") Signed-off-by: Lucas Amaral --- hw/display/virtio-gpu-virgl.c | 45 +++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index b7a2d160..f6583b48 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -185,25 +185,34 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g, return -EBUSY; } =20 - ret =3D virgl_renderer_resource_map_fixed(res->base.resource_id, - gl->hostmem_mmap + offset); - switch (ret) { - case 0: - res->map_fixed =3D gl->hostmem_mmap + offset; - return 0; - - case -EOPNOTSUPP: - /* - * MAP_FIXED is unsupported by this resource. - * Mapping falls back to a blob subregion method in that case. - */ - break; + /* + * MAP_FIXED requires host-page-aligned offset and size. Hosts with + * page sizes larger than the guest's (e.g. 16KB on ARM64) may receive + * non-aligned blob offsets. Fall through to the subregion method when + * alignment requirements are not met. + */ + if (QEMU_IS_ALIGNED(offset, qemu_real_host_page_size()) && + QEMU_IS_ALIGNED(res->base.blob_size, qemu_real_host_page_size())) { + ret =3D virgl_renderer_resource_map_fixed(res->base.resource_id, + gl->hostmem_mmap + offset); + switch (ret) { + case 0: + res->map_fixed =3D gl->hostmem_mmap + offset; + return 0; + + case -EOPNOTSUPP: + /* + * MAP_FIXED is unsupported by this resource. + * Mapping falls back to a blob subregion method in that case. + */ + break; =20 - default: - qemu_log_mask(LOG_GUEST_ERROR, - "%s: failed to map(fixed) virgl resource: %s\n", - __func__, strerror(-ret)); - return ret; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: failed to map(fixed) virgl resource: %s\n", + __func__, strerror(-ret)); + return ret; + } } #endif =20 --=20 2.52.0 From nobody Mon Apr 6 21:33:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1773769924; cv=none; d=zohomail.com; s=zohoarc; b=R9vHnJ89u/pIydlTHIlBH9uv8GNHDKSGs9UA/OzX+kb4K0fFgQdDdM1lD23RF4Xu4nko2MlJLMxTL6RuB8nyodp9f8PidW3t87ot4jiF7YtWuXaZDXafrNxgI2MZby5Eh4RNRHf6KE14Wu0Sa0hpGFVb7AyJ2DKTso8RvIU83yQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773769924; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=i/DK28lXQIwOLzrB1K190uj9fo4wlA326bvO6/LGKYk=; b=VShMdWf/+mdY2fmi2cNV3uG3ECiTyLaCuvvYcqf9ApXidsp/wp0IY4nyvD1WuAJeWk/VaLoHqGEaJkr5sPNXg6GyhIsn94mTbFfySukSNVO4r/Y2d9DUa+lESG0aSvJmPOYXNWYzg83JcLmdGHh3bk2RGz6NiaPfDpHzY9hIVgg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773769924353297.4889274343468; Tue, 17 Mar 2026 10:52:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2YXa-0003p8-6i; Tue, 17 Mar 2026 13:49:14 -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 1w2YXR-0003dW-Cg for qemu-devel@nongnu.org; Tue, 17 Mar 2026 13:49:06 -0400 Received: from mail-dy1-x132a.google.com ([2607:f8b0:4864:20::132a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w2YXM-00075f-1O for qemu-devel@nongnu.org; Tue, 17 Mar 2026 13:49:02 -0400 Received: by mail-dy1-x132a.google.com with SMTP id 5a478bee46e88-2c0bdf1988cso4567398eec.1 for ; Tue, 17 Mar 2026 10:48:58 -0700 (PDT) Received: from localhost.localdomain ([143.54.78.51]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2c0e5583533sm190487eec.18.2026.03.17.10.48.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 17 Mar 2026 10:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773769737; x=1774374537; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i/DK28lXQIwOLzrB1K190uj9fo4wlA326bvO6/LGKYk=; b=d1fNCgcEV0LoVPwu8ETQRZGukngVSy0u5O5K3OFKKb4OkBjJ6cN10fUTHQT3QjNhsJ FlkPSYgKyN6CHYR+tMJys7j9495a8Kj8aqgEiN3+2fp97snQEYcs5bzWuBggR9hg6pxl jKzyC+p4p5CWhHOnd8W9hKCiZwBhU+NEc6EXESjxRbzHnfl4CGWx8ndvMZCIYxm6dhJv WveGwwYHhAMr3/Q/MDBXlU6jjrOvURPNOs/cLtMKE6n0x0n5+4MH8gm6ecwf9YoSlAA1 35Dgr25uqTLV5B5hbQZc0BraE4EzTTCFiP/B3nBxO1qJqZuEBw11gNscVtfys4vkg1Dw qyoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773769737; x=1774374537; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=i/DK28lXQIwOLzrB1K190uj9fo4wlA326bvO6/LGKYk=; b=D9ncXR/YXGCdGzsyUvuVeGYmHa72c2qqNp9C0vdMVzOjbuFN77dIE2na5WxROAFJeW QQ9bDbaVuYc/Gg9zb4b14zxztt7tXKhaCymr0hLbPl66x79/8k8CN1V8VvSs63cZweaz fmExCP30Xecy3b3pFTs2qSSFqSTIjrq0Pd8+f4Id/TzqwNcyqFJlYDpxVDZma5xARnJ7 6WD34hp2z3WbhWkS1QpZKPBlT18MLKe1F6R5eIbGvST+04Su3iaOX7vvrvKa+F9LNstp kD/OYLuWiI6i70LkHBELzMKTgURECVxPGrZ5w42RId801XXtNKSFFM/0KW2xZVhID+da T0gg== X-Gm-Message-State: AOJu0YwPfPl8pkROZP5sNqmuBWtLxa/ngXCgEZxcOYefcCgh/6hAryXE ZRTYhTnN/p9zW4YjGz1hob6egeCpz8HzVwpQ1Z+VEVj2j4k5zK0Q5FinYkQA29o6 X-Gm-Gg: ATEYQzzAJawsPI60vAzAHFnBvYbx3+pKUvzy68vSymhymJNwqvuIRWxtdmTa1sGYpNI V6gN/B33SYPS614Tr+T/NFEotrxMPgA53XakgAbBcu3lz2nqc1pFVq9Fs9i/vtQtoXQ4lFK38BW N+8M4bXz6dmk7j9S2qHdjZgelbe+5uwKq2RRnojJxGGbXzMELxxquIhvBA8y0QC9Mn6FwkVbLDn N1sQP/PlQTfBD/S1aYQZHCit5iaR7ApPzJXNcrixjtMu6bPLo4i9K629Efka0Vw6VdvinYU4NN/ gVIIMYPPVIM71ki1am4BlEoCjvC+tgrANSq0dYCXkrqeooXgSm4gZ6l7SnFo5APJH1T370PIRIj lpviC0uIWGPmH0PBfSuOvZJ9b+VMHAj71fqbrO3N/Se193mOfbxtvBWiCOixcr7yb2dXY9hqHMl BK1diF2d8iSuUA5D+0l9FAmU4XJgaAa5nc5TbXYDnG7VUo5Qnpang4 X-Received: by 2002:a05:7301:6785:b0:2c0:dae2:9c50 with SMTP id 5a478bee46e88-2c0e5115c33mr139878eec.31.1773769737259; Tue, 17 Mar 2026 10:48:57 -0700 (PDT) From: Lucas Amaral To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, agraf@csgraf.de, peter.maydell@linaro.org, mohamed@unpredictable.fr, Lucas Amaral , Lucas Amaral Subject: [PATCH v4 2/3] accel/hvf: introduce map granule abstraction and IPA property Date: Tue, 17 Mar 2026 14:48:44 -0300 Message-ID: <20260317174845.31768-3-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260317174845.31768-1-lucaaamaral@gmail.com> References: <20260317174845.31768-1-lucaaamaral@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::132a; envelope-from=lucaaamaral@gmail.com; helo=mail-dy1-x132a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1773769926811154100 Add a map granule abstraction that decouples HVF memory mapping alignment from the host page size. On ARM64, Apple Silicon supports stage-2 translation with 4KB page granules regardless of the host OS page size (16KB on macOS). This allows running guests with 4KB pages without interior mapping failures. Introduce hvf_set_map_granule()/hvf_get_map_granule() in hvf-all.c to replace hard-coded qemu_real_host_page_size() references in do_hv_vm_protect() and hvf_set_phys_mem(). When the granule is not explicitly configured, fall back to host page size to preserve the previous behaviour. Add an "ipa-granule" accelerator property (auto, 4k, 16k) following the established kvm_arch_accel_class_init() pattern: ARM registers the property in hvf_arch_accel_class_init(), x86 provides an empty stub. This avoids #ifdef __aarch64__ in common code while keeping a single hvf-all.c shared by both targets. Fix hvf_set_phys_mem() to return early for non-aligned regions instead of clearing the add flag, which previously fell through to an incorrect unmap of a region that was never mapped. Signed-off-by: Lucas Amaral --- accel/hvf/hvf-all.c | 30 +++++++++++++++++++++++++++--- include/system/hvf.h | 15 +++++++++++++++ include/system/hvf_int.h | 2 ++ target/arm/hvf/hvf.c | 40 ++++++++++++++++++++++++++++++++++++++++ target/i386/hvf/hvf.c | 4 ++++ 5 files changed, 88 insertions(+), 3 deletions(-) diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c index 5f357c6d..d745fefd 100644 --- a/accel/hvf/hvf-all.c +++ b/accel/hvf/hvf-all.c @@ -10,6 +10,8 @@ =20 #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/units.h" +#include "qapi/error.h" #include "accel/accel-ops.h" #include "exec/cpu-common.h" #include "system/address-spaces.h" @@ -22,6 +24,21 @@ =20 bool hvf_allowed; =20 +static uint64_t hvf_map_granule; + +void hvf_set_map_granule(uint64_t size) +{ + hvf_map_granule =3D size; +} + +uint64_t hvf_get_map_granule(void) +{ + if (!hvf_map_granule) { + return qemu_real_host_page_size(); + } + return hvf_map_granule; +} + const char *hvf_return_string(hv_return_t ret) { switch (ret) { @@ -53,7 +70,7 @@ void assert_hvf_ok_impl(hv_return_t ret, const char *file= , unsigned int line, static void do_hv_vm_protect(hwaddr start, size_t size, hv_memory_flags_t flags) { - intptr_t page_mask =3D qemu_real_host_page_mask(); + intptr_t page_mask =3D -(intptr_t)hvf_get_map_granule(); hv_return_t ret; =20 trace_hvf_vm_protect(start, size, flags, @@ -83,7 +100,7 @@ static void hvf_set_phys_mem(MemoryRegionSection *sectio= n, bool add) MemoryRegion *area =3D section->mr; bool writable =3D !area->readonly && !area->rom_device; hv_memory_flags_t flags; - uint64_t page_size =3D qemu_real_host_page_size(); + uint64_t page_size =3D hvf_get_map_granule(); uint64_t gpa =3D section->offset_within_address_space; uint64_t size =3D int128_get64(section->size); hv_return_t ret; @@ -104,7 +121,7 @@ static void hvf_set_phys_mem(MemoryRegionSection *secti= on, bool add) if (!QEMU_IS_ALIGNED(size, page_size) || !QEMU_IS_ALIGNED(gpa, page_size)) { /* Not page aligned, so we can not map as RAM */ - add =3D false; + return; } =20 if (!add) { @@ -186,6 +203,11 @@ static int hvf_accel_init(AccelState *as, MachineState= *ms) int pa_range =3D 36; MachineClass *mc =3D MACHINE_GET_CLASS(ms); =20 + /* Resolve ipa-granule=3Dauto =E2=86=92 host page size */ + if (!s->ipa_granule) { + s->ipa_granule =3D qemu_real_host_page_size(); + } + hvf_set_map_granule(s->ipa_granule); =20 if (mc->get_physical_address_range) { pa_range =3D mc->get_physical_address_range(ms, @@ -223,6 +245,8 @@ static void hvf_accel_class_init(ObjectClass *oc, const= void *data) ac->init_machine =3D hvf_accel_init; ac->allowed =3D &hvf_allowed; ac->gdbstub_supported_sstep_flags =3D hvf_gdbstub_sstep_flags; + + hvf_arch_accel_class_init(oc); } =20 static const TypeInfo hvf_accel_type =3D { diff --git a/include/system/hvf.h b/include/system/hvf.h index d3dcf088..3c4c3b89 100644 --- a/include/system/hvf.h +++ b/include/system/hvf.h @@ -36,4 +36,19 @@ typedef struct HVFState HVFState; DECLARE_INSTANCE_CHECKER(HVFState, HVF_STATE, TYPE_HVF_ACCEL) =20 +#ifdef CONFIG_HVF_IS_POSSIBLE +/* + * Minimum alignment for hv_vm_map(). Returns the configured IPA granule + * or host page size if not set. + */ +void hvf_set_map_granule(uint64_t size); +uint64_t hvf_get_map_granule(void); +#else +static inline void hvf_set_map_granule(uint64_t size) {} +static inline uint64_t hvf_get_map_granule(void) +{ + return qemu_real_host_page_size(); +} +#endif + #endif diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h index 2621164c..9589b022 100644 --- a/include/system/hvf_int.h +++ b/include/system/hvf_int.h @@ -38,6 +38,7 @@ struct HVFState { =20 hvf_vcpu_caps *hvf_caps; uint64_t vtimer_offset; + uint32_t ipa_granule; QTAILQ_HEAD(, hvf_sw_breakpoint) hvf_sw_breakpoints; }; extern HVFState *hvf_state; @@ -57,6 +58,7 @@ void assert_hvf_ok_impl(hv_return_t ret, const char *file= , unsigned int line, const char *hvf_return_string(hv_return_t ret); int hvf_arch_init(void); hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range); +void hvf_arch_accel_class_init(ObjectClass *oc); uint32_t hvf_arch_get_default_ipa_bit_size(void); uint32_t hvf_arch_get_max_ipa_bit_size(void); void hvf_kick_vcpu_thread(CPUState *cpu); diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index 5fc8f6bb..1ba5bbf3 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -12,6 +12,8 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" #include "qemu/log.h" +#include "qemu/units.h" +#include "qapi/error.h" =20 #include "system/runstate.h" #include "system/hvf.h" @@ -1218,6 +1220,44 @@ void hvf_arch_vcpu_destroy(CPUState *cpu) assert_hvf_ok(ret); } =20 +static char *hvf_get_ipa_granule(Object *obj, Error **errp) +{ + HVFState *s =3D HVF_STATE(obj); + + if (s->ipa_granule =3D=3D 4 * KiB) { + return g_strdup("4k"); + } + if (s->ipa_granule =3D=3D 16 * KiB) { + return g_strdup("16k"); + } + return g_strdup("auto"); +} + +static void hvf_set_ipa_granule(Object *obj, const char *value, Error **er= rp) +{ + HVFState *s =3D HVF_STATE(obj); + + if (!strcmp(value, "auto")) { + s->ipa_granule =3D 0; + } else if (!strcmp(value, "4k")) { + s->ipa_granule =3D 4 * KiB; + } else if (!strcmp(value, "16k")) { + s->ipa_granule =3D 16 * KiB; + } else { + error_setg(errp, "invalid ipa-granule: '%s' (use auto, 4k, 16k)", + value); + } +} + +void hvf_arch_accel_class_init(ObjectClass *oc) +{ + object_class_property_add_str(oc, "ipa-granule", + hvf_get_ipa_granule, + hvf_set_ipa_granule); + object_class_property_set_description(oc, "ipa-granule", + "IPA granule for HVF stage-2 translation (auto, 4k, 16k)"); +} + hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range) { hv_return_t ret; diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index c0d028b1..565c79b3 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -228,6 +228,10 @@ int hvf_arch_init(void) return 0; } =20 +void hvf_arch_accel_class_init(ObjectClass *oc) +{ +} + /* 48-bit on all Intel Macs. Function currently unused. */ uint32_t hvf_arch_get_default_ipa_bit_size(void) { --=20 2.52.0 From nobody Mon Apr 6 21:33:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1773769822; cv=none; d=zohomail.com; s=zohoarc; b=NcnpnKq7VwNTZEzDilCG1QzcMBPPdqYfBLKNvu81Ts+F4lk2AUjeS810Xue07q/4W7oyQr2uLmsleI/+ulUjJ2C7y9sYIoS7XYLyttLpqY8nkecsvGzUs3Hvx44kAWyyUhYRmJaexBuDMt03E778DcPIzhzhR1qReXBvtJShLxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773769822; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hUSbLOobWbo0z0ehlzPpMYjcHrg09tA0492KwnfG5oI=; b=fK4zLUJSBVWAEp7xqD8dy4el52MXfMLTmAi+dJSuRBlKkb3lI8R5Z80gM3G3MGQXs1zd/pNtp5+PlLFSj1AVE/oa/6eJJYVRpd0TZlrjuwf1AvADuCYnjeb9vg9zTCvKadt8Zfyy5lLoNfh245pnKmKjIHEkgAZx/gPrdhrNlTU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773769822342756.4535246312472; Tue, 17 Mar 2026 10:50:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2YXb-0003x2-5L; Tue, 17 Mar 2026 13:49:15 -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 1w2YXR-0003dr-SA for qemu-devel@nongnu.org; Tue, 17 Mar 2026 13:49:07 -0400 Received: from mail-dy1-x1333.google.com ([2607:f8b0:4864:20::1333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w2YXN-000766-WD for qemu-devel@nongnu.org; Tue, 17 Mar 2026 13:49:03 -0400 Received: by mail-dy1-x1333.google.com with SMTP id 5a478bee46e88-2ba9c484e5eso7216849eec.1 for ; Tue, 17 Mar 2026 10:49:01 -0700 (PDT) Received: from localhost.localdomain ([143.54.78.51]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2c0e5583533sm190487eec.18.2026.03.17.10.48.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 17 Mar 2026 10:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773769740; x=1774374540; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hUSbLOobWbo0z0ehlzPpMYjcHrg09tA0492KwnfG5oI=; b=GQI6GNbLMrFKDfjxUD1Ph94a1PfNT6fn7m9K6bgtz+BzO0fMGLbuSWw2+3VWWF9gqX aMJxxG9pRRd4rJPSc8jvYt7bSX6IegliJAsR4id/4M0azQMZNpVx1R8iLG5Hm4Rcg58M 5tL2mgz8pgDe2VcbOPAOm+Xk8HrTvxNE/eMBZecPjauzpbZJVm7S5k2wJnedAKavVIrr nbcph28qqZloZ646G5cNXj6XDOCjSpHqGJAhBWzV1zHj9dHTVITCfQriUeyPdOFCQJ/N P0OwFaJPGzxKhHPVvrB3kp9xG08dylmPxxHDnRDrBPqNiuplWDVbcbZf5X8HJt5WXxcq 24Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773769740; x=1774374540; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=hUSbLOobWbo0z0ehlzPpMYjcHrg09tA0492KwnfG5oI=; b=gIlmdeam+OXgKd7MiNlq5XuuZVndOCguDMZU8bq7GbppyoDmMNpcrO2avJXa/oJki9 DrO71MT2ReAmIdEBaPKolZGTmHWsPt5aJzFAgPG8CbYZZiyjFoHbVdNwJFPL0X5MwScf K1Staxew6tvNPcjQ2gtm86WG2CkjZd6RsF2FyxNFIIy/J5/ywrQ7fGUq/bAzL+CEFN+N OFvPSYvZMDnMSndZ6kvgJ/hJ1c8vCUIVe/jOwdyBj5u/uUvO7Olqy2prWr6omlFQtRpp XinMA79ArjmjbjSqAVoHIiCBS9jQSVypQsWBQslhiK+ODjBpbwmy4LzLd4+OF22HBybO p6DQ== X-Gm-Message-State: AOJu0YxoelAZ5CpEgbUS4g/nBnf8M2EDrVjXv+fPdyxXnPEd67+WzjcN +UPG2ZZl6VAg38JJb+Uv2CQWFpwPM8rMaU0e0O6BP56xNbCGaYYlx1lt1vMpwXUf X-Gm-Gg: ATEYQzzijXMJByR4FUhtgA4G0sc9X9OMrABWrHP9JzAy1Er1Yq/idxYcHui1FNchQr4 SqmraHz7gih+eBwoZSfDfx2/ZyGH4xRpZBVRmSHB3lShpwq414Wq6KZo10GnbR6zGeDK4vKeFqg +Mg2z2nUfQCMK7sg5RqCvYASzo+Wa3+IaW/5XbXLsJ2uIJ9Qc0wVhsuBI4aFBjC3zpqgMTfCdnE 6zryMOMhwFT4oceIZZTeKkdt8IYppmC35L6cUNt5J52dbgU/fgB5UpEUPxcJMqgBL4A86ltg0pw wr7fEIbQMRtzP2EgIbwNeeQ/ykcq3ifLyi7VLWdcB/dChDsqxh0a7f0G7N5UlzZItujMVj5t40r wd3TGm94+CIenmck/noe1a0Ca1oGrFgZJBM0uIyk02undTzBQm+AoXxr8iHYfl/grB2T5Kg2EsA OXnqjkQRs6AtLJ2aDdeCAvXFopxiEwuOl9xr+lXyjclbJe200AGSp7 X-Received: by 2002:a05:693c:3011:b0:2c0:c55c:1574 with SMTP id 5a478bee46e88-2c0e51930cbmr117430eec.21.1773769740308; Tue, 17 Mar 2026 10:49:00 -0700 (PDT) From: Lucas Amaral To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, agraf@csgraf.de, peter.maydell@linaro.org, mohamed@unpredictable.fr, Lucas Amaral , Lucas Amaral Subject: [PATCH v4 3/3] target/arm/hvf: configure IPA granule on macOS 26 Date: Tue, 17 Mar 2026 14:48:45 -0300 Message-ID: <20260317174845.31768-4-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260317174845.31768-1-lucaaamaral@gmail.com> References: <20260317174845.31768-1-lucaaamaral@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1333; envelope-from=lucaaamaral@gmail.com; helo=mail-dy1-x1333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1773769825315154100 Content-Type: text/plain; charset="utf-8" Read the ipa-granule property (set by hvf_accel_init) and configure the HVF stage-2 translation granule via hv_vm_config_set_ipa_granule() on macOS 26+. When ipa-granule=3D4k, use HV_IPA_GRANULE_4KB to allow HVF to map memory at 4KB granularity, matching 4KB-page guests on hosts with larger page sizes. If macOS < 26 and a sub-host-page granule was requested, warn and fall back to the host page size. Signed-off-by: Lucas Amaral --- target/arm/hvf/hvf.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index 1ba5bbf3..e3b1e3e1 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -1269,6 +1269,38 @@ hv_return_t hvf_arch_vm_create(MachineState *ms, uin= t32_t pa_range) } chosen_ipa_bit_size =3D pa_range; =20 + /* + * Configure IPA granule from the ipa-granule property. + * hvf_get_map_granule() was set by hvf_accel_init() before this call. + */ + { + uint64_t granule =3D hvf_get_map_granule(); + bool granule_set =3D false; + +#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \ + (__MAC_OS_X_VERSION_MAX_ALLOWED >=3D MAC_OS_VERSION_26_0) + if (__builtin_available(macOS 26, *)) { + hv_ipa_granule_t hv_gran =3D (granule <=3D 4 * KiB) + ? HV_IPA_GRANULE_4KB : HV_IPA_GRANULE_16KB; + ret =3D hv_vm_config_set_ipa_granule(config, hv_gran); + if (ret !=3D HV_SUCCESS) { + error_report("HVF: failed to set IPA granule: %s", + hvf_return_string(ret)); + goto cleanup; + } + granule_set =3D true; + } +#endif + + if (!granule_set && granule < qemu_real_host_page_size()) { + warn_report("HVF: ipa-granule=3D%zuKB requested but macOS < 26= ; " + "falling back to host page size (%zuKB)", + (size_t)(granule / KiB), + (size_t)(qemu_real_host_page_size() / KiB)); + hvf_set_map_granule(qemu_real_host_page_size()); + } + } + ret =3D hv_vm_create(config); =20 cleanup: --=20 2.52.0