From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Michael Roth <michael.roth@amd.com>
Subject: [PATCH gmem 2/5] KVM: selftests: Handle memslot splits in private mem conversions test
Date: Mon, 23 Oct 2023 12:15:29 -0700 [thread overview]
Message-ID: <20231023191532.2405326-3-seanjc@google.com> (raw)
In-Reply-To: <20231023191532.2405326-1-seanjc@google.com>
Rework the SYNC_{SHARED,PRIVATE} handling in the private memory conversion
test to play nice with ranges that are covered by multiple memslots. This
will allow letting the user specify the number of memslots, and more
importantly allow testing KVM_SET_MEMORY_ATTRIBUTES calls that also split
across memslots.
Opportunistically update the error messages to clarify whether the assert
fired in the guest vs. host.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
.../kvm/x86_64/private_mem_conversions_test.c | 44 +++++++++++--------
1 file changed, 25 insertions(+), 19 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..c3992a295b5a 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
@@ -28,25 +28,25 @@
#define PER_CPU_DATA_SIZE ((uint64_t)(SZ_2M + PAGE_SIZE))
/* Horrific macro so that the line info is captured accurately :-( */
-#define memcmp_g(gpa, pattern, size) \
-do { \
- uint8_t *mem = (uint8_t *)gpa; \
- size_t i; \
- \
- for (i = 0; i < size; i++) \
- __GUEST_ASSERT(mem[i] == pattern, \
- "Expected 0x%x at offset %lu (gpa 0x%llx), got 0x%x", \
- pattern, i, gpa + i, mem[i]); \
+#define memcmp_g(gpa, pattern, size) \
+do { \
+ uint8_t *mem = (uint8_t *)gpa; \
+ size_t i; \
+ \
+ for (i = 0; i < size; i++) \
+ __GUEST_ASSERT(mem[i] == pattern, \
+ "Guest expected 0x%x at offset %lu (gpa 0x%llx), got 0x%x", \
+ pattern, i, gpa + i, mem[i]); \
} while (0)
-static void memcmp_h(uint8_t *mem, uint8_t pattern, size_t size)
+static void memcmp_h(uint8_t *mem, uint64_t gpa, uint8_t pattern, size_t size)
{
size_t i;
for (i = 0; i < size; i++)
TEST_ASSERT(mem[i] == pattern,
- "Expected 0x%x at offset %lu, got 0x%x",
- pattern, i, mem[i]);
+ "Host expected 0x%x at gpa 0x%lx, got 0x%x",
+ pattern, gpa + i, mem[i]);
}
/*
@@ -335,19 +335,25 @@ static void *__test_mem_conversions(void *__vcpu)
case UCALL_ABORT:
REPORT_GUEST_ASSERT(uc);
case UCALL_SYNC: {
- uint8_t *hva = addr_gpa2hva(vm, uc.args[1]);
- uint64_t size = uc.args[2];
+ uint64_t gpa = uc.args[1];
+ size_t size = uc.args[2];
+ size_t i;
TEST_ASSERT(uc.args[0] == SYNC_SHARED ||
uc.args[0] == SYNC_PRIVATE,
"Unknown sync command '%ld'", uc.args[0]);
- /* In all cases, the host should observe the shared data. */
- memcmp_h(hva, uc.args[3], size);
+ for (i = 0; i < size; i += vm->page_size) {
+ size_t nr_bytes = min_t(size_t, vm->page_size, size - i);
+ uint8_t *hva = addr_gpa2hva(vm, gpa + i);
- /* For shared, write the new pattern to guest memory. */
- if (uc.args[0] == SYNC_SHARED)
- memset(hva, uc.args[4], size);
+ /* In all cases, the host should observe the shared data. */
+ memcmp_h(hva, gpa + i, uc.args[3], nr_bytes);
+
+ /* For shared, write the new pattern to guest memory. */
+ if (uc.args[0] == SYNC_SHARED)
+ memset(hva, uc.args[4], nr_bytes);
+ }
break;
}
case UCALL_DONE:
--
2.42.0.758.gaed0368e0e-goog
next prev parent reply other threads:[~2023-10-23 19:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-23 19:15 [PATCH gmem 0/5] KVM: selftests: Fix multiple memslots in conv test Sean Christopherson
2023-10-23 19:15 ` [PATCH gmem 1/5] KVM: selftests: Rework fallocate() helper to work across multiple memslots Sean Christopherson
2023-10-23 19:15 ` Sean Christopherson [this message]
2023-10-23 19:15 ` [PATCH gmem 3/5] KVM: selftests: Let user specify nr of memslots in private mem conversion Sean Christopherson
2023-10-23 19:15 ` [PATCH gmem 4/5] KVM: selftests: Use dedicated pattern for testing that mem is shared by default Sean Christopherson
2023-10-23 19:15 ` [PATCH gmem 5/5] KVM: selftests: Verify default pattern was written in private mem conversion 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=20231023191532.2405326-3-seanjc@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=pbonzini@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
all inboxes | Powered by JetHome®