target/i386: emulate LAM in TCG
v3 cover target/i386: emulate LAM in TCG
This series emulates LAM in TCG for x86_64 system mode and reports it in "-cpu max". linux-user support will follow in a separate series.
Patch 1 keeps the CR3 LAM bits out of the PML5 table address. Patch 2 makes the large-page check in tlb_flush_range_locked() compare under the flush mask, as agreed in [2]. Patch 3 adds MMU indexes for LAM-masked data accesses. Patch 4 is the LAM emulation, and patch 5 adds a system-mode test.
The design follows the RFC thread [1]:
- On a TLB miss, get_physical_address() masks the address and runs the canonical check and the page walk on the result. The entry is installed under the tagged address, so each tag of a page has its own entry. INVLPG and INVLPGA flush every tagged alias with tlb_flush_page_bits_by_mmuidx(), and a change of CR4.LAM_SUP flushes the TLB.
- Patch 3 adds LAM forms of the three 64-bit data MMU indexes and an hflags bit, HF_LAM, that is set while LAM is enabled. With HF_LAM set, data accesses use the LAM indexes, and only those are masked. Instruction fetches always use the normal indexes, so fetch and data entries for a tagged address are in separate TLBs. Without LAM, only the normal indexes are used.
- Exceptions do not report the tagged address, which answers Richard's question [3]. On #PF, CR2 receives the masked address (SDM Vol. 3A, section 4.4.3), and #GP reports no address.
- gdbstub, monitor, and qemu_plugin_translate_vaddr() translate a tagged address as a data access does.
Known gaps:
- Data breakpoints on an untagged address do not fire for accesses through a tagged alias.
- With LAM_U48 and 5-level paging, gdbstub, monitor, and qemu_plugin_translate_vaddr() translate an instruction address at or above 2^47 as a data address, not as a fetch does.
v3:
- Patch 3: LAM forms of the 64-bit data MMU indexes, selected by the new HF_LAM bit, in place of the fetch MMU indexes, as Richard suggested [5] and agreed [6].
- Patch 4: mask only for the LAM MMU indexes.
- Patch 5: test exception delivery with a tagged IDTR base, which covers the LAM indexes from x86_mmu_index_kernel_pl().
v2:
- New patch 3: separate MMU indexes for instruction fetch, as Richard suggested [4].
- Patch 4: mask only for non-fetch MMU indexes.
- Patch 5: set exe_name only where it differs from the default, for the check added in commit 1138de1d.
v2: https://lore.kernel.org/qemu-devel/[email protected]/
v1: https://lore.kernel.org/qemu-devel/[email protected]/
[1] https://lists.nongnu.org/archive/html/qemu-devel/2026-10/msg01840.html
[2] https://lists.nongnu.org/archive/html/qemu-devel/2026-11/msg01599.html
[3] https://lists.nongnu.org/archive/html/qemu-devel/2026-10/msg05620.html
[4] https://lore.kernel.org/qemu-devel/[email protected]/
[5] https://lists.nongnu.org/archive/html/qemu-devel/2026-11/msg04655.html
[6] https://lists.nongnu.org/archive/html/qemu-devel/2026-11/msg04942.html
Tim (5):
target/i386: mask the PML5 table address taken from CR3 accel/tcg: compare large pages under the flush mask target/i386: add MMU indexes for LAM-masked data accesses target/i386: emulate LAM in TCG tests/tcg/x86_64: add a LAM system test
accel/tcg/cputlb.c | 4 +- target/i386/cpu.c | 2 +- target/i386/cpu.h | 89 ++- target/i386/helper.c | 21 +- target/i386/tcg/seg_helper.c | 2 +- target/i386/tcg/system/excp_helper.c | 15 +- target/i386/tcg/system/misc_helper.c | 24 +- target/i386/tcg/system/svm_helper.c | 3 +- target/i386/tcg/tcg-cpu.c | 12 +- tests/tcg/x86_64/system/boot.S | 14 + tests/tcg/x86_64/system/lam.c | 835 +++++++++++++++++++++++++++ tests/tcg/x86_64/system/meson.build | 16 + 12 files changed, 1018 insertions(+), 19 deletions(-) create mode 100644 tests/tcg/x86_64/system/lam.c
base-commit: 45b7c3e45e2b778e560a0734daa6aa0059bc0edc
Signature · 1 line
2.47.3
PATCH v3 1/5 target/i386: mask the PML5 table address taken from CR3
The 5-level page walks in mmu_translate() and x86_cpu_translate_for_debug() take the PML5 table address from CR3 with ~0xfff, which keeps CR3 bits 63:52. The 4-level walks already use PG_ADDRESS_MASK. Use PG_ADDRESS_MASK for the 5-level walks as well, so that CR3 control bits above the physical address width, such as the LAM bits 61 and 62, do not become part of the table address.
--- target/i386/helper.c | 2 +- target/i386/tcg/system/excp_helper.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
target/i386/helper.c +1 -1
@@ -297,7 +297,7 @@ bool x86_cpu_translate_for_debug(CPUState *cs, vaddr addr, }if (la57) { - pml5e_addr = ((env->cr[3 ] & ~0xfff ) + + pml5e_addr = ((env->cr[3 ] &PG_ADDRESS_MASK ) + (((addr >>48 ) &0x1ff ) <<3 )) & a20_mask; pml5e =x86_ldq_phys (cs, pml5e_addr);if (!(pml5e &PG_PRESENT_MASK )) {
target/i386/tcg/system/excp_helper.c +2 -1
@@ -173,7 +173,8 @@ static bool mmu_translate(CPUX86State *env, const TranslateParams *in,/* * Page table level 5 */ - pte_addr = (in->cr3 & ~0xfff ) + (((addr >>48 ) &0x1ff ) <<3 ); + pte_addr = (in->cr3 &PG_ADDRESS_MASK ) + + (((addr >>48 ) &0x1ff ) <<3 );if (!ptw_translate (&pte_trans, pte_addr)) {return false; }
Signature · 1 line
2.47.3
PATCH v3 2/5 accel/tcg: compare large pages under the flush mask
In reply to Timtlb_flush_range_locked() flushes entries whose address matches the range under @mask, the low @bits of the address. Its large page check, however, compares the range end with the recorded large page in all bits. If the large page was entered under an address that differs from the flushed range above @bits, the check fails, and the large page is not flushed.
Compare under @mask as well. This matters for the x86 LAM emulation in a later patch, which installs TLB entries under tagged addresses and flushes every tagged alias on INVLPG of the untagged address with tlb_flush_page_bits_by_mmuidx().
--- accel/tcg/cputlb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
accel/tcg/cputlb.c +3 -1
@@ -691,8 +691,10 @@ static void tlb_flush_range_locked(CPUState *cpu, int midx,* Check if we need to flush due to large pages. * Because large_page_mask contains all 1's from the msb, * we only need to test the end of the range. +* Compare under @mask, ignoring bits above @bits. */ -if (((addr + len -1 ) & d->large_page_mask) == d->large_page_addr) { +if (((addr + len -1 ) & d->large_page_mask & mask) == + (d->large_page_addr & mask)) {tlb_debug ("forcing full flush midx %d (" "%016" VADDR_PRIx"/%016" VADDR_PRIx")\n" , midx, d->large_page_addr, d->large_page_mask);
Signature · 1 line
2.47.3
PATCH v3 5/5 tests/tcg/x86_64: add a LAM system test
In reply to TimTest LAM_U57, LAM_U48, and LAM_SUP at CPL 0: tagged aliases, the canonical checks on the masked address, CR2 on #PF, TLB flushes on CR3 and CR4.LAM_SUP writes and on INVLPG of an untagged 4 KiB or 2 MiB page, helpers and atomics, instruction fetches through tagged addresses, and exception delivery with a tagged IDTR base.
The test runs with 4-level paging and with 5-level paging, for which boot.S gains an LA57 option, each with and without LAM in CPUID. Each run has its own build, which fails unless CPUID reports LAM exactly when expected. The identity map uses 4 KiB pages, which leaves the 2 MiB test page as the only large page in the TLB.
---
v3: test exception delivery with a tagged IDTR base.
tests/tcg/x86_64/system/boot.S | 14 + tests/tcg/x86_64/system/lam.c | 835 ++++++++++++++++++++++++++++ tests/tcg/x86_64/system/meson.build | 16 + 3 files changed, 865 insertions(+) create mode 100644 tests/tcg/x86_64/system/lam.c
tests/tcg/x86_64/system/boot.S +14 -0
@@ -91,6 +91,10 @@ _start: /* Enable PAE mode (bit 5). */ mov %cr4, %eax btsl $5, %eax +#ifdef LA57 + /* Enable 5-level paging (bit 12). */ + btsl $12, %eax +#endif mov %eax, %cr4 #define MSR_EFER 0xc0000080 /* extended feature register */
@@ -102,7 +106,11 @@ _start: wrmsr /* Enable paging */ +#ifdef LA57 + mov $.Lpml5, %ecx +#else mov $.Lpml4, %ecx +#endif mov %ecx, %cr3 mov %cr0, %eax
@@ -272,3 +280,9 @@ i = 0 .align 4096 .Lpml4: .quad .Lpdp + 7 /* 0-512 GB */ + +#ifdef LA57 +.align 4096 +.Lpml5: + .quad .Lpml4 + 7 +#endif
tests/tcg/x86_64/system/lam.c new file +835 -0
835 lines not on this page · raw message
tests/tcg/x86_64/system/meson.build +16 -0
@@ -48,6 +48,22 @@ tests += { } } +# The LAM test takes exceptions on the current stack, without CR4.OSFXSR. +lam_cflags = cflags + ['-mno-red-zone', '-mgeneral-regs-only'] +foreach paging, extra: {'': [], '-la57': ['-DLA57']} + foreach suffix, cpu: {'': 'max', '-off': 'max,lam=off'} + lam_test = { + 'cflags': lam_cflags + extra + + ['-DEXPECT_LAM=' + (suffix == '' ? '1' : '0')], + 'qemu_args': ['-cpu', cpu] + qemu_def_args, + } + if paging + suffix != '' + lam_test += {'exe_name': 'lam' + paging + suffix} + endif + tests += {'lam.c': lam_test} + endforeach +endforeach + if 'qemu-system-x86_64' in emulators tcg_tests += { 'x86_64-softmmu': {
Signature · 1 line
2.47.3
PATCH v3 3/5 target/i386: add MMU indexes for LAM-masked data accesses
In reply to TimAdd LAM forms of the three 64-bit data indexes, and a hflags bit, HF_LAM, that is set when CPUID reports LAM and any of CR3.LAM_U57, CR3.LAM_U48, and CR4.LAM_SUP is set. cpu_x86_update_cr3() and cpu_x86_update_cr4() keep the bit up to date. The bit is part of the TB flags, since translate.c fixes the data mmu_idx per TB.
While HF_LAM is set, x86_mmu_index_pl() and x86_mmu_index_kernel_pl() return the LAM forms. Instruction fetches always use the normal indexes, since LAM applies only to data accesses. If LAM is not enabled, only the normal indexes are used.
This lets the fetch and data translations of a linear address differ, which LAM needs.
---
v3: new patch, in place of the v2 fetch MMU indexes, as suggested in review of v2.
target/i386/cpu.h | 46 ++++++++++++++++++++++++++++++++---- target/i386/helper.c | 13 ++++++++++ target/i386/tcg/seg_helper.c | 2 +- target/i386/tcg/tcg-cpu.c | 12 ++++++++-- 4 files changed, 65 insertions(+), 8 deletions(-)
target/i386/cpu.h +41 -5
@@ -192,6 +192,7 @@ typedef enum X86Seg {#define HF_UMIP_SHIFT 27/* CR4.UMIP */ #define HF_AVX_EN_SHIFT 28/* AVX Enabled (CR4+XCR0) */ #define HF_APX_EN_SHIFT 29/* APX Enabled (CR4+XCR0) */ +#define HF_LAM_SHIFT 30/* LAM enabled (CR3+CR4) */ #define HF_CPL_MASK (3 << HF_CPL_SHIFT)#define HF_INHIBIT_IRQ_MASK (1 << HF_INHIBIT_IRQ_SHIFT)
@@ -220,6 +221,7 @@ typedef enum X86Seg {#define HF_UMIP_MASK (1 << HF_UMIP_SHIFT)#define HF_AVX_EN_MASK (1 << HF_AVX_EN_SHIFT)#define HF_APX_EN_MASK (1 << HF_APX_EN_SHIFT) +#define HF_LAM_MASK (1 << HF_LAM_SHIFT)/* hflags2 */
@@ -260,6 +262,9 @@ typedef enum X86Seg {#define CR0_CD_MASK (1U << 30)#define CR0_PG_MASK (1U << 31) +#define CR3_LAM_U57_MASK (1ULL << 61) +#define CR3_LAM_U48_MASK (1ULL << 62) +#define CR4_VME_MASK (1U << 0)#define CR4_PVI_MASK (1U << 1)#define CR4_TSD_MASK (1U << 2)
@@ -2781,6 +2786,7 @@ static inline bool x86_has_cpuid_0x1f(X86CPU *cpu)void x86_cpu_set_a20 (X86CPU *cpu,int a20_state);void cpu_sync_avx_hflag (CPUX86State *env);void cpu_sync_apx_hflag (CPUX86State *env); +void cpu_sync_lam_hflag (CPUX86State *env); typedef enum X86ASIdx { X86ASIdx_MEM = 0,
@@ -2838,8 +2844,11 @@ uint64_t cpu_get_tsc(CPUX86State *env);#define MMU_USER32_IDX 3#define MMU_KNOSMAP64_IDX 4#define MMU_KNOSMAP32_IDX 5 -#define MMU_PHYS_IDX 6 -#define MMU_NESTED_IDX 7 +#define MMU_KSMAP64_LAM_IDX 6 +#define MMU_USER64_LAM_IDX 7 +#define MMU_KNOSMAP64_LAM_IDX 8 +#define MMU_PHYS_IDX 9 +#define MMU_NESTED_IDX 10#ifdef CONFIG_USER_ONLY #ifdef TARGET_X86_64
@@ -2851,18 +2860,45 @@ uint64_t cpu_get_tsc(CPUX86State *env);static inline bool is_mmu_index_smap (int mmu_index) { -return (mmu_index & ~1 ) ==MMU_KSMAP64_IDX ; +return (mmu_index & ~1 ) ==MMU_KSMAP64_IDX || + mmu_index ==MMU_KSMAP64_LAM_IDX ; }static inline bool is_mmu_index_user (int mmu_index) { -return (mmu_index & ~1 ) ==MMU_USER64_IDX ; +return (mmu_index & ~1 ) ==MMU_USER64_IDX || + mmu_index ==MMU_USER64_LAM_IDX ; +} + +/* LAM masks the linear addresses of accesses with these indexes */ +static inline bool is_mmu_index_lam (int mmu_index) +{ +return mmu_index >=MMU_KSMAP64_LAM_IDX && + mmu_index <=MMU_KNOSMAP64_LAM_IDX ; }static inline bool is_mmu_index_32 (int mmu_index) {assert (mmu_index <MMU_PHYS_IDX ); -return mmu_index &1 ; +return !is_mmu_index_lam (mmu_index) && (mmu_index &1 ); +} + +/* The LAM form of a 64-bit data index, if LAM is enabled */ +static inline int x86_mmu_index_lam (CPUX86State *env,int mmu_index) +{ +if (!(env->hflags &HF_LAM_MASK )) { +return mmu_index; + } +switch (mmu_index) { +case MMU_KSMAP64_IDX : +return MMU_KSMAP64_LAM_IDX ; +case MMU_USER64_IDX : +return MMU_USER64_LAM_IDX ; +case MMU_KNOSMAP64_IDX : +return MMU_KNOSMAP64_LAM_IDX ; +default : +return mmu_index; + } }#define CC_DST (env->cc_dst)
target/i386/helper.c +13 -0
@@ -46,6 +46,17 @@ void cpu_sync_apx_hflag(CPUX86State *env) } } +void cpu_sync_lam_hflag (CPUX86State *env) +{ +if ((env->features[FEAT_7_1_EAX ] &CPUID_7_1_EAX_LAM ) && + ((env->cr[3 ] & (CR3_LAM_U57_MASK |CR3_LAM_U48_MASK )) || + (env->cr[4 ] &CR4_LAM_SUP_MASK ))) { + env->hflags |=HF_LAM_MASK ; + }else { + env->hflags &= ~HF_LAM_MASK ; + } +} +void cpu_sync_avx_hflag (CPUX86State *env) { if ((env->cr[4] & CR4_OSXSAVE_MASK)
@@ -188,6 +199,7 @@ void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0)void cpu_x86_update_cr3 (CPUX86State *env,target_ulong new_cr3) { env->cr[3 ] = new_cr3; +cpu_sync_lam_hflag (env);if (env->cr[0 ] &CR0_PG_MASK ) {qemu_log_mask (CPU_LOG_MMU ,"CR3 update: CR3=" TARGET_FMT_lx"\n" , new_cr3);
@@ -261,6 +273,7 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4)cpu_sync_bndcs_hflags (env);cpu_sync_avx_hflag (env);cpu_sync_apx_hflag (env); +cpu_sync_lam_hflag (env); }#if !defined(CONFIG_USER_ONLY )
target/i386/tcg/seg_helper.c +1 -1
@@ -138,7 +138,7 @@ static int x86_mmu_index_kernel_pl(CPUX86State *env, unsigned pl) (pl <3 && (env->eflags &AC_MASK ) ?MMU_KNOSMAP64_IDX :MMU_KSMAP64_IDX ); -return mmu_index_base + mmu_index_32; +return x86_mmu_index_lam (env, mmu_index_base + mmu_index_32); }int cpu_mmu_index_kernel (CPUX86State *env)
target/i386/tcg/tcg-cpu.c +10 -2
@@ -116,7 +116,7 @@ static void x86_restore_state_to_opc(CPUState *cs, } } -int x86_mmu_index_pl (CPUX86State *env,unsigned pl) +static int x86_mmu_index_pl_nolam (CPUX86State *env,unsigned pl) {int mmu_index_32 = (env->hflags &HF_CS64_MASK ) ?0 :1 ; int mmu_index_base =
@@ -127,10 +127,18 @@ int x86_mmu_index_pl(CPUX86State *env, unsigned pl)return mmu_index_base + mmu_index_32; } +int x86_mmu_index_pl (CPUX86State *env,unsigned pl) +{ +return x86_mmu_index_lam (env,x86_mmu_index_pl_nolam (env, pl)); +} +static int x86_cpu_mmu_index (CPUState *cs,bool ifetch) {CPUX86State *env =cpu_env (cs); -return x86_mmu_index_pl (env, env->hflags &HF_CPL_MASK ); +unsigned pl = env->hflags &HF_CPL_MASK ; + +/* LAM does not apply to instruction fetches */ +return ifetch ?x86_mmu_index_pl_nolam (env, pl) :x86_mmu_index_pl (env, pl); }#ifndef CONFIG_USER_ONLY
Signature · 1 line
2.47.3
PATCH v3 4/5 target/i386: emulate LAM in TCG
In reply to TimLinear Address Masking (LAM) lets software keep metadata in bits 62:57 or 62:48 of 64-bit data addresses. CR3.LAM_U57 and CR3.LAM_U48 enable it for user addresses, and CR4.LAM_SUP for supervisor addresses. Implement it in TCG and add it to TCG_7_1_EAX_FEATURES.
get_physical_address() masks the address and runs the canonical check and the page walk on the result. Since masking keeps bit 63, this is the canonical check that the SDM specifies for LAM. CR2 receives the masked address on #PF. The TLB entry is installed under the tagged address, which is the same way target/arm does it for top-byte-ignore. Only accesses with the LAM MMU indexes are masked. Instruction fetches always use the normal indexes, and data accesses use the LAM indexes while LAM is enabled, so fetch and data entries for a tagged address do not share a TLB.
Since each tag of a page has its own entry, INVLPG and INVLPGA flush every tagged alias with tlb_flush_page_bits_by_mmuidx(), and a change of CR4.LAM_SUP flushes the TLB.
MOV to CR3 and VMRUN accept the CR3 LAM bits if CPUID reports LAM. Masking checks CPUID too, since RSM and gdbstub load CR3 without checking reserved bits.
x86_cpu_translate_for_debug() masks addresses as for a data access, for gdbstub, monitor, and qemu_plugin_translate_vaddr(). With LAM_U48 and 5-level paging, it therefore translates an instruction address at or above 2^47 differently from a fetch.
---
v3: mask only for the LAM MMU indexes.
v2: mask only for non-fetch MMU indexes.
target/i386/cpu.c | 2 +- target/i386/cpu.h | 43 ++++++++++++++++++++++++++++ target/i386/helper.c | 6 +++- target/i386/tcg/system/excp_helper.c | 12 ++++++-- target/i386/tcg/system/misc_helper.c | 24 ++++++++++++++-- target/i386/tcg/system/svm_helper.c | 3 +- 6 files changed, 82 insertions(+), 8 deletions(-)
target/i386/cpu.c +1 -1
@@ -1006,7 +1006,7 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,#define TCG_7_0_EDX_FEATURES (CPUID_7_0_EDX_FSRM | CPUID_7_0_EDX_KERNEL_FEATURES)#define TCG_7_1_EAX_FEATURES (CPUID_7_1_EAX_FZRM | CPUID_7_1_EAX_FSRS | \ - CPUID_7_1_EAX_FSRC | CPUID_7_1_EAX_CMPCCXADD) + CPUID_7_1_EAX_FSRC | CPUID_7_1_EAX_CMPCCXADD | CPUID_7_1_EAX_LAM)#define TCG_7_1_ECX_FEATURES 0#define TCG_7_1_EDX_FEATURES CPUID_7_1_EDX_APXF#define TCG_7_2_EDX_FEATURES 0
target/i386/cpu.h +43 -0
49 lines not on this page · raw message
target/i386/helper.c +5 -1
@@ -216,7 +216,8 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4)#endif if ((new_cr4 ^ env->cr[4 ]) & (CR4_PGE_MASK |CR4_PAE_MASK |CR4_PSE_MASK | -CR4_SMEP_MASK |CR4_SMAP_MASK |CR4_LA57_MASK )) { +CR4_SMEP_MASK |CR4_SMAP_MASK |CR4_LA57_MASK | +CR4_LAM_SUP_MASK )) {tlb_flush (env_cpu (env)); }
@@ -303,6 +304,9 @@ bool x86_cpu_translate_for_debug(CPUState *cs, vaddr addr,uint64_t pml4e_addr, pml4e;int32_t sext; +/* LAM: translate as for a data access */ + addr =x86_lam_mask_addr (env, addr); +/* test virtual address sign extension */ sext = la57 ? (int64_t )addr >>56 : (int64_t )addr >>47 ;if (sext !=0 && sext !=-1 ) {
target/i386/tcg/system/excp_helper.c +10 -2
@@ -587,9 +587,17 @@ static bool get_physical_address(CPUX86State *env, vaddr addr, in.pg_mode =get_pg_mode (env);if (in.pg_mode &PG_MODE_LMA ) { -/* test virtual address sign extension */ int shift = in.pg_mode &PG_MODE_LA57 ?56 :47 ; -int64_t sext = (int64_t )addr >> shift; +int64_t sext; + +/* LAM masks data addresses but not instruction fetches */ +if (is_mmu_index_lam (mmu_idx)) { + addr =x86_lam_mask_addr (env, addr); + in.addr = addr; + } + +/* test virtual address sign extension */ + sext = (int64_t )addr >> shift;if (sext !=0 && sext !=-1 ) { *err = (TranslateFault ){ .exception_index = EXCP0D_GPF,
target/i386/tcg/system/misc_helper.c +22 -2
@@ -90,8 +90,7 @@ void HELPER(write_crN)(CPUX86State *env, int reg, target_ulong t0)cpu_x86_update_cr0 (env, t0);break ;case 3 : -if ((env->efer &MSR_EFER_LMA ) && - (t0 & ((~0ULL ) <<env_archcpu (env)->phys_bits))) { +if ((env->efer &MSR_EFER_LMA ) && (t0 &cr3_reserved_bits (env))) {cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); }if (!(env->efer &MSR_EFER_LMA )) {
@@ -504,6 +503,27 @@ void HELPER(rdmsr)(CPUX86State *env)void HELPER (flush_page )(CPUX86State *env,target_ulong addr) { +#ifdef TARGET_X86_64 +if (env->hflags &HF_LMA_MASK ) { +int shift = env->cr[4 ] &CR4_LA57_MASK ?56 :47 ; +int64_t sext = (int64_t )addr >> shift; +unsigned lam_bits; + +/* no LAM for the operand: non-canonical is a no-op */ +if (sext !=0 && sext !=-1 ) { +return ; + } + +/* TLB entries are per tag: flush every tagged alias */ + lam_bits =x86_lam_addr_bits (env, addr); +if (lam_bits <64 ) { +tlb_flush_page_bits_by_mmuidx (env_cpu (env), addr, +MAKE_64BIT_MASK (0 ,NB_MMU_MODES ), + lam_bits); +return ; + } + } +#endif tlb_flush_page (env_cpu (env), addr); }
target/i386/tcg/system/svm_helper.c +1 -2
@@ -315,8 +315,7 @@ void HELPER(vmrun)(CPUX86State *env, int aflag, int next_eip_addend)cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); } new_cr3 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr3)); -if ((env->efer &MSR_EFER_LMA ) && - (new_cr3 & ((~0ULL ) << cpu->phys_bits))) { +if ((env->efer &MSR_EFER_LMA ) && (new_cr3 &cr3_reserved_bits (env))) {cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); } new_cr4 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr4));
Signature · 1 line
2.47.3