All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaron Lewis <aaronlewis@google.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com,
	Aaron Lewis <aaronlewis@google.com>
Subject: [PATCH 6/8] KVM: selftests: Add additional pages to the guest to accommodate ucall
Date: Wed,  1 Mar 2023 05:34:23 +0000	[thread overview]
Message-ID: <20230301053425.3880773-7-aaronlewis@google.com> (raw)
In-Reply-To: <20230301053425.3880773-1-aaronlewis@google.com>

Add additional pages to the guest to account for the number of pages
the ucall framework uses.

This is done in preparation for adding string formatting options to
the guest through ucall helpers.

Signed-off-by: Aaron Lewis <aaronlewis@google.com>
---
 tools/testing/selftests/kvm/include/ucall_common.h | 1 +
 tools/testing/selftests/kvm/lib/kvm_util.c         | 4 ++++
 tools/testing/selftests/kvm/lib/ucall_common.c     | 5 +++++
 3 files changed, 10 insertions(+)

diff --git a/tools/testing/selftests/kvm/include/ucall_common.h b/tools/testing/selftests/kvm/include/ucall_common.h
index 1a6aaef5ccae..0b1fde23729b 100644
--- a/tools/testing/selftests/kvm/include/ucall_common.h
+++ b/tools/testing/selftests/kvm/include/ucall_common.h
@@ -34,6 +34,7 @@ void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu);
 void ucall(uint64_t cmd, int nargs, ...);
 uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc);
 void ucall_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa);
+int ucall_header_size(void);
 
 /*
  * Perform userspace call without any associated data.  This bare call avoids
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 3ea24a5f4c43..e1d6a2f40d2d 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -307,6 +307,7 @@ static uint64_t vm_nr_pages_required(enum vm_guest_mode mode,
 				     uint32_t nr_runnable_vcpus,
 				     uint64_t extra_mem_pages)
 {
+	uint64_t page_size = vm_guest_mode_params[mode].page_size;
 	uint64_t nr_pages;
 
 	TEST_ASSERT(nr_runnable_vcpus,
@@ -335,6 +336,9 @@ static uint64_t vm_nr_pages_required(enum vm_guest_mode mode,
 	 */
 	nr_pages += (nr_pages + extra_mem_pages) / PTES_PER_MIN_PAGE * 2;
 
+	/* Account for the number of pages needed by ucall. */
+	nr_pages += align_up(ucall_header_size(), page_size) / page_size;
+
 	return vm_adjust_num_guest_pages(mode, nr_pages);
 }
 
diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c
index 2f0e2ea941cc..b6a75858fe0d 100644
--- a/tools/testing/selftests/kvm/lib/ucall_common.c
+++ b/tools/testing/selftests/kvm/lib/ucall_common.c
@@ -11,6 +11,11 @@ struct ucall_header {
 	struct ucall ucalls[KVM_MAX_VCPUS];
 };
 
+int ucall_header_size(void)
+{
+	return sizeof(struct ucall_header);
+}
+
 /*
  * ucall_pool holds per-VM values (global data is duplicated by each VM), it
  * must not be accessed from host code.
-- 
2.40.0.rc0.216.gc4246ad0f0-goog


  parent reply	other threads:[~2023-03-01  5:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-01  5:34 [PATCH 0/8] Add printf and formatted asserts in the guest Aaron Lewis
2023-03-01  5:34 ` [PATCH 1/8] KVM: selftests: Hoist XGETBV and XSETBV to make them more accessible Aaron Lewis
2023-03-01  5:34 ` [PATCH 2/8] KVM: selftests: Add XFEATURE masks to common code Aaron Lewis
2023-03-01  5:34 ` [PATCH 3/8] KVM: selftests: Add strnlen() to the string overrides Aaron Lewis
2023-03-01  5:34 ` [PATCH 4/8] KVM: selftests: Copy printf.c to KVM selftests Aaron Lewis
2023-03-23 22:04   ` Sean Christopherson
2023-04-17 15:59     ` Aaron Lewis
2023-04-18 15:03       ` Sean Christopherson
2023-04-18 16:06         ` Andrew Jones
2023-04-20 17:50           ` Sean Christopherson
2023-04-21  6:03             ` Andrew Jones
2023-03-01  5:34 ` [PATCH 5/8] KVM: selftests: Add vsprintf() " Aaron Lewis
2023-03-23 21:59   ` Sean Christopherson
2023-04-17 16:08     ` Aaron Lewis
2023-04-18 15:04       ` Sean Christopherson
2023-03-01  5:34 ` Aaron Lewis [this message]
2023-03-23 22:07   ` [PATCH 6/8] KVM: selftests: Add additional pages to the guest to accommodate ucall Sean Christopherson
2023-03-01  5:34 ` [PATCH 7/8] KVM: selftests: Add string formatting options to ucall Aaron Lewis
2023-03-01  8:07   ` Shaoqin Huang
2023-03-02 14:52     ` Aaron Lewis
2023-03-23 22:12   ` Sean Christopherson
2023-03-01  5:34 ` [PATCH 8/8] KVM: selftests: Add a selftest for guest prints and formatted asserts Aaron Lewis
2023-03-23 20:57 ` [PATCH 0/8] Add printf and formatted asserts in the guest 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=20230301053425.3880773-7-aaronlewis@google.com \
    --to=aaronlewis@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.