From: Ben Gardon <bgardon@google.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
linux-kselftest@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Cannon Matthews <cannonmatthews@google.com>,
Peter Xu <peterx@redhat.com>, Andrew Jones <drjones@redhat.com>,
Peter Shier <pshier@google.com>, Oliver Upton <oupton@google.com>,
Ben Gardon <bgardon@google.com>
Subject: [PATCH v4 05/10] KVM: selftests: Pass args to vCPU in global vCPU args struct
Date: Thu, 23 Jan 2020 10:04:31 -0800 [thread overview]
Message-ID: <20200123180436.99487-6-bgardon@google.com> (raw)
In-Reply-To: <20200123180436.99487-1-bgardon@google.com>
In preparation for supporting multiple vCPUs in the demand paging test,
pass arguments to the vCPU in a consolidated global struct instead of
syncing multiple globals.
Signed-off-by: Ben Gardon <bgardon@google.com>
---
.../selftests/kvm/demand_paging_test.c | 38 +++++++++++++------
1 file changed, 27 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
index 9d7514e96a639..9e2a5f7dfa140 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -42,7 +42,6 @@
*/
static uint64_t host_page_size;
static uint64_t guest_page_size;
-static uint64_t guest_num_pages;
static char *guest_data_prototype;
@@ -59,18 +58,30 @@ static uint64_t guest_test_phys_mem;
*/
static uint64_t guest_test_virt_mem = DEFAULT_GUEST_TEST_MEM;
+struct vcpu_args {
+ uint64_t gva;
+ uint64_t pages;
+
+ /* Only used by the host userspace part of the vCPU thread */
+ int vcpu_id;
+ struct kvm_vm *vm;
+};
+
+static struct vcpu_args vcpu_args;
+
/*
* Continuously write to the first 8 bytes of each page in the demand paging
* memory region.
*/
static void guest_code(void)
{
+ uint64_t gva = vcpu_args.gva;
+ uint64_t pages = vcpu_args.pages;
int i;
- for (i = 0; i < guest_num_pages; i++) {
- uint64_t addr = guest_test_virt_mem;
+ for (i = 0; i < pages; i++) {
+ uint64_t addr = gva + (i * guest_page_size);
- addr += i * guest_page_size;
addr &= ~(host_page_size - 1);
*(uint64_t *)addr = 0x0123456789ABCDEF;
}
@@ -85,15 +96,16 @@ static uint64_t host_num_pages;
static void *vcpu_worker(void *data)
{
int ret;
- struct kvm_vm *vm = data;
+ struct kvm_vm *vm = vcpu_args.vm;
+ int vcpu_id = vcpu_args.vcpu_id;
struct kvm_run *run;
- run = vcpu_state(vm, VCPU_ID);
+ run = vcpu_state(vm, vcpu_id);
/* Let the guest access its memory */
- ret = _vcpu_run(vm, VCPU_ID);
+ ret = _vcpu_run(vm, vcpu_id);
TEST_ASSERT(ret == 0, "vcpu_run failed: %d\n", ret);
- if (get_ucall(vm, VCPU_ID, NULL) != UCALL_SYNC) {
+ if (get_ucall(vm, vcpu_id, NULL) != UCALL_SYNC) {
TEST_ASSERT(false,
"Invalid guest sync status: exit_reason=%s\n",
exit_reason_str(run->exit_reason));
@@ -285,6 +297,7 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
pthread_t uffd_handler_thread;
int pipefd[2];
struct kvm_vm *vm;
+ uint64_t guest_num_pages;
int r;
/*
@@ -370,10 +383,13 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
/* Export the shared variables to the guest */
sync_global_to_guest(vm, host_page_size);
sync_global_to_guest(vm, guest_page_size);
- sync_global_to_guest(vm, guest_test_virt_mem);
- sync_global_to_guest(vm, guest_num_pages);
- pthread_create(&vcpu_thread, NULL, vcpu_worker, vm);
+ vcpu_args.vm = vm;
+ vcpu_args.vcpu_id = VCPU_ID;
+ vcpu_args.gva = guest_test_virt_mem;
+ vcpu_args.pages = guest_num_pages;
+ sync_global_to_guest(vm, vcpu_args);
+ pthread_create(&vcpu_thread, NULL, vcpu_worker, &vcpu_args);
/* Wait for the vcpu thread to quit */
pthread_join(vcpu_thread, NULL);
--
2.25.0.341.g760bfbb309-goog
next prev parent reply other threads:[~2020-01-23 18:05 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-23 18:04 [PATCH v4 00/10] Create a userfaultfd demand paging test Ben Gardon
2020-01-23 18:04 ` [PATCH v4 01/10] KVM: selftests: Create a " Ben Gardon
2020-01-24 9:49 ` Andrew Jones
2020-01-27 9:18 ` Thomas Huth
2020-01-23 18:04 ` [PATCH v4 02/10] KVM: selftests: Add demand paging content to the " Ben Gardon
2020-01-23 18:04 ` [PATCH v4 03/10] KVM: selftests: Add configurable demand paging delay Ben Gardon
2020-01-23 18:04 ` [PATCH v4 04/10] KVM: selftests: Add memory size parameter to the demand paging test Ben Gardon
2020-01-24 10:01 ` Andrew Jones
2020-01-23 18:04 ` Ben Gardon [this message]
2020-01-23 18:04 ` [PATCH v4 06/10] KVM: selftests: Add support for vcpu_args_set to aarch64 and s390x Ben Gardon
2020-01-24 9:03 ` Paolo Bonzini
2020-01-24 9:35 ` Andrew Jones
2020-01-24 9:44 ` Paolo Bonzini
2020-01-24 10:45 ` Andrew Jones
2020-01-24 18:33 ` Christian Borntraeger
2020-01-25 9:34 ` Paolo Bonzini
2020-01-27 8:38 ` Andrew Jones
2020-01-27 9:01 ` Thomas Huth
2020-01-23 18:04 ` [PATCH v4 07/10] KVM: selftests: Support multiple vCPUs in demand paging test Ben Gardon
2020-01-24 10:16 ` Andrew Jones
2020-01-24 10:49 ` Andrew Jones
2020-01-25 9:39 ` Paolo Bonzini
2020-01-27 8:39 ` Andrew Jones
2020-01-23 18:04 ` [PATCH v4 08/10] KVM: selftests: Time guest demand paging Ben Gardon
2020-01-24 10:21 ` Andrew Jones
2020-01-23 18:04 ` [PATCH v4 09/10] KVM: selftests: Stop memslot creation in KVM internal memslot region Ben Gardon
2020-01-24 8:58 ` Paolo Bonzini
2020-01-24 18:41 ` Ben Gardon
2020-01-25 9:37 ` Paolo Bonzini
2020-01-27 17:28 ` Ben Gardon
2020-01-23 18:04 ` [PATCH v4 10/10] KVM: selftests: Move memslot 0 above KVM internal memslots Ben Gardon
2020-01-24 9:01 ` Paolo Bonzini
2020-01-24 18:53 ` Ben Gardon
2020-01-27 9:42 ` Thomas Huth
2020-01-24 9:03 ` [PATCH v4 00/10] Create a userfaultfd demand paging test Paolo Bonzini
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=20200123180436.99487-6-bgardon@google.com \
--to=bgardon@google.com \
--cc=cannonmatthews@google.com \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=pshier@google.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;
as well as URLs for NNTP newsgroup(s).