All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH] gitignore: Add tags file to .gitignore
@ 2021-06-09 14:02 Siddharth Chandrasekaran
  2021-06-09 14:02 ` [kvm-unit-tests PATCH] x86: Add hyper-v overlay page tests Siddharth Chandrasekaran
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Siddharth Chandrasekaran @ 2021-06-09 14:02 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Siddharth Chandrasekaran, Evgeny Iakovlev, Liran Alon,
	Ioannis Aslanidis, kvm, Siddharth Chandrasekaran

Add ctags tags file to .gitignore so they don't get checked-in
accidentally.

Signed-off-by: Siddharth Chandrasekaran <sidcha@amazon.de>
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 784cb2d..8534fb7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+tags
 .gdbinit
 *.a
 *.d
-- 
2.17.1




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [kvm-unit-tests PATCH] x86: Add hyper-v overlay page tests
  2021-06-09 14:02 [kvm-unit-tests PATCH] gitignore: Add tags file to .gitignore Siddharth Chandrasekaran
@ 2021-06-09 14:02 ` Siddharth Chandrasekaran
  2021-06-09 14:02 ` [kvm-unit-tests PATCH] x86: Fix misspelled KVM parameter in error message Siddharth Chandrasekaran
  2021-06-09 14:23 ` [kvm-unit-tests PATCH] gitignore: Add tags file to .gitignore Paolo Bonzini
  2 siblings, 0 replies; 5+ messages in thread
From: Siddharth Chandrasekaran @ 2021-06-09 14:02 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Siddharth Chandrasekaran, Evgeny Iakovlev, Liran Alon,
	Ioannis Aslanidis, kvm, Siddharth Chandrasekaran

Patch series [1] starts treating hypercall code page as an overlay page
(along with the existing synic event and message pages). Add KVM unit
tests to make sure the underlying page contents are intact with various
overlay workflows.

[1]: https://www.spinics.net/lists/kvm/msg244569.html

Signed-off-by: Siddharth Chandrasekaran <sidcha@amazon.de>
---
 x86/Makefile.common  |  3 ++
 x86/hyperv.h         |  1 +
 x86/hyperv_overlay.c | 96 ++++++++++++++++++++++++++++++++++++++++++++
 x86/unittests.cfg    |  5 +++
 4 files changed, 105 insertions(+)
 create mode 100644 x86/hyperv_overlay.c

diff --git a/x86/Makefile.common b/x86/Makefile.common
index 55f7f28..85dc427 100644
--- a/x86/Makefile.common
+++ b/x86/Makefile.common
@@ -62,6 +62,7 @@ tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \
                $(TEST_DIR)/init.flat $(TEST_DIR)/smap.flat \
                $(TEST_DIR)/hyperv_synic.flat $(TEST_DIR)/hyperv_stimer.flat \
                $(TEST_DIR)/hyperv_connections.flat \
+               $(TEST_DIR)/hyperv_overlay.flat \
                $(TEST_DIR)/umip.flat $(TEST_DIR)/tsx-ctrl.flat
 
 test_cases: $(tests-common) $(tests)
@@ -82,6 +83,8 @@ $(TEST_DIR)/hyperv_stimer.elf: $(TEST_DIR)/hyperv.o
 
 $(TEST_DIR)/hyperv_connections.elf: $(TEST_DIR)/hyperv.o
 
+$(TEST_DIR)/hyperv_overlay.elf: $(TEST_DIR)/hyperv.o
+
 arch_clean:
 	$(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \
 	$(TEST_DIR)/.*.d lib/x86/.*.d \
diff --git a/x86/hyperv.h b/x86/hyperv.h
index e135221..6f69c29 100644
--- a/x86/hyperv.h
+++ b/x86/hyperv.h
@@ -52,6 +52,7 @@
 #define HV_X64_MSR_STIMER3_CONFIG               0x400000B6
 #define HV_X64_MSR_STIMER3_COUNT                0x400000B7
 
+#define HV_OVERLAY_ENABLE                       (1ULL << 0)
 #define HV_SYNIC_CONTROL_ENABLE                 (1ULL << 0)
 #define HV_SYNIC_SIMP_ENABLE                    (1ULL << 0)
 #define HV_SYNIC_SIEFP_ENABLE                   (1ULL << 0)
diff --git a/x86/hyperv_overlay.c b/x86/hyperv_overlay.c
new file mode 100644
index 0000000..4472f64
--- /dev/null
+++ b/x86/hyperv_overlay.c
@@ -0,0 +1,96 @@
+#include "vm.h"
+#include "hyperv.h"
+#include "alloc_page.h"
+
+/**
+ * Test if the underlying GPA contents are preserved when an
+ * overlay is mounted there.
+ */
+static int test_underlay_intact(void *page, u64 msr)
+{
+	int i;
+	u64 gpa = (u64)virt_to_phys(page);
+
+	memset(page, 0xAA, PAGE_SIZE);
+
+	/* Enable overlay */
+	wrmsr(msr, gpa | HV_OVERLAY_ENABLE);
+
+	/* Write to overlay */
+	memset(page, 0x55, PAGE_SIZE);
+
+	/* Disable overlay */
+	wrmsr(msr, 0);
+
+	for (i = 0; i < PAGE_SIZE; i++)
+		if (((u8 *)page)[i] != 0xAA)
+			return -1;
+
+	return 0;
+}
+
+/**
+ * Test if Guest OS ID reset unmounts hypercall overlay and
+ * exposes the underlying page.
+ */
+static int test_guest_os_id_reset(void *page)
+{
+	int i;
+	u64 gpa = (u64)virt_to_phys(page);
+
+	memset(page, 0xAA, PAGE_SIZE);
+
+	/* Enable overlay */
+	wrmsr(HV_X64_MSR_HYPERCALL, gpa | HV_OVERLAY_ENABLE);
+
+	/* Write to overlay */
+	memset(page, 0x55, PAGE_SIZE);
+
+	/* Guest OS ID reset forces overlay unmap */
+	wrmsr(HV_X64_MSR_GUEST_OS_ID, 0);
+
+	for (i = 0; i < PAGE_SIZE; i++)
+		if (((u8 *)page)[i] != 0xAA)
+			return -1;
+
+	return 0;
+}
+
+int main(int ac, char **av)
+{
+	int rc;
+	void *page;
+	u64 guestid = (0x8f00ull << 48);
+
+	setup_vm();
+
+	page = alloc_page();
+	if (!page)
+		report_abort("Failed to allocate page for overlay tests");
+
+	rc = test_underlay_intact(page, HV_X64_MSR_HYPERCALL);
+	report(rc != 0, "Hypercall page before guest OS ID write");
+
+	wrmsr(HV_X64_MSR_GUEST_OS_ID, guestid);
+	rc = test_underlay_intact(page, HV_X64_MSR_HYPERCALL);
+	report(rc == 0, "Hypercall page after guest OS ID write");
+
+	rc = test_guest_os_id_reset(page);
+	report(rc == 0, "Guest OS ID reset removes hcall overlay");
+
+	if (!synic_supported()) {
+		report_skip("Hyper-V SynIC is not supported");
+		goto summary;
+	}
+
+	rc = test_underlay_intact(page, HV_X64_MSR_SIMP);
+	report(rc == 0, "SynIC message page");
+
+	rc = test_underlay_intact(page, HV_X64_MSR_SIEFP);
+	report(rc == 0, "SynIC event page");
+
+	free_page(page);
+
+summary:
+	return report_summary();
+}
diff --git a/x86/unittests.cfg b/x86/unittests.cfg
index 0698d15..330a829 100644
--- a/x86/unittests.cfg
+++ b/x86/unittests.cfg
@@ -372,6 +372,11 @@ arch = x86_64
 groups = hyperv
 check = /sys/devices/system/clocksource/clocksource0/current_clocksource=tsc
 
+[hyperv_overlay]
+file = hyperv_overlay.flat
+extra_params = -cpu kvm64,hv_vpindex,hv_synic
+groups = hyperv
+
 [intel_iommu]
 file = intel-iommu.flat
 arch = x86_64
-- 
2.17.1




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [kvm-unit-tests PATCH] x86: Fix misspelled KVM parameter in error message
  2021-06-09 14:02 [kvm-unit-tests PATCH] gitignore: Add tags file to .gitignore Siddharth Chandrasekaran
  2021-06-09 14:02 ` [kvm-unit-tests PATCH] x86: Add hyper-v overlay page tests Siddharth Chandrasekaran
@ 2021-06-09 14:02 ` Siddharth Chandrasekaran
  2021-06-09 14:23   ` Paolo Bonzini
  2021-06-09 14:23 ` [kvm-unit-tests PATCH] gitignore: Add tags file to .gitignore Paolo Bonzini
  2 siblings, 1 reply; 5+ messages in thread
From: Siddharth Chandrasekaran @ 2021-06-09 14:02 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Siddharth Chandrasekaran, Evgeny Iakovlev, Liran Alon,
	Ioannis Aslanidis, kvm, Siddharth Chandrasekaran

KVM module parameter force_emulation_prefix is misspelled with a
"forced"; fix it.

Signed-off-by: Siddharth Chandrasekaran <sidcha@amazon.de>
---
 x86/emulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/x86/emulator.c b/x86/emulator.c
index 6100b6d..97f28ba 100644
--- a/x86/emulator.c
+++ b/x86/emulator.c
@@ -1124,7 +1124,7 @@ int main(void)
 		test_mov_dr(mem);
 	} else {
 		report_skip("skipping register-only tests, "
-			    "use kvm.forced_emulation_prefix=1 to enable");
+			    "use kvm.force_emulation_prefix=1 to enable");
 	}
 
 	test_push16(mem);
-- 
2.17.1




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [kvm-unit-tests PATCH] gitignore: Add tags file to .gitignore
  2021-06-09 14:02 [kvm-unit-tests PATCH] gitignore: Add tags file to .gitignore Siddharth Chandrasekaran
  2021-06-09 14:02 ` [kvm-unit-tests PATCH] x86: Add hyper-v overlay page tests Siddharth Chandrasekaran
  2021-06-09 14:02 ` [kvm-unit-tests PATCH] x86: Fix misspelled KVM parameter in error message Siddharth Chandrasekaran
@ 2021-06-09 14:23 ` Paolo Bonzini
  2 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2021-06-09 14:23 UTC (permalink / raw)
  To: Siddharth Chandrasekaran
  Cc: Siddharth Chandrasekaran, Evgeny Iakovlev, Liran Alon,
	Ioannis Aslanidis, kvm

On 09/06/21 16:02, Siddharth Chandrasekaran wrote:
> Add ctags tags file to .gitignore so they don't get checked-in
> accidentally.
> 
> Signed-off-by: Siddharth Chandrasekaran <sidcha@amazon.de>
> ---
>   .gitignore | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/.gitignore b/.gitignore
> index 784cb2d..8534fb7 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -1,3 +1,4 @@
> +tags
>   .gdbinit
>   *.a
>   *.d
> 

If you're using them, you might consider adding the Makefile rules to 
create the files.  Alternatively, you can add "tags" to your global 
~/.git/info/exclude.

Having the file but not the rules feels like the worst of both worlds...


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [kvm-unit-tests PATCH] x86: Fix misspelled KVM parameter in error message
  2021-06-09 14:02 ` [kvm-unit-tests PATCH] x86: Fix misspelled KVM parameter in error message Siddharth Chandrasekaran
@ 2021-06-09 14:23   ` Paolo Bonzini
  0 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2021-06-09 14:23 UTC (permalink / raw)
  To: Siddharth Chandrasekaran
  Cc: Siddharth Chandrasekaran, Evgeny Iakovlev, Liran Alon,
	Ioannis Aslanidis, kvm

On 09/06/21 16:02, Siddharth Chandrasekaran wrote:
> KVM module parameter force_emulation_prefix is misspelled with a
> "forced"; fix it.
> 
> Signed-off-by: Siddharth Chandrasekaran <sidcha@amazon.de>
> ---
>   x86/emulator.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/x86/emulator.c b/x86/emulator.c
> index 6100b6d..97f28ba 100644
> --- a/x86/emulator.c
> +++ b/x86/emulator.c
> @@ -1124,7 +1124,7 @@ int main(void)
>   		test_mov_dr(mem);
>   	} else {
>   		report_skip("skipping register-only tests, "
> -			    "use kvm.forced_emulation_prefix=1 to enable");
> +			    "use kvm.force_emulation_prefix=1 to enable");
>   	}
>   
>   	test_push16(mem);
> 

Queued this one, thanks!

Paolo


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-09 14:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09 14:02 [kvm-unit-tests PATCH] gitignore: Add tags file to .gitignore Siddharth Chandrasekaran
2021-06-09 14:02 ` [kvm-unit-tests PATCH] x86: Add hyper-v overlay page tests Siddharth Chandrasekaran
2021-06-09 14:02 ` [kvm-unit-tests PATCH] x86: Fix misspelled KVM parameter in error message Siddharth Chandrasekaran
2021-06-09 14:23   ` Paolo Bonzini
2021-06-09 14:23 ` [kvm-unit-tests PATCH] gitignore: Add tags file to .gitignore Paolo Bonzini

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.