Skip to content

Commit 03a0c81

Browse files
sean-jcbonzini
authored andcommitted
KVM: selftests: Use non-atomic clear/set bit helpers in KVM tests
Use the dedicated non-atomic helpers for {clear,set}_bit() and their test variants, i.e. the double-underscore versions. Depsite being defined in atomic.h, and despite the kernel versions being atomic in the kernel, tools' {clear,set}_bit() helpers aren't actually atomic. Move to the double-underscore versions so that the versions that are expected to be atomic (for kernel developers) can be made atomic without affecting users that don't want atomic operations. Leave the usage in ucall_free() as-is, it's the one place in tools/ that actually wants/needs atomic behavior. Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 75d7ba3 commit 03a0c81

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

tools/testing/selftests/kvm/aarch64/arch_timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static void *test_vcpu_run(void *arg)
222222

223223
/* Currently, any exit from guest is an indication of completion */
224224
pthread_mutex_lock(&vcpu_done_map_lock);
225-
set_bit(vcpu_idx, vcpu_done_map);
225+
__set_bit(vcpu_idx, vcpu_done_map);
226226
pthread_mutex_unlock(&vcpu_done_map_lock);
227227

228228
switch (get_ucall(vcpu, &uc)) {

tools/testing/selftests/kvm/dirty_log_test.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@
4444
# define BITOP_LE_SWIZZLE ((BITS_PER_LONG-1) & ~0x7)
4545
# define test_bit_le(nr, addr) \
4646
test_bit((nr) ^ BITOP_LE_SWIZZLE, addr)
47-
# define set_bit_le(nr, addr) \
48-
set_bit((nr) ^ BITOP_LE_SWIZZLE, addr)
49-
# define clear_bit_le(nr, addr) \
50-
clear_bit((nr) ^ BITOP_LE_SWIZZLE, addr)
51-
# define test_and_set_bit_le(nr, addr) \
52-
test_and_set_bit((nr) ^ BITOP_LE_SWIZZLE, addr)
53-
# define test_and_clear_bit_le(nr, addr) \
54-
test_and_clear_bit((nr) ^ BITOP_LE_SWIZZLE, addr)
47+
# define __set_bit_le(nr, addr) \
48+
__set_bit((nr) ^ BITOP_LE_SWIZZLE, addr)
49+
# define __clear_bit_le(nr, addr) \
50+
__clear_bit((nr) ^ BITOP_LE_SWIZZLE, addr)
51+
# define __test_and_set_bit_le(nr, addr) \
52+
__test_and_set_bit((nr) ^ BITOP_LE_SWIZZLE, addr)
53+
# define __test_and_clear_bit_le(nr, addr) \
54+
__test_and_clear_bit((nr) ^ BITOP_LE_SWIZZLE, addr)
5555
#else
56-
# define test_bit_le test_bit
57-
# define set_bit_le set_bit
58-
# define clear_bit_le clear_bit
59-
# define test_and_set_bit_le test_and_set_bit
60-
# define test_and_clear_bit_le test_and_clear_bit
56+
# define test_bit_le test_bit
57+
# define __set_bit_le __set_bit
58+
# define __clear_bit_le __clear_bit
59+
# define __test_and_set_bit_le __test_and_set_bit
60+
# define __test_and_clear_bit_le __test_and_clear_bit
6161
#endif
6262

6363
#define TEST_DIRTY_RING_COUNT 65536
@@ -305,7 +305,7 @@ static uint32_t dirty_ring_collect_one(struct kvm_dirty_gfn *dirty_gfns,
305305
TEST_ASSERT(cur->offset < num_pages, "Offset overflow: "
306306
"0x%llx >= 0x%x", cur->offset, num_pages);
307307
//pr_info("fetch 0x%x page %llu\n", *fetch_index, cur->offset);
308-
set_bit_le(cur->offset, bitmap);
308+
__set_bit_le(cur->offset, bitmap);
309309
dirty_ring_last_page = cur->offset;
310310
dirty_gfn_set_collected(cur);
311311
(*fetch_index)++;
@@ -560,15 +560,15 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap)
560560
value_ptr = host_test_mem + page * host_page_size;
561561

562562
/* If this is a special page that we were tracking... */
563-
if (test_and_clear_bit_le(page, host_bmap_track)) {
563+
if (__test_and_clear_bit_le(page, host_bmap_track)) {
564564
host_track_next_count++;
565565
TEST_ASSERT(test_bit_le(page, bmap),
566566
"Page %"PRIu64" should have its dirty bit "
567567
"set in this iteration but it is missing",
568568
page);
569569
}
570570

571-
if (test_and_clear_bit_le(page, bmap)) {
571+
if (__test_and_clear_bit_le(page, bmap)) {
572572
bool matched;
573573

574574
host_dirty_count++;
@@ -661,7 +661,7 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap)
661661
* should report its dirtyness in the
662662
* next run
663663
*/
664-
set_bit_le(page, host_bmap_track);
664+
__set_bit_le(page, host_bmap_track);
665665
}
666666
}
667667
}

tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void guest_code(struct vmx_pages *vmx_pages, struct hyperv_test_pages *hv_pages,
142142
/* Intercept RDMSR 0xc0000100 */
143143
vmwrite(CPU_BASED_VM_EXEC_CONTROL, vmreadz(CPU_BASED_VM_EXEC_CONTROL) |
144144
CPU_BASED_USE_MSR_BITMAPS);
145-
set_bit(MSR_FS_BASE & 0x1fff, vmx_pages->msr + 0x400);
145+
__set_bit(MSR_FS_BASE & 0x1fff, vmx_pages->msr + 0x400);
146146
GUEST_ASSERT(!vmresume());
147147
GUEST_ASSERT(vmreadz(VM_EXIT_REASON) == EXIT_REASON_MSR_READ);
148148
current_evmcs->guest_rip += 2; /* rdmsr */
@@ -154,7 +154,7 @@ void guest_code(struct vmx_pages *vmx_pages, struct hyperv_test_pages *hv_pages,
154154
current_evmcs->guest_rip += 2; /* rdmsr */
155155

156156
/* Intercept RDMSR 0xc0000101 without telling KVM about it */
157-
set_bit(MSR_GS_BASE & 0x1fff, vmx_pages->msr + 0x400);
157+
__set_bit(MSR_GS_BASE & 0x1fff, vmx_pages->msr + 0x400);
158158
/* Make sure HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP is set */
159159
current_evmcs->hv_clean_fields |= HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP;
160160
GUEST_ASSERT(!vmresume());

tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static void __attribute__((__flatten__)) guest_code(struct svm_test_data *svm,
103103

104104
/* Intercept RDMSR 0xc0000100 */
105105
vmcb->control.intercept |= 1ULL << INTERCEPT_MSR_PROT;
106-
set_bit(2 * (MSR_FS_BASE & 0x1fff), svm->msr + 0x800);
106+
__set_bit(2 * (MSR_FS_BASE & 0x1fff), svm->msr + 0x800);
107107
run_guest(vmcb, svm->vmcb_gpa);
108108
GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
109109
vmcb->save.rip += 2; /* rdmsr */
@@ -115,7 +115,7 @@ static void __attribute__((__flatten__)) guest_code(struct svm_test_data *svm,
115115
vmcb->save.rip += 2; /* rdmsr */
116116

117117
/* Intercept RDMSR 0xc0000101 without telling KVM about it */
118-
set_bit(2 * (MSR_GS_BASE & 0x1fff), svm->msr + 0x800);
118+
__set_bit(2 * (MSR_GS_BASE & 0x1fff), svm->msr + 0x800);
119119
/* Make sure HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP is set */
120120
vmcb->control.clean |= HV_VMCB_NESTED_ENLIGHTENMENTS;
121121
run_guest(vmcb, svm->vmcb_gpa);

0 commit comments

Comments
 (0)