lkml.org 
[lkml]   [2022]   [May]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
Subject[PATCH] selftests: KVM/x86: Add APIC state into kvm_x86_state
From
Add APIC state into kvm_x86_state and properly save/restore it in
vcpu_{save,load}_state().

Doing so fix a bug that was triggered internally in Google. The selftest
(WIP) creates an L1 which then creates an L2 and runs L2 in vcpu0. Before
L2 finish, it exits to L0, save the state, stops the VM, restarts it and
add the vcpu back and finally load the state back. The test uses another
vcpu to shoot a posted interrupt. The result demonstrates that the L2,
after this vm save/restore, was not able to receive posted interrupt.

Our debugging shows that it is the APIC state was software disabled after
vcpu_load_state(). Adding the APIC state into the kvm_x86_state and loading
it in vcpu_load_state() fixes the issue.

Cc: Jim Mattson <jmattson@google.com>

Signed-off-by: Mingwei Zhang <mizhang@google.com>
---
tools/testing/selftests/kvm/include/x86_64/processor.h | 1 +
tools/testing/selftests/kvm/lib/x86_64/processor.c | 8 ++++++++
2 files changed, 9 insertions(+)

diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
index d0d51adec76eb..e4683429bd8b8 100644
--- a/tools/testing/selftests/kvm/include/x86_64/processor.h
+++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
@@ -123,6 +123,7 @@ struct kvm_x86_state {
struct kvm_nested_state nested;
char nested_[16384];
};
+ struct kvm_lapic_state apic;
struct kvm_msrs msrs;
};

diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
index 33ea5e9955d9b..113f4ce752579 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
@@ -1173,6 +1173,10 @@ struct kvm_x86_state *vcpu_save_state(struct kvm_vm *vm, uint32_t vcpuid)
TEST_ASSERT(r == 0, "Unexpected result from KVM_GET_DEBUGREGS, r: %i",
r);

+ r = ioctl(vcpu->fd, KVM_GET_LAPIC, &state->apic);
+ TEST_ASSERT(r == 0, "Unexpected result from KVM_GET_LAPIC, r: %i",
+ r);
+
free(list);
return state;
}
@@ -1222,6 +1226,10 @@ void vcpu_load_state(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_x86_state *s
TEST_ASSERT(r == 0, "Unexpected result from KVM_SET_NESTED_STATE, r: %i",
r);
}
+
+ r = ioctl(vcpu->fd, KVM_SET_LAPIC, &state->apic);
+ TEST_ASSERT(r == 0,
+ "Unexpected result from KVM_SET_LAPIC, r: %i", r);
}

void kvm_x86_state_cleanup(struct kvm_x86_state *state)
base-commit: f3f19f939c11925dadd3f4776f99f8c278a7017b
--
2.36.1.124.g0e6072fb45-goog

\
 
 \ /
  Last update: 2022-05-25 07:26    [W:0.035 / U:0.152 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site