Fixes for clang builds
Subsystems (2)
cover Fixes for clang builds
From: Bill Wendling <[email protected]>
This is a series of patches which allow clang to build the kvm-unit-tests.
Bill Wendling (7):
x86: emulator: use "SSE2" for the target
pci: use uint32_t for unsigned long values
x86: realmode: syscall: add explicit size suffix to ambiguous
instructions
svm: change operand to output-only for matching constraint
svm: convert neg shift to unsigned shift
x86: VMX: use inline asm to get stack pointer
x86: VMX: the "noclone" attribute is gcc-specific
lib/linux/pci_regs.h | 4 ++-- x86/emulator.c | 2 +- x86/realmode.c | 6 +++--- x86/svm.c | 6 +++--- x86/syscall.c | 2 +- x86/vmx_tests.c | 11 ++++++++--- 6 files changed, 18 insertions(+), 13 deletions(-)
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 1/7 x86: emulator: use "SSE2" for the target
From: Bill Wendling <[email protected]>
The movdqu and movapd instructions are SSE2 instructions. Clang interprets the __attribute__((target("sse"))) as allowing SSE only instructions. Using SSE2 instructions cause an error.
--- x86/emulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
x86/emulator.c +1 -1
@@ -658,7 +658,7 @@ static bool sseeq(sse_union *v1, sse_union *v2)return ok; } -static __attribute__((target ("sse" )))void test_sse (sse_union *mem) +static __attribute__((target ("sse2" )))void test_sse (sse_union *mem) {sse_union v;
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 2/7 pci: use uint32_t for unsigned long values
In reply to [email protected]From: Bill Wendling <[email protected]>
The "pci_bar_*" functions use 64-bit masks, but the results are assigned to 32-bit variables. Use 32-bit masks, since we're interested only in the least significant 4-bits.
--- lib/linux/pci_regs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/linux/pci_regs.h +2 -2
@@ -96,8 +96,8 @@#define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02/* Below 1M [obsolete] */ #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04/* 64 bit address */ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08/* prefetchable? */ -#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL) -#define PCI_BASE_ADDRESS_IO_MASK (~0x03UL) +#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fU) +#define PCI_BASE_ADDRESS_IO_MASK (~0x03U)/* bit 1 is reserved if address_space = 1 */ /* Header type 0 (normal devices) */
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
Re: [kvm-unit-tests PATCH 2/7] pci: use uint32_t for unsigned long values
Quoted 29 lines · On Tue, Feb 25, 2020 at 11:44:22PM -0800, [email protected] wrote:
From: Bill Wendling <[email protected]>
The "pci_bar_*" functions use 64-bit masks, but the results are assigned to 32-bit variables. Use 32-bit masks, since we're interested only in the least significant 4-bits.
Signed-off-by Bill Wendling <[email protected]>--- lib/linux/pci_regs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/linux/pci_regs.h +2
-2@@ -96,8 +96,8 @@#define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02/* Below 1M [obsolete] */ #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04/* 64 bit address */ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08/* prefetchable? */ -#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL) -#define PCI_BASE_ADDRESS_IO_MASK (~0x03UL) +#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fU) +#define PCI_BASE_ADDRESS_IO_MASK (~0x03U)/* bit 1 is reserved if address_space = 1 */ /* Header type 0 (normal devices) */ Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
This file comes directly from the Linux source. If it's not changed there, then it shouldn't change here.
Thanks,
drew
Re: [kvm-unit-tests PATCH 2/7] pci: use uint32_t for unsigned long values
I suspect then that how it's used in the kvm-unit-tests isn't correct. Or at least it's not how it's used in the Linux source code. Would it be better to cast all uses of these masks to uint32_t?
-bw
Quoted 38 lines · Andrew Jones
Quoted 27 lines · On Tue, Feb 25, 2020 at 11:44:22PM -0800, [email protected] wrote:
From: Bill Wendling <[email protected]>
The "pci_bar_*" functions use 64-bit masks, but the results are assigned to 32-bit variables. Use 32-bit masks, since we're interested only in the least significant 4-bits.
Signed-off-by Bill Wendling <[email protected]>--- lib/linux/pci_regs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/linux/pci_regs.h +2
-3@@ -96,8 +96,8 @@#define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02/* Below 1M [obsolete] */ #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04/* 64 bit address */ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08/* prefetchable? */ -#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL) -#define PCI_BASE_ADDRESS_IO_MASK (~0x03UL) +#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fU) +#define PCI_BASE_ADDRESS_IO_MASK (~0x03U)/* bit 1 is reserved if address_space = 1 */ /* Header type 0 (normal devices) */ --Quoted 2 lines
2.25.0.265.gbab2e86ba0-goog
This file comes directly from the Linux source. If it's not changed there, then it shouldn't change here.
Thanks,
drew
Re: [kvm-unit-tests PATCH 2/7] pci: use uint32_t for unsigned long values
Quoted 3 lines · Bill Wendling
I suspect then that how it's used in the kvm-unit-tests isn't correct. Or at least it's not how it's used in the Linux source code. Would it be better to cast all uses of these masks to
uint32_t?
Yup. If clang is upset about kvm-unit-test's use of these masks, then we need to change how they're used, as we can't change how they're defined.
There's only one occurrence of each though, and in the same function, pci_bar_mask(). I'd probably just change the return type of that function to uint64_t, rather than add casts.
Thanks,
drew
Quoted 44 lines
-bw
Quoted 38 lines · Andrew Jones
Quoted 27 lines · On Tue, Feb 25, 2020 at 11:44:22PM -0800, [email protected] wrote:
From: Bill Wendling <[email protected]>
The "pci_bar_*" functions use 64-bit masks, but the results are assigned to 32-bit variables. Use 32-bit masks, since we're interested only in the least significant 4-bits.
Signed-off-by Bill Wendling <[email protected]>--- lib/linux/pci_regs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/linux/pci_regs.h +2
-3@@ -96,8 +96,8 @@#define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02/* Below 1M [obsolete] */ #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04/* 64 bit address */ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08/* prefetchable? */ -#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL) -#define PCI_BASE_ADDRESS_IO_MASK (~0x03UL) +#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fU) +#define PCI_BASE_ADDRESS_IO_MASK (~0x03U)/* bit 1 is reserved if address_space = 1 */ /* Header type 0 (normal devices) */ --Quoted 2 lines
2.25.0.265.gbab2e86ba0-goog
This file comes directly from the Linux source. If it's not changed there, then it shouldn't change here.
Thanks,
drew
PATCH 3/7 x86: realmode: syscall: add explicit size suffix to ambiguous instructions
In reply to [email protected]From: Bill Wendling <[email protected]>
Clang requires explicit size suffixes for potentially ambiguous instructions:
x86/realmode.c:1647:2: error: ambiguous instructions require an explicit suffix (could be 'cmpb', 'cmpw', or 'cmpl')
MK_INSN_PERF(perf_memory_load, "cmp $0, (%edi)");
^
x86/realmode.c:1591:10: note: expanded from macro 'MK_INSN_PERF'
"1:" insn "\n" \
^<inline asm>:8:3: note: instantiated into assembly here 1:cmp $0, (%edi)
^
The 'w' and 'l' suffixes generate code that's identical to the gcc version without them.
--- x86/realmode.c | 6 +++--- x86/syscall.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
x86/realmode.c +3 -3
@@ -1644,7 +1644,7 @@ static void test_perf_memory_load(void) {u32 cyc, tmp; -MK_INSN_PERF (perf_memory_load,"cmp $0, (%edi)" ); +MK_INSN_PERF (perf_memory_load,"cmpw $0, (%edi)" );init_inregs (&(struct regs ){ .edi = (u32)&tmp });
@@ -1657,7 +1657,7 @@ static void test_perf_memory_store(void) {u32 cyc, tmp; -MK_INSN_PERF (perf_memory_store,"mov %ax, (%edi)" ); +MK_INSN_PERF (perf_memory_store,"movw %ax, (%edi)" );init_inregs (&(struct regs ){ .edi = (u32)&tmp });
@@ -1670,7 +1670,7 @@ static void test_perf_memory_rmw(void) {u32 cyc, tmp; -MK_INSN_PERF (perf_memory_rmw,"add $1, (%edi)" ); +MK_INSN_PERF (perf_memory_rmw,"addw $1, (%edi)" );init_inregs (&(struct regs ){ .edi = (u32)&tmp });
x86/syscall.c +1 -1
@@ -38,7 +38,7 @@ static void handle_db(struct ex_regs *regs)/* expects desired ring 3 flags in rax */ asm("syscall32_target:\n" -" cmp $0, code_segment_upon_db(%rip)\n" +" cmpl $0, code_segment_upon_db(%rip)\n" " jne back_to_test\n" " mov %eax,%r11d\n" " sysretl\n" );
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 4/7 svm: change operand to output-only for matching constraint
In reply to [email protected]From: Bill Wendling <[email protected]>
According to GNU extended asm documentation, "the two operands [of matching constraints] must include one input-only operand and one output-only operand." So remove the read/write modifier from the output constraint.
--- x86/svm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
x86/svm.c +2 -2
@@ -288,8 +288,8 @@ static void test_run(struct test *test, struct vmcb *vmcb) "cli \n\t" "stgi" : // inputs clobbered by the guest: - "+D" (the_test), // first argument register - "+b" (the_vmcb) // callee save register! + "=D" (the_test), // first argument register +"=b" (the_vmcb)// callee save register! : [test] "0" (the_test), [vmcb_phys] "1"(the_vmcb), [PREPARE_GIF_CLEAR] "i" (offsetof(struct test, prepare_gif_clear))
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 5/7 svm: convert neg shift to unsigned shift
In reply to [email protected]From: Bill Wendling <[email protected]>
Shifting a negative signed value is undefined. Use a shift of an unsigned value instead.
--- x86/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
x86/svm.c +1 -1
@@ -1148,7 +1148,7 @@ static bool npt_rw_l1mmio_check(struct test *test) }#define TSC_ADJUST_VALUE (1ll << 32) -#define TSC_OFFSET_VALUE (-1ll << 48) +#define TSC_OFFSET_VALUE (~0ull << 48)static bool ok;static void tsc_adjust_prepare (struct test *test)
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 6/7 x86: VMX: use inline asm to get stack pointer
In reply to [email protected]From: Bill Wendling <[email protected]>
The only supported use of a local register variable is to specify registers for input and output operands when calling Extended asm. Using it to automatically collect the value in the register isn't supported as the contents of the register aren't guaranteed. Instead use inline asm to get the stack pointer explicitly.
--- x86/vmx_tests.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
x86/vmx_tests.c +4 -2
@@ -2165,8 +2165,9 @@ static void into_guest_main(void) .offset = (uintptr_t)&&into, .selector = KERNEL_CS32, }; - registeruintptr_t rsp asm("rsp" ); +uintptr_t rsp =0 ; + asmvolatile ("mov %%rsp, %0" :"=r" (rsp));if (fp.offset != (uintptr_t )&&into) {printf ("Code address too high.\n" );return ;
@@ -3261,8 +3262,9 @@ static void try_compat_invvpid(void *unused) .offset = (uintptr_t)&&invvpid, .selector = KERNEL_CS32, }; - registeruintptr_t rsp asm("rsp" ); + registeruintptr_t rsp =0 ; + asmvolatile ("mov %%rsp, %0" :"=r" (rsp));TEST_ASSERT_MSG (fp.offset == (uintptr_t )&&invvpid,"Code address too high." );TEST_ASSERT_MSG (rsp == (u32 )rsp,"Stack address too high." );
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 7/7 x86: VMX: the "noclone" attribute is gcc-specific
In reply to [email protected]From: Bill Wendling <[email protected]>
Don't use the "noclone" attribute for clang as it's not supported.
--- x86/vmx_tests.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
x86/vmx_tests.c +4 -1
@@ -4976,7 +4976,10 @@ extern unsigned char test_mtf1;extern unsigned char test_mtf2;extern unsigned char test_mtf3; -__attribute__((noclone))static void test_mtf_guest (void ) +#ifndef __clang__ +__attribute__((noclone)) +#endif +static void test_mtf_guest (void ) { asm ("vmcall;\n\t" "out %al, $0x80;\n\t"
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
Re: [kvm-unit-tests PATCH 7/7] x86: VMX: the "noclone" attribute is gcc-specific
Quoted 6 lines · On Tue, Feb 25, 2020 at 11:45 PM <[email protected]> wrote:
From: Bill Wendling <[email protected]>
Don't use the "noclone" attribute for clang as it's not supported.
Signed-off-by Bill Wendling <[email protected]>
Quoted 23 lines
--- x86/vmx_tests.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)x86/vmx_tests.c +4
-2@@ -4976,7 +4976,10 @@ extern unsigned char test_mtf1;extern unsigned char test_mtf2;extern unsigned char test_mtf3; -__attribute__((noclone))static void test_mtf_guest (void ) +#ifndef __clang__ +__attribute__((noclone)) +#endif +static void test_mtf_guest (void ) { asm ("vmcall;\n\t" "out %al, $0x80;\n\t" --2.25.0.265.gbab2e86ba0-goog
Re: [kvm-unit-tests PATCH 7/7] x86: VMX: the "noclone" attribute is gcc-specific
Blech...
Quoted 9 lines · Oliver Upton
Quoted 6 lines · On Tue, Feb 25, 2020 at 11:45 PM <[email protected]> wrote:
From: Bill Wendling <[email protected]>
Don't use the "noclone" attribute for clang as it's not supported.
Signed-off-by Bill Wendling <[email protected]>Signed-off-by Oliver Upton <[email protected]>
s/Signed-off-by/Reviewed-by/
Quoted 23 lines
Quoted 23 lines
--- x86/vmx_tests.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)x86/vmx_tests.c +4
-2@@ -4976,7 +4976,10 @@ extern unsigned char test_mtf1;extern unsigned char test_mtf2;extern unsigned char test_mtf3; -__attribute__((noclone))static void test_mtf_guest (void ) +#ifndef __clang__ +__attribute__((noclone)) +#endif +static void test_mtf_guest (void ) { asm ("vmcall;\n\t" "out %al, $0x80;\n\t" --2.25.0.265.gbab2e86ba0-goog
v2 cover Fixes for clang builds
In reply to [email protected]Changes to "pci: cast masks to uint32_t for unsigned long values" to cast the masks instead of changing the values in the header.
Bill Wendling (2):
x86: emulator: use "SSE2" for the target
pci: cast masks to uint32_t for unsigned long values
Eric Hankland (2):
x86: pmu: Test WRMSR on a running counter
x86: pmu: Test perfctr overflow after WRMSR on a running counter
Oliver Upton (1):
x86: VMX: Add tests for monitor trap flag
Paolo Bonzini (2):
x86: provide enabled and disabled variation of the PCID test
vmx: tweak XFAILS for #DB test
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 1/7 x86: emulator: use "SSE2" for the target
The movdqu and movapd instructions are SSE2 instructions. Clang interprets the __attribute__((target("sse"))) as allowing SSE only instructions. Using SSE2 instructions cause an error.
--- x86/emulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
x86/emulator.c +1 -1
@@ -658,7 +658,7 @@ static bool sseeq(sse_union *v1, sse_union *v2)return ok; } -static __attribute__((target ("sse" )))void test_sse (sse_union *mem) +static __attribute__((target ("sse2" )))void test_sse (sse_union *mem) {sse_union v;
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH v2 1/7 x86: pmu: Test WRMSR on a running counter
In reply to Bill WendlingFrom: Eric Hankland <[email protected]>
Ensure that the value of the counter was successfully set to 0 after writing it while the counter was running.
--- x86/pmu.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
x86/pmu.c +16 -0
@@ -420,6 +420,21 @@ static void check_rdpmc(void)report_prefix_pop (); } +static void check_running_counter_wrmsr (void ) +{ +pmu_counter_t evt = { + .ctr =MSR_IA32_PERFCTR0 , + .config =EVNTSEL_OS |EVNTSEL_USR | gp_events[1 ].unit_sel, + .count =0 , + }; + +start_event (&evt); +loop (); +wrmsr (MSR_IA32_PERFCTR0 ,0 ); +stop_event (&evt); +report (evt.count < gp_events[1 ].min,"running counter wrmsr" ); +} +int main (int ac,char **av) {struct cpuid id =cpuid (10 );
@@ -454,6 +469,7 @@ int main(int ac, char **av)check_counters_many ();check_counter_overflow ();check_gp_counter_cmask (); +check_running_counter_wrmsr ();return report_summary (); }
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 2/7 pci: use uint32_t for unsigned long values
In reply to Bill WendlingThe "pci_bar_*" functions use 64-bit masks, but the results are assigned to 32-bit variables. Use 32-bit masks, since we're interested only in the least significant 4-bits.
--- lib/linux/pci_regs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/linux/pci_regs.h +2 -2
@@ -96,8 +96,8 @@#define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02/* Below 1M [obsolete] */ #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04/* 64 bit address */ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08/* prefetchable? */ -#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL) -#define PCI_BASE_ADDRESS_IO_MASK (~0x03UL) +#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fU) +#define PCI_BASE_ADDRESS_IO_MASK (~0x03U)/* bit 1 is reserved if address_space = 1 */ /* Header type 0 (normal devices) */
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
Paolo Bonzini
maintainerRe: [kvm-unit-tests PATCH 2/7] pci: use uint32_t for unsigned long values
Quoted 15 lines · Bill Wendling
The "pci_bar_*" functions use 64-bit masks, but the results are assigned to 32-bit variables. Use 32-bit masks, since we're interested only in the least significant 4-bits.
Signed-off-by Bill Wendling <[email protected]>--- lib/linux/pci_regs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/linux/pci_regs.h +0
-0
lib/linux/pci_regs.h line 103
Quoted 10 lines
lib/linux/pci_regs.h +2
-2@@ -96,8 +96,8 @@#define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02/* Below 1M [obsolete] */ #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04/* 64 bit address */ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08/* prefetchable? */ -#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL) -#define PCI_BASE_ADDRESS_IO_MASK (~0x03UL) +#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fU) +#define PCI_BASE_ADDRESS_IO_MASK (~0x03U)/* bit 1 is reserved if address_space = 1 */ /* Header type 0 (normal devices) */
Removing the "U" is even better because it will then sign-extend automatically.
Paolo
Re: [kvm-unit-tests PATCH 2/7] pci: use uint32_t for unsigned long values
Quoted 24 lines · Paolo Bonzini
Quoted 23 lines · Bill Wendling
The "pci_bar_*" functions use 64-bit masks, but the results are assigned to 32-bit variables. Use 32-bit masks, since we're interested only in the least significant 4-bits.
Signed-off-by Bill Wendling <[email protected]>--- lib/linux/pci_regs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/linux/pci_regs.h +2
-2@@ -96,8 +96,8 @@#define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02/* Below 1M [obsolete] */ #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04/* 64 bit address */ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08/* prefetchable? */ -#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL) -#define PCI_BASE_ADDRESS_IO_MASK (~0x03UL) +#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fU) +#define PCI_BASE_ADDRESS_IO_MASK (~0x03U)/* bit 1 is reserved if address_space = 1 */
Quoted 6 lines
lib/linux/pci_regs.h line 103
Quoted 2 lines
lib/linux/pci_regs.h +0
-0/* Header type 0 (normal devices) */ Removing the "U" is even better because it will then sign-extend automatically.
We don't want this patch at all though. We shouldn't change pci_regs.h since it comes from linux and someday we may update again and lose any changes we make. We should change how these masks are used instead.
Thanks,
drew
Paolo Bonzini
maintainerRe: [kvm-unit-tests PATCH 2/7] pci: use uint32_t for unsigned long values
Quoted 32 lines · Andrew Jones
Quoted 24 lines · Paolo Bonzini
Quoted 23 lines · Bill Wendling
The "pci_bar_*" functions use 64-bit masks, but the results are assigned to 32-bit variables. Use 32-bit masks, since we're interested only in the least significant 4-bits.
Signed-off-by Bill Wendling <[email protected]>--- lib/linux/pci_regs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/linux/pci_regs.h +2
-2@@ -96,8 +96,8 @@#define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02/* Below 1M [obsolete] */ #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04/* 64 bit address */ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08/* prefetchable? */ -#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL) -#define PCI_BASE_ADDRESS_IO_MASK (~0x03UL) +#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fU) +#define PCI_BASE_ADDRESS_IO_MASK (~0x03U)/* bit 1 is reserved if address_space = 1 */ Quoted 6 lines
lib/linux/pci_regs.h line 103
Quoted 2 lines
lib/linux/pci_regs.h +0
-0/* Header type 0 (normal devices) */ Removing the "U" is even better because it will then sign-extend automatically.
Quoted 3 lines
We don't want this patch at all though. We shouldn't change
pci_regs.hsince it comes from linux and someday we may update again and lose any changes we make. We should change how these masks are used instead.
I will try to get the change into Linux.
Paolo
PATCH v2 2/7 x86: provide enabled and disabled variation of the PCID test
In reply to Bill WendlingFrom: Paolo Bonzini <[email protected]>
The PCID test checks for exceptions when PCID=0 or INVPCID=0 in CPUID. Cover that by adding a separate testcase with different CPUID.
--- x86/unittests.cfg | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
x86/unittests.cfg +6 -1
@@ -228,7 +228,12 @@ extra_params = --append "10000000 `date +%s`" [pcid] file = pcid.flat -extra_params = -cpu qemu64,+pcid +extra_params = -cpu qemu64,+pcid,+invpcid +arch = x86_64 + +[pcid-disabled] +file = pcid.flat +extra_params = -cpu qemu64,-pcid,-invpcid arch = x86_64 [rdpru]
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH v2 3/7 x86: pmu: Test perfctr overflow after WRMSR on a running counter
In reply to Bill WendlingFrom: Eric Hankland <[email protected]>
Ensure that a WRMSR on a running counter will correctly update when the counter should overflow (similar to the existing overflow test case but with the counter being written to while it is running).
--- x86/pmu.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
x86/pmu.c +18 -1
@@ -422,17 +422,34 @@ static void check_rdpmc(void)static void check_running_counter_wrmsr (void ) { +uint64_t status;pmu_counter_t evt = { .ctr =MSR_IA32_PERFCTR0 , .config =EVNTSEL_OS |EVNTSEL_USR | gp_events[1 ].unit_sel, .count =0 , }; +report_prefix_push ("running counter wrmsr" ); +start_event (&evt);loop ();wrmsr (MSR_IA32_PERFCTR0 ,0 );stop_event (&evt); -report (evt.count < gp_events[1 ].min,"running counter wrmsr" ); +report (evt.count < gp_events[1 ].min,"cntr" ); + +/* clear status before overflow test */ +wrmsr (MSR_CORE_PERF_GLOBAL_OVF_CTRL , +rdmsr (MSR_CORE_PERF_GLOBAL_STATUS )); + + evt.count =0 ; +start_event (&evt); +wrmsr (MSR_IA32_PERFCTR0 ,-1 ); +loop (); +stop_event (&evt); + status =rdmsr (MSR_CORE_PERF_GLOBAL_STATUS ); +report (status &1 ,"status" ); + +report_prefix_pop (); }int main (int ac,char **av)
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 3/7 x86: realmode: syscall: add explicit size suffix to ambiguous instructions
In reply to Bill WendlingClang requires explicit size suffixes for potentially ambiguous instructions:
x86/realmode.c:1647:2: error: ambiguous instructions require an explicit suffix (could be 'cmpb', 'cmpw', or 'cmpl')
MK_INSN_PERF(perf_memory_load, "cmp $0, (%edi)");
^
x86/realmode.c:1591:10: note: expanded from macro 'MK_INSN_PERF'
"1:" insn "\n" \
^<inline asm>:8:3: note: instantiated into assembly here 1:cmp $0, (%edi)
^
The 'w' and 'l' suffixes generate code that's identical to the gcc version without them.
--- x86/realmode.c | 6 +++--- x86/syscall.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
x86/realmode.c +3 -3
@@ -1644,7 +1644,7 @@ static void test_perf_memory_load(void) {u32 cyc, tmp; -MK_INSN_PERF (perf_memory_load,"cmp $0, (%edi)" ); +MK_INSN_PERF (perf_memory_load,"cmpw $0, (%edi)" );init_inregs (&(struct regs ){ .edi = (u32)&tmp });
@@ -1657,7 +1657,7 @@ static void test_perf_memory_store(void) {u32 cyc, tmp; -MK_INSN_PERF (perf_memory_store,"mov %ax, (%edi)" ); +MK_INSN_PERF (perf_memory_store,"movw %ax, (%edi)" );init_inregs (&(struct regs ){ .edi = (u32)&tmp });
@@ -1670,7 +1670,7 @@ static void test_perf_memory_rmw(void) {u32 cyc, tmp; -MK_INSN_PERF (perf_memory_rmw,"add $1, (%edi)" ); +MK_INSN_PERF (perf_memory_rmw,"addw $1, (%edi)" );init_inregs (&(struct regs ){ .edi = (u32)&tmp });
x86/syscall.c +1 -1
@@ -38,7 +38,7 @@ static void handle_db(struct ex_regs *regs)/* expects desired ring 3 flags in rax */ asm("syscall32_target:\n" -" cmp $0, code_segment_upon_db(%rip)\n" +" cmpl $0, code_segment_upon_db(%rip)\n" " jne back_to_test\n" " mov %eax,%r11d\n" " sysretl\n" );
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 4/7 svm: change operand to output-only for matching constraint
In reply to Bill WendlingAccording to GNU extended asm documentation, "the two operands [of matching constraints] must include one input-only operand and one output-only operand." So remove the read/write modifier from the output constraint.
--- x86/svm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
x86/svm.c +2 -2
@@ -288,8 +288,8 @@ static void test_run(struct test *test, struct vmcb *vmcb) "cli \n\t" "stgi" : // inputs clobbered by the guest: - "+D" (the_test), // first argument register - "+b" (the_vmcb) // callee save register! + "=D" (the_test), // first argument register +"=b" (the_vmcb)// callee save register! : [test] "0" (the_test), [vmcb_phys] "1"(the_vmcb), [PREPARE_GIF_CLEAR] "i" (offsetof(struct test, prepare_gif_clear))
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH v2 4/7 vmx: tweak XFAILS for #DB test
In reply to Bill WendlingFrom: Paolo Bonzini <[email protected]>
These were already fixed by KVM_CAP_EXCEPTION_PAYLOAD, but they were failing on old QEMUs that did not support it. The recent KVM patch "KVM: x86: Deliver exception payload on KVM_GET_VCPU_EVENTS" however fixed them even there, so it is about time to flip the arguments to check_db_exit and avoid ugly XPASS results with newer versions of QEMU.
--- x86/vmx_tests.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
x86/vmx_tests.c +2 -2
@@ -8332,7 +8332,7 @@ static void vmx_db_test(void)* modified DR6, but fails miserably. */ single_step_guest ("Software synthesized single-step" , starting_dr6,0 ); -check_db_exit (true, true, false, &post_wbinvd,DR_STEP , starting_dr6); +check_db_exit (false, false, false, &post_wbinvd,DR_STEP , starting_dr6);/* * L0 synthesized #DB trap for single-step in MOVSS shadow is
@@ -8342,7 +8342,7 @@ static void vmx_db_test(void)*/ single_step_guest ("Software synthesized single-step in MOVSS shadow" , starting_dr6,BIT (12 ) |DR_STEP |DR_TRAP0 ); -check_db_exit (true, true, true, &post_movss_wbinvd,DR_STEP |DR_TRAP0 , +check_db_exit (true, false, true, &post_movss_wbinvd,DR_STEP |DR_TRAP0 , starting_dr6);/*
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 5/7 svm: convert neg shift to unsigned shift
In reply to Bill WendlingShifting a negative signed value is undefined. Use a shift of an unsigned value instead.
--- x86/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
x86/svm.c +1 -1
@@ -1148,7 +1148,7 @@ static bool npt_rw_l1mmio_check(struct test *test) }#define TSC_ADJUST_VALUE (1ll << 32) -#define TSC_OFFSET_VALUE (-1ll << 48) +#define TSC_OFFSET_VALUE (~0ull << 48)static bool ok;static void tsc_adjust_prepare (struct test *test)
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
Paolo Bonzini
maintainerRe: [kvm-unit-tests PATCH 5/7] svm: convert neg shift to unsigned shift
Quoted 4 lines · Bill Wendling
Shifting a negative signed value is undefined. Use a shift of an unsigned value instead.
Signed-off-by Bill Wendling <[email protected]>
In practice only UBSAN complains; GCC even documents that it does not treat it as undefined (which would be insane, especially if the multiplication by 2 does not overflow as in this case):
GCC does not use the latitude given in C99 only to treat certain aspects of signed '<<' as undefined, but this is subject to change.
But in the interest of purity we should instead compile with -fwrapv.
Paolo
Quoted 18 lines
--- x86/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)x86/svm.c +1
-1@@ -1148,7 +1148,7 @@ static bool npt_rw_l1mmio_check(struct test *test) }#define TSC_ADJUST_VALUE (1ll << 32) -#define TSC_OFFSET_VALUE (-1ll << 48) +#define TSC_OFFSET_VALUE (~0ull << 48)static bool ok;static void tsc_adjust_prepare (struct test *test)
PATCH v2 5/7 x86: VMX: Add tests for monitor trap flag
In reply to Bill WendlingFrom: Oliver Upton <[email protected]>
Test to verify that MTF VM-exits into host are synthesized when the 'monitor trap flag' processor-based VM-execution control is set under various conditions.
Expect an MTF VM-exit if instruction execution produces no events other than MTF. Should instruction execution produce a concurrent debug-trap and MTF event, expect an MTF VM-exit with the 'pending debug exceptions' VMCS field set. Expect an MTF VM-exit to follow event delivery should instruction execution generate a higher-priority event, such as a general-protection fault. Lastly, expect an MTF VM-exit to follow delivery of a debug-trap software exception (INT1/INT3/INTO/INT n).
--- x86/vmx.h | 1 + x86/vmx_tests.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+)
x86/vmx.h +1 -0
@@ -399,6 +399,7 @@ enum Ctrl0 {CPU_NMI_WINDOW =1ul <<22 ,CPU_IO =1ul <<24 ,CPU_IO_BITMAP =1ul <<25 , +CPU_MTF =1ul <<27 ,CPU_MSR_BITMAP =1ul <<28 ,CPU_MONITOR =1ul <<29 , CPU_PAUSE = 1ul << 30,
x86/vmx_tests.c +157 -0
168 lines not on this page · raw message
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH v2 6/7 x86: emulator: use "SSE2" for the target
In reply to Bill WendlingThe movdqu and movapd instructions are SSE2 instructions. Clang interprets the __attribute__((target("sse"))) as allowing SSE only instructions. Using SSE2 instructions cause an error.
--- x86/emulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
x86/emulator.c +1 -1
@@ -658,7 +658,7 @@ static bool sseeq(sse_union *v1, sse_union *v2)return ok; } -static __attribute__((target ("sse" )))void test_sse (sse_union *mem) +static __attribute__((target ("sse2" )))void test_sse (sse_union *mem) {sse_union v;
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 6/7 x86: VMX: use inline asm to get stack pointer
In reply to Bill WendlingThe only supported use of a local register variable is to specify registers for input and output operands when calling Extended asm. Using it to automatically collect the value in the register isn't supported as the contents of the register aren't guaranteed. Instead use inline asm to get the stack pointer explicitly.
--- x86/vmx_tests.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
x86/vmx_tests.c +4 -2
@@ -2165,8 +2165,9 @@ static void into_guest_main(void) .offset = (uintptr_t)&&into, .selector = KERNEL_CS32, }; - registeruintptr_t rsp asm("rsp" ); +uintptr_t rsp =0 ; + asmvolatile ("mov %%rsp, %0" :"=r" (rsp));if (fp.offset != (uintptr_t )&&into) {printf ("Code address too high.\n" );return ;
@@ -3261,8 +3262,9 @@ static void try_compat_invvpid(void *unused) .offset = (uintptr_t)&&invvpid, .selector = KERNEL_CS32, }; - registeruintptr_t rsp asm("rsp" ); + registeruintptr_t rsp =0 ; + asmvolatile ("mov %%rsp, %0" :"=r" (rsp));TEST_ASSERT_MSG (fp.offset == (uintptr_t )&&invvpid,"Code address too high." );TEST_ASSERT_MSG (rsp == (u32 )rsp,"Stack address too high." );
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH v2 7/7 pci: cast masks to uint32_t for unsigned long values
In reply to Bill WendlingThe "pci_bar_*" functions use 64-bit masks, but the results are assigned to 32-bit variables. Cast mask usages to 32-bit, since we're interested only in the least significant 4-bits.
--- lib/pci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/pci.c +2 -1
@@ -107,7 +107,8 @@ pcidevaddr_t pci_find_dev(uint16_t vendor_id, uint16_t device_id)uint32_t pci_bar_mask (uint32_t bar) {return (bar &PCI_BASE_ADDRESS_SPACE_IO ) ? -PCI_BASE_ADDRESS_IO_MASK :PCI_BASE_ADDRESS_MEM_MASK ; + (uint32_t )PCI_BASE_ADDRESS_IO_MASK : + (uint32_t )PCI_BASE_ADDRESS_MEM_MASK ; }uint32_t pci_bar_get (struct pci_dev *dev,int bar_num)
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 7/7 x86: VMX: the "noclone" attribute is gcc-specific
In reply to Bill WendlingDon't use the "noclone" attribute for clang as it's not supported.
--- x86/vmx_tests.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
x86/vmx_tests.c +4 -1
@@ -4976,7 +4976,10 @@ extern unsigned char test_mtf1;extern unsigned char test_mtf2;extern unsigned char test_mtf3; -__attribute__((noclone))static void test_mtf_guest (void ) +#ifndef __clang__ +__attribute__((noclone)) +#endif +static void test_mtf_guest (void ) { asm ("vmcall;\n\t" "out %al, $0x80;\n\t"
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
Paolo Bonzini
maintainerRe: [kvm-unit-tests PATCH 7/7] x86: VMX: the "noclone" attribute is gcc-specific
Quoted 14 lines · Bill Wendling
Don't use the "noclone" attribute for clang as it's not supported.
Signed-off-by Bill Wendling <[email protected]>--- x86/vmx_tests.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)x86/vmx_tests.c +0
-0@@ -4976,7 +4976,10 @@ extern unsigned char test_mtf1;extern unsigned char test_mtf2;
x86/vmx_tests.c extern unsigned char test_mtf1; · line 4985
Quoted 10 lines
x86/vmx_tests.c +4
-1extern unsigned char test_mtf3; -__attribute__((noclone))static void test_mtf_guest (void ) +#ifndef __clang__ +__attribute__((noclone)) +#endif +static void test_mtf_guest (void ) { asm ("vmcall;\n\t" "out %al, $0x80;\n\t"
It's not needed at all, let's drop it.
Paolo
Re: [kvm-unit-tests PATCH 7/7] x86: VMX: the "noclone" attribute is gcc-specific
Quoted 29 lines · Paolo Bonzini
Quoted 14 lines · Bill Wendling
Don't use the "noclone" attribute for clang as it's not supported.
Signed-off-by Bill Wendling <[email protected]>--- x86/vmx_tests.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)x86/vmx_tests.c +0
-0@@ -4976,7 +4976,10 @@ extern unsigned char test_mtf1;extern unsigned char test_mtf2;x86/vmx_tests.c extern unsigned char test_mtf1; · line 4985
Quoted 10 lines
x86/vmx_tests.c +4
-1extern unsigned char test_mtf3; -__attribute__((noclone))static void test_mtf_guest (void ) +#ifndef __clang__ +__attribute__((noclone)) +#endif +static void test_mtf_guest (void ) { asm ("vmcall;\n\t" "out %al, $0x80;\n\t"It's not needed at all, let's drop it.
Quoted 2 lines
Paolo
If we wanted to be absolutely certain that the extern labels used for assertions about the guest RIP are correct, we may still want it. Alternatively, I could rewrite the test such that the guest will report the instruction boundary where it anticipates MTF whenever it makes the vmcall to request the host turns on MTF.
--
Thanks,
Oliver
Paolo Bonzini
maintainerRe: [kvm-unit-tests PATCH 7/7] x86: VMX: the "noclone" attribute is gcc-specific
Quoted 5 lines · Oliver Upton
If we wanted to be absolutely certain that the extern labels used for assertions about the guest RIP are correct, we may still want it. Alternatively, I could rewrite the test such that the guest will report the instruction boundary where it anticipates MTF whenever it makes the vmcall to request the host turns on MTF.
Right, but it's used only once, and as a function pointer at that, so there's only so much that the compiler can do to "optimize". Let's think about how to fix it if it breaks.
Paolo
Re: [kvm-unit-tests PATCH 7/7] x86: VMX: the "noclone" attribute is gcc-specific
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Oliver Upton
If we wanted to be absolutely certain that the extern labels used for assertions about the guest RIP are correct, we may still want it. Alternatively, I could rewrite the test such that the guest will report the instruction boundary where it anticipates MTF whenever it makes the vmcall to request the host turns on MTF.
Quoted 6 lines
Right, but it's used only once, and as a function pointer at that, so there's only so much that the compiler can do to "optimize". Let's think about how to fix it if it breaks.
Paolo
Very true. Unchecked paranoia of the compiler isn't warranted here.
Thanks :)
--
Best,
Oliver
Hi Bill,
Quoted 12 lines · Bill Wendling
Changes to "pci: cast masks to
uint32_tfor unsigned long values" to cast the masks instead of changing the values in the header.Bill Wendling (2):
x86: emulator: use "SSE2" for the target
pci: cast masks touint32_tfor unsigned long valuesEric Hankland (2):
x86: pmu: Test WRMSR on a running counter
x86: pmu: Test perfctr overflow after WRMSR on a running counter
Quoted 7 lines
Oliver Upton (1):
x86: VMX: Add tests for monitor trap flagPaolo Bonzini (2):
x86: provide enabled and disabled variation of the PCID test
vmx: tweak XFAILS for #DB test
These patches have already been pushed. Was there any reason to squash your v1 patches into the commits that introduced the clang issues? Otherwise, I'd strongly suggest re-posting the v1 series with just the clang fixes.
Thanks!
--
Best,
Oliver
v3 cover Fixes for clang builds
In reply to Bill WendlingChanges to "pci: cast masks to uint32_t for unsigned long values" to cast the masks instead of changing the values in the header.
This is a re-send of the v2 patches, which included patches that shouldn't have been included.
Bill Wendling (7):
x86: emulator: use "SSE2" for the target
pci: cast masks to uint32_t for unsigned long values
x86: realmode: syscall: add explicit size suffix to ambiguous
instructions
svm: change operand to output-only for matching constraint
svm: convert neg shift to unsigned shift
x86: VMX: use inline asm to get stack pointer
x86: VMX: the "noclone" attribute is gcc-specific
lib/pci.c | 3 ++- x86/emulator.c | 2 +- x86/realmode.c | 6 +++--- x86/svm.c | 6 +++--- x86/syscall.c | 2 +- x86/vmx_tests.c | 11 ++++++++--- 6 files changed, 18 insertions(+), 12 deletions(-)
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v3 1/7 x86: emulator: use "SSE2" for the target
The movdqu and movapd instructions are SSE2 instructions. Clang interprets the __attribute__((target("sse"))) as allowing SSE only instructions. Using SSE2 instructions cause an error.
--- x86/emulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
x86/emulator.c +1 -1
@@ -658,7 +658,7 @@ static bool sseeq(sse_union *v1, sse_union *v2)return ok; } -static __attribute__((target ("sse" )))void test_sse (sse_union *mem) +static __attribute__((target ("sse2" )))void test_sse (sse_union *mem) {sse_union v;
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v3 2/7 pci: cast masks to uint32_t for unsigned long values
In reply to Bill WendlingThe "pci_bar_*" functions use 64-bit masks, but the results are assigned to 32-bit variables. Cast mask usages to 32-bit, since we're interested only in the least significant 4-bits.
--- lib/pci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/pci.c +2 -1
@@ -107,7 +107,8 @@ pcidevaddr_t pci_find_dev(uint16_t vendor_id, uint16_t device_id)uint32_t pci_bar_mask (uint32_t bar) {return (bar &PCI_BASE_ADDRESS_SPACE_IO ) ? -PCI_BASE_ADDRESS_IO_MASK :PCI_BASE_ADDRESS_MEM_MASK ; + (uint32_t )PCI_BASE_ADDRESS_IO_MASK : + (uint32_t )PCI_BASE_ADDRESS_MEM_MASK ; }uint32_t pci_bar_get (struct pci_dev *dev,int bar_num)
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v3 3/7 x86: realmode: syscall: add explicit size suffix to ambiguous instructions
In reply to Bill WendlingClang requires explicit size suffixes for potentially ambiguous instructions:
x86/realmode.c:1647:2: error: ambiguous instructions require an explicit suffix (could be 'cmpb', 'cmpw', or 'cmpl')
MK_INSN_PERF(perf_memory_load, "cmp $0, (%edi)");
^
x86/realmode.c:1591:10: note: expanded from macro 'MK_INSN_PERF'
"1:" insn "\n" \
^<inline asm>:8:3: note: instantiated into assembly here 1:cmp $0, (%edi)
^
The 'w' and 'l' suffixes generate code that's identical to the gcc version without them.
--- x86/realmode.c | 6 +++--- x86/syscall.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
x86/realmode.c +3 -3
@@ -1644,7 +1644,7 @@ static void test_perf_memory_load(void) {u32 cyc, tmp; -MK_INSN_PERF (perf_memory_load,"cmp $0, (%edi)" ); +MK_INSN_PERF (perf_memory_load,"cmpw $0, (%edi)" );init_inregs (&(struct regs ){ .edi = (u32)&tmp });
@@ -1657,7 +1657,7 @@ static void test_perf_memory_store(void) {u32 cyc, tmp; -MK_INSN_PERF (perf_memory_store,"mov %ax, (%edi)" ); +MK_INSN_PERF (perf_memory_store,"movw %ax, (%edi)" );init_inregs (&(struct regs ){ .edi = (u32)&tmp });
@@ -1670,7 +1670,7 @@ static void test_perf_memory_rmw(void) {u32 cyc, tmp; -MK_INSN_PERF (perf_memory_rmw,"add $1, (%edi)" ); +MK_INSN_PERF (perf_memory_rmw,"addw $1, (%edi)" );init_inregs (&(struct regs ){ .edi = (u32)&tmp });
x86/syscall.c +1 -1
@@ -38,7 +38,7 @@ static void handle_db(struct ex_regs *regs)/* expects desired ring 3 flags in rax */ asm("syscall32_target:\n" -" cmp $0, code_segment_upon_db(%rip)\n" +" cmpl $0, code_segment_upon_db(%rip)\n" " jne back_to_test\n" " mov %eax,%r11d\n" " sysretl\n" );
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v3 4/7 svm: change operand to output-only for matching constraint
In reply to Bill WendlingAccording to GNU extended asm documentation, "the two operands [of matching constraints] must include one input-only operand and one output-only operand." So remove the read/write modifier from the output constraint.
--- x86/svm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
x86/svm.c +2 -2
@@ -288,8 +288,8 @@ static void test_run(struct test *test, struct vmcb *vmcb) "cli \n\t" "stgi" : // inputs clobbered by the guest: - "+D" (the_test), // first argument register - "+b" (the_vmcb) // callee save register! + "=D" (the_test), // first argument register +"=b" (the_vmcb)// callee save register! : [test] "0" (the_test), [vmcb_phys] "1"(the_vmcb), [PREPARE_GIF_CLEAR] "i" (offsetof(struct test, prepare_gif_clear))
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v3 5/7 svm: convert neg shift to unsigned shift
In reply to Bill WendlingShifting a negative signed value is undefined. Use a shift of an unsigned value instead.
--- x86/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
x86/svm.c +1 -1
@@ -1148,7 +1148,7 @@ static bool npt_rw_l1mmio_check(struct test *test) }#define TSC_ADJUST_VALUE (1ll << 32) -#define TSC_OFFSET_VALUE (-1ll << 48) +#define TSC_OFFSET_VALUE (~0ull << 48)static bool ok;static void tsc_adjust_prepare (struct test *test)
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v3 6/7 x86: VMX: use inline asm to get stack pointer
In reply to Bill WendlingThe only supported use of a local register variable is to specify registers for input and output operands when calling Extended asm. Using it to automatically collect the value in the register isn't supported as the contents of the register aren't guaranteed. Instead use inline asm to get the stack pointer explicitly.
--- x86/vmx_tests.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
x86/vmx_tests.c +4 -2
@@ -2165,8 +2165,9 @@ static void into_guest_main(void) .offset = (uintptr_t)&&into, .selector = KERNEL_CS32, }; - registeruintptr_t rsp asm("rsp" ); +uintptr_t rsp =0 ; + asmvolatile ("mov %%rsp, %0" :"=r" (rsp));if (fp.offset != (uintptr_t )&&into) {printf ("Code address too high.\n" );return ;
@@ -3261,8 +3262,9 @@ static void try_compat_invvpid(void *unused) .offset = (uintptr_t)&&invvpid, .selector = KERNEL_CS32, }; - registeruintptr_t rsp asm("rsp" ); + registeruintptr_t rsp =0 ; + asmvolatile ("mov %%rsp, %0" :"=r" (rsp));TEST_ASSERT_MSG (fp.offset == (uintptr_t )&&invvpid,"Code address too high." );TEST_ASSERT_MSG (rsp == (u32 )rsp,"Stack address too high." );
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v3 7/7 x86: VMX: the "noclone" attribute is gcc-specific
In reply to Bill WendlingDon't use the "noclone" attribute for clang as it's not supported.
--- x86/vmx_tests.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
x86/vmx_tests.c +4 -1
@@ -4976,7 +4976,10 @@ extern unsigned char test_mtf1;extern unsigned char test_mtf2;extern unsigned char test_mtf3; -__attribute__((noclone))static void test_mtf_guest (void ) +#ifndef __clang__ +__attribute__((noclone)) +#endif +static void test_mtf_guest (void ) { asm ("vmcall;\n\t" "out %al, $0x80;\n\t"
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Re: [kvm-unit-tests PATCH v3 7/7] x86: VMX: the "noclone" attribute is gcc-specific
Hi Bill,
Perhaps it would be better to drill down the noclone attribute by GCC version as well. May I suggest the following?
lib/compiler.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef _LIB_COMPILER_H_ +#define _LIB_COMPILER_H_ + +#if GCC_VERSION >=40500 +#define __noclone __attribute__((__noclone__, __optimize__("no-tracer"))) +#endif /* GCC_VERSION >= 40500 */ + +#if !defined(__noclone) +#define __noclone +#endif + +#endif /* _LIB_COMPILER_H_ */
x86/vmx_tests.c +2 -1
@@ -5,6 +5,7 @@*/ #include <asm/debugreg.h> +#include <compiler.h> #include "vmx.h" #include "msr.h"
@@ -4974,7 +4975,7 @@ extern unsigned char test_mtf1;extern unsigned char test_mtf2;extern unsigned char test_mtf3; -__attribute__((noclone))static void test_mtf_guest (void ) +__noclone static void test_mtf_guest (void ) { asm ("vmcall;\n\t" "out %al, $0x80;\n\t"
Signature · 2 lines
Thanks, Oliver
Quoted 27 lines · Bill Wendling
Don't use the "noclone" attribute for clang as it's not supported.
Signed-off-by Bill Wendling <[email protected]>--- x86/vmx_tests.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)x86/vmx_tests.c +4
-2@@ -4976,7 +4976,10 @@ extern unsigned char test_mtf1;extern unsigned char test_mtf2;extern unsigned char test_mtf3; -__attribute__((noclone))static void test_mtf_guest (void ) +#ifndef __clang__ +__attribute__((noclone)) +#endif +static void test_mtf_guest (void ) { asm ("vmcall;\n\t" "out %al, $0x80;\n\t" --2.25.1.481.gfbce0eb801-goog
Paolo Bonzini
maintainerQuoted 2 lines · Bill Wendling
Changes to "pci: cast masks to
uint32_tfor unsigned long values" to cast the masks instead of changing the values in the header.
Applied 1-3-4 and a tweaked version of 2 and 7.
For 5, let's use -fwrapv instead.
For 6, clang people should stop implementing GCC extensions in half and declaring themselves compatible. It's just a sanity check, you can wrap it all with #ifndef __clang__.
Paolo