From nobody Sun May 17 02:19:43 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=1776989225; cv=none; d=zohomail.com; s=zohoarc; b=Janh5+VMEKqgjNNN2TcxJJY/jUWNQAOnzdnYRNIJsHiknRVq2rd+vVAMTZMzf1IkBt2lx9NnV91HJzzQI+ssRx2aVw4OeqmNR7ziovK+Oivga6b28W4V77B422JEy8hQ6Ymv/WiPPgj8CXkT6F9ZX2M931jJawKbPFfT4ftidG4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776989225; 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=IxXZT7vARp3pFAh3SYOiXvQyT531CJO9+ucqq8AAcRWTroVDbX+JiGkHz8SEJSaNN7Z/XpCIWtyEx31Qfh0s9VvZBxVsZNZUjdua5Yba662XfQU6XtaKWUJRRGtUJv0xKDU4JUOcBCjeq6ubZtx3pfCwZ5/N9H7215OmanxW/+M= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776989225897258.44607093973207; Thu, 23 Apr 2026 17:07:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wG43W-0006fa-Fd; Thu, 23 Apr 2026 20:06:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wG43R-0006ex-Rg for qemu-devel@nongnu.org; Thu, 23 Apr 2026 20:05:57 -0400 Received: from mail-dy1-x132f.google.com ([2607:f8b0:4864:20::132f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wG43Q-0000yW-5h for qemu-devel@nongnu.org; Thu, 23 Apr 2026 20:05:57 -0400 Received: by mail-dy1-x132f.google.com with SMTP id 5a478bee46e88-2d8ffdc31d0so6824948eec.0 for ; Thu, 23 Apr 2026 17:05:55 -0700 (PDT) Received: from localhost.localdomain ([2804:7f4:c030:44a8:c4b9:45be:963d:f3a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ea8e4b373dsm12958055eec.6.2026.04.23.17.05.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 23 Apr 2026 17:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776989154; x=1777593954; 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=J2Y4Oi3sVRMaT2q9TiQJHMk+PjqyMUozfm/XifvWHdu+iDnIYDE2MowwDq/Nyx341b Y7feFqXWeP7tXB4/7Q160fgsQjLW0GUv+PxqUrNR3m4+hB5IPpPSBi2PY64ODVVwsQCz 34Go+jHqQ5C3R9hamV0oHN6R7GyoSJ5EqqxyPv/HNrxLR3ShGseRvy0qsFgKx7Jpw8df nLHr921CTLtFwTmD3XtJch3eL4OZh2HLOVgwOVOiUynFMnc+cz6mIygJ9T6nG3ShbiBF BXWifCBngWdssWB7HmWPHXVVh/Bk3hKwVlGgJTimlsQQvQ5KDxwnhEL0V6KGoidc2uVu rb9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776989154; x=1777593954; 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=g6tnOGBlbVpmzLiHHnpDsy/fRPmQOVzIaLXNDGL87QEC7El+T/QLoX3waRVOUoUOWK 8aoTpTNhp4rbtpLvusJYneXqFd+Olb0g+QxCWtkmBWRwAVa3oUDb5PD54/h5ztPG121o 3NjGlxAzVblZHlJr1EQRxU9YEYZeUo0maLy+Q1B3COcGi8HStsJ7CCiGJngDBjN0x4b0 ZcuPEKAFsC71nDQNImwgfr7PAagF17mGuVKi6KRj3A0YxB6UlZNDrJtDQhd+k9LyofMh 70k6zvq9egOSvC8in5XN1MM6S/cjswyBrCnMd1q2CS3iL5/L2il3I2xk/T+x+4jO79wt rMRg== X-Gm-Message-State: AOJu0YxlpT29kbAVIY+B6SHORh1rWfXhnj1PxXYNjFMoB+wNcZOw5bL9 3pbmDGJrnU0F61F6XbIt5qxEJilgMDAtGvIbBNVFB5grGkyUfHKZD1u6sPu4SIILSXo= X-Gm-Gg: AeBDieuBcYTUGr6NQUGzUWS0dNcqdtlf3DW18sunm/HuT5isxAkss/qPcx7JKHXhFlz nsz3KNm21dFUYb+oxHFSbhn09D0pSbP7cpLjQyLzyBTj7SX3m8OR/cZpzhAesGzpAyIlH6X+sgT vpoHm7z+c6BfYR5jLy+aoc1qLLBQHbz+Z+xO5UzVsYpI9Y2Z5oBTrsooWQBh8CG3RiMxQrrHgma fE7hDN0/vkFO4SL5g9Kw88Nr1RN6xCubHhQhV0Ijlld8Df9yoYcfFrTOXMGRN8QIvQ72IOxKrxv hlbaLWPNWJ1DxnAyvgaGVMfsTW9H3zOnNW3e7iyBe5bakTuQ6dK4Pn7+2y+IqyF15wloSa67QRK sjRUQN4QBlZxw0PGUFZn8fPjdYL83gqXPpBGeduBjzgqdb4ljxcOO8nw3/ZnVPpdcBGrM9OfQTk 08NTgV+DVewy2R9Q9WDzHDbJ7hWSSIRLeImmHX7RrAGZuGari8/grMqMv/YZfU7t3IH4RbpsJu X-Received: by 2002:a05:693c:2b04:b0:2d1:a3ea:d8d4 with SMTP id 5a478bee46e88-2e4647d03a2mr16651570eec.6.1776989154285; Thu, 23 Apr 2026 17:05: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, alex.bennee@linaro.org, Lucas Amaral Subject: [PATCH v5 1/3] virtio-gpu: validate host page alignment for MAP_FIXED blobs Date: Thu, 23 Apr 2026 21:05:42 -0300 Message-ID: <20260424000544.9617-2-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260424000544.9617-1-lucaaamaral@gmail.com> References: <20260424000544.9617-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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::132f; envelope-from=lucaaamaral@gmail.com; helo=mail-dy1-x132f.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: 1776989226786158500 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 Sun May 17 02:19:43 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=1776989223; cv=none; d=zohomail.com; s=zohoarc; b=fTMTcmRvsssUSaOmAazQkWjRSoELb5U9SZ4UjJSuxDRKSfkyrjFdz1VNqMfUReD7cFptm563LUUCUZpnWRGFjeetfe1LlturbIRZxuDjZOceg6FgZERefMBV+2Nwguq2sVeF5+aiAxMt5Qd5s2zJKB1LIanYcX/CI/DuMMcoT18= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776989223; 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=romhlJbT++e95ezZHaRqmY4KWUmngLYBLnwDrcI19RA=; b=WbbOQEgmxe36UnPQ/5sU/wXvj048o6qwf4+IIYJMQ9sGa2G14HTSDfnNAYrHuZ1BZDuifyBzpI6jYFWNLnBE/iffRFayAYGxf7xbDOxgJDWybk2UHLeS6pD8SzRdYr8jmGU6h+8M3Q86S1dFXjBB/qcGY32jxLq3JmI+DNl/C0Q= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776989223257929.9681002707042; Thu, 23 Apr 2026 17:07:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wG43X-0006gI-L5; Thu, 23 Apr 2026 20:06:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wG43W-0006fm-1P for qemu-devel@nongnu.org; Thu, 23 Apr 2026 20:06:02 -0400 Received: from mail-dy1-x1336.google.com ([2607:f8b0:4864:20::1336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wG43T-0000z1-IP for qemu-devel@nongnu.org; Thu, 23 Apr 2026 20:06:01 -0400 Received: by mail-dy1-x1336.google.com with SMTP id 5a478bee46e88-2d9916deb14so12928898eec.0 for ; Thu, 23 Apr 2026 17:05:59 -0700 (PDT) Received: from localhost.localdomain ([2804:7f4:c030:44a8:c4b9:45be:963d:f3a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ea8e4b373dsm12958055eec.6.2026.04.23.17.05.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 23 Apr 2026 17:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776989158; x=1777593958; 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=romhlJbT++e95ezZHaRqmY4KWUmngLYBLnwDrcI19RA=; b=j6O1imUGACXpj0y1l+Ez0T5qpdBx5+K5Nlv0Q3muemBZvcc0GnClN+0zwz1znejNmd 9r+4GCm467fbXEWqj2zPv8bQkIm8/6fUlqrAfkTuay0wYYneUY0BI4XBtqYzct+/GUEc iQ+kAzO7fy7kMWrGxQ09LkFjcIQ0Ttv3LwoLOE1e601Zm6KsAKuOQRuKBJl++sHc4XD/ ZSCulCttBNDl23TjctYtQc/enKqiVD49flMejKAtE8Yqi2bjledieBmDbEYqpQBQJI6l mkdRYGHQwGiriSEtXt5WacqTIK1P7RzWRA4O0IF3CYiisocGNAdoz2fxXZMt5AKOqA1L URjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776989158; x=1777593958; 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=romhlJbT++e95ezZHaRqmY4KWUmngLYBLnwDrcI19RA=; b=nWagFQDbNjtJLBk7KEUklA8IIrHDFsj5NQlPndKWRPQfeadfIExd5nQCxNGOzUvDlK GDIjyr/K44X997vKtkqRt4ExJCR211a0jhOBz0wnE95q4MgygLqI2+zIahU9R91oqg38 g0Ejpjvn+85bxazkgbCgtFeQljub1mK52jjehTgFe5dA4aiZCSj85U+V+IUnLw302Y79 XRCDwZ8qzH3EvlN0E1DEuy+wRw2aQSPQYj6XVQKwjdjc16XU43JujHRErkVdS1MYfzKC i433HfVN6SLDJj55AooOOwMI+H7Pu3gvkpqsYJkO9YXIlGJUmUBVKe6Bggf8s3A15KRO uHcQ== X-Gm-Message-State: AOJu0YxZGa35sGVsPKUqjdKGKFeQ1eaGO6zPKrJXTHB+lj33ozIB4d0F ps9WlxuYAvY8d3c3Ypz9TG/AL4O1H4T0DqvEVjO9tFV2+xbL9PiyjmiOPJhfcOrbCio= X-Gm-Gg: AeBDieusfoiXf0UWx+Hre5p5Xra2jeYkKcqVZSVTQS05U9zyKc6d7qMcntB6PZEdxwA GezBQ0Lq+/UhoSRMk95ashUVJLyUbXE+9bPN+3jLVUpMqthryD9gaOCAdaeeFSut7xyhI9nFfo/ wOZqsBCACHqIsgtIHGZhOwaRgKagU7U8ArJvuC9Lbyxpkhd4mKL5MZqTpG3BXn7rZ0qBuJvkRWC SWxewU7ov26SfmQE1fDmmW9GkxIPMe3+pMSr0RwU7Bz/78pkMSKxSHtJ+Sr5doPkiK2EdbxTe3t RY+8bcwrlqzQuD0bja2VmHhZd7dDZCAjCmaKfj3tuLyyLcLlJrGhvOzQ/tc8aH69tXfS2Pk+6ct QdlzldLX6Y8A5yIQHp21CWVzf5Nt138ZnDE8cc4/SHoLcELafrwMuUm9fONt72Mt/7W9059Fhv0 X1BhxTcDBhEVS6yTs2M//LSCTqpKjj2qPF12Jcg2KyFk5SFfwHcYqYIKFfMBL/ikr8qqtkZGUd X-Received: by 2002:a05:7300:5728:b0:2be:2953:fd74 with SMTP id 5a478bee46e88-2e479723e13mr16627599eec.14.1776989157771; Thu, 23 Apr 2026 17:05: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, alex.bennee@linaro.org, Lucas Amaral Subject: [PATCH v5 2/3] accel/hvf: introduce map granule abstraction and IPA property Date: Thu, 23 Apr 2026 21:05:43 -0300 Message-ID: <20260424000544.9617-3-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260424000544.9617-1-lucaaamaral@gmail.com> References: <20260424000544.9617-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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1336; envelope-from=lucaaamaral@gmail.com; helo=mail-dy1-x1336.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: 1776989226218154101 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 000e54bd..1b5860c7 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" @@ -1219,6 +1221,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 (!g_strcmp0(value, "auto")) { + s->ipa_granule =3D 0; + } else if (!g_strcmp0(value, "4k")) { + s->ipa_granule =3D 4 * KiB; + } else if (!g_strcmp0(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 Sun May 17 02:19:43 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=1776989223; cv=none; d=zohomail.com; s=zohoarc; b=fZ3IncsCbSCSAZ7R5tNHKvlIcpYxU08DavOAJT97UTJGDyGoi8QJCxmAl8q1L5G3BXEm89Qp0VEad1EvQgfVgmRn9aanEMd1Z3MYaUuT1Tthk0NUqkPtmNR2It+l41cm2NfMRFqddbcP/p93BfoWqnaLvD2FUrhlr5xefq443A4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776989223; 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=R9pycH1vrpngd62Fq+G7Rj4pLVjPW3yDgHDKQsT+bWY=; b=cBft7e62h5nyqxwTXhHzJJZ9ksjHaifejmOD1babkMGUG1o23fxSL8YJix8o8EpuFXc8Z0vcUj11yogBm1sDh9KrUGXxhgEmO3lYgkzfQd4g0kD4LeyjBLWr9U+E0Bk3XXwF7AfL9ecYbbQuUDO0ZL/HIrK2RDEVjmMLZO7XbO8= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1776989223278942.1134428789891; Thu, 23 Apr 2026 17:07:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wG43c-0006hd-QC; Thu, 23 Apr 2026 20:06:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wG43Z-0006gr-0g for qemu-devel@nongnu.org; Thu, 23 Apr 2026 20:06:05 -0400 Received: from mail-dy1-x1335.google.com ([2607:f8b0:4864:20::1335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wG43X-0000zO-Gq for qemu-devel@nongnu.org; Thu, 23 Apr 2026 20:06:04 -0400 Received: by mail-dy1-x1335.google.com with SMTP id 5a478bee46e88-2ba895adfeaso8087510eec.0 for ; Thu, 23 Apr 2026 17:06:03 -0700 (PDT) Received: from localhost.localdomain ([2804:7f4:c030:44a8:c4b9:45be:963d:f3a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ea8e4b373dsm12958055eec.6.2026.04.23.17.05.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 23 Apr 2026 17:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776989162; x=1777593962; 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=R9pycH1vrpngd62Fq+G7Rj4pLVjPW3yDgHDKQsT+bWY=; b=HkUuW2i9cWbX9o+aadbLE8r6bqZ+HMln5icK1XGv4LJKuQlsPBJEHWJveoeEqGoPMY 51xqBxinLb0LSWSdeRw7Jd9+G9O6XqPm3iZONOmijN0+gg07Zd7nQmNur7MgTplZH7yt xZDkvEuc9imqr8+2MzUgS8NTQh98MOxNDICB/8TBEJwqlhoSn7joBxsykO07UPgrVGaD nNt+olbyFYk/9BjRQGSfjdL40Qar+mFD2ixqt+mM4AKUvkgjKkQOd2AQ8tLQxYiew+Mu 4NiWuf4x9nCeAnjERSU71F+Qx5+icFXruze5Auu2lvFmvSON7BpmG1jRKsWqOYeQ705Z c9OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776989162; x=1777593962; 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=R9pycH1vrpngd62Fq+G7Rj4pLVjPW3yDgHDKQsT+bWY=; b=IhP1eai7703W0E+anDuDLp9Ee0TxuZqXY7k5lP+UNQBpDz5xrbc2VuUFafLDG2Iu9Z GnL21LKMV44ggTq3ieq9o+21idly3UKm5ojHIhBwCBGkek796qRAqIrDbkO54Mwa9KBT DoSCtLkNUEifB1MEzHfAJBou2Ks5+Ds/pgK6h4ILTZ+xhwvF9kbvhy7gyWAnAfI62CQ1 VRE+wgZ/P0VPx2xVvVU2pmh5WMCtGiaR7gzYquiT2l5zkBKZEsVyGCjg5PhdZC0IR1J+ vOz4pdw6Fld7pw+4zLFVcZ2xHq4aPAAPV95hJsdsb1GeSUtXI6b9SPkABh7lbxPdg+Vq b0IA== X-Gm-Message-State: AOJu0YwAbo8nWWseeKIre2w0uNFQ7vHOMUvMNi3tk+tzHQTDUqWsRRaP cwKvqDkGhwKtZA4TQIkDHh5LP9sxD9qlpG0AE0UfxoWYblNfxPowQu32iBP2WOm6jWM= X-Gm-Gg: AeBDiesI6Ya/eQ04fz9rUNZBXix0+4T4PgRkotSaA4LBKphrv/ll7V8q0mWiqfaA4oq 3bHLwRZMw6JcCnA+17AaTEa9x09XykkP9AsUHhf0/yY/qYEnBH5F8UuRGKPuBzZK6nwkMuf0i8o dQEj6EtwzmPE8voODDjOkglOCsvyKlPxVT4w3cgw2VYCxp+DiHa3T/CqXfwpR1fwi0CpyMumr97 Mt/FIRIOLa9ajceSgcr4v3QxtCo7DqHqAieb60vx5QiIwF8WXFprvmSy/afHq1r8IXqDqv2dfhs zNlYO/m6YLxBzVn7liEXtf85yZQf2m35/Ei70ESrkOoSJzP7cW9mCuXCAz4AS6E9ZnblzctFoKL +wxyfK2s252rmUiC882OoAIlFEBmo/Gc2EdQq+lD+B/wcomreIxuu6aZ8JSaUQCfzV3E2Nkrx2x PpGp53FPG6LJf+QD7cLTl1Vf3Aw/Rv5cGKV6JR2xxU/ZXkRh3pgBpFb53OIS3no4xGFA2nYym2 X-Received: by 2002:a05:693c:2c0f:b0:2d3:4252:b127 with SMTP id 5a478bee46e88-2e479017537mr15538048eec.26.1776989161517; Thu, 23 Apr 2026 17:06:01 -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, alex.bennee@linaro.org, Lucas Amaral Subject: [PATCH v5 3/3] target/arm/hvf: configure IPA granule on macOS 26 Date: Thu, 23 Apr 2026 21:05:44 -0300 Message-ID: <20260424000544.9617-4-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260424000544.9617-1-lucaaamaral@gmail.com> References: <20260424000544.9617-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=lists1p.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1335; envelope-from=lucaaamaral@gmail.com; helo=mail-dy1-x1335.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: 1776989226218154100 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 1b5860c7..f506fc01 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -1270,6 +1270,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