Skip to content

Commit 9bf5da1

Browse files
committed
KVM: selftests: Add coverage for 'b' (byte) sized fastops emulation
Extend the fastops test to cover instructions that operate on 8-bit data. Support for 8-bit instructions was omitted from the original commit purely due to complications with BT not having a r/m8 variant. To keep the RFLAGS.CF behavior deterministic and not heavily biased to '0' or '1', continue using BT, but cast and load the to-be-tested value into a dedicated 32-bit constraint. Supporting 8-bit operations will allow using guest_test_fastops() as-is to provide full coverage for DIV and IDIV. For divide operations, covering all operand sizes _is_ interesting, because KVM needs provide exception fixup for each size (failure to handle a #DE could panic the host). Link: https://lore.kernel.org/all/[email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 7b39b6c commit 9bf5da1

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

tools/testing/selftests/kvm/x86/fastops_test.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
*/
1111
#define guest_execute_fastop_1(FEP, insn, __val, __flags) \
1212
({ \
13-
__asm__ __volatile__("bt $0, %[val]\n\t" \
13+
__asm__ __volatile__("bt $0, %[ro_val]\n\t" \
1414
FEP insn " %[val]\n\t" \
1515
"pushfq\n\t" \
1616
"pop %[flags]\n\t" \
1717
: [val]"+r"(__val), [flags]"=r"(__flags) \
18-
: : "cc", "memory"); \
18+
: [ro_val]"rm"((uint32_t)__val) \
19+
: "cc", "memory"); \
1920
})
2021

2122
#define guest_test_fastop_1(insn, type_t, __val) \
@@ -36,12 +37,13 @@
3637

3738
#define guest_execute_fastop_2(FEP, insn, __input, __output, __flags) \
3839
({ \
39-
__asm__ __volatile__("bt $0, %[output]\n\t" \
40+
__asm__ __volatile__("bt $0, %[ro_val]\n\t" \
4041
FEP insn " %[input], %[output]\n\t" \
4142
"pushfq\n\t" \
4243
"pop %[flags]\n\t" \
4344
: [output]"+r"(__output), [flags]"=r"(__flags) \
44-
: [input]"r"(__input) : "cc", "memory"); \
45+
: [input]"r"(__input), [ro_val]"rm"((uint32_t)__output) \
46+
: "cc", "memory"); \
4547
})
4648

4749
#define guest_test_fastop_2(insn, type_t, __val1, __val2) \
@@ -63,12 +65,13 @@
6365

6466
#define guest_execute_fastop_cl(FEP, insn, __shift, __output, __flags) \
6567
({ \
66-
__asm__ __volatile__("bt $0, %[output]\n\t" \
68+
__asm__ __volatile__("bt $0, %[ro_val]\n\t" \
6769
FEP insn " %%cl, %[output]\n\t" \
6870
"pushfq\n\t" \
6971
"pop %[flags]\n\t" \
7072
: [output]"+r"(__output), [flags]"=r"(__flags) \
71-
: "c"(__shift) : "cc", "memory"); \
73+
: "c"(__shift), [ro_val]"rm"((uint32_t)__output) \
74+
: "cc", "memory"); \
7275
})
7376

7477
#define guest_test_fastop_cl(insn, type_t, __val1, __val2) \
@@ -115,14 +118,16 @@ do { \
115118
guest_test_fastop_2("add" suffix, type_t, vals[i], vals[j]); \
116119
guest_test_fastop_2("adc" suffix, type_t, vals[i], vals[j]); \
117120
guest_test_fastop_2("and" suffix, type_t, vals[i], vals[j]); \
121+
if (sizeof(type_t) != 1) { \
118122
guest_test_fastop_2("bsf" suffix, type_t, vals[i], vals[j]); \
119123
guest_test_fastop_2("bsr" suffix, type_t, vals[i], vals[j]); \
120124
guest_test_fastop_2("bt" suffix, type_t, vals[i], vals[j]); \
121125
guest_test_fastop_2("btc" suffix, type_t, vals[i], vals[j]); \
122126
guest_test_fastop_2("btr" suffix, type_t, vals[i], vals[j]); \
123127
guest_test_fastop_2("bts" suffix, type_t, vals[i], vals[j]); \
124-
guest_test_fastop_2("cmp" suffix, type_t, vals[i], vals[j]); \
125128
guest_test_fastop_2("imul" suffix, type_t, vals[i], vals[j]); \
129+
} \
130+
guest_test_fastop_2("cmp" suffix, type_t, vals[i], vals[j]); \
126131
guest_test_fastop_2("or" suffix, type_t, vals[i], vals[j]); \
127132
guest_test_fastop_2("sbb" suffix, type_t, vals[i], vals[j]); \
128133
guest_test_fastop_2("sub" suffix, type_t, vals[i], vals[j]); \
@@ -142,6 +147,7 @@ do { \
142147

143148
static void guest_code(void)
144149
{
150+
guest_test_fastops(uint8_t, "b");
145151
guest_test_fastops(uint16_t, "w");
146152
guest_test_fastops(uint32_t, "l");
147153
guest_test_fastops(uint64_t, "q");

0 commit comments

Comments
 (0)