From: Ben Gardon <bgardon@google.com>
To: 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>,
Ben Gardon <bgardon@google.com>
Subject: [PATCH 3/9] KVM: selftests: Add memory size parameter to the demand paging test
Date: Fri, 27 Sep 2019 09:18:31 -0700 [thread overview]
Message-ID: <20190927161836.57978-4-bgardon@google.com> (raw)
In-Reply-To: <20190927161836.57978-1-bgardon@google.com>
Add an argument to allow the demand paging test to work on larger and
smaller guest sizes.
Signed-off-by: Ben Gardon <bgardon@google.com>
---
.../selftests/kvm/demand_paging_test.c | 55 ++++++++++++-------
1 file changed, 34 insertions(+), 21 deletions(-)
diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
index 61ba4e6a8214a..19982a33a0ca2 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -32,6 +32,8 @@
/* Default guest test virtual memory offset */
#define DEFAULT_GUEST_TEST_MEM 0xc0000000
+#define DEFAULT_GUEST_TEST_MEM_SIZE (1 << 30) /* 1G */
+
#define __NR_userfaultfd 323
/*
@@ -255,10 +257,9 @@ static int setup_demand_paging(struct kvm_vm *vm,
return 0;
}
-#define GUEST_MEM_SHIFT 30 /* 1G */
#define PAGE_SHIFT_4K 12
-static void run_test(enum vm_guest_mode mode)
+static void run_test(enum vm_guest_mode mode, uint64_t guest_memory_bytes)
{
pthread_t vcpu_thread;
pthread_t uffd_handler_thread;
@@ -266,33 +267,40 @@ static void run_test(enum vm_guest_mode mode)
int r;
/*
- * We reserve page table for 2 times of extra dirty mem which
- * will definitely cover the original (1G+) test range. Here
- * we do the calculation with 4K page size which is the
- * smallest so the page number will be enough for all archs
- * (e.g., 64K page size guest will need even less memory for
- * page tables).
+ * We reserve page table for twice the ammount of memory we intend
+ * to use in the test region for demand paging. Here we do the
+ * calculation with 4K page size which is the smallest so the page
+ * number will be enough for all archs. (e.g., 64K page size guest
+ * will need even less memory for page tables).
*/
vm = create_vm(mode, VCPU_ID,
- 2ul << (GUEST_MEM_SHIFT - PAGE_SHIFT_4K),
+ (2 * guest_memory_bytes) >> PAGE_SHIFT_4K,
guest_code);
guest_page_size = vm_get_page_size(vm);
- /*
- * A little more than 1G of guest page sized pages. Cover the
- * case where the size is not aligned to 64 pages.
- */
- guest_num_pages = (1ul << (GUEST_MEM_SHIFT -
- vm_get_page_shift(vm))) + 16;
+
+ TEST_ASSERT(guest_memory_bytes % guest_page_size == 0,
+ "Guest memory size is not guest page size aligned.");
+
+ guest_num_pages = guest_memory_bytes / guest_page_size;
+
#ifdef __s390x__
/* Round up to multiple of 1M (segment size) */
guest_num_pages = (guest_num_pages + 0xff) & ~0xffUL;
#endif
+ /*
+ * If there should be more memory in the guest test region than there
+ * can be pages in the guest, it will definitely cause problems.
+ */
+ TEST_ASSERT(guest_num_pages < vm_get_max_gfn(vm),
+ "Requested more guest memory than address space allows.\n"
+ " guest pages: %lx max gfn: %lx\n",
+ guest_num_pages, vm_get_max_gfn(vm));
host_page_size = getpagesize();
- host_num_pages = (guest_num_pages * guest_page_size) / host_page_size +
- !!((guest_num_pages * guest_page_size) %
- host_page_size);
+ TEST_ASSERT(guest_memory_bytes % host_page_size == 0,
+ "Guest memory size is not host page size aligned.");
+ host_num_pages = guest_memory_bytes / host_page_size;
guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
guest_page_size;
@@ -369,7 +377,7 @@ static void help(char *name)
int i;
puts("");
- printf("usage: %s [-h] [-m mode]\n", name);
+ printf("usage: %s [-h] [-m mode] [-b bytes test memory]\n", name);
printf(" -m: specify the guest mode ID to test\n"
" (default: test all supported modes)\n"
" This option may be used multiple times.\n"
@@ -378,6 +386,8 @@ static void help(char *name)
printf(" %d: %s%s\n", i, vm_guest_mode_string(i),
vm_guest_mode_params[i].supported ? " (supported)" : "");
}
+ printf(" -b: specify the number of bytes of memory which should be\n"
+ " allocated to the guest.\n");
puts("");
exit(0);
}
@@ -385,6 +395,7 @@ static void help(char *name)
int main(int argc, char *argv[])
{
bool mode_selected = false;
+ uint64_t guest_memory_bytes = DEFAULT_GUEST_TEST_MEM_SIZE;
unsigned int mode;
int opt, i;
#ifdef __aarch64__
@@ -410,7 +421,7 @@ int main(int argc, char *argv[])
vm_guest_mode_params_init(VM_MODE_P40V48_4K, true, true);
#endif
- while ((opt = getopt(argc, argv, "hm:")) != -1) {
+ while ((opt = getopt(argc, argv, "hm:b:")) != -1) {
switch (opt) {
case 'm':
if (!mode_selected) {
@@ -423,6 +434,8 @@ int main(int argc, char *argv[])
"Guest mode ID %d too big", mode);
vm_guest_mode_params[mode].enabled = true;
break;
+ case 'b':
+ guest_memory_bytes = strtoull(optarg, NULL, 0);
case 'h':
default:
help(argv[0]);
@@ -436,7 +449,7 @@ int main(int argc, char *argv[])
TEST_ASSERT(vm_guest_mode_params[i].supported,
"Guest mode ID %d (%s) not supported.",
i, vm_guest_mode_string(i));
- run_test(i);
+ run_test(i, guest_memory_bytes);
}
return 0;
--
2.23.0.444.g18eeb5a265-goog
next prev parent reply other threads:[~2019-09-27 16:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-27 16:18 [PATCH 0/9] Create a userfaultfd demand paging test Ben Gardon
2019-09-27 16:18 ` [PATCH 1/9] KVM: selftests: Create a " Ben Gardon
2019-09-27 16:18 ` [PATCH 2/9] KVM: selftests: Add demand paging content to the " Ben Gardon
2019-09-29 7:11 ` Peter Xu
2019-09-27 16:18 ` Ben Gardon [this message]
2019-09-27 16:18 ` [PATCH 4/9] KVM: selftests: Pass args to vCPU instead of using globals Ben Gardon
2019-10-03 7:38 ` Andrew Jones
2019-09-27 16:18 ` [PATCH 5/9] KVM: selftests: Support multiple vCPUs in demand paging test Ben Gardon
2019-09-27 16:18 ` [PATCH 6/9] KVM: selftests: Time guest demand paging Ben Gardon
2019-09-27 16:18 ` [PATCH 7/9] KVM: selftests: Add parameter to _vm_create for memslot 0 base paddr Ben Gardon
2019-10-03 8:10 ` Andrew Jones
2019-09-27 16:18 ` [PATCH 8/9] KVM: selftests: Support large VMs in demand paging test Ben Gardon
2019-09-29 7:22 ` [PATCH 0/9] Create a userfaultfd " Peter Xu
2019-09-30 17:02 ` Ben Gardon
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=20190927161836.57978-4-bgardon@google.com \
--to=bgardon@google.com \
--cc=cannonmatthews@google.com \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterx@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;
as well as URLs for NNTP newsgroup(s).