From: Michael Roth <michael.roth@amd.com>
To: <kvm@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <seanjc@google.com>,
<pbonzini@redhat.com>, <vannapurve@google.com>
Subject: [PATCH gmem] KVM: selftests: Fix gmem conversion tests for multiple vCPUs
Date: Mon, 16 Oct 2023 13:47:37 -0500 [thread overview]
Message-ID: <20231016184737.1027930-1-michael.roth@amd.com> (raw)
Currently the private_mem_conversions_test crashes if invoked with the
-n <num_vcpus> option without also specifying multiple memslots via -m.
This is because the current implementation assumes -m is specified and
always sets up the per-vCPU memory with a dedicated memslot for each
vCPU. When -m is not specified, the test skips setting up
memslots/memory for secondary vCPUs.
The current code does seem to try to handle using a single memslot for
multiple vCPUs in some places, e.g. the call-site, but
test_mem_conversions() is missing the important bit of sizing the single
memslot appropriately to handle all the per-vCPU memory. Implement that
handling.
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
.../kvm/x86_64/private_mem_conversions_test.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c
index c04e7d61a585..5eb693fead33 100644
--- a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c
+++ b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c
@@ -388,10 +388,14 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type, uint32_t
gmem_flags = 0;
memfd = vm_create_guest_memfd(vm, memfd_size, gmem_flags);
- for (i = 0; i < nr_memslots; i++)
- vm_mem_add(vm, src_type, BASE_DATA_GPA + size * i,
- BASE_DATA_SLOT + i, size / vm->page_size,
- KVM_MEM_PRIVATE, memfd, size * i);
+ if (nr_memslots == 1)
+ vm_mem_add(vm, src_type, BASE_DATA_GPA, BASE_DATA_SLOT,
+ memfd_size / vm->page_size, KVM_MEM_PRIVATE, memfd, 0);
+ else
+ for (i = 0; i < nr_memslots; i++)
+ vm_mem_add(vm, src_type, BASE_DATA_GPA + size * i,
+ BASE_DATA_SLOT + i, size / vm->page_size,
+ KVM_MEM_PRIVATE, memfd, size * i);
for (i = 0; i < nr_vcpus; i++) {
uint64_t gpa = BASE_DATA_GPA + i * size;
--
2.25.1
next reply other threads:[~2023-10-16 18:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-16 18:47 Michael Roth [this message]
2023-10-18 1:10 ` Sean Christopherson
2023-10-23 18:06 ` 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=20231016184737.1027930-1-michael.roth@amd.com \
--to=michael.roth@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=vannapurve@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
all inboxes | Powered by JetHome®