From nobody Wed Apr 8 03:09:22 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=1773196109; cv=none; d=zohomail.com; s=zohoarc; b=coWhEMJCwD9XMQCm6N9ZpH8OOGfH0m5ZaHrX8LsibCmKA7jj4Ly8+VAJsN+6JWelVNAHhSIO+vEjAcnqfY6b6pzvbH2YjRrs99AaaUdaNnQDBNMuYGskz3OeuNmUeeuzN9V1YplgSoPnwlamOnDYWs2r8e7qvOsg438c0nRjdrM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773196109; 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=EXwwiABDq8rPzJnL1JUdTxpV62wLUq0WTiy3Tyw5lEg=; b=DvVggn+tFFlEA13HNpCCpGNXPn+5j6T5bRPcgc+Yv1B//XbfZ5JUH9vKBEpzqvKbGI4Q8DcTYJwk4YGzGutXEVSOPnbw2ywgBdEbGMNqIY9g+/3gyaorjKlpoNGi7xnliVX+MkojOB86qNguYIYMTS2eO99fgERPWZ5FMC2e4u4= 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 1773196109347863.3733836334559; Tue, 10 Mar 2026 19:28:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w09IZ-0000fh-Ce; Tue, 10 Mar 2026 22:27:47 -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 1w09IX-0000cI-Gk for qemu-devel@nongnu.org; Tue, 10 Mar 2026 22:27:45 -0400 Received: from mail-dl1-x122f.google.com ([2607:f8b0:4864:20::122f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w09IV-0003t0-MF for qemu-devel@nongnu.org; Tue, 10 Mar 2026 22:27:45 -0400 Received: by mail-dl1-x122f.google.com with SMTP id a92af1059eb24-128e3125372so517312c88.0 for ; Tue, 10 Mar 2026 19:27:41 -0700 (PDT) Received: from 192.168.0.29 ([2804:14d:4c71:86dd:80a9:8ba1:b664:ae3d]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-128e7bf1e1asm937039c88.3.2026.03.10.19.27.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 10 Mar 2026 19:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773196060; x=1773800860; 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=EXwwiABDq8rPzJnL1JUdTxpV62wLUq0WTiy3Tyw5lEg=; b=cMckmbEYxoTOwQXzPfancI+xVFDnkB6C0h04ougu2aYf0A/yvr8jPMR5uvkAd0tbAn wBpuDNQHXZ/6XeijgnrPH7hqFwRlOHbgNJgn+ML9MC0LnNhneTUxJ+KH4PY/U1SAlzPd T5cnOIfGb2S5+EtH2Q5O7GwoiMe853Mtd/c9GL9FT6PRkbmXYKEtbpsqECHFBe+TrCOH 9/VcoCFgIOG5eoYJCi4J8zBXL47zfX08J8d9ZqbIbXYTjy30HT7USHKWphWYdJYINwhG tOP8eKPPSnM4QNW7RW2HanV85F7NTkW2BnvSIQL9RPrad6jqiI5M7ZnZ9QO6z3iVp1Wc OzCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773196060; x=1773800860; 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=EXwwiABDq8rPzJnL1JUdTxpV62wLUq0WTiy3Tyw5lEg=; b=GLcAKM6/z35iw/Yaz633Mi8WIscPxmq68HbdUJQ+lBTY4keMdUtJqBzQt5PJG2Sg+3 /Uh9GwnGtGc33AR75vHVdyNvF2SxaunnG2GRhplLgIqQieAamb6GlRmzdyK5397niJsl pGhjjMoDk9mGFt+t40XnifXC0NSIY5Rya5B9JETlwxSNNqPZX+GeatQ94xKLzPxYKOaK ix+4rZ4FI+v7QWpSJNtL+Etjer3OoI0rb4OtyuWZScTP7lXDmWz+dFI0ka9jmsdb6q1g ZR7n3HOvw+VqAkkdCXMrUsFKudl7sJMBVch9XskTVIeLKVELCnocI+9COJdvJGTooE7v bgkw== X-Gm-Message-State: AOJu0Yxb/3gtr1RacmzrXTMGD++C1wdIAY1yG7x1C/SzxAdjuRG34WCC mF4AsP2YbqgtmFupAruRqC8cRz22Hl97mvzFn3XYAwYSNz9xgmLXkjwtWSR2wQ== X-Gm-Gg: ATEYQzw0latx9kVonzYh2uBS8/msG12oJC5yskgZHpPoUx4lUCirPIM3XPa80rhF5EV IPN2Wc+EUX7WUq+AZI1FO5zzeTNzbv1ReJSzEEoNk6I2nBIkahAKpgBzfU5yIggRrJibZBSZKyI syr/out1YaTS2hVurKYGkcAbXoSTJzEcOfYSJTfUI/hz37oDuwAU2S2J3RzkHZ2tJYPRHK2WwpC 24U2LFIRhYy6k+kA9A4xNByeQ7Lp5ng/0iNF10bvigfzRvxoGeftK8as4SUW6xrrXmq63mtNGrg eF+Mgiw1ulkzRedNaqIXCrQyHWo0n0YtWS2BbFJ6dkwsuvOVLM0lF0yxlBFVJ6zI8/LZ70fWYxS SyXVPNSl3Scu/dta76qr/5DvF9vBcBkgdcSZrA8gRZYnhjalj2KL/KZE+Mbrdd+p9fGmtPoi/Qi myxYjbTc4/dtkiWbZC4lWrOUw3UyLsnpFtjStXjaFj8TGbhyC6msw= X-Received: by 2002:a05:7022:e28:b0:128:cdb7:76e1 with SMTP id a92af1059eb24-128e7a2f765mr320314c88.13.1773196060236; Tue, 10 Mar 2026 19:27:40 -0700 (PDT) From: Lucas Amaral To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Lucas Amaral Subject: [PATCH v2 1/2] accel/hvf: introduce map granule abstraction and IPA property Date: Tue, 10 Mar 2026 23:27:31 -0300 Message-ID: <20260311022732.64141-2-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260311022732.64141-1-lucaaamaral@gmail.com> References: <20260309214906.92578-1-lucaaamaral@gmail.com> <20260311022732.64141-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::122f; envelope-from=lucaaamaral@gmail.com; helo=mail-dl1-x122f.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, FSL_HELO_BARE_IP_2=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: 1773196110985154100 Replace hardcoded qemu_real_host_page_size() in HVF memory mapping with a configurable map granule. Non-aligned regions now return early instead of proceeding with add=3Dfalse. Add an 'ipa-granule' property (auto, 4k, 16k) on the HVF accelerator object for aarch64, allowing the user to select the IPA page granule for HVF stage-2 address translation: -accel hvf,ipa-granule=3D4k 'auto' (the default) resolves to the host page size (16KB on macOS ARM64). The actual HVF configuration is handled by the arch-specific hvf_arch_vm_create() in a subsequent patch. Signed-off-by: Lucas Amaral --- accel/hvf/hvf-all.c | 67 ++++++++++++++++++++++++++++++++++++++-- include/system/hvf.h | 15 +++++++++ include/system/hvf_int.h | 1 + 3 files changed, 80 insertions(+), 3 deletions(-) diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c index 033c677..d94926b 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" @@ -23,6 +25,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) { @@ -54,7 +71,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, @@ -84,7 +101,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; @@ -105,7 +122,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) { @@ -187,6 +204,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, @@ -217,6 +239,37 @@ static int hvf_gdbstub_sstep_flags(AccelState *as) return SSTEP_ENABLE | SSTEP_NOIRQ; } =20 +#ifdef __aarch64__ +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); + } +} +#endif /* __aarch64__ */ + static void hvf_accel_class_init(ObjectClass *oc, const void *data) { AccelClass *ac =3D ACCEL_CLASS(oc); @@ -224,6 +277,14 @@ static void hvf_accel_class_init(ObjectClass *oc, cons= t void *data) ac->init_machine =3D hvf_accel_init; ac->allowed =3D &hvf_allowed; ac->gdbstub_supported_sstep_flags =3D hvf_gdbstub_sstep_flags; + +#ifdef __aarch64__ + 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)"); +#endif } =20 static const TypeInfo hvf_accel_type =3D { diff --git a/include/system/hvf.h b/include/system/hvf.h index d3dcf08..d1b702b 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 host page size (16KB on + * macOS ARM64), or 4KB when HVF 4KB IPA granule is configured (macOS 26+). + */ +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 2621164..4c1caba 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; --=20 2.52.0 From nobody Wed Apr 8 03:09:22 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=1773196096; cv=none; d=zohomail.com; s=zohoarc; b=dIcxHQHM8hAHEv3oa7CyviYSsB9vbYLSB3b7peWosE/pHS0QZrac1UvTBCshHDNGHXvv6zQng897dvhmBeXoBIB+eX9cqOictrCZ7Dj5ia3JvXIzg+QXBpnIiM/8owjTucu3ZRV3/J0ty49hJh7YHXf5GPQ5fvew5nhc525d2P4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773196096; 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=PDUOS+T/pU3klFSXmoTYqnaw4i2qHj3Ih1tuYbUSnhI=; b=FQ36xaMHw8fSnput4icC9JepJvAMmmBby9E2gtRF6qLtwQ29Lqjom5qSW1G1NigxR2td1Hqo4XiC4HwvW89S3FHP9ji1W+c5DRr63+emAJZJHUEXG0wwajJA4/IkpKhY7X1RNLVt/84RWWJmS6mHyiVNEq2Fv2qnZk+vs8rrOrU= 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 1773196096429990.5598151606557; Tue, 10 Mar 2026 19:28:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w09Ib-0000iT-FD; Tue, 10 Mar 2026 22:27:49 -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 1w09IY-0000f5-La for qemu-devel@nongnu.org; Tue, 10 Mar 2026 22:27:46 -0400 Received: from mail-dl1-x1233.google.com ([2607:f8b0:4864:20::1233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w09IW-0003tJ-Ks for qemu-devel@nongnu.org; Tue, 10 Mar 2026 22:27:46 -0400 Received: by mail-dl1-x1233.google.com with SMTP id a92af1059eb24-128d7db88b9so3299206c88.0 for ; Tue, 10 Mar 2026 19:27:44 -0700 (PDT) Received: from 192.168.0.29 ([2804:14d:4c71:86dd:80a9:8ba1:b664:ae3d]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-128e7bf1e1asm937039c88.3.2026.03.10.19.27.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 10 Mar 2026 19:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773196063; x=1773800863; 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=PDUOS+T/pU3klFSXmoTYqnaw4i2qHj3Ih1tuYbUSnhI=; b=agUuk4+eEcR3z8x7GeRnmtHkx7w5VUiTueHDSv1+pfwLgZRc7wq0XSEdJ95VxMp5/F Ga6S7aKP1jHvDhKm3CVesjeVdGFBIbUVv2BPNQHic9J3gfMuc23AjucObY09eAytkWbY JwouC6cb1mSzPoXm4pt9Yu6ers9JEGeeCkRe5d/B7iXpIQKE0+Fmulm+TdYJVid4vEpI 2BqFFATEG78UUNk0AFMwPoAn9Sr7I+iKcQzX60Wil/u0SmySyaDhWoldF7NgsH+gvc54 J27SoUExNatnfPl18xQlPIJeEgDi4JY4K4CpuGB3Ysi0vCgAcLBKS5Ky5WsaHgEdpSLb KezA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773196063; x=1773800863; 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=PDUOS+T/pU3klFSXmoTYqnaw4i2qHj3Ih1tuYbUSnhI=; b=WslfGjbbYq2Zp6wBvhDhHfeY9/kOtotClVlk41Kj1xrz66qGZwqYHnDYcy1cVHVVJ+ BzqN8SFj4lj7lyL5Q6Rts10O+o6yIpJA/yIqzD2gyUlhd3UujbXL8cRAFfstJ1fuQCFP 87LXy1aGXQuFMiKAsHxKLog+YUvlccx2qQcy3Ya8+cVOFCA0zrN0u4hCKx0asAf+zOWS HOkbDL3YkNbioxf2VFOlH5eB4XIl+gR8pNx0/UFKEKlr0kB2vJPkpOSnUErr5GeU3/Po dFjJ/BBXGrZkq22GPeqsgo0K5oExJQAjYagNBFA7oLOrn/KIAxOtrg4t3LvgWGGCIFwO aJ9Q== X-Gm-Message-State: AOJu0Yym3DpMsnH5DcT63zalo7OtklbO/EODFffbJyK1KbWfsK48S2Ct 9ULDXuBuFlDSuO/rWdbZQNH+wSNDtyXwaAw/zFKeKIqS6VXRZUeNe2/kuFlqQg== X-Gm-Gg: ATEYQzwWKT3f03obc7gdU3Lblntp48ZOKGdJaUrUAOvzYNWdA1ZrgcQ590p1W4s/JKj d6/oro3dlFqms5I1NuqOHws6lwZWujWsTj0bIkeY/TptV0PrvpGVHykzigH7WTTDJrPXO5NOuCe QqFof4DgJQv77UN49/jQcpiz9uoKF7/Eu9msvWxkd8CErUpdNwTECUJIVCVs+QcB5aerWZJul0K IC2g+9fsx3kISUR/ULA/7IN2aunZx1tGCdoNw/me6A4H1c3+BwAxqtzOQ6m0fhZoYYn3euwMbel N3X/PhT91qV7EFkdGzm8bRqJ4GZAmRrfpRFMMCD7pIOlWrouoyFppDXeRHKVKXLPbq3MojxhrhF WHLg5kWWG7O+R65ULz6CemaobOWruT4xHU85Mk2L2nOGHn5lGFwQ8wPtpNN1slmfuBOyqJ/cMRa LxWcy+zqdEOvG8T7y5Q3YZca84sSCwHJdqxrV2SphqPuHH0rz9sxc= X-Received: by 2002:a05:7022:78a:b0:123:3364:2ca8 with SMTP id a92af1059eb24-128e785c05bmr449636c88.39.1773196062585; Tue, 10 Mar 2026 19:27:42 -0700 (PDT) From: Lucas Amaral To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Lucas Amaral Subject: [PATCH v2 2/2] target/arm/hvf: configure IPA granule on macOS 26 Date: Tue, 10 Mar 2026 23:27:32 -0300 Message-ID: <20260311022732.64141-3-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260311022732.64141-1-lucaaamaral@gmail.com> References: <20260309214906.92578-1-lucaaamaral@gmail.com> <20260311022732.64141-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::1233; envelope-from=lucaaamaral@gmail.com; helo=mail-dl1-x1233.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, FSL_HELO_BARE_IP_2=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: 1773196098772154100 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. If macOS < 26 and a sub-host-page granule was requested, warn and fall back to the host page size (16KB). After resolution, warn if the map granule exceeds the guest page size, as Venus blob BAR mappings require page-aligned offsets. Signed-off-by: Lucas Amaral Reviewed-by: Mohamed Mediouni --- target/arm/hvf/hvf.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index 7952b01..a6f139d 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -11,7 +11,9 @@ =20 #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/units.h" #include "qemu/log.h" +#include "exec/target_page.h" =20 #include "system/runstate.h" #include "system/hvf.h" @@ -960,6 +962,53 @@ hv_return_t hvf_arch_vm_create(MachineState *ms, uint3= 2_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; + +#ifdef MAC_OS_VERSION_26_0 +#if 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 +#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()); + } + + /* + * Venus blob mapping safety: warn if the resolved map granule + * exceeds the guest page size, as virtio-gpu blob BAR mappings + * require page-aligned offsets and would hang otherwise. + */ + if (hvf_get_map_granule() > qemu_target_page_size()) { + warn_report("HVF map granule (%zu) > guest page size (%zu); " + "Venus blob BAR mappings may hang. " + "Consider ipa-granule=3D4k (requires macOS 26+) or= " + "guest F_BLOB_ALIGNMENT support.", + (size_t)hvf_get_map_granule(), + qemu_target_page_size()); + } + } + ret =3D hv_vm_create(config); =20 cleanup: --=20 2.52.0