KVM: selftests: Convert userspace_io_test away from VCPU_ID
Convert userspace_io_test to use vm_create_with_one_vcpu() and pass around a 'struct kvm_vcpu' object instead of using a global VCPU_ID. Note, this is a "functional" change in the sense that the test now creates a vCPU with vcpu_id==0 instead of vcpu_id==1. The non-zero VCPU_ID was 100% arbitrary and added little to no validation coverage. If testing non-zero vCPU IDs is desirable for generic tests, that can be done in the future by tweaking the VM creation helpers. Opportunistically use vcpu_run() instead of _vcpu_run() with an open coded assert that KVM_RUN succeeded. Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
committed by
Paolo Bonzini
parent
87f1b5b3c0
commit
ada1bf4d65
@@ -10,8 +10,6 @@
|
|||||||
#include "kvm_util.h"
|
#include "kvm_util.h"
|
||||||
#include "processor.h"
|
#include "processor.h"
|
||||||
|
|
||||||
#define VCPU_ID 1
|
|
||||||
|
|
||||||
static void guest_ins_port80(uint8_t *buffer, unsigned int count)
|
static void guest_ins_port80(uint8_t *buffer, unsigned int count)
|
||||||
{
|
{
|
||||||
unsigned long end;
|
unsigned long end;
|
||||||
@@ -52,31 +50,29 @@ static void guest_code(void)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
struct kvm_vcpu *vcpu;
|
||||||
struct kvm_regs regs;
|
struct kvm_regs regs;
|
||||||
struct kvm_run *run;
|
struct kvm_run *run;
|
||||||
struct kvm_vm *vm;
|
struct kvm_vm *vm;
|
||||||
struct ucall uc;
|
struct ucall uc;
|
||||||
int rc;
|
|
||||||
|
|
||||||
/* Tell stdout not to buffer its content */
|
/* Tell stdout not to buffer its content */
|
||||||
setbuf(stdout, NULL);
|
setbuf(stdout, NULL);
|
||||||
|
|
||||||
/* Create VM */
|
vm = vm_create_with_one_vcpu(&vcpu, guest_code);
|
||||||
vm = vm_create_default(VCPU_ID, 0, guest_code);
|
run = vcpu->run;
|
||||||
run = vcpu_state(vm, VCPU_ID);
|
|
||||||
|
|
||||||
memset(®s, 0, sizeof(regs));
|
memset(®s, 0, sizeof(regs));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
rc = _vcpu_run(vm, VCPU_ID);
|
vcpu_run(vm, vcpu->id);
|
||||||
|
|
||||||
TEST_ASSERT(rc == 0, "vcpu_run failed: %d\n", rc);
|
|
||||||
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
|
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
|
||||||
"Unexpected exit reason: %u (%s),\n",
|
"Unexpected exit reason: %u (%s),\n",
|
||||||
run->exit_reason,
|
run->exit_reason,
|
||||||
exit_reason_str(run->exit_reason));
|
exit_reason_str(run->exit_reason));
|
||||||
|
|
||||||
if (get_ucall(vm, VCPU_ID, &uc))
|
if (get_ucall(vm, vcpu->id, &uc))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TEST_ASSERT(run->io.port == 0x80,
|
TEST_ASSERT(run->io.port == 0x80,
|
||||||
@@ -89,13 +85,13 @@ int main(int argc, char *argv[])
|
|||||||
* scope from a testing perspective as it's not ABI in any way,
|
* scope from a testing perspective as it's not ABI in any way,
|
||||||
* i.e. it really is abusing internal KVM knowledge.
|
* i.e. it really is abusing internal KVM knowledge.
|
||||||
*/
|
*/
|
||||||
vcpu_regs_get(vm, VCPU_ID, ®s);
|
vcpu_regs_get(vm, vcpu->id, ®s);
|
||||||
if (regs.rcx == 2)
|
if (regs.rcx == 2)
|
||||||
regs.rcx = 1;
|
regs.rcx = 1;
|
||||||
if (regs.rcx == 3)
|
if (regs.rcx == 3)
|
||||||
regs.rcx = 8192;
|
regs.rcx = 8192;
|
||||||
memset((void *)run + run->io.data_offset, 0xaa, 4096);
|
memset((void *)run + run->io.data_offset, 0xaa, 4096);
|
||||||
vcpu_regs_set(vm, VCPU_ID, ®s);
|
vcpu_regs_set(vm, vcpu->id, ®s);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (uc.cmd) {
|
switch (uc.cmd) {
|
||||||
|
|||||||
Reference in New Issue
Block a user