{"id":2196561,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2196561/?format=json","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.0/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260215052225.22513-5-mohamed@unpredictable.fr>","date":"2026-02-15T05:22:15","name":"[v3,04/14] target/i386: emulate, hvf: move x86_mmu to common code","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"6cfc87c65cafe4d26eaf32673b85e054a8e79cf7","submitter":{"id":91318,"url":"http://patchwork.ozlabs.org/api/1.0/people/91318/?format=json","name":"Mohamed Mediouni","email":"mohamed@unpredictable.fr"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260215052225.22513-5-mohamed@unpredictable.fr/mbox/","series":[{"id":492201,"url":"http://patchwork.ozlabs.org/api/1.0/series/492201/?format=json","date":"2026-02-15T05:22:12","name":"whpx: x86 updates (2026-02)","version":3,"mbox":"http://patchwork.ozlabs.org/series/492201/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2196561/checks/","tags":{},"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=unpredictable.fr header.i=@unpredictable.fr\n header.a=rsa-sha256 header.s=sig1 header.b=gJTsQ55M;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fDDpJ4QHWz1xxL\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 15 Feb 2026 16:23:35 +1100 (AEDT)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1vrUau-0000KX-Np; Sun, 15 Feb 2026 00:22:56 -0500","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <mohamed@unpredictable.fr>)\n id 1vrUao-0000Hd-9H\n for qemu-devel@nongnu.org; Sun, 15 Feb 2026 00:22:51 -0500","from p-west2-cluster2-host2-snip4-10.eps.apple.com ([57.103.68.203]\n helo=outbound.mr.icloud.com)\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <mohamed@unpredictable.fr>)\n id 1vrUam-0004rM-IC\n for qemu-devel@nongnu.org; Sun, 15 Feb 2026 00:22:50 -0500","from outbound.mr.icloud.com (unknown [127.0.0.2])\n by p00-icloudmta-asmtp-us-west-2a-60-percent-1 (Postfix) with ESMTPS id\n 65B131800190; Sun, 15 Feb 2026 05:22:46 +0000 (UTC)","from localhost.localdomain (unknown [17.57.152.38])\n by p00-icloudmta-asmtp-us-west-2a-60-percent-1 (Postfix) with ESMTPSA id\n E8C501800094; Sun, 15 Feb 2026 05:22:42 +0000 (UTC)"],"Dkim-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr;\n s=sig1; t=1771132967; x=1773724967;\n bh=tOIg27vUU88mwrgezr591bqoq+9r1MOdy71woXavApE=;\n h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:x-icloud-hme;\n b=gJTsQ55M1l+aj8n3//qPrwomS7V21x+k7hD5OupiZjgL8qm8RkvWs4lDOgos0WyfyXhnJ/uCOcVPONVnwt7MIwSW78YPziNCpGsomR7XxbnClTyJi2Fs2RSSOj3GBk8nDBGZWy/mutyoNbg6jk3RYh0yMP1I+qebQySMojju7lOYcBmjLm/+hK0vxp6R8M+0/0n/dn4p35yukYG992aVZOrwBo1Ot8hZlu7NKxVOCO7vLX7TABPzjsKHMCZK10r04Bbdvl8s/ndlM2vt3EH8XWIxKVTxDsWNwc21hlBy4DZFWzNFAPKokWcLry9p3hrTtxIjo5E4I71jrv+jm34OxA==","mail-alias-created-date":"1752046281608","From":"Mohamed Mediouni <mohamed@unpredictable.fr>","To":"qemu-devel@nongnu.org","Cc":"Phil Dennis-Jordan <phil@philjordan.eu>,\n Bernhard Beschow <shentey@gmail.com>, Cameron Esfahani <dirty@apple.com>,\n Magnus Kulke <magnuskulke@linux.microsoft.com>, qemu-arm@nongnu.org,\n Peter Maydell <peter.maydell@linaro.org>,\n Roman Bolshakov <rbolshakov@ddn.com>, Paolo Bonzini <pbonzini@redhat.com>,\n Mohamed Mediouni <mohamed@unpredictable.fr>,\n Pedro Barbuda <pbarbuda@microsoft.com>,\n =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= <berrange@redhat.com>, =?utf-8?q?Marc?=\n\t=?utf-8?q?-Andr=C3=A9_Lureau?= <marcandre.lureau@redhat.com>,\n Magnus Kulke <magnus.kulke@linux.microsoft.com>, =?utf-8?q?Philippe_Mathieu?=\n\t=?utf-8?q?-Daud=C3=A9?= <philmd@linaro.org>, Wei Liu <wei.liu@kernel.org>,\n Zhao Liu <zhao1.liu@intel.com>","Subject":"[PATCH v3 04/14] target/i386: emulate,\n hvf: move x86_mmu to common code","Date":"Sun, 15 Feb 2026 06:22:15 +0100","Message-ID":"<20260215052225.22513-5-mohamed@unpredictable.fr>","X-Mailer":"git-send-email 2.50.1","In-Reply-To":"<20260215052225.22513-1-mohamed@unpredictable.fr>","References":"<20260215052225.22513-1-mohamed@unpredictable.fr>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","X-Proofpoint-GUID":"tMoW4fO6zFhPXsQ3F-TVpJQMXCZASCm8","X-Proofpoint-ORIG-GUID":"tMoW4fO6zFhPXsQ3F-TVpJQMXCZASCm8","X-Authority-Info-Out":"v=2.4 cv=bIEb4f+Z c=1 sm=1 tr=0 ts=69915827\n cx=c_apl:c_apl_out:c_pps a=9OgfyREA4BUYbbCgc0Y0oA==:117\n a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=IkcTkHD0fZMA:10 a=HzLeVaNsDn8A:10\n a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22\n a=KKAkSRfTAAAA:8 a=NAek0MM3JjVz2OpMgrkA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10\n a=cvBusfyB2V15izCimMoJ:22","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwMjE1MDAzNiBTYWx0ZWRfX36lvfWghgENo\n DkezWIsnEIMAWFcFDAQ6xnVxud/+H7HXfYHUEJbzJneJY0hQRNRN2WYk7shA6ipFSaIixujlSqm\n 2J8sEk3pu6UazJ68uT5fgqTY8Sqpicb84lbbAXZq/j27meQooMNqr9Slk7+88TSpMzmpDJHhcKc\n XTzpE9SNkwPyruelpYNAkgUXgopZheKGCzkYT+3oxgNP+69n6/Xc2p6IDFJYfGY1tzYmNWDGoKX\n 2chpRfPM7RsoKPQbZFIzIuZ+jr1SZcS7KQa8AJlyxK40+N03wfJo03/HzziHE6+Cf4b3KvPBhwu\n BqMnAIfYI+KUWMQAsAYbgX/J1NoNN4JB2p9Tm/FvTepVBSkenFPFc9eBBorpKs=","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-02-15_02,2026-02-13_01,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=notspam policy=default score=0 mlxscore=0\n spamscore=0 clxscore=1030 adultscore=0 mlxlogscore=999 lowpriorityscore=0\n malwarescore=0 bulkscore=0 suspectscore=0 phishscore=0 classifier=spam\n authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000\n definitions=main-2602150036","X-JNJ":"\n AAAAAAABpvwjwoCnagoaj3z6vZgzbZ+2YbYjyromENN5RqOf9/pLNqbtErUmfbFJkGJn/853pTvpT3PpnMoVWewgMVDUSpUE90O5PsFaxcXa3L4ImBLxXIdVHf4dvW9XT9B/0QZT+gcWh5zjeKko5YN8aEg7U7Svjsl2pfIJQXbEegJJZ71rM8wgoSLL2HbxXmKBAe9N0hQxiwd8OIZis+MQxvrBqJ4QtIjTINu6umIGkmuzEAkcx/1y7Ku7y9gt6kuj+KJ7nfjZD0TGLXLYN1wBC7Oke4JIxdK006bZjx1Trq0GJ4cQC85Psw3Hm6dVib/3hfPz9FC3jYznPyrdCdAA9AJWGmWWNsmg4ph9QYLvhybd641E4IdN24NN6elDHf4z5Vjam45wz5fOiankW7H1Wc4up7j2EZ52pX4YfUcevGI9cgMDPqUnGEOhik+QCOEM+VVGXR2lHXexMbgfnOxJQKiE9S+gvU1sSQP6Tnjm+MN4im0w3N4WOkhmrTdzrcEDBd+/deEIJTdcauvUIKtQZge3fyHg2o/xxgqDQaX5lcuOjm73o7lMePvCoWkuRbrrBam9VV5SJpQdqqjPvOXaq0cl25pNuP4Ot0pvu00eR/0ckQFpofF235I68InkaS/lFk+lwRUL5Zyxi0uxN5NrE7Ra3E/Xzk7aKBPDrTgi8Dk5mV4SKzKooPzazw9eY1+VBPeKXQecHhb76jwRIhgF8sddZLuiAiWYsiHNB+79lXt+A5Ac/l7DKNYKsadJQmWdv/XSH0Eix/mR0AuPeBKcRHfyWusYGjOY/mi8x3x7","Received-SPF":"pass client-ip=57.103.68.203;\n envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com","X-Spam_score_int":"-27","X-Spam_score":"-2.8","X-Spam_bar":"--","X-Spam_report":"(-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n SPF_HELO_PASS=-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 <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>\nReviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>\n---\n target/i386/emulate/meson.build        |  1 +\n target/i386/{hvf => emulate}/x86_mmu.c | 14 +++++++++-----\n target/i386/{hvf => emulate}/x86_mmu.h |  0\n target/i386/hvf/hvf.c                  | 10 +++++++++-\n target/i386/hvf/meson.build            |  1 -\n target/i386/hvf/x86.c                  |  2 +-\n target/i386/hvf/x86_task.c             |  2 +-\n 7 files changed, 21 insertions(+), 9 deletions(-)\n rename target/i386/{hvf => emulate}/x86_mmu.c (95%)\n rename target/i386/{hvf => emulate}/x86_mmu.h (100%)","diff":"diff --git a/target/i386/emulate/meson.build b/target/i386/emulate/meson.build\nindex b6dafb6a5b..dd047c424a 100644\n--- a/target/i386/emulate/meson.build\n+++ b/target/i386/emulate/meson.build\n@@ -2,6 +2,7 @@ emulator_files = files(\n   'x86_decode.c',\n   'x86_emu.c',\n   'x86_flags.c',\n+  'x86_mmu.c'\n )\n \n i386_system_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: emulator_files)\ndiff --git a/target/i386/hvf/x86_mmu.c b/target/i386/emulate/x86_mmu.c\nsimilarity index 95%\nrename from target/i386/hvf/x86_mmu.c\nrename to target/i386/emulate/x86_mmu.c\nindex fe44d2edf4..b82a55a3da 100644\n--- a/target/i386/hvf/x86_mmu.c\n+++ b/target/i386/emulate/x86_mmu.c\n@@ -19,10 +19,10 @@\n #include \"qemu/osdep.h\"\n #include \"panic.h\"\n #include \"cpu.h\"\n+#include \"system/address-spaces.h\"\n+#include \"system/memory.h\"\n #include \"emulate/x86.h\"\n-#include \"x86_mmu.h\"\n-#include \"vmcs.h\"\n-#include \"vmx.h\"\n+#include \"emulate/x86_mmu.h\"\n \n #define pte_present(pte) (pte & PT_PRESENT)\n #define pte_write_access(pte) (pte & PT_WRITE)\n@@ -99,6 +99,8 @@ static bool get_pt_entry(CPUState *cpu, struct gpt_translation *pt,\n static bool test_pt_entry(CPUState *cpu, struct gpt_translation *pt,\n                           int level, int *largeness, bool pae)\n {\n+    X86CPU *x86_cpu = X86_CPU(cpu);\n+    CPUX86State *env = &x86_cpu->env;\n     uint64_t pte = pt->pte[level];\n \n     if (pt->write_access) {\n@@ -127,7 +129,7 @@ static bool test_pt_entry(CPUState *cpu, struct gpt_translation *pt,\n         pt->err_code |= MMU_PAGE_PT;\n     }\n \n-    uint32_t cr0 = rvmcs(cpu->accel->fd, VMCS_GUEST_CR0);\n+    uint32_t cr0 = env->cr[0];\n     /* check protection */\n     if (cr0 & CR0_WP_MASK) {\n         if (pt->write_access && !pte_write_access(pte)) {\n@@ -179,9 +181,11 @@ static inline uint64_t large_page_gpa(struct gpt_translation *pt, bool pae,\n static bool walk_gpt(CPUState *cpu, target_ulong addr, int err_code,\n                      struct gpt_translation *pt, bool pae)\n {\n+    X86CPU *x86_cpu = X86_CPU(cpu);\n+    CPUX86State *env = &x86_cpu->env;\n     int top_level, level;\n     int largeness = 0;\n-    target_ulong cr3 = rvmcs(cpu->accel->fd, VMCS_GUEST_CR3);\n+    target_ulong cr3 = env->cr[3];\n     uint64_t page_mask = pae ? PAE_PTE_PAGE_MASK : LEGACY_PTE_PAGE_MASK;\n     \n     memset(pt, 0, sizeof(*pt));\ndiff --git a/target/i386/hvf/x86_mmu.h b/target/i386/emulate/x86_mmu.h\nsimilarity index 100%\nrename from target/i386/hvf/x86_mmu.h\nrename to target/i386/emulate/x86_mmu.h\ndiff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c\nindex ce54020f00..0b3674ad33 100644\n--- a/target/i386/hvf/hvf.c\n+++ b/target/i386/hvf/hvf.c\n@@ -62,7 +62,7 @@\n #include \"emulate/x86.h\"\n #include \"x86_descr.h\"\n #include \"emulate/x86_flags.h\"\n-#include \"x86_mmu.h\"\n+#include \"emulate/x86_mmu.h\"\n #include \"emulate/x86_decode.h\"\n #include \"emulate/x86_emu.h\"\n #include \"x86_task.h\"\n@@ -254,11 +254,19 @@ static void hvf_read_segment_descriptor(CPUState *s, struct x86_segment_descript\n \n static void hvf_read_mem(CPUState *cpu, void *data, target_ulong gva, int bytes)\n {\n+    X86CPU *x86_cpu = X86_CPU(cpu);\n+    CPUX86State *env = &x86_cpu->env;\n+    env->cr[0] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR0);\n+    env->cr[3] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR3);\n     vmx_read_mem(cpu, data, gva, bytes);\n }\n \n static void hvf_write_mem(CPUState *cpu, void *data, target_ulong gva, int bytes)\n {\n+    X86CPU *x86_cpu = X86_CPU(cpu);\n+    CPUX86State *env = &x86_cpu->env;\n+    env->cr[0] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR0);\n+    env->cr[3] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR3);\n     vmx_write_mem(cpu, gva, data, bytes);\n }\n \ndiff --git a/target/i386/hvf/meson.build b/target/i386/hvf/meson.build\nindex 519d190f0e..22bf886978 100644\n--- a/target/i386/hvf/meson.build\n+++ b/target/i386/hvf/meson.build\n@@ -3,7 +3,6 @@ i386_system_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: files(\n   'x86.c',\n   'x86_cpuid.c',\n   'x86_descr.c',\n-  'x86_mmu.c',\n   'x86_task.c',\n   'x86hvf.c',\n   'hvf-cpu.c',\ndiff --git a/target/i386/hvf/x86.c b/target/i386/hvf/x86.c\nindex 5c75ec9a00..2fa210ff60 100644\n--- a/target/i386/hvf/x86.c\n+++ b/target/i386/hvf/x86.c\n@@ -23,7 +23,7 @@\n #include \"emulate/x86_emu.h\"\n #include \"vmcs.h\"\n #include \"vmx.h\"\n-#include \"x86_mmu.h\"\n+#include \"emulate/x86_mmu.h\"\n #include \"x86_descr.h\"\n \n /* static uint32_t x86_segment_access_rights(struct x86_segment_descriptor *var)\ndiff --git a/target/i386/hvf/x86_task.c b/target/i386/hvf/x86_task.c\nindex bdf8b51ae6..b1e541a642 100644\n--- a/target/i386/hvf/x86_task.c\n+++ b/target/i386/hvf/x86_task.c\n@@ -16,7 +16,7 @@\n #include \"vmx.h\"\n #include \"emulate/x86.h\"\n #include \"x86_descr.h\"\n-#include \"x86_mmu.h\"\n+#include \"emulate/x86_mmu.h\"\n #include \"emulate/x86_decode.h\"\n #include \"emulate/x86_emu.h\"\n #include \"x86_task.h\"\n","prefixes":["v3","04/14"]}