Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Marc Zyngier <maz@kernel.org>,
	Oliver Upton <oliver.upton@linux.dev>,
	 Paolo Bonzini <pbonzini@redhat.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	 Janosch Frank <frankja@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	 Sean Christopherson <seanjc@google.com>,
	Anup Patel <anup@brainfault.org>,
	 Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	 Albert Ou <aou@eecs.berkeley.edu>
Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	 kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,
	 linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	 Ackerley Tng <ackerleytng@google.com>
Subject: [PATCH 06/18] KVM: selftests: Rework platform_info_test to actually verify #GP
Date: Thu, 14 Mar 2024 16:26:25 -0700	[thread overview]
Message-ID: <20240314232637.2538648-7-seanjc@google.com> (raw)
In-Reply-To: <20240314232637.2538648-1-seanjc@google.com>

Rework platform_info_test to actually handle and verify the expected #GP
on RDMSR when the associated KVM capability is disabled.  Currently, the
test _deliberately_ doesn't handle the #GP, and instead lets it escalated
to a triple fault shutdown.

In addition to verifying that KVM generates the correct fault, handling
the #GP will be necessary (without even more shenanigans) when a future
change to the core KVM selftests library configures the IDT and exception
handlers by default (the test subtly relies on the IDT limit being '0').

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 .../selftests/kvm/x86_64/platform_info_test.c | 66 +++++++++----------
 1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/tools/testing/selftests/kvm/x86_64/platform_info_test.c b/tools/testing/selftests/kvm/x86_64/platform_info_test.c
index cdad7e2124c8..6300bb70f028 100644
--- a/tools/testing/selftests/kvm/x86_64/platform_info_test.c
+++ b/tools/testing/selftests/kvm/x86_64/platform_info_test.c
@@ -26,40 +26,18 @@
 static void guest_code(void)
 {
 	uint64_t msr_platform_info;
+	uint8_t vector;
 
-	for (;;) {
-		msr_platform_info = rdmsr(MSR_PLATFORM_INFO);
-		GUEST_ASSERT_EQ(msr_platform_info & MSR_PLATFORM_INFO_MAX_TURBO_RATIO,
-				MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
-		GUEST_SYNC(0);
-		asm volatile ("inc %r11");
-	}
-}
+	GUEST_SYNC(true);
+	msr_platform_info = rdmsr(MSR_PLATFORM_INFO);
+	GUEST_ASSERT_EQ(msr_platform_info & MSR_PLATFORM_INFO_MAX_TURBO_RATIO,
+			MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
 
-static void test_msr_platform_info_enabled(struct kvm_vcpu *vcpu)
-{
-	struct ucall uc;
+	GUEST_SYNC(false);
+	vector = rdmsr_safe(MSR_PLATFORM_INFO, &msr_platform_info);
+	GUEST_ASSERT_EQ(vector, GP_VECTOR);
 
-	vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, true);
-	vcpu_run(vcpu);
-	TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
-
-	switch (get_ucall(vcpu, &uc)) {
-	case UCALL_SYNC:
-		break;
-	case UCALL_ABORT:
-		REPORT_GUEST_ASSERT(uc);
-	default:
-		TEST_FAIL("Unexpected ucall %lu", uc.cmd);
-		break;
-	}
-}
-
-static void test_msr_platform_info_disabled(struct kvm_vcpu *vcpu)
-{
-	vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, false);
-	vcpu_run(vcpu);
-	TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN);
+	GUEST_DONE();
 }
 
 int main(int argc, char *argv[])
@@ -67,16 +45,38 @@ int main(int argc, char *argv[])
 	struct kvm_vcpu *vcpu;
 	struct kvm_vm *vm;
 	uint64_t msr_platform_info;
+	struct ucall uc;
 
 	TEST_REQUIRE(kvm_has_cap(KVM_CAP_MSR_PLATFORM_INFO));
 
 	vm = vm_create_with_one_vcpu(&vcpu, guest_code);
 
+	vm_init_descriptor_tables(vm);
+	vcpu_init_descriptor_tables(vcpu);
+
 	msr_platform_info = vcpu_get_msr(vcpu, MSR_PLATFORM_INFO);
 	vcpu_set_msr(vcpu, MSR_PLATFORM_INFO,
 		     msr_platform_info | MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
-	test_msr_platform_info_enabled(vcpu);
-	test_msr_platform_info_disabled(vcpu);
+
+	for (;;) {
+		vcpu_run(vcpu);
+		TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
+
+		switch (get_ucall(vcpu, &uc)) {
+		case UCALL_SYNC:
+			vm_enable_cap(vm, KVM_CAP_MSR_PLATFORM_INFO, uc.args[1]);
+			break;
+		case UCALL_DONE:
+			goto done;
+		case UCALL_ABORT:
+			REPORT_GUEST_ASSERT(uc);
+		default:
+			TEST_FAIL("Unexpected ucall %lu", uc.cmd);
+			break;
+		}
+	}
+
+done:
 	vcpu_set_msr(vcpu, MSR_PLATFORM_INFO, msr_platform_info);
 
 	kvm_vm_free(vm);
-- 
2.44.0.291.gc1ea87d7ee-goog


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  parent reply	other threads:[~2024-03-14 23:29 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14 23:26 [PATCH 00/18] KVM: selftests: Clean up x86's DT initialization Sean Christopherson
2024-03-14 23:26 ` [PATCH 01/18] Revert "kvm: selftests: move base kvm_util.h declarations to kvm_util_base.h" Sean Christopherson
2024-03-28  2:49   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 02/18] KVM: sefltests: Add kvm_util_types.h to hold common types, e.g. vm_vaddr_t Sean Christopherson
2024-03-28  2:48   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 03/18] KVM: selftests: Move GDT, IDT, and TSS fields to x86's kvm_vm_arch Sean Christopherson
2024-03-28  2:48   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 04/18] KVM: selftests: Fix off-by-one initialization of GDT limit Sean Christopherson
2024-03-14 23:26 ` [PATCH 05/18] KVM: selftests: Move platform_info_test's main assert into guest code Sean Christopherson
2024-03-14 23:26 ` Sean Christopherson [this message]
2024-03-14 23:26 ` [PATCH 07/18] KVM: selftests: Explicitly clobber the IDT in the "delete memslot" testcase Sean Christopherson
2024-03-14 23:26 ` [PATCH 08/18] KVM: selftests: Move x86's descriptor table helpers "up" in processor.c Sean Christopherson
2024-03-28  2:47   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 09/18] KVM: selftests: Rename x86's vcpu_setup() to vcpu_init_sregs() Sean Christopherson
2024-03-28  2:47   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 10/18] KVM: selftests: Init IDT and exception handlers for all VMs/vCPUs on x86 Sean Christopherson
2024-03-28  2:46   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 11/18] KVM: selftests: Map x86's exception_handlers at VM creation, not vCPU setup Sean Christopherson
2024-03-28  2:35   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 12/18] KVM: selftests: Allocate x86's GDT during VM creation Sean Christopherson
2024-03-28  2:33   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 13/18] KVM: selftests: Drop superfluous switch() on vm->mode in vcpu_init_sregs() Sean Christopherson
2024-03-28  2:28   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 14/18] KVM: selftests: Fold x86's descriptor tables helpers into vcpu_init_sregs() Sean Christopherson
2024-03-28  2:50   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 15/18] KVM: selftests: Allocate x86's TSS at VM creation Sean Christopherson
2024-03-28  2:50   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 16/18] KVM: selftests: Add macro for TSS selector, rename up code/data macros Sean Christopherson
2024-03-28  2:52   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 17/18] KVM: selftests: Init x86's segments during VM creation Sean Christopherson
2024-03-28  2:51   ` Ackerley Tng
2024-03-14 23:26 ` [PATCH 18/18] KVM: selftests: Drop @selector from segment helpers Sean Christopherson
2024-03-28  2:51   ` Ackerley Tng
2024-04-29 20:45 ` [PATCH 00/18] KVM: selftests: Clean up x86's DT initialization Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240314232637.2538648-7-seanjc@google.com \
    --to=seanjc@google.com \
    --cc=ackerleytng@google.com \
    --cc=anup@brainfault.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=borntraeger@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm-riscv@lists.infradead.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox