target/i386: emulate, hvf: move x86_mmu to common code
Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Link: https://lore.kernel.org/r/20260223233950.96076-6-mohamed@unpredictable.fr Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Mohamed Mediouni committed
Feb 24, 2026 at 00:39 UTC
2c87eb5cad9d0e6712a3704f05eb24b9b1608d0d
7 files changed
+21
-9
target/i386/emulate/meson.build
+1
@@ -2,6 +2,7 @@ emulator_files = files(
2
'x86_decode.c',
3
'x86_emu.c',
4
'x86_flags.c',
5
+ 'x86_mmu.c'
6
)
7
8
i386_system_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: emulator_files)
target/i386/emulate/x86_mmu.c
renamed
+9
-5
@@ -19,10 +19,10 @@
19
#include "qemu/osdep.h"
20
#include "panic.h"
21
#include "cpu.h"
22
+#include "system/address-spaces.h"
23
+#include "system/memory.h"
24
#include "emulate/x86.h"
23
-#include "x86_mmu.h"
24
-#include "vmcs.h"
25
-#include "vmx.h"
25
+#include "emulate/x86_mmu.h"
26
27
#define pte_present(pte) (pte & PT_PRESENT)
28
#define pte_write_access(pte) (pte & PT_WRITE)
@@ -99,6 +99,8 @@ static bool get_pt_entry(CPUState *cpu, struct gpt_translation *pt,
99
static bool test_pt_entry(CPUState *cpu, struct gpt_translation *pt,
100
int level, int *largeness, bool pae)
101
{
102
+ X86CPU *x86_cpu = X86_CPU(cpu);
103
+ CPUX86State *env = &x86_cpu->env;
104
uint64_t pte = pt->pte[level];
105
106
if (pt->write_access) {
@@ -127,7 +129,7 @@ static bool test_pt_entry(CPUState *cpu, struct gpt_translation *pt,
129
pt->err_code |= MMU_PAGE_PT;
130
}
131
130
- uint32_t cr0 = rvmcs(cpu->accel->fd, VMCS_GUEST_CR0);
132
+ uint32_t cr0 = env->cr[0];
133
/* check protection */
134
if (cr0 & CR0_WP_MASK) {
135
if (pt->write_access && !pte_write_access(pte)) {
@@ -179,9 +181,11 @@ static inline uint64_t large_page_gpa(struct gpt_translation *pt, bool pae,
181
static bool walk_gpt(CPUState *cpu, target_ulong addr, int err_code,
182
struct gpt_translation *pt, bool pae)
183
{
184
+ X86CPU *x86_cpu = X86_CPU(cpu);
185
+ CPUX86State *env = &x86_cpu->env;
186
int top_level, level;
187
int largeness = 0;
184
- target_ulong cr3 = rvmcs(cpu->accel->fd, VMCS_GUEST_CR3);
188
+ target_ulong cr3 = env->cr[3];
189
uint64_t page_mask = pae ? PAE_PTE_PAGE_MASK : LEGACY_PTE_PAGE_MASK;
190
191
memset(pt, 0, sizeof(*pt));
target/i386/emulate/x86_mmu.h
renamed
target/i386/hvf/hvf.c
+9
-1
@@ -62,7 +62,7 @@
62
#include "emulate/x86.h"
63
#include "x86_descr.h"
64
#include "emulate/x86_flags.h"
65
-#include "x86_mmu.h"
65
+#include "emulate/x86_mmu.h"
66
#include "emulate/x86_decode.h"
67
#include "emulate/x86_emu.h"
68
#include "x86_task.h"
@@ -254,11 +254,19 @@ static void hvf_read_segment_descriptor(CPUState *s, struct x86_segment_descript
254
255
static void hvf_read_mem(CPUState *cpu, void *data, target_ulong gva, int bytes)
256
{
257
+ X86CPU *x86_cpu = X86_CPU(cpu);
258
+ CPUX86State *env = &x86_cpu->env;
259
+ env->cr[0] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR0);
260
+ env->cr[3] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR3);
261
vmx_read_mem(cpu, data, gva, bytes);
262
}
263
264
static void hvf_write_mem(CPUState *cpu, void *data, target_ulong gva, int bytes)
265
{
266
+ X86CPU *x86_cpu = X86_CPU(cpu);
267
+ CPUX86State *env = &x86_cpu->env;
268
+ env->cr[0] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR0);
269
+ env->cr[3] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR3);
270
vmx_write_mem(cpu, gva, data, bytes);
271
}
272
target/i386/hvf/meson.build
-1
@@ -3,7 +3,6 @@ i386_system_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: files(
3
'x86.c',
4
'x86_cpuid.c',
5
'x86_descr.c',
6
- 'x86_mmu.c',
6
'x86_task.c',
7
'x86hvf.c',
8
'hvf-cpu.c',
target/i386/hvf/x86.c
+1
-1
@@ -23,7 +23,7 @@
23
#include "emulate/x86_emu.h"
24
#include "vmcs.h"
25
#include "vmx.h"
26
-#include "x86_mmu.h"
26
+#include "emulate/x86_mmu.h"
27
#include "x86_descr.h"
28
29
/* static uint32_t x86_segment_access_rights(struct x86_segment_descriptor *var)
target/i386/hvf/x86_task.c
+1
-1
@@ -16,7 +16,7 @@
16
#include "vmx.h"
17
#include "emulate/x86.h"
18
#include "x86_descr.h"
19
-#include "x86_mmu.h"
19
+#include "emulate/x86_mmu.h"
20
#include "emulate/x86_decode.h"
21
#include "emulate/x86_emu.h"
22
#include "x86_task.h"