Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: selftests: Define cpu_relax() helpers for s390 and x86

Add cpu_relax() for s390 and x86 for use in arch-agnostic tests. arm64
already defines its own version.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20220226001546.360188-28-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Sean Christopherson and committed by
Paolo Bonzini
17ae5ebc a4187c9b

+13
+8
tools/testing/selftests/kvm/include/s390x/processor.h
··· 5 5 #ifndef SELFTEST_KVM_PROCESSOR_H 6 6 #define SELFTEST_KVM_PROCESSOR_H 7 7 8 + #include <linux/compiler.h> 9 + 8 10 /* Bits in the region/segment table entry */ 9 11 #define REGION_ENTRY_ORIGIN ~0xfffUL /* region/segment table origin */ 10 12 #define REGION_ENTRY_PROTECT 0x200 /* region protection bit */ ··· 20 18 #define PAGE_INVALID 0x400 /* HW invalid bit */ 21 19 #define PAGE_PROTECT 0x200 /* HW read-only bit */ 22 20 #define PAGE_NOEXEC 0x100 /* HW no-execute bit */ 21 + 22 + /* Is there a portable way to do this? */ 23 + static inline void cpu_relax(void) 24 + { 25 + barrier(); 26 + } 23 27 24 28 #endif
+5
tools/testing/selftests/kvm/include/x86_64/processor.h
··· 363 363 return 0; 364 364 } 365 365 366 + static inline void cpu_relax(void) 367 + { 368 + asm volatile("rep; nop" ::: "memory"); 369 + } 370 + 366 371 bool is_intel_cpu(void); 367 372 bool is_amd_cpu(void); 368 373