From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1843FC433FE for ; Wed, 4 May 2022 22:53:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354592AbiEDW5U (ORCPT ); Wed, 4 May 2022 18:57:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379551AbiEDWy1 (ORCPT ); Wed, 4 May 2022 18:54:27 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABBA94C43C for ; Wed, 4 May 2022 15:50:49 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id h9-20020a631209000000b0039cc31b22aeso1345478pgl.9 for ; Wed, 04 May 2022 15:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=GQfPzPtdZfr3rPuoQKIQO/wdm3b/PW1yxF0crxQV5Zs=; b=kC4ouZvYCf46p3Y2P0o/cGpVwFOkvvoFMpskIQzIVlYFFIp2DI+jf+SPulbjsfbzon FJDgUnGIF44Q26D8Gp2pYnDYlvtrt4E/e4YOfvzmJdsYngbG14pEnbUbYGIylkgs0/di 9KwtE3LJBS+Z97eArW2mUF4kOIFVKZdjzVkzKYVLYYqnNbBdPVue7SZAMZq5qYinonyz b6HuhKr736F1cp4ZgFiaIPQZhUM7AHKFptNpaoVYYz7WIIRFt5NaOZcu0nWfaFV67KDp eg12SwnlpQqST7AkBL1qlxBlXSGxer/1B+DiY3x79IJFjixzhBH4Jy6lk09HYU/l2oZg eniA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=GQfPzPtdZfr3rPuoQKIQO/wdm3b/PW1yxF0crxQV5Zs=; b=Ohwd6pPvA9YggF65mme1y0CojnsJxV7sUUCxbkmT34eMQXL68BeGQbPjoae4H/jZXq qwXf1gZNgJZu4pNnt/YA2dEeCpmcKd8X6XuHX/CyJ9vcwaxfkPdoaI5AHr4KaizwcAPA qIb76AfhAhsIM9FRUXWox3fkfi+mCkh6HvsNv3+mbRD4yEYL+cJskYg4oouf9S7Pq38f TEgGYvv8sEnRTlDmwbXfe/KPM52jSGdzEMQ2WKkmzJ5l/ytpsz6Vk1Jsydk8gPwHP1S7 gKbVKxlVvINHTAWJJQcl7AbGCP2OUUETMjMM4jj7Gu1tdlftm3nrBYH/RxEc9+OCoGiS dtog== X-Gm-Message-State: AOAM533lAr40x+exbvQEGefU7vM4Z8KQSBsn78Upec0fXbzi2pRG2j34 yIjdDwFDizYxOTFF00K6+559LmkyGeo= X-Google-Smtp-Source: ABdhPJzjlJsIZtRISyX7XcoGaf2pPor2TUTf37ombDeCId1LYhgAoiVcsqmG+g1J+VBBehYaMPu8qWwu+DU= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:903:22cb:b0:15e:d715:1bd8 with SMTP id y11-20020a17090322cb00b0015ed7151bd8mr863353plg.159.1651704649219; Wed, 04 May 2022 15:50:49 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 4 May 2022 22:47:51 +0000 In-Reply-To: <20220504224914.1654036-1-seanjc@google.com> Message-Id: <20220504224914.1654036-46-seanjc@google.com> Mime-Version: 1.0 References: <20220504224914.1654036-1-seanjc@google.com> X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH 045/128] KVM: selftests: Convert vmx_preemption_timer_test away from VCPU_ID From: Sean Christopherson To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Vitaly Kuznetsov , Andrew Jones , David Matlack , Ben Gardon , Oliver Upton , Sean Christopherson Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Convert vmx_preemption_timer_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==5. 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(), the test expects KVM_RUN to succeed. Signed-off-by: Sean Christopherson --- .../kvm/x86_64/vmx_preemption_timer_test.c | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c b/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c index f5b4ae914131..168adc5b2272 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c @@ -22,7 +22,6 @@ #include "processor.h" #include "vmx.h" -#define VCPU_ID 5 #define PREEMPTION_TIMER_VALUE 100000000ull #define PREEMPTION_TIMER_VALUE_THRESHOLD1 80000000ull @@ -159,6 +158,7 @@ int main(int argc, char *argv[]) struct kvm_regs regs1, regs2; struct kvm_vm *vm; struct kvm_run *run; + struct kvm_vcpu *vcpu; struct kvm_x86_state *state; struct ucall uc; int stage; @@ -175,22 +175,22 @@ int main(int argc, char *argv[]) } /* Create VM */ - vm = vm_create_default(VCPU_ID, 0, guest_code); - run = vcpu_state(vm, VCPU_ID); + vm = vm_create_with_one_vcpu(&vcpu, guest_code); + run = vcpu->run; - vcpu_regs_get(vm, VCPU_ID, ®s1); + vcpu_regs_get(vm, vcpu->id, ®s1); vcpu_alloc_vmx(vm, &vmx_pages_gva); - vcpu_args_set(vm, VCPU_ID, 1, vmx_pages_gva); + vcpu_args_set(vm, vcpu->id, 1, vmx_pages_gva); for (stage = 1;; stage++) { - _vcpu_run(vm, VCPU_ID); + vcpu_run(vm, vcpu->id); TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, "Stage %d: unexpected exit reason: %u (%s),\n", stage, run->exit_reason, exit_reason_str(run->exit_reason)); - switch (get_ucall(vm, VCPU_ID, &uc)) { + switch (get_ucall(vm, vcpu->id, &uc)) { case UCALL_ABORT: TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0], __FILE__, uc.args[1]); @@ -232,22 +232,22 @@ int main(int argc, char *argv[]) stage, uc.args[4], uc.args[5]); } - state = vcpu_save_state(vm, VCPU_ID); + state = vcpu_save_state(vm, vcpu->id); memset(®s1, 0, sizeof(regs1)); - vcpu_regs_get(vm, VCPU_ID, ®s1); + vcpu_regs_get(vm, vcpu->id, ®s1); kvm_vm_release(vm); /* Restore state in a new VM. */ - kvm_vm_restart(vm); - vm_vcpu_add(vm, VCPU_ID); - vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid()); - vcpu_load_state(vm, VCPU_ID, state); - run = vcpu_state(vm, VCPU_ID); + vcpu = vm_recreate_with_one_vcpu(vm); + + vcpu_set_cpuid(vm, vcpu->id, kvm_get_supported_cpuid()); + vcpu_load_state(vm, vcpu->id, state); + run = vcpu->run; kvm_x86_state_cleanup(state); memset(®s2, 0, sizeof(regs2)); - vcpu_regs_get(vm, VCPU_ID, ®s2); + vcpu_regs_get(vm, vcpu->id, ®s2); TEST_ASSERT(!memcmp(®s1, ®s2, sizeof(regs2)), "Unexpected register values after vcpu_load_state; rdi: %lx rsi: %lx", (ulong) regs2.rdi, (ulong) regs2.rsi); -- 2.36.0.464.gb9c8b46e94-goog