Re: [kvm-unit-tests v3 08/13] powerpc/spapr_vpa: Add basic VPA tests

2023-04-04 Thread Thomas Huth

On 27/03/2023 14.45, Nicholas Piggin wrote:

The VPA is an optional memory structure shared between the hypervisor
and operating system, defined by PAPR. This test defines the structure
and adds registration, deregistration, and a few simple sanity tests.

[Thanks to Thomas Huth for suggesting many of the test cases.]
Signed-off-by: Nicholas Piggin 
---

...

diff --git a/powerpc/Makefile.ppc64 b/powerpc/Makefile.ppc64
index ea68447..b0ed2b1 100644
--- a/powerpc/Makefile.ppc64
+++ b/powerpc/Makefile.ppc64
@@ -19,7 +19,7 @@ reloc.o  = $(TEST_DIR)/reloc64.o
  OBJDIRS += lib/ppc64
  
  # ppc64 specific tests

-tests =
+tests = $(TEST_DIR)/spapr_vpa.elf
  
  include $(SRCDIR)/$(TEST_DIR)/Makefile.common


That reminds me: We added all other tests to Makefile.common ... without 
ever checking them on 32-bit. Since we removed the early 32-bit code long 
ago already (see commit 2a814baab80af990eaf), it just might not make sense 
anymore to keep the separation for 64-bit and 32-bit Makefiles around here 
anymore --> could be a future cleanup to merge the Makefiles in the powerpc 
folder.


Anyway, that's not a problem of your patch here which looks fine, so:

Reviewed-by: Thomas Huth 



[kvm-unit-tests v3 08/13] powerpc/spapr_vpa: Add basic VPA tests

2023-03-27 Thread Nicholas Piggin
The VPA is an optional memory structure shared between the hypervisor
and operating system, defined by PAPR. This test defines the structure
and adds registration, deregistration, and a few simple sanity tests.

[Thanks to Thomas Huth for suggesting many of the test cases.]
Signed-off-by: Nicholas Piggin 
---
Since v2:
- Added to unittests.cfg [Thomas review]
- Removed __always_inline header hunk [Thomas review]
- Updated comments [Thomas review]
- Better coverage of VPA registration error cases [Thomas review]
- Fix unbalanced prefix push [Thomas review]
- Don't print VPA contents unless -v option is given.
- Split VPA hcall register/unregister tests from testing of elements
  of the VPA when it has been registered into different functions and
  prefixes.

 lib/powerpc/asm/hcall.h |   1 +
 lib/ppc64/asm/vpa.h |  62 +++
 powerpc/Makefile.ppc64  |   2 +-
 powerpc/spapr_vpa.c | 172 
 powerpc/unittests.cfg   |   3 +
 5 files changed, 239 insertions(+), 1 deletion(-)
 create mode 100644 lib/ppc64/asm/vpa.h
 create mode 100644 powerpc/spapr_vpa.c

diff --git a/lib/powerpc/asm/hcall.h b/lib/powerpc/asm/hcall.h
index 1173fea..e0f5009 100644
--- a/lib/powerpc/asm/hcall.h
+++ b/lib/powerpc/asm/hcall.h
@@ -18,6 +18,7 @@
 #define H_SET_SPRG00x24
 #define H_SET_DABR 0x28
 #define H_PAGE_INIT0x2c
+#define H_REGISTER_VPA 0xDC
 #define H_CEDE 0xE0
 #define H_GET_TERM_CHAR0x54
 #define H_PUT_TERM_CHAR0x58
diff --git a/lib/ppc64/asm/vpa.h b/lib/ppc64/asm/vpa.h
new file mode 100644
index 000..11dde01
--- /dev/null
+++ b/lib/ppc64/asm/vpa.h
@@ -0,0 +1,62 @@
+#ifndef _ASMPOWERPC_VPA_H_
+#define _ASMPOWERPC_VPA_H_
+/*
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+
+#ifndef __ASSEMBLY__
+
+struct vpa {
+   uint32_tdescriptor;
+   uint16_tsize;
+   uint8_t reserved1[3];
+   uint8_t status;
+   uint8_t reserved2[14];
+   uint32_tfru_node_id;
+   uint32_tfru_proc_id;
+   uint8_t reserved3[56];
+   uint8_t vhpn_change_counters[8];
+   uint8_t reserved4[80];
+   uint8_t cede_latency;
+   uint8_t maintain_ebb;
+   uint8_t reserved5[6];
+   uint8_t dtl_enable_mask;
+   uint8_t dedicated_cpu_donate;
+   uint8_t maintain_fpr;
+   uint8_t maintain_pmc;
+   uint8_t reserved6[28];
+   uint64_tidle_estimate_purr;
+   uint8_t reserved7[28];
+   uint16_tmaintain_nr_slb;
+   uint8_t idle;
+   uint8_t maintain_vmx;
+   uint32_tvp_dispatch_count;
+   uint32_tvp_dispatch_dispersion;
+   uint64_tvp_fault_count;
+   uint64_tvp_fault_tb;
+   uint64_tpurr_exprop_idle;
+   uint64_tspurr_exprop_idle;
+   uint64_tpurr_exprop_busy;
+   uint64_tspurr_exprop_busy;
+   uint64_tpurr_donate_idle;
+   uint64_tspurr_donate_idle;
+   uint64_tpurr_donate_busy;
+   uint64_tspurr_donate_busy;
+   uint64_tvp_wait3_tb;
+   uint64_tvp_wait2_tb;
+   uint64_tvp_wait1_tb;
+   uint64_tpurr_exprop_adjunct_busy;
+   uint64_tspurr_exprop_adjunct_busy;
+   uint32_tsupervisor_pagein_count;
+   uint8_t reserved8[4];
+   uint64_tpurr_exprop_adjunct_idle;
+   uint64_tspurr_exprop_adjunct_idle;
+   uint64_tadjunct_insns_executed;
+   uint8_t reserved9[120];
+   uint64_tdtl_index;
+   uint8_t reserved10[96];
+};
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASMPOWERPC_VPA_H_ */
diff --git a/powerpc/Makefile.ppc64 b/powerpc/Makefile.ppc64
index ea68447..b0ed2b1 100644
--- a/powerpc/Makefile.ppc64
+++ b/powerpc/Makefile.ppc64
@@ -19,7 +19,7 @@ reloc.o  = $(TEST_DIR)/reloc64.o
 OBJDIRS += lib/ppc64
 
 # ppc64 specific tests
-tests =
+tests = $(TEST_DIR)/spapr_vpa.elf
 
 include $(SRCDIR)/$(TEST_DIR)/Makefile.common
 
diff --git a/powerpc/spapr_vpa.c b/powerpc/spapr_vpa.c
new file mode 100644
index 000..5586eb8
--- /dev/null
+++ b/powerpc/spapr_vpa.c
@@ -0,0 +1,172 @@
+/*
+ * Test sPAPR "Per Virtual Processor Area" and H_REGISTER_VPA hypervisor call
+ * (also known as VPA, also known as lppaca in the Linux pseries kernel).
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include  /* for endian accessors */
+
+static int verbose;
+
+static void print_vpa(struct vpa *vpa)
+{
+   printf("VPA\n");
+   printf("descriptor: 0x%08x\n", 
be32_to_cpu(vpa->descriptor));
+   printf("size: