i386, Rust for 2026-11-17
Subsystems (2)
The following changes since commit 97c88c61d45dee6e1f9bc160a338048189846d28:
Merge tag 'docs-security-devices-pull-request' of https://gitlab.com/berrange/qemu into staging (2026-11-16 15:48:48 -0800)
are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to 5705f0759f17896ae60257af7fc7d23858777fc0:
rust/common: rename IntegerExt::bit() to single_bit() (2026-11-17 14:35:23 +0100)
----------------------------------------------------------------
* target/i386/kvm: fix latched INIT lost in kvm_put_vcpu_events()
* target/i386/kvm: set VM ioctl KVM_SET_TSC_KHZ to maintain TSC synchronization
* target/i386/tcg: fix CPUID checks for TZCNT and LZCNT
* target/i386/tcg: reject VEX encodings of PBLENDVB, BLENDVPS and BLENDVPD
* target/i386/tcg: fix SETCC(zu) optimization
* target/i386/tcg: fix lea address calculation for CS register
* target/i386/tcg: Fix 64-bit RSP truncation on far transfers
* target/i386/tcg: all scalar instructions should be LIG
* target/i386/tcg: treat ENTER's size operand as unsigned
* target/i386/tcg: remove unused argument of decode_ops
* target/i386/tcg: remove unused operand sizes
* tests/tcg: fix load/restore for test-avx and test-mmx
* rust: fix failure with nightly libstd
----------------------------------------------------------------
Denis V. Lunev (1):
target/i386/kvm: fix latched INIT lost in kvm_put_vcpu_events()
Dongli Zhang (1):
target/i386/kvm: set VM ioctl KVM_SET_TSC_KHZ to maintain TSC synchronization
Mark Cave-Ayland (1):
target/i386/tcg: fix lea address calculation for CS register
NickSampanis (3):
target/i386/tcg: Fix 64-bit RSP truncation on retf in 64-bit mode target/i386/tcg: Fix 64-bit RSP truncation on far call in 64-bit mode target/i386/tcg: Fix 64-bit RSP truncation on far call through a call gate
Paolo Bonzini (7):
target/i386/tcg: fix CPUID checks for TZCNT and LZCNT target/i386/tcg: reject VEX encodings of PBLENDVB, BLENDVPS and BLENDVPD target/i386/tcg: fix SETCC(zu) optimization
tests/tcg: fix load/restore for test-avx and test-mmx target/i386/tcg: all scalar instructions should be LIG target/i386/tcg: remove unused argument of decode_ops target/i386/tcg: remove unused operand sizes
Samuel Tardieu (1):
rust/common: rename IntegerExt::bit() to single_bit()
z Y (1):
target/i386/tcg: treat ENTER's size operand as unsigned
target/i386/tcg/decode-new.h | 7 ++-- target/i386/kvm/kvm.c | 19 ++++++++- target/i386/tcg/seg_helper.c | 15 +++++-- target/i386/tcg/translate.c | 22 +++++++++- tests/tcg/i386/test-avx.c | 22 +++++----- tests/tcg/i386/test-i386-blendv.c | 51 +++++++++++++++++++++++ tests/tcg/i386/test-i386-enter.c | 42 +++++++++++++++++++ tests/tcg/i386/test-mmx.c | 22 +++++----- target/i386/tcg/decode-new.c.inc | 88 +++++++++++++++++++-------------------- target/i386/tcg/emit.c.inc | 8 ++++ rust/common/src/bitops.rs | 8 ++-- tests/tcg/i386/meson.build | 2 + tests/tcg/x86_64/meson.build | 2 + 13 files changed, 229 insertions(+), 79 deletions(-) create mode 100644 tests/tcg/i386/test-i386-blendv.c create mode 100644 tests/tcg/i386/test-i386-enter.c
Signature · 1 line
2.56.0
[PULL 02/15] target/i386/tcg: reject VEX encodings of PBLENDVB, BLENDVPS and BLENDVPD
The opcodes 66 0F 38 10, 14 and 15 (PBLENDVB, BLENDVPS and BLENDVPD) have vex_class 4, which allows both the legacy and the VEX encoding, so VEX.66.0F38 10, 14 and 15 were decoded as the same instructions. The VEX forms of these instructions are VPBLENDVB, VBLENDVPS and VBLENDVPD, which have four operands and are in map 0F 3A, so the VEX opcodes in map 0F 38 should raise #UD.
Keep vex_class 4, which provides the legacy SSE checks, and add a new vex_special that raises #UD if the VEX or EVEX prefix is present. This is borderline disgusting, but an effective solution to x86's opcode sprawl will have to wait for a new AI policy...
--- target/i386/tcg/decode-new.h | 3 ++ tests/tcg/i386/test-i386-blendv.c | 51 +++++++++++++++++++++++++++++++ target/i386/tcg/decode-new.c.inc | 16 +++++++--- tests/tcg/i386/meson.build | 1 + tests/tcg/x86_64/meson.build | 1 + 5 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 tests/tcg/i386/test-i386-blendv.c
target/i386/tcg/decode-new.h +3 -0
@@ -257,6 +257,9 @@ typedef enum X86InsnSpecial { typedef enum X86VEXSpecial { X86_VEX_None, + /* SSE and AVX instructions use different encoding */ + X86_VEX_SSEOnly, + /* Legacy SSE instructions that allow unaligned operands */ X86_VEX_SSEUnaligned,
tests/tcg/i386/test-i386-blendv.c new file +51 -0
51 lines not on this page · raw message
target/i386/tcg/decode-new.c.inc +12 -4
@@ -120,7 +120,8 @@ * * (*) AMD lists VPBLENDVB as related to SSE4.1 PBLENDVB, which may * explain why it is considered exception class 4. However, - * Intel says that VEX-only instructions should be in class 6... + * the two have different encodings (in 0F38 for SSE, in 0F3A + * for AVX). * * (+) Not found in Intel's table 2-16 *
@@ -250,6 +251,7 @@ #define vex2_rep3 .vex_class = 2, .vex_special = X86_VEX_REPScalar, #define vex3 .vex_class = 3, #define vex4 .vex_class = 4, +#define sse4 .vex_class = 4, .vex_special = X86_VEX_SSEOnly, #define vex4_unal .vex_class = 4, .vex_special = X86_VEX_SSEUnaligned, #define vex4_rep5 .vex_class = 4, .vex_special = X86_VEX_REPScalar, #define vex5 .vex_class = 5,
@@ -732,10 +734,10 @@ static const X86OpEntry opcodes_0F38_00toEF[240] = { [0x06] = X86_OP_ENTRY3(PHSUBD, V,x, H,x, W,x, vex4 cpuid(SSSE3) mmx avx2_256 p_00_66), [0x07] = X86_OP_ENTRY3(PHSUBSW, V,x, H,x, W,x, vex4 cpuid(SSSE3) mmx avx2_256 p_00_66), - [0x10] = X86_OP_ENTRY2(PBLENDVB, V,x, W,x, vex4 cpuid(SSE41) avx2_256 p_66), + [0x10] = X86_OP_ENTRY2(PBLENDVB, V,x, W,x, sse4 cpuid(SSE41) p_66), [0x13] = X86_OP_ENTRY2(VCVTPH2PS, V,x, W,xh, vex11 chk(W0) cpuid(F16C) p_66), - [0x14] = X86_OP_ENTRY2(BLENDVPS, V,x, W,x, vex4 cpuid(SSE41) p_66), - [0x15] = X86_OP_ENTRY2(BLENDVPD, V,x, W,x, vex4 cpuid(SSE41) p_66), + [0x14] = X86_OP_ENTRY2(BLENDVPS, V,x, W,x, sse4 cpuid(SSE41) p_66), + [0x15] = X86_OP_ENTRY2(BLENDVPD, V,x, W,x, sse4 cpuid(SSE41) p_66), /* Listed incorrectly as type 4 */ [0x16] = X86_OP_ENTRY3(VPERMD, V,qq, H,qq, W,qq, vex6 chk(W0) cpuid(AVX2) p_66), /* vpermps */ [0x17] = X86_OP_ENTRY3(VPTEST, None,None, V,x, W,x, vex4 cpuid(SSE41) p_66),
@@ -3114,6 +3116,12 @@ static bool validate_vex(DisasContext *s, X86DecodedInsn *decode) } break; + case X86_VEX_SSEOnly: + if (s->prefix & PREFIX_VEX) { + goto illegal; + } + break; + case X86_VEX_SSEUnaligned: /* handled in sse_needs_alignment. */ break;
tests/tcg/i386/meson.build +1 -0
@@ -10,6 +10,7 @@ tests += { }, 'test-aes.c': {'cflags': ['-O1', '-msse2', '-maes']}, 'test-i386-adcox.c': {'cflags': ['-O2']}, + 'test-i386-blendv.c': {}, 'test-i386-bmi2.c': {'cflags': ['-O2', '-fwrapv']}, 'test-i386-f2xm1.c': {}, 'test-i386-fbstp.c': {},
tests/tcg/x86_64/meson.build +1 -0
@@ -47,6 +47,7 @@ tests += { 'exe_name': 'test-x86_64' }, '../i386/test-i386-adcox.c': {'cflags': ['-O2']}, + '../i386/test-i386-blendv.c': {}, '../i386/test-i386-bmi2.c': {'cflags': ['-O2', '-fwrapv']}, '../i386/test-idiv-overflow.c': {}, }
Signature · 1 line
2.56.0
Re: [PULL 02/15] target/i386/tcg: reject VEX encodings of PBLENDVB, BLENDVPS and BLENDVPD
Quoted 8 lines · Paolo Bonzini
The opcodes 66 0F 38 10, 14 and 15 (PBLENDVB, BLENDVPS and BLENDVPD) have
vex_class4, which allows both the legacy and the VEX encoding, so VEX.66.0F38 10, 14 and 15 were decoded as the same instructions. The VEX forms of these instructions are VPBLENDVB, VBLENDVPS and VBLENDVPD, which have four operands and are in map 0F 3A, so the VEX opcodes in map 0F 38 should raise #UD.
Quoted 6 lines
Keep
vex_class4, which provides the legacy SSE checks, and add a newvex_specialthat raises #UD if the VEX or EVEX prefix is present. This is borderline disgusting, but an effective solution to x86's opcode sprawl will have to wait for a new AI policy...Signed-off-by Paolo Bonzini <[email protected]>
Hi; this test case fails "make check" if built with clang.
Configure flags:
'--cc=clang' '--cxx=clang++'
'--target-list=x86_64-softmmu,x86_64-linux-user,i386-softmmu,i386-linux-user' '--enable-debug'
The failure happens because clang complains about the clobbers line in the SSE_INSN macro:
FAILED: tests/tcg/i386-linux-user-test-i386-blendv.test /home/pm215/qemu/tests/tcg/../docker/docker.py --command podman run --run-as-current-user -- --security-opt label=disable --platform linux/amd64 -w /home/pm215/qemu/build/x86-clang -v /home/pm215/qemu/build/x86-clang:/home/pm215/qemu/build/x86-clang -v /home/pm215/qemu:/home/pm215/qemu qemu/debian-i686-cross i686-linux-gnu-gcc ../../tests/tcg/i386/test-i386-blendv.c -o tests/tcg/i386-linux-user-test-i386-blendv.test -static -MMD -MF tests/tcg/i386-linux-user-test-i386-blendv.d -Wall -Werror -O0 -g -fno-strict-aliasing -fno-stack-protector ../../tests/tcg/i386/test-i386-blendv.c: In function ‘main’:../../tests/tcg/i386/test-i386-blendv.c:20:22: error: the register ‘xmm1’ cannot be clobbered in ‘asm’ for the current target
20 | #define SSE_INSN(op) asm volatile(".byte 0x66, 0x0f, 0x38, "
#op ", 0xc9" \
| ^~~../../tests/tcg/i386/test-i386-blendv.c:43:5: note: in expansion of macro ‘SSE_INSN’
43 | SSE_INSN(0x10);
| ^~~~~~~~../../tests/tcg/i386/test-i386-blendv.c:20:22: error: the register ‘xmm1’ cannot be clobbered in ‘asm’ for the current target
20 | #define SSE_INSN(op) asm volatile(".byte 0x66, 0x0f, 0x38, "
#op ", 0xc9" \
| ^~~../../tests/tcg/i386/test-i386-blendv.c:44:5: note: in expansion of macro ‘SSE_INSN’
44 | SSE_INSN(0x14);
| ^~~~~~~~../../tests/tcg/i386/test-i386-blendv.c:20:22: error: the register ‘xmm1’ cannot be clobbered in ‘asm’ for the current target
20 | #define SSE_INSN(op) asm volatile(".byte 0x66, 0x0f, 0x38, "
#op ", 0xc9" \
| ^~~../../tests/tcg/i386/test-i386-blendv.c:45:5: note: in expansion of macro ‘SSE_INSN’
45 | SSE_INSN(0x15);
| ^~~~~~~~tests/tcg/i386/test-i386-blendv.c line 21
Quoted 3 lines
tests/tcg/i386/test-i386-blendv.c new file +3
-0+/* 66 0F 38 xx with modrm = 11 001 001 (xmm1, xmm1 operands). */ +#define SSE_INSN (op) asm volatile(".byte 0x66, 0x0f, 0x38, " #op ", 0xc9" \ + : : : "xmm0", "xmm1")
thanks
-- PMM
Re: [PULL 02/15] target/i386/tcg: reject VEX encodings of PBLENDVB, BLENDVPS and BLENDVPD
Quoted 15 lines · Peter Maydell
Quoted 13 lines · Paolo Bonzini
The opcodes 66 0F 38 10, 14 and 15 (PBLENDVB, BLENDVPS and BLENDVPD) have
vex_class4, which allows both the legacy and the VEX encoding, so VEX.66.0F38 10, 14 and 15 were decoded as the same instructions. The VEX forms of these instructions are VPBLENDVB, VBLENDVPS and VBLENDVPD, which have four operands and are in map 0F 3A, so the VEX opcodes in map 0F 38 should raise #UD.Keep
vex_class4, which provides the legacy SSE checks, and add a newvex_specialthat raises #UD if the VEX or EVEX prefix is present. This is borderline disgusting, but an effective solution to x86's opcode sprawl will have to wait for a new AI policy...
Quoted 8 lines
Quoted 1 line
Signed-off-by Paolo Bonzini <[email protected]>Hi; this test case fails "make check" if built with clang.
Configure flags:
'--cc=clang' '--cxx=clang++'
'--target-list=x86_64-softmmu,x86_64-linux-user,i386-softmmu,i386-linux-user' '--enable-debug'
...and in fact it breaks with gcc too:
/home/pm215/qemu/tests/tcg/../docker/docker.py --command podman run --run-as-current-user -- --security-opt label=disable --platform linux/amd64 -w /home/pm215/qemu/build/x86 -v /home/pm215/qemu/build/x86:/home/pm215/qemu/build/x86 -v /home/pm215/qemu:/home/pm215/qemu qemu/debian-i686-cross i686-linux-gnu-gcc ../../tests/tcg/i386/test-i386-blendv.c -o tests/tcg/i386-linux-user-test-i386-blendv.test -static -MMD -MF tests/tcg/i386-linux-user-test-i386-blendv.d -Wall -Werror -O0 -g -fno-strict-aliasing -fno-stack-protector ../../tests/tcg/i386/test-i386-blendv.c: In function ‘main’:../../tests/tcg/i386/test-i386-blendv.c:20:22: error: the register ‘xmm1’ cannot be clobbered in ‘asm’ for the current target
20 | #define SSE_INSN(op) asm volatile(".byte 0x66, 0x0f, 0x38, "
#op ", 0xc9" \
| ^~~../../tests/tcg/i386/test-i386-blendv.c:43:5: note: in expansion of macro ‘SSE_INSN’
43 | SSE_INSN(0x10);
| ^~~~~~~~../../tests/tcg/i386/test-i386-blendv.c:20:22: error: the register ‘xmm1’ cannot be clobbered in ‘asm’ for the current target
20 | #define SSE_INSN(op) asm volatile(".byte 0x66, 0x0f, 0x38, "
#op ", 0xc9" \
| ^~~../../tests/tcg/i386/test-i386-blendv.c:44:5: note: in expansion of macro ‘SSE_INSN’
44 | SSE_INSN(0x14);
| ^~~~~~~~../../tests/tcg/i386/test-i386-blendv.c:20:22: error: the register ‘xmm1’ cannot be clobbered in ‘asm’ for the current target
20 | #define SSE_INSN(op) asm volatile(".byte 0x66, 0x0f, 0x38, "
#op ", 0xc9" \
| ^~~../../tests/tcg/i386/test-i386-blendv.c:45:5: note: in expansion of macro ‘SSE_INSN’
45 | SSE_INSN(0x15);
| ^~~~~~~~I'm not sure how this made it through CI, maybe it's a compiler version related thing?
thanks
-- PMM
Re: [PULL 02/15] target/i386/tcg: reject VEX encodings of PBLENDVB, BLENDVPS and BLENDVPD
Quoted 62 lines · Peter Maydell
Quoted 15 lines · Peter Maydell
Quoted 13 lines · Paolo Bonzini
The opcodes 66 0F 38 10, 14 and 15 (PBLENDVB, BLENDVPS and BLENDVPD) have
vex_class4, which allows both the legacy and the VEX encoding, so VEX.66.0F38 10, 14 and 15 were decoded as the same instructions. The VEX forms of these instructions are VPBLENDVB, VBLENDVPS and VBLENDVPD, which have four operands and are in map 0F 3A, so the VEX opcodes in map 0F 38 should raise #UD.Keep
vex_class4, which provides the legacy SSE checks, and add a newvex_specialthat raises #UD if the VEX or EVEX prefix is present. This is borderline disgusting, but an effective solution to x86's opcode sprawl will have to wait for a new AI policy...Quoted 8 lines
Quoted 1 line
Signed-off-by Paolo Bonzini <[email protected]>Hi; this test case fails "make check" if built with clang.
Configure flags:
'--cc=clang' '--cxx=clang++''--target-list=x86_64-softmmu,x86_64-linux-user,i386-softmmu,i386-linux-user' '--enable-debug'
...and in fact it breaks with gcc too:
/home/pm215/qemu/tests/tcg/../docker/docker.py--command podman run --run-as-current-user -- --security-opt label=disable --platform linux/amd64 -w/home/pm215/qemu/build/x86-v /home/pm215/qemu/build/x86:/home/pm215/qemu/build/x86 -v /home/pm215/qemu:/home/pm215/qemu qemu/debian-i686-cross i686-linux-gnu-gcc../../tests/tcg/i386/test-i386-blendv.c-o tests/tcg/i386-linux-user-test-i386-blendv.test -static -MMD -MF tests/tcg/i386-linux-user-test-i386-blendv.d -Wall -Werror -O0 -g -fno-strict-aliasing -fno-stack-protector../../tests/tcg/i386/test-i386-blendv.c: In function ‘main’:../../tests/tcg/i386/test-i386-blendv.c:20:22: error: the register ‘xmm1’ cannot be clobbered in ‘asm’ for the current target20 | #define SSE_INSN(op) asm volatile(".byte 0x66, 0x0f, 0x38, "#op ",
0xc9" \
| ^~~../../tests/tcg/i386/test-i386-blendv.c:43:5: note: in expansion of macro ‘SSE_INSN’43 | SSE_INSN(0x10); | ^~~~~~~~ ../../tests/tcg/i386/test-i386-blendv.c:20:22: error: the register ‘xmm1’ cannot be clobbered in ‘asm’ for the current target 20 | #define SSE_INSN(op) asm volatile(".byte 0x66, 0x0f, 0x38, "#op ",
0xc9" \
| ^~~../../tests/tcg/i386/test-i386-blendv.c:44:5: note: in expansion of macro ‘SSE_INSN’44 | SSE_INSN(0x14); | ^~~~~~~~ ../../tests/tcg/i386/test-i386-blendv.c:20:22: error: the register ‘xmm1’ cannot be clobbered in ‘asm’ for the current target 20 | #define SSE_INSN(op) asm volatile(".byte 0x66, 0x0f, 0x38, "#op ",
0xc9" \
| ^~~../../tests/tcg/i386/test-i386-blendv.c:45:5: note: in expansion of macro ‘SSE_INSN’
Quoted 5 lines
45 | SSE_INSN(0x15); | ^~~~~~~~I'm not sure how this made it through CI, maybe it's a compiler version related thing?
Plus or minus version, I expect it's how the compiler is configured, whether sse is enabled by default for i686. We just need to add -msse to cflags to ensure it.
r~
[PULL 04/15] target/i386/kvm: fix latched INIT lost in kvm_put_vcpu_events()
In reply to Paolo BonziniFrom: "Denis V. Lunev" <[email protected]>
CPU_INTERRUPT_INIT is 0x0400, while kvm_vcpu_events.smi.latched_init is a __u8. The assignment truncates the masked value to 0, so every KVM_SET_VCPU_EVENTS tells KVM to clear an INIT it has latched for a vCPU in SMM. smi.pending survives only because CPU_INTERRUPT_SMI is 0x0040; normalize both with !! like the neighbouring fields.
--- target/i386/kvm/kvm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/i386/kvm/kvm.c +3 -2
@@ -5514,8 +5514,9 @@ static int kvm_put_vcpu_events(X86CPU *cpu, KvmPutState level)/* As soon as these are moved to the kernel, remove them * from cs->interrupt_request. */ - events.smi.pending = cs->interrupt_request &CPU_INTERRUPT_SMI ; - events.smi.latched_init = cs->interrupt_request &CPU_INTERRUPT_INIT ; + events.smi.pending = !!(cs->interrupt_request &CPU_INTERRUPT_SMI ); + events.smi.latched_init = + !!(cs->interrupt_request &CPU_INTERRUPT_INIT );cpu_reset_interrupt (cs,CPU_INTERRUPT_INIT |CPU_INTERRUPT_SMI ); }else {/* Keep these in cs->interrupt_request. */
Signature · 1 line
2.56.0
[PULL 08/15] target/i386/tcg: Fix 64-bit RSP truncation on retf in 64-bit mode
In reply to Paolo BonziniFrom: NickSampanis <[email protected]>
When executing retf in 64-bit mode with a 16- or 32-bit operand size, helper_ret_protected() is invoked with a shift of 0 or 1. However, in 64-bit mode, operand size should only govern the number of bytes that are popped, not how wide the stack pointer is because in 64-bit mode the SS attributes are ignored.
By falling back to get_sp_mask(SS.flags), QEMU applied a 16-bit mask (0xffff) with SS.B clear, and a 32-bit mask (0xffffffff) with SS.B set. As a result, a 64-bit RSP pointing above 4 GiB was truncated. As observed in testing, the truncated stack pop read the wrong address, loading corrupted values for the new CS and RIP which resulted in a #GP fault and then a triple fault.
Fix this by ensuring that helper_ret_protected() uses the full 64-bit stack pointer with no mask applied whenever the active code segment (CS) is running in 64-bit mode.
--- target/i386/tcg/seg_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/tcg/seg_helper.c +1 -1
@@ -2056,7 +2056,7 @@ static inline void helper_ret_protected(CPUX86State *env, int shift, sa.mmu_index =x86_mmu_index_pl (env, cpl);#ifdef TARGET_X86_64 -if (shift ==2 ) { +if (shift ==2 || (env->hflags &HF_CS64_MASK )) { sa.sp_mask =-1 ; } else#endif
Signature · 1 line
2.56.0
[PULL 09/15] target/i386/tcg: Fix 64-bit RSP truncation on far call in 64-bit mode
In reply to Paolo BonziniFrom: NickSampanis <[email protected]>
When executing a direct far call to a code segment (no call gate involved) in 64-bit mode with a 16- or 32-bit operand size, lcall_protected falls back to get_sp_mask(SS.flags). This gives a 16- or 32-bit mask, but in 64-bit mode the stack always uses the full RSP and the attributes are ignored. As a result, the pushes of the return address and the stack pointer update (SET_ESP) truncate RSP. This is the same bug fixed for retf in the previous patch.
Use the full stack pointer, with no mask, for a direct far call when CS is 64-bit.
--- target/i386/tcg/seg_helper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
target/i386/tcg/seg_helper.c +5 -1
@@ -1731,7 +1731,11 @@ void HELPER(lcall_protected)(CPUX86State *env, int new_cs, target_ulong new_eip,#endif { sa.sp = env->regs[R_ESP ]; - sa.sp_mask =get_sp_mask (env->segs[R_SS ].flags); +if (env->hflags &HF_CS64_MASK ) { + sa.sp_mask =-1 ; + }else { + sa.sp_mask =get_sp_mask (env->segs[R_SS ].flags); + } sa.ss_base = env->segs[R_SS ].base;if (shift) {pushl (&sa, env->segs[R_CS ].selector);
Signature · 1 line
2.56.0
[PULL 15/15] rust/common: rename IntegerExt::bit() to single_bit()
In reply to Paolo BonziniFrom: Samuel Tardieu <[email protected]>
An experimental Rust nightly feature get_set_bit introduces a bit() method on integer types which checks whether a specific bit is set. This clashes with QEMU's IntegerExt::bit() associated function which returns an integer with one particular bit set.
While the get_set_bit feature has no planned stabilization date yet, this is reported as a unstable_name_collisions warning when compiling with the strict_rust_lints option, and warnings are turned into errors. Renaming IntegerExt::bit() to IntegerExt::single_bit() prevents this.
--- rust/common/src/bitops.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
rust/common/src/bitops.rs +4 -4
@@ -34,7 +34,7 @@ pub trait IntegerExt:#[inline] #[must_use] -fn bit (start:u32 ) ->Self +fn single_bit (start:u32 ) ->Self {debug_assert! (start <Self ::BITS );
@@ -105,9 +105,9 @@ fn test_extract() { }#[test] -fn test_bit () { -assert_eq! (u8 ::bit (7 ),128 ); -assert_eq! (u32 ::bit (16 ),0x10000 ); +fn test_single_bit () { +assert_eq! (u8 ::single_bit (7 ),128 ); +assert_eq! (u32 ::single_bit (16 ),0x10000 ); }#[test]
Signature · 1 line
2.56.0
[PULL 01/15] target/i386/tcg: fix CPUID checks for TZCNT and LZCNT
In reply to Paolo Bonzinidecode_0FBC() decodes F3 0F BC as TZCNT only if the CPU has ABM, and decode_0FBD() decodes F3 0F BD as LZCNT only if the CPU has BMI1. The features are the other way round: TZCNT is part of BMI1, and LZCNT is part of ABM.
--- target/i386/tcg/decode-new.c.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/tcg/decode-new.c.inc +2 -2
@@ -688,7 +688,7 @@ static void decode_0FBC(DisasContext *s, CPUX86State *env, X86OpEntry *entry, ui X86_OP_ENTRYwr(TZCNT, G,v, E,v, zextT0), /* 0xf3 */ X86_OP_ENTRY2(BSF, G,v, E,v, zextT1), /* 0xf2 */ }; - if (!(s->cpuid_ext3_features & CPUID_EXT3_ABM)) { + if (!(s->cpuid_7_0_ebx_features & CPUID_7_0_EBX_BMI1)) { *entry = opcodes_0FBC[0]; } else { *entry = *decode_by_prefix(s, opcodes_0FBC);
@@ -703,7 +703,7 @@ static void decode_0FBD(DisasContext *s, CPUX86State *env, X86OpEntry *entry, ui X86_OP_ENTRYwr(LZCNT, G,v, E,v, zextT0), /* 0xf3 */ X86_OP_ENTRY2(BSR, G,v, E,v, zextT1), /* 0xf2 */ }; - if (!(s->cpuid_7_0_ebx_features & CPUID_7_0_EBX_BMI1)) { + if (!(s->cpuid_ext3_features & CPUID_EXT3_ABM)) { *entry = opcodes_0FBD[0]; } else { *entry = *decode_by_prefix(s, opcodes_0FBD);
Signature · 1 line
2.56.0
[PULL 14/15] target/i386/tcg: treat ENTER's size operand as unsigned
In reply to Paolo BonziniFrom: z Y <[email protected]>
The first immediate operand of ENTER is the size of the dynamic storage area and is unsigned. Decoding it as a signed immediate sign-extends values with bit 15 set, moving the stack pointer in the wrong direction.
Decode it with I_unsigned and add a regression test covering 32-bit and 64-bit guests.
Tested with a minimal x86_64-linux-user build; the new test fails before the change and passes after it.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4643
--- target/i386/tcg/translate.c | 2 +- tests/tcg/i386/test-i386-enter.c | 42 ++++++++++++++++++++++++++++++++ target/i386/tcg/decode-new.c.inc | 2 +- tests/tcg/i386/meson.build | 1 + tests/tcg/x86_64/meson.build | 1 + 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 tests/tcg/i386/test-i386-enter.c
target/i386/tcg/translate.c +1 -1
@@ -1989,7 +1989,7 @@ static void gen_popa(DisasContext *s)gen_stack_update (s,8 * size); } -static void gen_enter (DisasContext *s,int esp_addend,int level) +static void gen_enter (DisasContext *s,uint16_t esp_addend,int level) {MemOp d_ot =mo_pushpop (s, s->dflag);MemOp a_ot =mo_stacksize (s);
tests/tcg/i386/test-i386-enter.c new file +42 -0
42 lines not on this page · raw message
target/i386/tcg/decode-new.c.inc +1 -1
@@ -1972,7 +1972,7 @@ static const X86OpEntry opcodes_root[256] = { [0xBE] = X86_OP_ENTRYwr(MOV, LoBits,v, I,v), [0xBF] = X86_OP_ENTRYwr(MOV, LoBits,v, I,v), - [0xC8] = X86_OP_ENTRYrr(ENTER, I,w, I,b), + [0xC8] = X86_OP_ENTRYrr(ENTER, I_unsigned, w, I, b), [0xC9] = X86_OP_ENTRY0(LEAVE), [0xCA] = X86_OP_ENTRYr(RETF, I,w), [0xCB] = X86_OP_ENTRY0(RETF),
tests/tcg/i386/meson.build +1 -0
@@ -37,6 +37,7 @@ tests += { '-lm', '-fno-pie', '-Wl,--no-warn-rwx-segments'], }, 'test-idiv-overflow.c': {}, + 'test-i386-enter.c': {'cflags': ['-O2', '-fomit-frame-pointer']}, '../multiarch/sha512.c': { 'exe_name': 'sha512-sse', 'cflags': ['-msse4.1', '-O3'],
tests/tcg/x86_64/meson.build +1 -0
@@ -50,6 +50,7 @@ tests += { '../i386/test-i386-blendv.c': {}, '../i386/test-i386-bmi2.c': {'cflags': ['-O2', '-fwrapv']}, '../i386/test-idiv-overflow.c': {}, + '../i386/test-i386-enter.c': {'cflags': ['-O2', '-fomit-frame-pointer']}, } tests += {
Signature · 1 line
2.56.0
Re: [PULL 14/15] target/i386/tcg: treat ENTER's size operand as unsigned
Quoted 1 line · Paolo Bonzini
From: z Y <[email protected]>
Zixin Wang <[email protected]> as S-o-b?
Quoted 23 lines
The first immediate operand of ENTER is the size of the dynamic storage area and is unsigned. Decoding it as a signed immediate sign-extends values with bit 15 set, moving the stack pointer in the wrong direction.
Decode it with
I_unsignedand add a regression test covering 32-bit and 64-bit guests.Tested with a minimal x86_64-linux-user build; the new test fails before the change and passes after it.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4643
Signed-off-by Zixin Wang <[email protected]>Link https://lore.kernel.org/r/CABG6VKODisrETOuH5thhimg_DtJLH+1wmARKL5OsoND5Qse_TA@mail.gmail.com open hereSigned-off-by Paolo Bonzini <[email protected]>--- target/i386/tcg/translate.c | 2 +- tests/tcg/i386/test-i386-enter.c | 42 ++++++++++++++++++++++++++++++++ target/i386/tcg/decode-new.c.inc | 2 +- tests/tcg/i386/meson.build | 1 + tests/tcg/x86_64/meson.build | 1 + 5 files changed, 46 insertions(+), 2 deletions(-)create mode 100644
tests/tcg/i386/test-i386-enter.c
Re: [PULL 14/15] target/i386/tcg: treat ENTER's size operand as unsigned
Hi Philippe,
Yes, "Zixin Wang <[email protected]>" is the correct name for the S-o-b. Could you also update the author From line to match? The "z Y" there was just a stale display name in my tooling, and I've since fixed it on my side.
The patch content itself is unchanged, so no need to resend anything.
Thanks,
Zixin Wang
Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 1 line · Paolo Bonzini
From: z Y <[email protected]>
Zixin Wang <[email protected]> as S-o-b?
Quoted 23 lines
The first immediate operand of ENTER is the size of the dynamic storage area and is unsigned. Decoding it as a signed immediate sign-extends values with bit 15 set, moving the stack pointer in the wrong direction.
Decode it with
I_unsignedand add a regression test covering 32-bit and 64-bit guests.Tested with a minimal x86_64-linux-user build; the new test fails before the change and passes after it.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4643
Signed-off-by Zixin Wang <[email protected]>Link https://lore.kernel.org/r/CABG6VKODisrETOuH5thhimg_DtJLH+1wmARKL5OsoND5Qse_TA@mail.gmail.com open hereSigned-off-by Paolo Bonzini <[email protected]>--- target/i386/tcg/translate.c | 2 +- tests/tcg/i386/test-i386-enter.c | 42 ++++++++++++++++++++++++++++++++ target/i386/tcg/decode-new.c.inc | 2 +- tests/tcg/i386/meson.build | 1 + tests/tcg/x86_64/meson.build | 1 + 5 files changed, 46 insertions(+), 2 deletions(-)create mode 100644
tests/tcg/i386/test-i386-enter.c
[PULL 12/15] target/i386/tcg: remove unused argument of decode_ops
In reply to Paolo Bonzini--- target/i386/tcg/decode-new.c.inc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
target/i386/tcg/decode-new.c.inc +2 -3
@@ -2827,8 +2827,7 @@ static bool extract_evex_params(DisasContext *s, X86DecodedInsn *decode) } -static bool decode_ops(DisasContext *s, CPUX86State *env, X86DecodeFunc decode_func, - X86DecodedInsn *decode) +static bool decode_ops(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { X86OpEntry *e = &decode->e;
@@ -3608,7 +3607,7 @@ static void disas_insn(DisasContext *s, CPUState *cpu) } } - if (!decode_ops(s, env, decode_func, &decode)) { + if (!decode_ops(s, env, &decode)) { goto illegal_op; } if (!validate_cr0_exceptions(s, &decode)) {
Signature · 1 line
2.56.0
[PULL 10/15] target/i386/tcg: Fix 64-bit RSP truncation on far call through a call gate
In reply to Paolo BonziniFrom: NickSampanis <[email protected]>
In long mode, a call gate is 16 bytes and always has a 64-bit target. For a same-privilege call through a call gate, which can also be reached by a compatibility-mode caller, lcall_protected uses get_sp_mask(SS.flags) even though the pushes are 8 bytes. Consequently, the pushes and the stack pointer update (SET_ESP) truncate RSP. This is the same bug as in the previous two patches.
Use the full stack pointer when shift == 2, the same as the inner-privilege branch. This condition tests the gate's own size rather than the caller's mode, which is why it checks shift == 2 instead of HF_CS64_MASK.
--- target/i386/tcg/seg_helper.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
target/i386/tcg/seg_helper.c +6 -1
@@ -1925,7 +1925,12 @@ void HELPER(lcall_protected)(CPUX86State *env, int new_cs, target_ulong new_eip,/* to same privilege */ sa.mmu_index =x86_mmu_index_pl (env, cpl); sa.sp = env->regs[R_ESP ]; - sa.sp_mask =get_sp_mask (env->segs[R_SS ].flags); +#ifdef TARGET_X86_64 +if (shift ==2 ) { + sa.sp_mask =-1 ; + } else +#endif + sa.sp_mask =get_sp_mask (env->segs[R_SS ].flags); sa.ss_base = env->segs[R_SS ].base;/* push_size = (4 << shift); */ new_stack =0 ;
Signature · 1 line
2.56.0
[PULL 13/15] target/i386/tcg: remove unused operand sizes
In reply to Paolo Bonzini--- target/i386/tcg/decode-new.h | 4 ---- target/i386/tcg/decode-new.c.inc | 10 ++++------ 2 files changed, 4 insertions(+), 10 deletions(-)
target/i386/tcg/decode-new.h +0 -4
@@ -73,15 +73,11 @@ typedef enum X86OpSize { X86_SIZE_d,/* 32-bit */ X86_SIZE_dq,/* SSE/AVX 128-bit */ X86_SIZE_p,/* Far pointer */ - X86_SIZE_pd,/* SSE/AVX packed double precision */ - X86_SIZE_pi,/* MMX */ - X86_SIZE_ps,/* SSE/AVX packed single precision */ X86_SIZE_q,/* 64-bit */ X86_SIZE_qq,/* AVX 256-bit */ X86_SIZE_s,/* Descriptor */ X86_SIZE_sd,/* SSE/AVX scalar double precision */ X86_SIZE_ss,/* SSE/AVX scalar single precision */ - X86_SIZE_si,/* 32-bit GPR */ X86_SIZE_v,/* 16/32/64-bit, based on operand size */ X86_SIZE_w,/* 16-bit */ X86_SIZE_x, /* 128/256-bit, based on operand size */
target/i386/tcg/decode-new.c.inc +4 -6
@@ -73,8 +73,8 @@ * the V/U/H/W types to P/N/P/Q if there is no prefix, as well as changing * "x" to "q" if there is no prefix. * - * In addition, the ss/ps/sd/pd types are sometimes mushed together as "x" - * if the difference is expressed via prefixes. Individual instructions + * In addition, the ss/sd types are sometimes mushed together as "x" + * if the difference is expressed via prefixes; individual instructions * are separated by prefix in the generator functions. * * There is a custom size "xh" used to address half of a SSE/AVX operand.
@@ -82,6 +82,8 @@ * for 256-bit AVX operands, etc. It is used for conversion operations * such as VCVTPH2PS or VCVTSS2SD. * + * pi/ps/pd are simply written as "q" or "x". + * * There are a couple cases in which instructions (e.g. MOVD) write the * whole XMM or MM register but are established incorrectly in the manual * as "d" or "q". These have to be fixed for the decoder to work correctly.
@@ -2448,7 +2450,6 @@ static bool decode_op_size(DisasContext *s, X86OpEntry *e, X86OpSize size, MemOp *ot = s->dflag; return true; - case X86_SIZE_pi: /* MMX */ case X86_SIZE_q: /* 64-bit */ case X86_SIZE_sd: /* SSE/AVX scalar double precision */ *ot = MO_64;
@@ -2497,9 +2498,6 @@ static bool decode_op_size(DisasContext *s, X86OpEntry *e, X86OpSize size, MemOp *ot = MO_64; return true; } - /* fall through */ - case X86_SIZE_ps: /* SSE/AVX packed single precision */ - case X86_SIZE_pd: /* SSE/AVX packed double precision */ *ot = s->vex_l ? MO_256 : MO_128; return true;
Signature · 1 line
2.56.0
[PULL 05/15] target/i386/kvm: set VM ioctl KVM_SET_TSC_KHZ to maintain TSC synchronization
In reply to Paolo BonziniFrom: Dongli Zhang <[email protected]>
When the guest and host use different TSC frequencies - specifically when "tsc-frequency" is configured - the guest TSC becomes unsynchronized after additional vCPUs are added.
Suppose the host TSC frequency is 2596.102 MHz. Here are steps to reproduce:
Create the QEMU instance with a different TSC frequency 2596.100 MHz.
-cpu host,tsc-frequency=2596100000 \
-smp 2,maxcpus=8 \
After the guest VM has booted, add two additional vCPUs.
(qemu) device_add host-x86_64-cpu,id=core2,socket-id=0,core-id=2,thread-id=0 (qemu) device_add host-x86_64-cpu,id=core3,socket-id=0,core-id=3,thread-id=0
The guest TSC becomes unsynchronized. The vCPUs end up with different TSC offsets.
host# cat /sys/kernel/debug/kvm/167789-11/vcpu0/tsc-offset -345550695701016
host# cat /sys/kernel/debug/kvm/167789-11/vcpu1/tsc-offset -345550695701016
host# cat /sys/kernel/debug/kvm/167789-11/vcpu2/tsc-offset -345700146347894
host# cat /sys/kernel/debug/kvm/167789-11/vcpu3/tsc-offset -345700945993728
This issue occurs because KVM synchronizes the guest TSC twice for each newly added vCPU. In other words, kvm_synchronize_tsc() is invoked twice per vCPU by KVM.
During the first synchronization, kvm->arch.default_tsc_khz is used. During the second synchronization, the TSC frequency configured by QEMU is used. Because different TSC frequencies are used during these two synchronization steps, the guest TSC becomes unsynchronized in KVM.
Linux kernel commit ffbb61d09fc5 ("KVM: x86: Accept KVM_[GS]ET_TSC_KHZ as a VM ioctl.") introduced support in KVM to help mitigate this issue. QEMU should add corresponding support to address the problem on its side.
Always issue the VM ioctl KVM_SET_TSC_KHZ before creating any vCPUs, so that the default TSC frequency is set correctly for all subsequently created vCPUs.
--- target/i386/kvm/kvm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
target/i386/kvm/kvm.c +14 -0
@@ -2064,6 +2064,9 @@ int kvm_arch_pre_create_vcpu(CPUState *cpu, Error **errp)int ret;if (first) { +X86CPU *x86cpu =X86_CPU (cpu); +CPUX86State *env = &x86cpu->env; + first = false;/*
@@ -2085,6 +2088,17 @@ int kvm_arch_pre_create_vcpu(CPUState *cpu, Error **errp)return ret; } } + +if (!is_tdx_vm () && env->tsc_khz && +kvm_check_extension (kvm_state,KVM_CAP_VM_TSC_CONTROL )) { + ret =kvm_vm_ioctl (kvm_state,KVM_SET_TSC_KHZ , env->tsc_khz); +if (ret <0 ) { +error_setg_errno (errp, -ret, +"Unable to set TSC frequency to %" PRId64" kHz" , + env->tsc_khz); +return ret; + } + } }if (is_tdx_vm ()) {
Signature · 1 line
2.56.0
[PULL 03/15] target/i386/tcg: fix SETCC(zu) optimization
In reply to Paolo BonziniWith EVEX.ND=1, SETcc zero extends its result to the whole register, which validate_evex_apx() requests with EXT_Unsigned. QEMU is trying to avoid the extension by changing the size of the operand, but it sets a field of the row that is unused, because op1 is None.
Do it in gen_SETcc() instead. The result of setcc is 0 or 1, so writing the whole register has the same effect as the zero extension, and gen_writeback() skips the extension.
--- target/i386/tcg/decode-new.c.inc | 3 --- target/i386/tcg/emit.c.inc | 8 ++++++++ 2 files changed, 8 insertions(+), 3 deletions(-)
target/i386/tcg/decode-new.c.inc +0 -3
@@ -2109,9 +2109,6 @@ static void decode_EVEX4cc(DisasContext *s, CPUX86State *env, X86OpEntry *entry, if (s->prefix & PREFIX_REPNZ) { *entry = setcc; - if (EVEX_APX_ND(s)) { - entry->s1 = X86_SIZE_q; /* optimization for zu */ - } } else { *entry = (EVEX_APX_ND(s) ? cfcmov_nd1 : cfcmov_nd0)[EVEX_APX_NF(s)][mod == 3]; }
target/i386/tcg/emit.c.inc +8 -0
@@ -4136,6 +4136,14 @@ static void gen_SCAS(DisasContext *s, X86DecodedInsn *decode) static void gen_SETcc(DisasContext *s, X86DecodedInsn *decode) { gen_setcc(s, decode->b & 0xf, s->T0); + + /* + * With APX ZU, the written value requests zero extension. Since T0 is + * 0 or 1, writing the whole register is the same and saves the extension. + */ + if (decode->op[0].ext == X86_EXT_Unsigned && !decode->op[0].has_ea) { + decode->op[0].ot = MO_TL; + } } static void gen_SFENCE(DisasContext *s, X86DecodedInsn *decode)
Signature · 1 line
2.56.0
[PULL 11/15] target/i386/tcg: all scalar instructions should be LIG
In reply to Paolo BonziniAdd the vex_lig modifier to other scalar instructions, both defined via REPScalar and those listed as separate rows. The current edition of the manual lists them this way, but QEMU was either ignoring VEX.L but not resetting it, or raising #UD on VEX.L=1.
--- target/i386/tcg/decode-new.c.inc | 48 +++++++++++++++----------------- 1 file changed, 23 insertions(+), 25 deletions(-)
target/i386/tcg/decode-new.c.inc +23 -25
@@ -834,31 +834,31 @@ static const X86OpEntry opcodes_0F38_00toEF[240] = { /* Should be exception type 2 or 3 but they do not have legacy SSE equivalents? */ [0x98] = X86_OP_ENTRY3(VFMADD132Px, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), - [0x99] = X86_OP_ENTRY3(VFMADD132Sx, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), + [0x99] = X86_OP_ENTRY3(VFMADD132Sx, V,x, H,x, W,x, vex6 vex_lig cpuid(FMA) p_66), [0x9a] = X86_OP_ENTRY3(VFMSUB132Px, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), - [0x9b] = X86_OP_ENTRY3(VFMSUB132Sx, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), + [0x9b] = X86_OP_ENTRY3(VFMSUB132Sx, V,x, H,x, W,x, vex6 vex_lig cpuid(FMA) p_66), [0x9c] = X86_OP_ENTRY3(VFNMADD132Px, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), - [0x9d] = X86_OP_ENTRY3(VFNMADD132Sx, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), + [0x9d] = X86_OP_ENTRY3(VFNMADD132Sx, V,x, H,x, W,x, vex6 vex_lig cpuid(FMA) p_66), [0x9e] = X86_OP_ENTRY3(VFNMSUB132Px, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), - [0x9f] = X86_OP_ENTRY3(VFNMSUB132Sx, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), + [0x9f] = X86_OP_ENTRY3(VFNMSUB132Sx, V,x, H,x, W,x, vex6 vex_lig cpuid(FMA) p_66), [0xa8] = X86_OP_ENTRY3(VFMADD213Px, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), - [0xa9] = X86_OP_ENTRY3(VFMADD213Sx, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), + [0xa9] = X86_OP_ENTRY3(VFMADD213Sx, V,x, H,x, W,x, vex6 vex_lig cpuid(FMA) p_66), [0xaa] = X86_OP_ENTRY3(VFMSUB213Px, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), - [0xab] = X86_OP_ENTRY3(VFMSUB213Sx, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), + [0xab] = X86_OP_ENTRY3(VFMSUB213Sx, V,x, H,x, W,x, vex6 vex_lig cpuid(FMA) p_66), [0xac] = X86_OP_ENTRY3(VFNMADD213Px, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), - [0xad] = X86_OP_ENTRY3(VFNMADD213Sx, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), + [0xad] = X86_OP_ENTRY3(VFNMADD213Sx, V,x, H,x, W,x, vex6 vex_lig cpuid(FMA) p_66), [0xae] = X86_OP_ENTRY3(VFNMSUB213Px, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), - [0xaf] = X86_OP_ENTRY3(VFNMSUB213Sx, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), + [0xaf] = X86_OP_ENTRY3(VFNMSUB213Sx, V,x, H,x, W,x, vex6 vex_lig cpuid(FMA) p_66), [0xb8] = X86_OP_ENTRY3(VFMADD231Px, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), - [0xb9] = X86_OP_ENTRY3(VFMADD231Sx, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), + [0xb9] = X86_OP_ENTRY3(VFMADD231Sx, V,x, H,x, W,x, vex6 vex_lig cpuid(FMA) p_66), [0xba] = X86_OP_ENTRY3(VFMSUB231Px, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), - [0xbb] = X86_OP_ENTRY3(VFMSUB231Sx, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), + [0xbb] = X86_OP_ENTRY3(VFMSUB231Sx, V,x, H,x, W,x, vex6 vex_lig cpuid(FMA) p_66), [0xbc] = X86_OP_ENTRY3(VFNMADD231Px, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), - [0xbd] = X86_OP_ENTRY3(VFNMADD231Sx, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), + [0xbd] = X86_OP_ENTRY3(VFNMADD231Sx, V,x, H,x, W,x, vex6 vex_lig cpuid(FMA) p_66), [0xbe] = X86_OP_ENTRY3(VFNMSUB231Px, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), - [0xbf] = X86_OP_ENTRY3(VFNMSUB231Sx, V,x, H,x, W,x, vex6 cpuid(FMA) p_66), + [0xbf] = X86_OP_ENTRY3(VFNMSUB231Sx, V,x, H,x, W,x, vex6 vex_lig cpuid(FMA) p_66), [0xc8] = X86_OP_ENTRY2(SHA1NEXTE, V,dq, W,dq, cpuid(SHA_NI)), [0xc9] = X86_OP_ENTRY2(SHA1MSG1, V,dq, W,dq, cpuid(SHA_NI)),
@@ -1064,7 +1064,7 @@ static void decode_0F10(DisasContext *s, CPUX86State *env, X86OpEntry *entry, ui static const X86OpEntry opcodes_0F10_reg[4] = { X86_OP_ENTRY3(MOVDQ, V,x, None,None, W,x, vex4_unal), /* MOVUPS */ X86_OP_ENTRY3(MOVDQ, V,x, None,None, W,x, vex4_unal), /* MOVUPD */ - X86_OP_ENTRY3(VMOVSS, V,x, H,x, W,x, vex5), + X86_OP_ENTRY3(VMOVSS, V,x, H,x, W,x, vex5 vex_lig), X86_OP_ENTRY3(VMOVLPx, V,x, H,x, W,x, vex5), /* MOVSD */ };
@@ -1087,7 +1087,7 @@ static void decode_0F11(DisasContext *s, CPUX86State *env, X86OpEntry *entry, ui static const X86OpEntry opcodes_0F11_reg[4] = { X86_OP_ENTRY3(MOVDQ, W,x, None,None, V,x, vex4_unal), /* MOVUPS */ X86_OP_ENTRY3(MOVDQ, W,x, None,None, V,x, vex4_unal), /* MOVUPD */ - X86_OP_ENTRY3(VMOVSS, W,x, H,x, V,x, vex5), + X86_OP_ENTRY3(VMOVSS, W,x, H,x, V,x, vex5 vex_lig), X86_OP_ENTRY3(VMOVLPx, W,x, H,x, V,q, vex5), /* MOVSD */ };
@@ -1166,8 +1166,8 @@ static void decode_0F2A(DisasContext *s, CPUX86State *env, X86OpEntry *entry, ui static const X86OpEntry opcodes_0F2A[4] = { X86_OP_ENTRY3(CVTPI2Px, V,x, None,None, Q,q), X86_OP_ENTRY3(CVTPI2Px, V,x, None,None, Q,q), - X86_OP_ENTRY3(VCVTSI2Sx, V,x, H,x, E,y, vex3), - X86_OP_ENTRY3(VCVTSI2Sx, V,x, H,x, E,y, vex3), + X86_OP_ENTRY3(VCVTSI2Sx, V,x, H,x, E,y, vex3 vex_lig), + X86_OP_ENTRY3(VCVTSI2Sx, V,x, H,x, E,y, vex3 vex_lig), }; *entry = *decode_by_prefix(s, opcodes_0F2A); }
@@ -1191,8 +1191,8 @@ static void decode_0F2C(DisasContext *s, CPUX86State *env, X86OpEntry *entry, ui /* Listed as ps/pd in the manual, but CVTTPS2PI only reads 64-bit. */ X86_OP_ENTRY3(CVTTPx2PI, P,q, None,None, W,q), X86_OP_ENTRY3(CVTTPx2PI, P,q, None,None, W,dq), - X86_OP_ENTRY3(VCVTTSx2SI, G,y, None,None, W,ss, vex3), - X86_OP_ENTRY3(VCVTTSx2SI, G,y, None,None, W,sd, vex3), + X86_OP_ENTRY3(VCVTTSx2SI, G,y, None,None, W,ss, vex3 vex_lig), + X86_OP_ENTRY3(VCVTTSx2SI, G,y, None,None, W,sd, vex3 vex_lig), }; *entry = *decode_by_prefix(s, opcodes_0F2C); }
@@ -1203,8 +1203,8 @@ static void decode_0F2D(DisasContext *s, CPUX86State *env, X86OpEntry *entry, ui /* Listed as ps/pd in the manual, but CVTPS2PI only reads 64-bit. */ X86_OP_ENTRY3(CVTPx2PI, P,q, None,None, W,q), X86_OP_ENTRY3(CVTPx2PI, P,q, None,None, W,dq), - X86_OP_ENTRY3(VCVTSx2SI, G,y, None,None, W,ss, vex3), - X86_OP_ENTRY3(VCVTSx2SI, G,y, None,None, W,sd, vex3), + X86_OP_ENTRY3(VCVTSx2SI, G,y, None,None, W,ss, vex3 vex_lig), + X86_OP_ENTRY3(VCVTSx2SI, G,y, None,None, W,sd, vex3 vex_lig), }; *entry = *decode_by_prefix(s, opcodes_0F2D); }
@@ -1452,8 +1452,8 @@ static const X86OpEntry opcodes_0F[256] = { [0x2B] = X86_OP_GROUP0(0F2B), [0x2C] = X86_OP_GROUP0(0F2C), [0x2D] = X86_OP_GROUP0(0F2D), - [0x2E] = X86_OP_GROUP3(VxCOMISx, None,None, V,x, W,x, vex3 p_00_66), /* VUCOMISS/SD */ - [0x2F] = X86_OP_GROUP3(VxCOMISx, None,None, V,x, W,x, vex3 p_00_66), /* VCOMISS/SD */ + [0x2E] = X86_OP_GROUP3(VxCOMISx, None,None, V,x, W,x, vex3 vex_lig p_00_66), /* VUCOMISS/SD */ + [0x2F] = X86_OP_GROUP3(VxCOMISx, None,None, V,x, W,x, vex3 vex_lig p_00_66), /* VCOMISS/SD */ [0x38] = X86_OP_GROUP0(0F38), [0x3a] = X86_OP_GROUP0(0F3A),
@@ -3103,9 +3103,7 @@ static bool validate_vex(DisasContext *s, X86DecodedInsn *decode) assert(e->vex_class == 1 || e->vex_class == 2 || e->vex_class == 4); if (s->prefix & (PREFIX_REPZ | PREFIX_REPNZ)) { e->vex_class = e->vex_class < 4 ? 3 : 5; - if (s->vex_l) { - goto illegal; - } + s->vex_l = 0; assert(e->op2 == X86_TYPE_W && e->s2 == X86_SIZE_x); if ((s->modrm >> 6) != 3) { e->s2 = s->prefix & PREFIX_REPNZ ? X86_SIZE_sd : X86_SIZE_ss;
Signature · 1 line
2.56.0
[PULL 06/15] target/i386/tcg: fix lea address calculation for CS register
In reply to Paolo BonziniFrom: Mark Cave-Ayland <[email protected]>
When the effective address calculation was simplified in commit 55a15eb3504 ("target/i386/tcg: simplify effective address calculation") the refactoring accidentally introduced the ADDSEG() macro into the CS base address inclusion test.
Fix the logic in gen_lea_v_seg_dest() to use CODE64() instead of ADDSEG() for the CS base address inclusion test, and at the same time split it into a switch statement to make the logic easier to follow.
--- target/i386/tcg/translate.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
target/i386/tcg/translate.c +19 -1
@@ -625,7 +625,25 @@ static void gen_lea_v_seg_dest(DisasContext *s, MemOp aflag, TCGv dest, TCGv a0, ovr_seg = def_seg; } - has_base = ovr_seg >=R_FS || (ovr_seg >=0 &&ADDSEG (s)); +switch (ovr_seg) { +case R_DS : +case R_ES : +case R_SS : + has_base =ADDSEG (s); +break ; +case R_CS : + has_base = !CODE64 (s); +break ; +case R_FS : +case R_GS : + has_base = true; +break ; +default : +assert (ovr_seg <0 ); + has_base = false; +break ; + } + easize =CODE64 (s) ?MO_64 :MO_32 ;if (has_base) {
Signature · 1 line
2.56.0
[PULL 07/15] tests/tcg: fix load/restore for test-avx and test-mmx
In reply to Paolo BonziniIf "r"(&result) uses %rsp, which GCC16 seems eager to do, the comparison fails because run_test()'s assembly block moves %rsp below the red zone. Use fixed registers instead.
--- tests/tcg/i386/test-avx.c | 22 ++++++++++++---------- tests/tcg/i386/test-mmx.c | 22 ++++++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-)
tests/tcg/i386/test-avx.c +12 -10
@@ -150,9 +150,10 @@ static void run_test(const TestDef *t)"push rbx\n\t" "push rcx\n\t" "push rdx\n\t" -"push %1\n\t" -"push %2\n\t" -"mov rax, %0\n\t" +"push rsi\n\t" +"push rdi\n\t" +"push rsi\n\t" // result +"push rdi\n\t" // fn "pushf\n\t" "pop rbx\n\t" "shr rbx, 8\n\t"
@@ -165,19 +166,21 @@ static void run_test(const TestDef *t) REG(LOADREG)"mov rax, 0x240[rax]\n\t" "call [rsp]\n\t" -"mov [rsp], rax\n\t" -"mov rax, 8[rsp]\n\t" +"mov [rsp], rax\n\t" // save rax +"mov rax, 8[rsp]\n\t" // get back result REG(STOREREG)"mov rbx, [rsp]\n\t" -"mov 0x240[rax], rbx\n\t" +"mov 0x240[rax], rbx\n\t" // rax "mov rbx, 0\n\t" -"mov 0x270[rax], rbx\n\t" -"mov 0x278[rax], rbx\n\t" +"mov 0x270[rax], rbx\n\t" // rsp +"mov 0x278[rax], rbx\n\t" // rbp "pushf\n\t" "pop rbx\n\t" "and rbx, 0xff\n\t" "mov 0x2c0[rax], rbx\n\t" "add rsp, 16\n\t" +"pop rdi\n\t" +"pop rsi\n\t" "pop rdx\n\t" "pop rcx\n\t" "pop rbx\n\t"
@@ -185,9 +188,8 @@ static void run_test(const TestDef *t)"add rsp, 128\n\t" MMREG(STOREMM) YMMREG(STOREYMM) - : : "r"(init), "r"(&result), "r"(t->fn) + : : "a"(init), "S"(&result), "D"(t->fn) : "memory", "cc", -"rsi" ,"rdi" ,"r8" ,"r9" ,"r10" ,"r11" ,"r12" ,"r13" ,"r14" ,"r15" ,"mm0" ,"mm1" ,"mm2" ,"mm3" ,"mm4" ,"mm5" ,"mm6" ,"mm7" , "ymm0", "ymm1", "ymm2", "ymm3", "ymm4", "ymm5",
tests/tcg/i386/test-mmx.c +12 -10
@@ -154,9 +154,10 @@ static void run_test(const TestDef *t)"push rbx\n\t" "push rcx\n\t" "push rdx\n\t" -"push %1\n\t" -"push %2\n\t" -"mov rax, %0\n\t" +"push rsi\n\t" +"push rdi\n\t" +"push rsi\n\t" // result +"push rdi\n\t" // fn "pushf\n\t" "pop rbx\n\t" "shr rbx, 8\n\t"
@@ -169,19 +170,21 @@ static void run_test(const TestDef *t) REG(LOADREG)"mov rax, 0xc0[rax]\n\t" "call [rsp]\n\t" -"mov [rsp], rax\n\t" -"mov rax, 8[rsp]\n\t" +"mov [rsp], rax\n\t" // save rax +"mov rax, 8[rsp]\n\t" // get back result REG(STOREREG)"mov rbx, [rsp]\n\t" -"mov 0xc0[rax], rbx\n\t" +"mov 0xc0[rax], rbx\n\t" // rax "mov rbx, 0\n\t" -"mov 0xf0[rax], rbx\n\t" -"mov 0xf8[rax], rbx\n\t" +"mov 0xf0[rax], rbx\n\t" // rsp +"mov 0xf8[rax], rbx\n\t" // rbp "pushf\n\t" "pop rbx\n\t" "and rbx, 0xff\n\t" "mov 0x140[rax], rbx\n\t" "add rsp, 16\n\t" +"pop rdi\n\t" +"pop rsi\n\t" "pop rdx\n\t" "pop rcx\n\t" "pop rbx\n\t"
@@ -190,9 +193,8 @@ static void run_test(const TestDef *t)MMREG (STOREMM) EMMS "\n\t" XMMREG(STOREXMM) - : : "r"(init), "r"(&result), "r"(t->fn) + : : "a"(init), "S"(&result), "D"(t->fn) : "memory", "cc", -"rsi" ,"rdi" ,"r8" ,"r9" ,"r10" ,"r11" ,"r12" ,"r13" ,"r14" ,"r15" ,"mm0" ,"mm1" ,"mm2" ,"mm3" ,"mm4" ,"mm5" ,"mm6" ,"mm7" , "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5",
Signature · 1 line
2.56.0