From nobody Tue Apr 7 07:34:03 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=1773546174; cv=none; d=zohomail.com; s=zohoarc; b=SDfGotKcI3jFN01SksfzWMblt6GnJM5+duk5G40wWoHJCYJWXVe8mHJUyHX8lkE9e4nYSVKE81tmpx7LsrNmWY32It/KEdH4poenzESupJ0c7DQbLvEDgUki2FgI3yrj7vTLtapMlixm/0SiWWSVSudqliHRSKM1V6s/SfK/8V8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773546174; 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=ANtbQBf0/3m05Q4OQwlXZdnmIh0X0oZJQzG3MRfdX2bOLWIBdEsM3wIp/eyv/u9qvL5lB4DPa+5tiVeGV9cTEsK0FGEoM50S4qcbNq9O8UWq0kNqXk7umGD32DHNbC9a6JDpVKzSDayiRXDjvmBulOWBhQqFTcbqx7GMSk9pvEU= 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 1773546174956285.08979023809536; Sat, 14 Mar 2026 20:42:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w1cMg-0004wF-4Z; Sat, 14 Mar 2026 23:42:06 -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 1w1cMe-0004vf-51 for qemu-devel@nongnu.org; Sat, 14 Mar 2026 23:42:04 -0400 Received: from mail-dl1-x1231.google.com ([2607:f8b0:4864:20::1231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w1cMc-0003ka-5T for qemu-devel@nongnu.org; Sat, 14 Mar 2026 23:42:03 -0400 Received: by mail-dl1-x1231.google.com with SMTP id a92af1059eb24-128e3125372so2526782c88.0 for ; Sat, 14 Mar 2026 20:42:01 -0700 (PDT) Received: from 192.168.7.2 ([189.6.247.75]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2beab57b2b2sm8862982eec.33.2026.03.14.20.41.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 14 Mar 2026 20:42:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773546120; x=1774150920; 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=jgS1ExvettYLyNojPaWzQ8XBvgLB81dAA/7ZEyeAB8+CUhrRSl///LagIGt0+Y8FXI N7PmhI8Oc8d8agPwahcUuEK2gd+xZIn1JNCtlHyZZCdBMcqeC1tAqzV8ksHNGroEv+cW u3EAZfzq3Fcg9fnRrHgOxCCWRMJNv+g9r50gDjrxqstgn+sNWf5yo29CWD3YPEpx4489 WCpCqOwmS2zJ+R3QXwCpKWpInmEnJvg4ARPTSCVAhaTh0N7RsphMpSd6K6Ei+eAFEtaH ti4n7TZlvWhGuQX4yUYtZQpgBq0ayWbN/1jzHHuEva4rHGDQdM9K/DmUv8OQVDaaSUmc MvxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773546120; x=1774150920; 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=YQVXAwYqY3BuID6hxfcdTKXdOMVCAxUcHCpmghMteYBjKaak/sE3BC+dzXZdJVcdd+ tZgsYY3TaqEoMCOwizJi4pGL7soba6st8EPbC/MPk8f1tukCX94lXrncxKF5zkMsEes2 lLTyQymRbsoYgydIpOa8dwr9pRsslHwyZdYFidr7n2Fhj6oT66xw1wgm1TaBLJ5sBDGm t+KQuQyKtMRqpK6ZLrTfuS9zLIqZwyhFA75GzbZYKy9pgnTiEyfZqe7Axl+TjiXPzEND Ql+wWO4ajqriw2Is7ctAiJ2NNNsTy36xOrFvdmxTxKmi3qBEuLo9WJB1o2LMvwIi2wH5 gn+w== X-Gm-Message-State: AOJu0YxvnvBWxcBdeR1xfBbM7r5Kl4swcXNopEPGZIZLWb4PvXwR2WHE KG63Pa2CDUKG1ckSmhPgn7saklMTKsd+bVoifFS5hjchjLbNMDCkX8miBTnB6A== X-Gm-Gg: ATEYQzxIWhHqKzR3cX0Zp5ioYZ6qZcok7aw/6CWiq8tXUZdjl2jtbpyH6ysng1vj2fE b7eSdAoAj2tYtmh3yDgWe0NEBxSTurhBO1ipthy8e1mHJeoPsc4VQWTB0Y20iGFibqMdPq+GSZr a0Z9LF60Ebj+H1Yn/Cs3II4cHWMgY+E37qVRf3iNubUUTPYFbc4vIo7IZAQaQaQa+gsC6BbxgAt x4ybMYBFhoBtvuKpjklLJXp8YJZPUKq0RwyDNUvEY9IqLG2vyqoqWJT+wnx9HHlqqgcHnfEChCG +nl2fHZAfvy2kduKoqkIGB5L3fppLkkILZgvqUT7aCd4/bl/Vp4udHyYtTcut7R8X7WfcqFHf9c IPQiFkwFTcCA+7ueTzE5Wkemt6iW1fHzOCS+bYIatHk5mWMweFLPrEfHcswVhufOZInMHCIkGit IUBI4Xt/thrqcZqQ2OeRFlP39n22yabx46w8PnyL0= X-Received: by 2002:a05:7022:2385:b0:123:331f:978f with SMTP id a92af1059eb24-128ecba8bb9mr5189261c88.7.1773546120423; Sat, 14 Mar 2026 20:42:00 -0700 (PDT) From: Lucas Amaral To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Lucas Amaral Subject: [PATCH 1/3] virtio-gpu: validate host page alignment for MAP_FIXED blobs Date: Sun, 15 Mar 2026 00:41:52 -0300 Message-ID: <20260315034154.41986-2-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260315034154.41986-1-lucaaamaral@gmail.com> References: <20260311022732.64141-1-lucaaamaral@gmail.com> <20260315034154.41986-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::1231; envelope-from=lucaaamaral@gmail.com; helo=mail-dl1-x1231.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: 1773546177930154100 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 Tue Apr 7 07:34:03 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=1773546178; cv=none; d=zohomail.com; s=zohoarc; b=gr4mm1I+TPwJW2BZU5Y1OGSGy243XECgt4HWZ93mp+FvN9DFng/0EYwzsS88gFDenaBd/Sam0YpvYzO8lzpixGT3i3a9f4abjVcHQ2/xt8BqwqjwqlopQBP1OUG+WS6loVcFwwuqfv7XGCIdqlRTlsUnmwBXUz0bswdc4rD9Lnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773546178; 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=gNZbCfB7IsH/7YaZ5EVWAknhWLoITwOaIb9kAXXWCA23cgsl9s+b/wEWlE7sjhQ/bbFEE9Lkm5RTrBNa+eMApVWlrqWw93BYnL0SMThwpv7/0o9NipIRfF351uMvPTbQP5KB5drMzh9Y7wDK2MheY6qWU4nXgddAjoRPLWflDe4= 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 1773546178703638.9993706902549; Sat, 14 Mar 2026 20:42:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w1cMi-0004xB-AS; Sat, 14 Mar 2026 23:42:08 -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 1w1cMg-0004wS-KT for qemu-devel@nongnu.org; Sat, 14 Mar 2026 23:42:06 -0400 Received: from mail-dy1-x1331.google.com ([2607:f8b0:4864:20::1331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w1cMe-0003l5-Tm for qemu-devel@nongnu.org; Sat, 14 Mar 2026 23:42:06 -0400 Received: by mail-dy1-x1331.google.com with SMTP id 5a478bee46e88-2bd9a485bd6so510089eec.1 for ; Sat, 14 Mar 2026 20:42:04 -0700 (PDT) Received: from 192.168.7.2 ([189.6.247.75]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2beab57b2b2sm8862982eec.33.2026.03.14.20.42.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 14 Mar 2026 20:42:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773546123; x=1774150923; 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=a/+Fw+nRp4LfGN0l7Pood0qrrlybkxz1isOco0wIVEDDO14p25EBZnYEzrOCgdmGvH g7NDjJkAPKf1dvJ3xPj0tDS8jHrKLgzhyM6OjnkhKLzmmCs18dw7izHI7/cfD9/er2R9 8raXW6sIqC7UCjTK80Je+Z3GnteEon63W5fRJ68k3FVKCTnffLgxZppb/saPsArexSzL eGSWNZUA7smX4L0hHRPK4EYY2hz2PVKrZzW8toy9jc9NVlUhdjYJ2NB7DuH607yJasiQ JkNqcjMMANeAkdBh10RINZ4i64irP7lm5PiispbaAbLaWVCbUlYu05FlaQIZSQpf/Fq9 TboQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773546123; x=1774150923; 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=WFRKwDLBj2hgecMSGjIOXX5GKXXENpbxlB12vTmXDomdbW3g+TJgcK3AYlZYZnIdo7 FvDsG0Jyqwow0qX5yP+QYilmaGrROt9O1AiZ5iLALqO5j11Uc+CXz2oM6uZq6vss9TeX 87NU8vPE2WlMWDy7bylCoPsPf6tJ/nfIG4X5oOeCGzcVObdoqYj0Qo7AmCNwlPhcny0x 9BW13ED9uWGBPd5ZjK1nmNiGZhbnxeoTtPs+rmx8mO59aLPurBJiMZPDexVrd/xdSIzf TOm8uHjKQVu0Cr8VrCxWSAq8Nwqc3XExEFWpbz16pfQAKRoH0H5UZqJKcjtd8X6wRaK/ R60w== X-Gm-Message-State: AOJu0YzQi5HQ8M7IZxQKlSTC0aDE1KmilZWKhjVcFmvl89JYLGiG+qjl qOjNkCpCgg52GQ5/mpe6w+m8OYsJdC5TFBC02i4HMjq6aaBHEk45SEoea0Njz53f X-Gm-Gg: ATEYQzyEsy8tZLEDPXZcUIMNZXQJ06O1aPrrxXX3K1B6IKQ0ODQYSFUQABhLmOiWtBC u0Iyo5yOASFUAnTLgiCDOdZ2sFIhBM0W5dagbGlEgQi3VEBxxuTgL46Ct5OpGuhV/BZUjkgEqqd EX6zOFeZMfyZyZLiTvt67+97ikjNLWb5Cm9DlKYv82uAXGBbRRImKZ1d+PDGkO0VEXt2E/HqKN7 HgrStce4Ps5+4Ct3JAMdH96AmkVhf3FXKASp6lZns6W5FuppmurEeqQQDFIqU9YumMk0vJP61Jc EsII691J5nmn5ZU+QQ1Ig7eiY3CUr81z/nfc+mPTnNcXuZHqMr8Yw4Q4uybP1ykNzW7r1j19+6u dD5fpUxi2SpkGFdtZHwM59Cy7AaZ9BomI2SIyi813/UZT418mCK4eFhyDMhf5SbWeZtVeh47NCn dSSZ7oX2u/DkXX7qNpa/YLlsSFBPeMDCP7kMfOJ7c= X-Received: by 2002:a05:7301:d8c:b0:2b9:80c1:bb5 with SMTP id 5a478bee46e88-2bea572a4aemr4005010eec.33.1773546122981; Sat, 14 Mar 2026 20:42:02 -0700 (PDT) From: Lucas Amaral To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Lucas Amaral , Lucas Amaral Subject: [PATCH 2/3] accel/hvf: introduce map granule abstraction and IPA property Date: Sun, 15 Mar 2026 00:41:53 -0300 Message-ID: <20260315034154.41986-3-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260315034154.41986-1-lucaaamaral@gmail.com> References: <20260311022732.64141-1-lucaaamaral@gmail.com> <20260315034154.41986-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::1331; envelope-from=lucaaamaral@gmail.com; helo=mail-dy1-x1331.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: 1773546181337154100 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 Tue Apr 7 07:34:03 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=1773546185; cv=none; d=zohomail.com; s=zohoarc; b=TcVS3N9Zvf9gaX4bswgBLUp25HX/2dLf4YbfMBqZ245+hpRT6GsJHTxC40s+Ob1zq/zyUMU1VHbYZxPtFlFwcCurjWjfLQkRmfKZem/8WOihyBeaD4O81IypxZB/+45jWyAHJTEH34VYK5yXLm3hZ8Nqrh9+313wEuQXJdXkfiY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773546185; 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=PARH97+zt9osbUjgGPyo19GBq5iScYdyPVcrjwrSwb1f2QizG4fNG3xoJ5gXhuJ+wSFXaTZGc2CFRdig3faRhCP6SP2ZkjJUPl/8Qv2vknbqaEAdvQoP7fm7N2KoFTzgQStvHFPTYslk/beG4ekm2HIq9Kn74TfWs82aEzyIZRk= 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 1773546185059682.7651280919217; Sat, 14 Mar 2026 20:43:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w1cMj-0004yX-UF; Sat, 14 Mar 2026 23:42:09 -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 1w1cMi-0004xK-Ff for qemu-devel@nongnu.org; Sat, 14 Mar 2026 23:42:08 -0400 Received: from mail-dy1-x1330.google.com ([2607:f8b0:4864:20::1330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w1cMg-0003lP-Sm for qemu-devel@nongnu.org; Sat, 14 Mar 2026 23:42:08 -0400 Received: by mail-dy1-x1330.google.com with SMTP id 5a478bee46e88-2bd9a485bd6so510134eec.1 for ; Sat, 14 Mar 2026 20:42:06 -0700 (PDT) Received: from 192.168.7.2 ([189.6.247.75]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2beab57b2b2sm8862982eec.33.2026.03.14.20.42.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 14 Mar 2026 20:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773546125; x=1774150925; 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=k7FAMz83i8B64qtbi1AGEVo74T7AsSryE+b9nMT6JcupWniqtwx4HQMQWY/8lV+SaR 89rlZ0OnfhBLAWmZHedktlv/pQyxYkYhUz5qW7y1lBAKBPAK8lkit6owI96rl1rob6Yx vG+tTl9JgHUymi9tzSyFpPt5FoDfGludzNwBj8Us7d2O2lAnKl67zQ7zpyx0bgM3OylO mTe6IGKTVJNm3qzQiubhdWKALOUZ1tJRnGHtnAbLzrSWUHtcT4b5EpqSHkY06NyUVNEh hmr6bcT9CJeP5OSZmUtLbWL2M5cEQmVZtXRbnyb/CKFAJXKggLttWqSdcwAjI8jqCCvZ 32hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773546125; x=1774150925; 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=FROgpJTD8lnKpVT/nOju84UkWBfcQo+U2Gs1TImAhPB8x2VOuEWvKBHZ119ULdaee0 clc1uRHwFfg0JDgfYpE10C5Nl4vaHwayNgwUHC5wiBPbItN1aCQmiMqKX7vfFU92C32S JHuItVVqcSSRW0M1tvpO4TP2hnR1jM9fGg5OBw7jaBIpraOMpGIJzbAya9gi8KiPyVzC nqXdsvMZUbNFbg/M9QpyuvGkDjxYuavfEFm1s2Ye7ybGZ1vbHZBd9tnlEg62WNQHC0hN 2Age7s/uyys0R4KSDxtcJ34WMUkDnH5T5QZ4rKYN0f5jGVpjY4yjSAeZU3+iYYp9kNU1 8sTQ== X-Gm-Message-State: AOJu0YyL9CIK4D0fW6ejLOvTRf3U9g19U8FLu+i4Ld7z2tWKdF6HAe1t C3MJl8FaSkgfHE8ApN5p8u2T8eZhMMH+S91/7hhV1rYxEUKrFj2wi2GoEhLejfd4 X-Gm-Gg: ATEYQzzHpHOiueznglsoGTil5qIqLZrT58WECLn/GCKJOwo25+y+BRL5DwDrJNVJcOg yHKTWt7UDjKBLiv3Z6oNhA9OFhaRmlKTO0pqujJqvkz+YTkln+ZVOQjJ6aMwgjV0xZjKWGlj0id PrIZElqg2W31XWbIu8nhhJLKNaWc2bF/EvIYQ2L4RJpdVflzSAQHr+4VnLBVtSppPvZASlyUGCv VGxNjcboj+NtkzFGq2694JjHSSU9aluXGdqmXVJMc47lwEEJkVhpHj0ilCIvQk/XW7t8D/xkqFS OKhj1Qgc0But0atPSPxPYAliS+B6t5Uu8W3W7D7d6Lo/+G8hBaQA+a6hatimeXTvp4COcKM8Spr g39AfFOLOh/pgWkftU/9I6fn4WiMO3xqdJs+9xb9eFdl7RdhOao/ug0AgQl/lIZw8JnMcFfj7uq srAJkiWmhqTRuei0KCIniFavWzaktkwjgVx6sSybJ4NZdNNvGQoA== X-Received: by 2002:a05:7300:c9e:b0:2ba:6b03:909b with SMTP id 5a478bee46e88-2bea558f037mr4190582eec.19.1773546125341; Sat, 14 Mar 2026 20:42:05 -0700 (PDT) From: Lucas Amaral To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Lucas Amaral , Lucas Amaral Subject: [PATCH 3/3] target/arm/hvf: configure IPA granule on macOS 26 Date: Sun, 15 Mar 2026 00:41:54 -0300 Message-ID: <20260315034154.41986-4-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260315034154.41986-1-lucaaamaral@gmail.com> References: <20260311022732.64141-1-lucaaamaral@gmail.com> <20260315034154.41986-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::1330; envelope-from=lucaaamaral@gmail.com; helo=mail-dy1-x1330.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: 1773546186634158500 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