From: Erdem Aktas <erdemaktas@google.com>
To: linux-kselftest@vger.kernel.org
Cc: erdemaktas@google.com, Sean Christopherson <seanjc@google.com>,
Peter Gonda <pgonda@google.com>, Marc Orr <marcorr@google.com>,
Sagi Shahar <sagis@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Shuah Khan <shuah@kernel.org>, Andrew Jones <drjones@redhat.com>,
Ben Gardon <bgardon@google.com>, Peter Xu <peterx@redhat.com>,
Emanuele Giuseppe Esposito <eesposit@redhat.com>,
Eric Auger <eric.auger@redhat.com>,
Ricardo Koller <ricarkol@google.com>,
Zhenzhong Duan <zhenzhong.duan@intel.com>,
Jim Mattson <jmattson@google.com>,
Aaron Lewis <aaronlewis@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Peter Shier <pshier@google.com>, Oliver Upton <oupton@google.com>,
Axel Rasmussen <axelrasmussen@google.com>,
Yanan Wang <wangyanan55@huawei.com>,
"Maciej S. Szmigiero" <maciej.szmigiero@oracle.com>,
David Matlack <dmatlack@google.com>,
Like Xu <like.xu@linux.intel.com>,
open list <linux-kernel@vger.kernel.org>,
"open list:KERNEL VIRTUAL MACHINE (KVM)" <kvm@vger.kernel.org>
Subject: [RFC PATCH 4/4] KVM: selftest: Adding test case for TDX port IO
Date: Mon, 26 Jul 2021 11:37:57 -0700 [thread overview]
Message-ID: <20210726183816.1343022-5-erdemaktas@google.com> (raw)
In-Reply-To: <20210726183816.1343022-1-erdemaktas@google.com>
Verifies TDVMCALL<INSTRUCTION.IO> READ and WRITE operations.
Signed-off-by: Erdem Aktas <erdemaktas@google.com>
Reviewed-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Peter Gonda <pgonda@google.com>
Reviewed-by: Marc Orr <marcorr@google.com>
Reviewed-by: Sagi Shahar <sagis@google.com>
---
.../selftests/kvm/x86_64/tdx_vm_tests.c | 107 ++++++++++++++++++
1 file changed, 107 insertions(+)
diff --git a/tools/testing/selftests/kvm/x86_64/tdx_vm_tests.c b/tools/testing/selftests/kvm/x86_64/tdx_vm_tests.c
index da7ea67b1..7b0b4b378 100644
--- a/tools/testing/selftests/kvm/x86_64/tdx_vm_tests.c
+++ b/tools/testing/selftests/kvm/x86_64/tdx_vm_tests.c
@@ -88,6 +88,112 @@ void verify_td_lifecycle(void)
kvm_vm_free(vm);
printf("\t ... PASSED\n");
}
+
+/*
+ * Verifies IO functionality by writing a |value| to a predefined port.
+ * Verifies that the read value is |value| + 1 from the same port.
+ * If all the tests are passed then write a value to port TDX_TEST_PORT
+ */
+TDX_GUEST_FUNCTION(guest_io_exit)
+{
+ uint64_t data_out, data_in, delta;
+
+ data_out = 0xAB;
+ tdvmcall_io(TDX_TEST_PORT, 1, 1, &data_out);
+ tdvmcall_io(TDX_TEST_PORT, 1, 0, &data_in);
+ delta = data_in - data_out - 1;
+ tdvmcall_io(TDX_TEST_PORT, 1, 1, &delta);
+}
+
+void verify_td_ioexit(void)
+{
+ struct kvm_vm *vm;
+ struct kvm_run *run;
+ uint32_t port_data;
+
+ printf("Verifying TD IO Exit:\n");
+ /* Create a TD VM with no memory.*/
+ vm = __vm_create(VM_MODE_DEFAULT, 0, O_RDWR, KVM_X86_TDX_VM);
+
+ /* Allocate TD guest memory and initialize the TD.*/
+ initialize_td(vm);
+
+ /* Initialize the TD vcpu and copy the test code to the guest memory.*/
+ vm_vcpu_add_tdx(vm, 0);
+
+ /* Setup and initialize VM memory */
+ prepare_source_image(vm, guest_io_exit,
+ TDX_FUNCTION_SIZE(guest_io_exit), 0);
+ finalize_td_memory(vm);
+
+ run = vcpu_state(vm, 0);
+
+ /* Wait for guest to do a IO write */
+ vcpu_run(vm, 0);
+ TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
+ "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
+ run->exit_reason,
+ exit_reason_str(run->exit_reason));
+
+ TEST_ASSERT((run->exit_reason == KVM_EXIT_IO)
+ && (run->io.port == TDX_TEST_PORT)
+ && (run->io.size == 1)
+ && (run->io.direction == 1),
+ "Got an unexpected IO exit values: %u (%s) %d %d %d\n",
+ run->exit_reason,
+ exit_reason_str(run->exit_reason),
+ run->io.port, run->io.size, run->io.direction);
+ port_data = *(uint8_t *)((void *)run + run->io.data_offset);
+
+ printf("\t ... IO WRITE: OK\n");
+ /*
+ * Wait for the guest to do a IO read. Provide the previos written data
+ * + 1 back to the guest
+ */
+ vcpu_run(vm, 0);
+ TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
+ "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n",
+ run->exit_reason,
+ exit_reason_str(run->exit_reason));
+
+ TEST_ASSERT(run->exit_reason == KVM_EXIT_IO &&
+ run->io.port == TDX_TEST_PORT &&
+ run->io.size == 1 &&
+ run->io.direction == 0,
+ "Got an unexpected IO exit values: %u (%s) %d %d %d\n",
+ run->exit_reason,
+ exit_reason_str(run->exit_reason),
+ run->io.port, run->io.size, run->io.direction);
+ *(uint8_t *)((void *)run + run->io.data_offset) = port_data + 1;
+
+ printf("\t ... IO READ: OK\n");
+ /*
+ * Wait for the guest to do a IO write to the TDX_TEST_PORT with the
+ * value of 0. Any value other than 0 means, the guest has not able to
+ * read/write values correctly.
+ */
+ vcpu_run(vm, 0);
+ TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
+ "KVM_EXIT_IO is expected but got an exit_reason: %u (%s)\n",
+ run->exit_reason,
+ exit_reason_str(run->exit_reason));
+
+ TEST_ASSERT(run->exit_reason == KVM_EXIT_IO &&
+ run->io.port == TDX_TEST_PORT &&
+ run->io.size == 1 &&
+ run->io.direction == 1 &&
+ *(uint32_t *)((void *)run + run->io.data_offset) == 0,
+ "Got an unexpected IO exit values: %u (%s) %d %d %d %d\n",
+ run->exit_reason,
+ exit_reason_str(run->exit_reason),
+ run->io.port, run->io.size, run->io.direction,
+ *(uint32_t *)((void *)run + run->io.data_offset));
+
+ printf("\t ... IO verify read/write values: OK\n");
+ kvm_vm_free(vm);
+ printf("\t ... PASSED\n");
+}
+
int main(int argc, char **argv)
{
if (!is_tdx_enabled()) {
@@ -97,6 +203,7 @@ int main(int argc, char **argv)
}
run_in_new_process(&verify_td_lifecycle);
+ run_in_new_process(&verify_td_ioexit);
return 0;
}
--
2.32.0.432.gabb21c7263-goog
next prev parent reply other threads:[~2021-07-26 18:43 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-26 18:37 [RFC PATCH 0/4] TDX KVM selftests Erdem Aktas
2021-07-26 18:37 ` [RFC PATCH 1/4] KVM: selftests: Add support for creating non-default type VMs Erdem Aktas
2021-07-26 22:26 ` David Matlack
2021-07-27 20:47 ` Sean Christopherson
2021-07-28 16:07 ` David Matlack
2021-07-28 20:11 ` Andrew Jones
2021-08-04 6:09 ` Xiaoyao Li
2021-08-04 14:24 ` Maxim Levitsky
2021-08-04 14:42 ` Xiaoyao Li
2021-08-04 14:45 ` Maxim Levitsky
2021-08-04 20:29 ` Erdem Aktas
2021-08-04 23:31 ` Sean Christopherson
2021-07-26 18:37 ` [RFC PATCH 2/4] KVM: selftest: Add helper functions to create TDX VMs Erdem Aktas
2021-07-26 18:37 ` [RFC PATCH 3/4] KVM: selftest: Adding TDX life cycle test Erdem Aktas
2021-07-26 22:42 ` David Matlack
2021-07-26 18:37 ` Erdem Aktas [this message]
2021-07-28 4:02 ` [RFC PATCH 0/4] TDX KVM selftests Duan, Zhenzhong
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=20210726183816.1343022-5-erdemaktas@google.com \
--to=erdemaktas@google.com \
--cc=aaronlewis@google.com \
--cc=axelrasmussen@google.com \
--cc=bgardon@google.com \
--cc=dmatlack@google.com \
--cc=drjones@redhat.com \
--cc=eesposit@redhat.com \
--cc=eric.auger@redhat.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=like.xu@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maciej.szmigiero@oracle.com \
--cc=marcorr@google.com \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=pgonda@google.com \
--cc=pshier@google.com \
--cc=ricarkol@google.com \
--cc=sagis@google.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=vkuznets@redhat.com \
--cc=wangyanan55@huawei.com \
--cc=zhenzhong.duan@intel.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
all inboxes | Powered by JetHome®