public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] KVM: s390: selftests: Add regression tests for CPU subfunctions
@ 2024-08-20  6:48 Hariharan Mari
  2024-08-20  6:48 ` [PATCH v2 1/5] KVM: s390: selftests: Add regression tests for SORTL and DFLTCC " Hariharan Mari
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Hariharan Mari @ 2024-08-20  6:48 UTC (permalink / raw)
  To: linux-kselftest
  Cc: linux-kernel, kvm, shuah, frankja, borntraeger, imbrenda, david,
	pbonzini, schlameuss

This patch series introduces a set of regression tests for various s390x
CPU subfunctions in KVM. The tests ensure that the KVM implementation accurately
reflects the behavior of actual CPU instructions for these subfunctions.

The series adds tests for a total of 15 instructions across five patches,
covering a range of operations including sorting, compression, and various
cryptographic functions. Each patch follows a consistent testing pattern:

1. Obtain the KVM_S390_VM_CPU_MACHINE_SUBFUNC attribute for the VM.
2. Execute the relevant asm instructions.
3. Compare KVM-reported results with direct instruction execution results.

Testing has been performed on s390x hardware with KVM support. All tests
pass successfully, verifying the correct implementation of these
subfunctions in KVM.

---
v2: 
* Fix facility_bit type from bool to int

---

Hariharan Mari (5):
  KVM: s390: selftests: Add regression tests for SORTL and DFLTCC CPU
    subfunctions
  KVM: s390: selftests: Add regression tests for PRNO, KDSA and KMA
    crypto subfunctions
  KVM: s390: selftests: Add regression tests for KMCTR, KMF, KMO and PCC
    crypto subfunctions
  KVM: s390: selftests: Add regression tests for KMAC, KMC, KM, KIMD and
    KLMD crypto subfunctions
  KVM: s390: selftests: Add regression tests for PLO subfunctions

 tools/testing/selftests/kvm/Makefile          |   1 +
 .../selftests/kvm/include/s390x/facility.h    |  50 +++
 .../kvm/s390x/cpumodel_subfuncs_test.c        | 343 ++++++++++++++++++
 3 files changed, 394 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/include/s390x/facility.h
 create mode 100644 tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c

-- 
2.45.2


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

* [PATCH v2 1/5] KVM: s390: selftests: Add regression tests for SORTL and DFLTCC CPU subfunctions
  2024-08-20  6:48 [PATCH v2 0/5] KVM: s390: selftests: Add regression tests for CPU subfunctions Hariharan Mari
@ 2024-08-20  6:48 ` Hariharan Mari
  2024-08-21  7:19   ` Christoph Schlameuss
  2024-08-21 15:44   ` Claudio Imbrenda
  2024-08-20  6:48 ` [PATCH v2 2/5] KVM: s390: selftests: Add regression tests for PRNO, KDSA and KMA crypto subfunctions Hariharan Mari
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 13+ messages in thread
From: Hariharan Mari @ 2024-08-20  6:48 UTC (permalink / raw)
  To: linux-kselftest
  Cc: linux-kernel, kvm, shuah, frankja, borntraeger, imbrenda, david,
	pbonzini, schlameuss

Introduce new regression tests to verify the ASM inline block in the SORTL
and DFLTCC CPU subfunctions for the s390x architecture. These tests ensure
that future changes to the ASM code are properly validated.

The test procedure:

1. Create a VM and request the KVM_S390_VM_CPU_MACHINE_SUBFUNC attribute
   from the KVM_S390_VM_CPU_MODEL group for this VM. This SUBFUNC attribute
   contains the results of all CPU subfunction instructions.
2. For each tested subfunction (SORTL and DFLTCC), execute the
   corresponding ASM instruction and capture the result array.
3. Perform a memory comparison between the results stored in the SUBFUNC
   attribute (obtained in step 1) and the ASM instruction results (obtained
   in step 2) for each tested subfunction.

This process ensures that the KVM implementation accurately reflects the
behavior of the actual CPU instructions for the tested subfunctions.

Suggested-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Hariharan Mari <hari55@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
---
 tools/testing/selftests/kvm/Makefile          |   1 +
 .../selftests/kvm/include/s390x/facility.h    |  50 ++++++++
 .../kvm/s390x/cpumodel_subfuncs_test.c        | 115 ++++++++++++++++++
 3 files changed, 166 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/include/s390x/facility.h
 create mode 100644 tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c

diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index ac280dcba996..9f418c594b55 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -183,6 +183,7 @@ TEST_GEN_PROGS_s390x += s390x/sync_regs_test
 TEST_GEN_PROGS_s390x += s390x/tprot
 TEST_GEN_PROGS_s390x += s390x/cmma_test
 TEST_GEN_PROGS_s390x += s390x/debug_test
+TEST_GEN_PROGS_s390x += s390x/cpumodel_subfuncs_test
 TEST_GEN_PROGS_s390x += s390x/shared_zeropage_test
 TEST_GEN_PROGS_s390x += demand_paging_test
 TEST_GEN_PROGS_s390x += dirty_log_test
diff --git a/tools/testing/selftests/kvm/include/s390x/facility.h b/tools/testing/selftests/kvm/include/s390x/facility.h
new file mode 100644
index 000000000000..65eef9a722ba
--- /dev/null
+++ b/tools/testing/selftests/kvm/include/s390x/facility.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright IBM Corp. 2024
+ *
+ * Authors:
+ *  Hariharan Mari <hari55@linux.ibm.com>
+ *
+ *  Get the facility bits with the STFLE instruction
+ */
+
+#ifndef SELFTEST_KVM_FACILITY_H
+#define SELFTEST_KVM_FACILITY_H
+
+#include <linux/bitops.h>
+
+#define NB_STFL_DOUBLEWORDS 32 /* alt_stfle_fac_list[16] + stfle_fac_list[16] */
+
+uint64_t stfl_doublewords[NB_STFL_DOUBLEWORDS];
+bool stfle_flag;
+
+static inline bool test_bit_inv(unsigned long nr,
+				const unsigned long *ptr)
+{
+	return test_bit(nr ^ (BITS_PER_LONG - 1), ptr);
+}
+
+static inline void stfle(uint64_t *fac, unsigned int nb_doublewords)
+{
+	register unsigned long r0 asm("0") = nb_doublewords - 1;
+
+	asm volatile("	.insn	s,0xb2b00000,0(%1)\n"
+			: "+d" (r0)
+			: "a" (fac)
+			: "memory", "cc");
+}
+
+static inline void setup_facilities(void)
+{
+	stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS);
+	stfle_flag = true;
+}
+
+static inline bool test_facility(int nr)
+{
+	if (!stfle_flag)
+		setup_facilities();
+	return test_bit_inv(nr, stfl_doublewords);
+}
+
+#endif
diff --git a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
new file mode 100644
index 000000000000..ea03ce2010bb
--- /dev/null
+++ b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright IBM Corp. 2024
+ *
+ * Authors:
+ *  Hariharan Mari <hari55@linux.ibm.com>
+ *
+ * The tests compare the result of the KVM ioctl for obtaining CPU subfunction
+ * data with those from an ASM block performing the same CPU subfunction.
+ * Currently KVM doesn't mask instruction query data reported via the CPU Model,
+ * allowing us to directly compare it with the data acquired through executing
+ * the queries in the test.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include "facility.h"
+
+#include "kvm_util.h"
+
+/**
+ * Query available CPU subfunctions
+ */
+struct kvm_s390_vm_cpu_subfunc cpu_subfunc;
+
+static void get_cpu_machine_subfuntions(struct kvm_vm *vm,
+					struct kvm_s390_vm_cpu_subfunc
+					*cpu_subfunc)
+{
+	int r;
+
+	r = __kvm_device_attr_get(vm->fd, KVM_S390_VM_CPU_MODEL,
+				  KVM_S390_VM_CPU_MACHINE_SUBFUNC, cpu_subfunc);
+
+	TEST_ASSERT(!r, "Get cpu subfunctions failed r=%d errno=%d", r, errno);
+}
+
+/*
+ * Testing Sort Lists (SORTL) CPU subfunction's ASM block
+ */
+static void test_sortl_asm_block(u8 (*query)[32])
+{
+	asm volatile("	lghi	0,0\n"
+			"	la	1,%[query]\n"
+			"	.insn	rre,0xb9380000,2,4\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "0", "1");
+}
+
+/*
+ * Testing Deflate Conversion Call (DFLTCC) CPU subfunction's ASM block
+ */
+static void test_dfltcc_asm_block(u8 (*query)[32])
+{
+	asm volatile("	lghi	0,0\n"
+			"	la	1,%[query]\n"
+			"	.insn	rrf,0xb9390000,2,4,6,0\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "0", "1");
+}
+
+typedef void (*testfunc_t)(u8 (*array)[]);
+
+struct testdef {
+	const char *subfunc_name;
+	u8 *subfunc_array;
+	size_t array_size;
+	testfunc_t test;
+	int facility_bit;
+} testlist[] = {
+	/* SORTL - Facility bit 150 */
+	{ "SORTL", cpu_subfunc.sortl, sizeof(cpu_subfunc.sortl),
+		test_sortl_asm_block, 150 },
+	/* DFLTCC - Facility bit 151 */
+	{ "DFLTCC", cpu_subfunc.dfltcc, sizeof(cpu_subfunc.dfltcc),
+		test_dfltcc_asm_block, 151 },
+};
+
+int main(int argc, char *argv[])
+{
+	struct kvm_vm *vm;
+	int idx;
+
+	ksft_print_header();
+
+	vm = vm_create(1);
+
+	memset(&cpu_subfunc, 0, sizeof(cpu_subfunc));
+	get_cpu_machine_subfuntions(vm, &cpu_subfunc);
+
+	ksft_set_plan(ARRAY_SIZE(testlist));
+	for (idx = 0; idx < ARRAY_SIZE(testlist); idx++) {
+		if (test_facility(testlist[idx].facility_bit)) {
+			u8 *array = malloc(testlist[idx].array_size);
+
+			testlist[idx].test((u8 (*)[testlist[idx].array_size])array);
+
+			TEST_ASSERT_EQ(memcmp(testlist[idx].subfunc_array,
+					      array, testlist[idx].array_size), 0);
+
+			ksft_test_result_pass("%s\n", testlist[idx].subfunc_name);
+			free(array);
+		} else {
+			ksft_test_result_skip("%s feature is not avaialable\n",
+					      testlist[idx].subfunc_name);
+		}
+	}
+
+	kvm_vm_free(vm);
+	ksft_finished();
+}
-- 
2.45.2


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

* [PATCH v2 2/5] KVM: s390: selftests: Add regression tests for PRNO, KDSA and KMA crypto subfunctions
  2024-08-20  6:48 [PATCH v2 0/5] KVM: s390: selftests: Add regression tests for CPU subfunctions Hariharan Mari
  2024-08-20  6:48 ` [PATCH v2 1/5] KVM: s390: selftests: Add regression tests for SORTL and DFLTCC " Hariharan Mari
@ 2024-08-20  6:48 ` Hariharan Mari
  2024-08-21  7:21   ` Christoph Schlameuss
  2024-08-20  6:48 ` [PATCH v2 3/5] KVM: s390: selftests: Add regression tests for KMCTR, KMF, KMO and PCC " Hariharan Mari
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Hariharan Mari @ 2024-08-20  6:48 UTC (permalink / raw)
  To: linux-kselftest
  Cc: linux-kernel, kvm, shuah, frankja, borntraeger, imbrenda, david,
	pbonzini, schlameuss

Extend the existing regression test framework for s390x CPU subfunctions
to include tests for the PRNO (Perform Random Number Operation), KDSA
(Compute Digital Signature Authentication) and KMA (Cipher Message with
Authentication) crypto functions.

The test procedure follows the established pattern:

1. Obtain KVM_S390_VM_CPU_MACHINE_SUBFUNC attribute for the VM.
2. Execute PRNO, KDSA and KMA instructions.
3. Compare KVM-reported results with direct instruction execution results.

Suggested-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Hariharan Mari <hari55@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
---
 .../kvm/s390x/cpumodel_subfuncs_test.c        | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
index ea03ce2010bb..2489e10d3cc2 100644
--- a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
+++ b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
@@ -37,6 +37,48 @@ static void get_cpu_machine_subfuntions(struct kvm_vm *vm,
 	TEST_ASSERT(!r, "Get cpu subfunctions failed r=%d errno=%d", r, errno);
 }
 
+/*
+ * Testing Crypto Perform Random Number Operation (PRNO) CPU subfunction's
+ * ASM block
+ */
+static void test_prno_asm_block(u8 (*query)[16])
+{
+	asm volatile("	la	%%r1,%[query]\n"
+			"	xgr	%%r0,%%r0\n"
+			"	.insn	rre,0xb93c0000,2,4\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "r0", "r1");
+}
+
+/*
+ * Testing Crypto Cipher Message with Authentication (KMA) CPU subfunction's
+ * ASM block
+ */
+static void test_kma_asm_block(u8 (*query)[16])
+{
+	asm volatile("	la	%%r1,%[query]\n"
+			"	xgr	%%r0,%%r0\n"
+			"	.insn	rrf,0xb9290000,2,4,6,0\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "r0", "r1");
+}
+
+/*
+ * Testing Crypto Compute Digital Signature Authentication (KDSA) CPU
+ * subfunction's ASM block
+ */
+static void test_kdsa_asm_block(u8 (*query)[16])
+{
+	asm volatile("	la	%%r1,%[query]\n"
+			"	xgr	%%r0,%%r0\n"
+			"	.insn	rre,0xb93a0000,0,2\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "r0", "r1");
+}
+
 /*
  * Testing Sort Lists (SORTL) CPU subfunction's ASM block
  */
@@ -72,6 +114,15 @@ struct testdef {
 	testfunc_t test;
 	int facility_bit;
 } testlist[] = {
+	/* MSA5 - Facility bit 57 */
+	{ "PPNO", cpu_subfunc.ppno, sizeof(cpu_subfunc.ppno),
+		test_prno_asm_block, 57 },
+	/* MSA8 - Facility bit 146 */
+	{ "KMA", cpu_subfunc.kma, sizeof(cpu_subfunc.kma),
+		test_kma_asm_block, 146 },
+	/* MSA9 - Facility bit 155 */
+	{ "KDSA", cpu_subfunc.kdsa, sizeof(cpu_subfunc.kdsa),
+		test_kdsa_asm_block, 155 },
 	/* SORTL - Facility bit 150 */
 	{ "SORTL", cpu_subfunc.sortl, sizeof(cpu_subfunc.sortl),
 		test_sortl_asm_block, 150 },
-- 
2.45.2


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

* [PATCH v2 3/5] KVM: s390: selftests: Add regression tests for KMCTR, KMF, KMO and PCC crypto subfunctions
  2024-08-20  6:48 [PATCH v2 0/5] KVM: s390: selftests: Add regression tests for CPU subfunctions Hariharan Mari
  2024-08-20  6:48 ` [PATCH v2 1/5] KVM: s390: selftests: Add regression tests for SORTL and DFLTCC " Hariharan Mari
  2024-08-20  6:48 ` [PATCH v2 2/5] KVM: s390: selftests: Add regression tests for PRNO, KDSA and KMA crypto subfunctions Hariharan Mari
@ 2024-08-20  6:48 ` Hariharan Mari
  2024-08-21  7:22   ` Christoph Schlameuss
  2024-08-20  6:48 ` [PATCH v2 4/5] KVM: s390: selftests: Add regression tests for KMAC, KMC, KM, KIMD and KLMD " Hariharan Mari
  2024-08-20  6:48 ` [PATCH v2 5/5] KVM: s390: selftests: Add regression tests for PLO subfunctions Hariharan Mari
  4 siblings, 1 reply; 13+ messages in thread
From: Hariharan Mari @ 2024-08-20  6:48 UTC (permalink / raw)
  To: linux-kselftest
  Cc: linux-kernel, kvm, shuah, frankja, borntraeger, imbrenda, david,
	pbonzini, schlameuss

Extend the existing regression test framework for s390x CPU subfunctions
to include tests for the KMCTR (Cipher Message with Counter) KMO
(Cipher Message with Output Feedback), KMF (Cipher Message with Cipher
Feedback) and PCC (Perform Cryptographic Computation) crypto functions.

The test procedure follows the established pattern.

Suggested-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Hariharan Mari <hari55@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
---
 .../kvm/s390x/cpumodel_subfuncs_test.c        | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
index 2489e10d3cc2..1fe4fc709afc 100644
--- a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
+++ b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
@@ -37,6 +37,62 @@ static void get_cpu_machine_subfuntions(struct kvm_vm *vm,
 	TEST_ASSERT(!r, "Get cpu subfunctions failed r=%d errno=%d", r, errno);
 }
 
+/*
+ * Testing Crypto Cipher Message with Counter (KMCTR) CPU subfunction's ASM
+ * block
+ */
+static void test_kmctr_asm_block(u8 (*query)[16])
+{
+	asm volatile("	la	%%r1,%[query]\n"
+			"	xgr	%%r0,%%r0\n"
+			"	.insn	rrf,0xb92d0000,2,4,6,0\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "r0", "r1");
+}
+
+/*
+ * Testing Crypto Cipher Message with Cipher Feedback (KMF) CPU subfunction's
+ * ASM block
+ */
+static void test_kmf_asm_block(u8 (*query)[16])
+{
+	asm volatile("	la	%%r1,%[query]\n"
+			"	xgr	%%r0,%%r0\n"
+			"	.insn	rre,0xb92a0000,2,4\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "r0", "r1");
+}
+
+/*
+ * Testing Crypto Cipher Message with Output Feedback (KMO) CPU subfunction's
+ * ASM block
+ */
+static void test_kmo_asm_block(u8 (*query)[16])
+{
+	asm volatile("	la	%%r1,%[query]\n"
+			"	xgr	%%r0,%%r0\n"
+			"	.insn	rre,0xb92b0000,2,4\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "r0", "r1");
+}
+
+/*
+ * Testing Crypto Perform Cryptographic Computation (PCC) CPU subfunction's
+ * ASM block
+ */
+static void test_pcc_asm_block(u8 (*query)[16])
+{
+	asm volatile("	la	%%r1,%[query]\n"
+			"	xgr	%%r0,%%r0\n"
+			"	.insn	rre,0xb92c0000,0,0\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "r0", "r1");
+}
+
 /*
  * Testing Crypto Perform Random Number Operation (PRNO) CPU subfunction's
  * ASM block
@@ -114,6 +170,15 @@ struct testdef {
 	testfunc_t test;
 	int facility_bit;
 } testlist[] = {
+	/* MSA - Facility bit 77 */
+	{ "KMCTR", cpu_subfunc.kmctr, sizeof(cpu_subfunc.kmctr),
+		test_kmctr_asm_block, 77 },
+	{ "KMF", cpu_subfunc.kmf, sizeof(cpu_subfunc.kmf),
+		test_kmf_asm_block, 77 },
+	{ "KMO", cpu_subfunc.kmo, sizeof(cpu_subfunc.kmo),
+		test_kmo_asm_block, 77 },
+	{ "PCC", cpu_subfunc.pcc, sizeof(cpu_subfunc.pcc),
+		test_pcc_asm_block, 77 },
 	/* MSA5 - Facility bit 57 */
 	{ "PPNO", cpu_subfunc.ppno, sizeof(cpu_subfunc.ppno),
 		test_prno_asm_block, 57 },
-- 
2.45.2


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

* [PATCH v2 4/5] KVM: s390: selftests: Add regression tests for KMAC, KMC, KM, KIMD and KLMD crypto subfunctions
  2024-08-20  6:48 [PATCH v2 0/5] KVM: s390: selftests: Add regression tests for CPU subfunctions Hariharan Mari
                   ` (2 preceding siblings ...)
  2024-08-20  6:48 ` [PATCH v2 3/5] KVM: s390: selftests: Add regression tests for KMCTR, KMF, KMO and PCC " Hariharan Mari
@ 2024-08-20  6:48 ` Hariharan Mari
  2024-08-21  7:23   ` Christoph Schlameuss
  2024-08-20  6:48 ` [PATCH v2 5/5] KVM: s390: selftests: Add regression tests for PLO subfunctions Hariharan Mari
  4 siblings, 1 reply; 13+ messages in thread
From: Hariharan Mari @ 2024-08-20  6:48 UTC (permalink / raw)
  To: linux-kselftest
  Cc: linux-kernel, kvm, shuah, frankja, borntraeger, imbrenda, david,
	pbonzini, schlameuss

Extend the existing regression test framework for s390x CPU subfunctions
to include tests for the KMAC (Compute Message Authentication Code),
KMC (Cipher Message with Chaining), KM (Cipher Message) KIMD (Compute
Intermediate Message Digest) and KLMD (Compute Last Message Digest)
crypto functions.

The test procedure follows the established pattern.

Suggested-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Hariharan Mari <hari55@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
---
 .../kvm/s390x/cpumodel_subfuncs_test.c        | 78 +++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
index 1fe4fc709afc..c31f445c6f03 100644
--- a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
+++ b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
@@ -37,6 +37,73 @@ static void get_cpu_machine_subfuntions(struct kvm_vm *vm,
 	TEST_ASSERT(!r, "Get cpu subfunctions failed r=%d errno=%d", r, errno);
 }
 
+/*
+ * Testing Crypto Compute Message Authentication Code (KMAC) CPU subfunction's
+ * ASM block
+ */
+static void test_kmac_asm_block(u8 (*query)[16])
+{
+	asm volatile("	la	%%r1,%[query]\n"
+			"	xgr	%%r0,%%r0\n"
+			"	.insn	rre,0xb91e0000,0,2\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "r0", "r1");
+}
+
+/*
+ * Testing Crypto Cipher Message with Chaining (KMC) CPU subfunction's ASM block
+ */
+static void test_kmc_asm_block(u8 (*query)[16])
+{
+	asm volatile("	la	%%r1,%[query]\n"
+			"	xgr	%%r0,%%r0\n"
+			"	.insn	rre,0xb92f0000,2,4\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "r0", "r1");
+}
+
+/*
+ * Testing Crypto Cipher Message (KM) CPU subfunction's ASM block
+ */
+static void test_km_asm_block(u8 (*query)[16])
+{
+	asm volatile("	la	%%r1,%[query]\n"
+			"	xgr	%%r0,%%r0\n"
+			"	.insn	rre,0xb92e0000,2,4\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "r0", "r1");
+}
+
+/*
+ * Testing Crypto Compute Intermediate Message Digest (KIMD) CPU subfunction's
+ * ASM block
+ */
+static void test_kimd_asm_block(u8 (*query)[16])
+{
+	asm volatile("	la	%%r1,%[query]\n"
+			"	xgr	%%r0,%%r0\n"
+			"	.insn	rre,0xb93e0000,0,2\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "r0", "r1");
+}
+
+/*
+ * Testing Crypto Compute Last Message Digest (KLMD) CPU subfunction's ASM block
+ */
+static void test_klmd_asm_block(u8 (*query)[16])
+{
+	asm volatile("	la	%%r1,%[query]\n"
+			"	xgr	%%r0,%%r0\n"
+			"	.insn	rre,0xb93f0000,0,2\n"
+			: [query] "=R" (*query)
+			:
+			: "cc", "r0", "r1");
+}
+
 /*
  * Testing Crypto Cipher Message with Counter (KMCTR) CPU subfunction's ASM
  * block
@@ -170,6 +237,17 @@ struct testdef {
 	testfunc_t test;
 	int facility_bit;
 } testlist[] = {
+	/* MSA - Facility bit 17 */
+	{ "KMAC", cpu_subfunc.kmac, sizeof(cpu_subfunc.kmac),
+		test_kmac_asm_block, 17 },
+	{ "KMC", cpu_subfunc.kmc, sizeof(cpu_subfunc.kmc),
+		test_kmc_asm_block, 17 },
+	{ "KM", cpu_subfunc.km, sizeof(cpu_subfunc.km),
+		test_km_asm_block, 17 },
+	{ "KIMD", cpu_subfunc.kimd, sizeof(cpu_subfunc.kimd),
+		test_kimd_asm_block, 17 },
+	{ "KLMD", cpu_subfunc.klmd, sizeof(cpu_subfunc.klmd),
+		test_klmd_asm_block, 17 },
 	/* MSA - Facility bit 77 */
 	{ "KMCTR", cpu_subfunc.kmctr, sizeof(cpu_subfunc.kmctr),
 		test_kmctr_asm_block, 77 },
-- 
2.45.2


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

* [PATCH v2 5/5] KVM: s390: selftests: Add regression tests for PLO subfunctions
  2024-08-20  6:48 [PATCH v2 0/5] KVM: s390: selftests: Add regression tests for CPU subfunctions Hariharan Mari
                   ` (3 preceding siblings ...)
  2024-08-20  6:48 ` [PATCH v2 4/5] KVM: s390: selftests: Add regression tests for KMAC, KMC, KM, KIMD and KLMD " Hariharan Mari
@ 2024-08-20  6:48 ` Hariharan Mari
  2024-08-21  7:25   ` Christoph Schlameuss
  2024-08-21 15:40   ` Claudio Imbrenda
  4 siblings, 2 replies; 13+ messages in thread
From: Hariharan Mari @ 2024-08-20  6:48 UTC (permalink / raw)
  To: linux-kselftest
  Cc: linux-kernel, kvm, shuah, frankja, borntraeger, imbrenda, david,
	pbonzini, schlameuss

Extend the existing regression test framework for s390x CPU subfunctions
to include tests for the Perform Locked Operation (PLO) subfunction
functions.

PLO was introduced in the very first 64-bit machine generation.
Hence it is assumed PLO is always installed in the Z Arch.
The test procedure follows the established pattern.

Suggested-by: Janosch Frank <frankja@linux.ibm.com>
Signed-off-by: Hariharan Mari <hari55@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
---
 .../kvm/s390x/cpumodel_subfuncs_test.c        | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
index c31f445c6f03..255984a52365 100644
--- a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
+++ b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
@@ -20,6 +20,8 @@
 
 #include "kvm_util.h"
 
+#define U8_MAX  ((u8)~0U)
+
 /**
  * Query available CPU subfunctions
  */
@@ -37,6 +39,33 @@ static void get_cpu_machine_subfuntions(struct kvm_vm *vm,
 	TEST_ASSERT(!r, "Get cpu subfunctions failed r=%d errno=%d", r, errno);
 }
 
+static inline int plo_test_bit(unsigned char nr)
+{
+	unsigned long function = (unsigned long)nr | 0x100;
+	int cc;
+
+	asm volatile("	lgr	0,%[function]\n"
+			/* Parameter registers are ignored for "test bit" */
+			"	plo	0,0,0,0(0)\n"
+			"	ipm	%0\n"
+			"	srl	%0,28\n"
+			: "=d" (cc)
+			: [function] "d" (function)
+			: "cc", "0");
+	return cc == 0;
+}
+
+/*
+ * Testing Perform Locked Operation (PLO) CPU subfunction's ASM block
+ */
+static void test_plo_asm_block(u8 (*query)[32])
+{
+	for (int i = 0; i <= U8_MAX; ++i) {
+		if (plo_test_bit(i))
+			(*query)[i >> 3] |= 0x80 >> (i & 7);
+	}
+}
+
 /*
  * Testing Crypto Compute Message Authentication Code (KMAC) CPU subfunction's
  * ASM block
@@ -237,6 +266,11 @@ struct testdef {
 	testfunc_t test;
 	int facility_bit;
 } testlist[] = {
+	/*  PLO was introduced in the very first 64-bit machine generation.
+	 *  Hence it is assumed PLO is always installed in Z Arch .
+	 */
+	{ "PLO", cpu_subfunc.plo, sizeof(cpu_subfunc.plo),
+		test_plo_asm_block, 1 },
 	/* MSA - Facility bit 17 */
 	{ "KMAC", cpu_subfunc.kmac, sizeof(cpu_subfunc.kmac),
 		test_kmac_asm_block, 17 },
-- 
2.45.2


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

* Re: [PATCH v2 1/5] KVM: s390: selftests: Add regression tests for SORTL and DFLTCC CPU subfunctions
  2024-08-20  6:48 ` [PATCH v2 1/5] KVM: s390: selftests: Add regression tests for SORTL and DFLTCC " Hariharan Mari
@ 2024-08-21  7:19   ` Christoph Schlameuss
  2024-08-21 15:44   ` Claudio Imbrenda
  1 sibling, 0 replies; 13+ messages in thread
From: Christoph Schlameuss @ 2024-08-21  7:19 UTC (permalink / raw)
  To: Hariharan Mari, linux-kselftest
  Cc: linux-kernel, kvm, shuah, frankja, borntraeger, imbrenda, david,
	pbonzini

On Tue Aug 20, 2024 at 8:48 AM CEST, Hariharan Mari wrote:
> Introduce new regression tests to verify the ASM inline block in the SORTL
> and DFLTCC CPU subfunctions for the s390x architecture. These tests ensure
> that future changes to the ASM code are properly validated.
>
> The test procedure:
>
> 1. Create a VM and request the KVM_S390_VM_CPU_MACHINE_SUBFUNC attribute
>    from the KVM_S390_VM_CPU_MODEL group for this VM. This SUBFUNC attribute
>    contains the results of all CPU subfunction instructions.
> 2. For each tested subfunction (SORTL and DFLTCC), execute the
>    corresponding ASM instruction and capture the result array.
> 3. Perform a memory comparison between the results stored in the SUBFUNC
>    attribute (obtained in step 1) and the ASM instruction results (obtained
>    in step 2) for each tested subfunction.
>
> This process ensures that the KVM implementation accurately reflects the
> behavior of the actual CPU instructions for the tested subfunctions.
>
> Suggested-by: Janosch Frank <frankja@linux.ibm.com>
> Signed-off-by: Hariharan Mari <hari55@linux.ibm.com>
> Reviewed-by: Janosch Frank <frankja@linux.ibm.com>

LGTM

Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>

> ---
>  tools/testing/selftests/kvm/Makefile          |   1 +
>  .../selftests/kvm/include/s390x/facility.h    |  50 ++++++++
>  .../kvm/s390x/cpumodel_subfuncs_test.c        | 115 ++++++++++++++++++
>  3 files changed, 166 insertions(+)
>  create mode 100644 tools/testing/selftests/kvm/include/s390x/facility.h
>  create mode 100644 tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c

[...]

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

* Re: [PATCH v2 2/5] KVM: s390: selftests: Add regression tests for PRNO, KDSA and KMA crypto subfunctions
  2024-08-20  6:48 ` [PATCH v2 2/5] KVM: s390: selftests: Add regression tests for PRNO, KDSA and KMA crypto subfunctions Hariharan Mari
@ 2024-08-21  7:21   ` Christoph Schlameuss
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Schlameuss @ 2024-08-21  7:21 UTC (permalink / raw)
  To: Hariharan Mari, linux-kselftest
  Cc: linux-kernel, kvm, shuah, frankja, borntraeger, imbrenda, david,
	pbonzini

On Tue Aug 20, 2024 at 8:48 AM CEST, Hariharan Mari wrote:
> Extend the existing regression test framework for s390x CPU subfunctions
> to include tests for the PRNO (Perform Random Number Operation), KDSA
> (Compute Digital Signature Authentication) and KMA (Cipher Message with
> Authentication) crypto functions.
>
> The test procedure follows the established pattern:
>
> 1. Obtain KVM_S390_VM_CPU_MACHINE_SUBFUNC attribute for the VM.
> 2. Execute PRNO, KDSA and KMA instructions.
> 3. Compare KVM-reported results with direct instruction execution results.
>
> Suggested-by: Janosch Frank <frankja@linux.ibm.com>
> Signed-off-by: Hariharan Mari <hari55@linux.ibm.com>
> Reviewed-by: Janosch Frank <frankja@linux.ibm.com>

LGTM

Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>

> ---
>  .../kvm/s390x/cpumodel_subfuncs_test.c        | 51 +++++++++++++++++++
>  1 file changed, 51 insertions(+)

[...]

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

* Re: [PATCH v2 3/5] KVM: s390: selftests: Add regression tests for KMCTR, KMF, KMO and PCC crypto subfunctions
  2024-08-20  6:48 ` [PATCH v2 3/5] KVM: s390: selftests: Add regression tests for KMCTR, KMF, KMO and PCC " Hariharan Mari
@ 2024-08-21  7:22   ` Christoph Schlameuss
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Schlameuss @ 2024-08-21  7:22 UTC (permalink / raw)
  To: Hariharan Mari, linux-kselftest
  Cc: linux-kernel, kvm, shuah, frankja, borntraeger, imbrenda, david,
	pbonzini

On Tue Aug 20, 2024 at 8:48 AM CEST, Hariharan Mari wrote:
> Extend the existing regression test framework for s390x CPU subfunctions
> to include tests for the KMCTR (Cipher Message with Counter) KMO
> (Cipher Message with Output Feedback), KMF (Cipher Message with Cipher
> Feedback) and PCC (Perform Cryptographic Computation) crypto functions.
>
> The test procedure follows the established pattern.
>
> Suggested-by: Janosch Frank <frankja@linux.ibm.com>
> Signed-off-by: Hariharan Mari <hari55@linux.ibm.com>
> Reviewed-by: Janosch Frank <frankja@linux.ibm.com>

LGTM

Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>

> ---
>  .../kvm/s390x/cpumodel_subfuncs_test.c        | 65 +++++++++++++++++++
>  1 file changed, 65 insertions(+)

[...]

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

* Re: [PATCH v2 4/5] KVM: s390: selftests: Add regression tests for KMAC, KMC, KM, KIMD and KLMD crypto subfunctions
  2024-08-20  6:48 ` [PATCH v2 4/5] KVM: s390: selftests: Add regression tests for KMAC, KMC, KM, KIMD and KLMD " Hariharan Mari
@ 2024-08-21  7:23   ` Christoph Schlameuss
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Schlameuss @ 2024-08-21  7:23 UTC (permalink / raw)
  To: Hariharan Mari, linux-kselftest
  Cc: linux-kernel, kvm, shuah, frankja, borntraeger, imbrenda, david,
	pbonzini

On Tue Aug 20, 2024 at 8:48 AM CEST, Hariharan Mari wrote:
> Extend the existing regression test framework for s390x CPU subfunctions
> to include tests for the KMAC (Compute Message Authentication Code),
> KMC (Cipher Message with Chaining), KM (Cipher Message) KIMD (Compute
> Intermediate Message Digest) and KLMD (Compute Last Message Digest)
> crypto functions.
>
> The test procedure follows the established pattern.
>
> Suggested-by: Janosch Frank <frankja@linux.ibm.com>
> Signed-off-by: Hariharan Mari <hari55@linux.ibm.com>
> Reviewed-by: Janosch Frank <frankja@linux.ibm.com>

LGTM

Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>

> ---
>  .../kvm/s390x/cpumodel_subfuncs_test.c        | 78 +++++++++++++++++++
>  1 file changed, 78 insertions(+)

[...]

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

* Re: [PATCH v2 5/5] KVM: s390: selftests: Add regression tests for PLO subfunctions
  2024-08-20  6:48 ` [PATCH v2 5/5] KVM: s390: selftests: Add regression tests for PLO subfunctions Hariharan Mari
@ 2024-08-21  7:25   ` Christoph Schlameuss
  2024-08-21 15:40   ` Claudio Imbrenda
  1 sibling, 0 replies; 13+ messages in thread
From: Christoph Schlameuss @ 2024-08-21  7:25 UTC (permalink / raw)
  To: Hariharan Mari, linux-kselftest
  Cc: linux-kernel, kvm, shuah, frankja, borntraeger, imbrenda, david,
	pbonzini

On Tue Aug 20, 2024 at 8:48 AM CEST, Hariharan Mari wrote:
> Extend the existing regression test framework for s390x CPU subfunctions
> to include tests for the Perform Locked Operation (PLO) subfunction
> functions.
>
> PLO was introduced in the very first 64-bit machine generation.
> Hence it is assumed PLO is always installed in the Z Arch.
> The test procedure follows the established pattern.
>
> Suggested-by: Janosch Frank <frankja@linux.ibm.com>
> Signed-off-by: Hariharan Mari <hari55@linux.ibm.com>
> Reviewed-by: Janosch Frank <frankja@linux.ibm.com>

LGTM (apart from the accidental whitespace)

Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com>

> ---
>  .../kvm/s390x/cpumodel_subfuncs_test.c        | 34 +++++++++++++++++++
>  1 file changed, 34 insertions(+)
>
> diff --git a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
> index c31f445c6f03..255984a52365 100644
> --- a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
> +++ b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
> @@ -20,6 +20,8 @@
>  
>  #include "kvm_util.h"
>  
> +#define U8_MAX  ((u8)~0U)
> +
>  /**
>   * Query available CPU subfunctions
>   */
> @@ -37,6 +39,33 @@ static void get_cpu_machine_subfuntions(struct kvm_vm *vm,
>  	TEST_ASSERT(!r, "Get cpu subfunctions failed r=%d errno=%d", r, errno);
>  }
>  
> +static inline int plo_test_bit(unsigned char nr)
> +{
> +	unsigned long function = (unsigned long)nr | 0x100;
> +	int cc;
> +
> +	asm volatile("	lgr	0,%[function]\n"
> +			/* Parameter registers are ignored for "test bit" */
> +			"	plo	0,0,0,0(0)\n"
> +			"	ipm	%0\n"
> +			"	srl	%0,28\n"
> +			: "=d" (cc)
> +			: [function] "d" (function)
> +			: "cc", "0");
> +	return cc == 0;
> +}
> +
> +/*
> + * Testing Perform Locked Operation (PLO) CPU subfunction's ASM block
> + */
> +static void test_plo_asm_block(u8 (*query)[32])
> +{
> +	for (int i = 0; i <= U8_MAX; ++i) {
> +		if (plo_test_bit(i))
> +			(*query)[i >> 3] |= 0x80 >> (i & 7);
> +	}
> +}
> +
>  /*
>   * Testing Crypto Compute Message Authentication Code (KMAC) CPU subfunction's
>   * ASM block
> @@ -237,6 +266,11 @@ struct testdef {
>  	testfunc_t test;
>  	int facility_bit;
>  } testlist[] = {
> +	/*  PLO was introduced in the very first 64-bit machine generation.
> +	 *  Hence it is assumed PLO is always installed in Z Arch .
                                                                 ^
accidental whitespace

> +	 */
> +	{ "PLO", cpu_subfunc.plo, sizeof(cpu_subfunc.plo),
> +		test_plo_asm_block, 1 },
>  	/* MSA - Facility bit 17 */
>  	{ "KMAC", cpu_subfunc.kmac, sizeof(cpu_subfunc.kmac),
>  		test_kmac_asm_block, 17 },


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

* Re: [PATCH v2 5/5] KVM: s390: selftests: Add regression tests for PLO subfunctions
  2024-08-20  6:48 ` [PATCH v2 5/5] KVM: s390: selftests: Add regression tests for PLO subfunctions Hariharan Mari
  2024-08-21  7:25   ` Christoph Schlameuss
@ 2024-08-21 15:40   ` Claudio Imbrenda
  1 sibling, 0 replies; 13+ messages in thread
From: Claudio Imbrenda @ 2024-08-21 15:40 UTC (permalink / raw)
  To: Hariharan Mari
  Cc: linux-kselftest, linux-kernel, kvm, shuah, frankja, borntraeger,
	david, pbonzini, schlameuss

On Tue, 20 Aug 2024 08:48:37 +0200
Hariharan Mari <hari55@linux.ibm.com> wrote:

> Extend the existing regression test framework for s390x CPU subfunctions
> to include tests for the Perform Locked Operation (PLO) subfunction
> functions.
> 
> PLO was introduced in the very first 64-bit machine generation.
> Hence it is assumed PLO is always installed in the Z Arch.
> The test procedure follows the established pattern.
> 
> Suggested-by: Janosch Frank <frankja@linux.ibm.com>
> Signed-off-by: Hariharan Mari <hari55@linux.ibm.com>
> Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  .../kvm/s390x/cpumodel_subfuncs_test.c        | 34 +++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
> index c31f445c6f03..255984a52365 100644
> --- a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
> +++ b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
> @@ -20,6 +20,8 @@
>  
>  #include "kvm_util.h"
>  
> +#define U8_MAX  ((u8)~0U)

a more descriptive macro name would be better, maybe something like:

#define PLO_MAX_PARAMETER 255

the current macro is not much better than having just a magic number :)

> +
>  /**
>   * Query available CPU subfunctions
>   */
> @@ -37,6 +39,33 @@ static void get_cpu_machine_subfuntions(struct kvm_vm *vm,
>  	TEST_ASSERT(!r, "Get cpu subfunctions failed r=%d errno=%d", r, errno);
>  }
>  
> +static inline int plo_test_bit(unsigned char nr)
> +{
> +	unsigned long function = (unsigned long)nr | 0x100;

I think the (unsigned long) cast is not needed

> +	int cc;
> +
> +	asm volatile("	lgr	0,%[function]\n"
> +			/* Parameter registers are ignored for "test bit" */
> +			"	plo	0,0,0,0(0)\n"
> +			"	ipm	%0\n"
> +			"	srl	%0,28\n"
> +			: "=d" (cc)
> +			: [function] "d" (function)
> +			: "cc", "0");
> +	return cc == 0;
> +}
> +
> +/*
> + * Testing Perform Locked Operation (PLO) CPU subfunction's ASM block
> + */
> +static void test_plo_asm_block(u8 (*query)[32])
> +{
> +	for (int i = 0; i <= U8_MAX; ++i) {
> +		if (plo_test_bit(i))
> +			(*query)[i >> 3] |= 0x80 >> (i & 7);
> +	}
> +}
> +
>  /*
>   * Testing Crypto Compute Message Authentication Code (KMAC) CPU subfunction's
>   * ASM block
> @@ -237,6 +266,11 @@ struct testdef {
>  	testfunc_t test;
>  	int facility_bit;
>  } testlist[] = {
> +	/*  PLO was introduced in the very first 64-bit machine generation.

multi-line comments should not have text in the opening line 

> +	 *  Hence it is assumed PLO is always installed in Z Arch .
> +	 */
> +	{ "PLO", cpu_subfunc.plo, sizeof(cpu_subfunc.plo),
> +		test_plo_asm_block, 1 },
>  	/* MSA - Facility bit 17 */
>  	{ "KMAC", cpu_subfunc.kmac, sizeof(cpu_subfunc.kmac),
>  		test_kmac_asm_block, 17 },


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

* Re: [PATCH v2 1/5] KVM: s390: selftests: Add regression tests for SORTL and DFLTCC CPU subfunctions
  2024-08-20  6:48 ` [PATCH v2 1/5] KVM: s390: selftests: Add regression tests for SORTL and DFLTCC " Hariharan Mari
  2024-08-21  7:19   ` Christoph Schlameuss
@ 2024-08-21 15:44   ` Claudio Imbrenda
  1 sibling, 0 replies; 13+ messages in thread
From: Claudio Imbrenda @ 2024-08-21 15:44 UTC (permalink / raw)
  To: Hariharan Mari
  Cc: linux-kselftest, linux-kernel, kvm, shuah, frankja, borntraeger,
	david, pbonzini, schlameuss

On Tue, 20 Aug 2024 08:48:33 +0200
Hariharan Mari <hari55@linux.ibm.com> wrote:

> Introduce new regression tests to verify the ASM inline block in the SORTL
> and DFLTCC CPU subfunctions for the s390x architecture. These tests ensure
> that future changes to the ASM code are properly validated.
> 
> The test procedure:
> 
> 1. Create a VM and request the KVM_S390_VM_CPU_MACHINE_SUBFUNC attribute
>    from the KVM_S390_VM_CPU_MODEL group for this VM. This SUBFUNC attribute
>    contains the results of all CPU subfunction instructions.
> 2. For each tested subfunction (SORTL and DFLTCC), execute the
>    corresponding ASM instruction and capture the result array.
> 3. Perform a memory comparison between the results stored in the SUBFUNC
>    attribute (obtained in step 1) and the ASM instruction results (obtained
>    in step 2) for each tested subfunction.
> 
> This process ensures that the KVM implementation accurately reflects the
> behavior of the actual CPU instructions for the tested subfunctions.
> 
> Suggested-by: Janosch Frank <frankja@linux.ibm.com>
> Signed-off-by: Hariharan Mari <hari55@linux.ibm.com>
> Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  tools/testing/selftests/kvm/Makefile          |   1 +
>  .../selftests/kvm/include/s390x/facility.h    |  50 ++++++++
>  .../kvm/s390x/cpumodel_subfuncs_test.c        | 115 ++++++++++++++++++
>  3 files changed, 166 insertions(+)
>  create mode 100644 tools/testing/selftests/kvm/include/s390x/facility.h
>  create mode 100644 tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
> 
> diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
> index ac280dcba996..9f418c594b55 100644
> --- a/tools/testing/selftests/kvm/Makefile
> +++ b/tools/testing/selftests/kvm/Makefile
> @@ -183,6 +183,7 @@ TEST_GEN_PROGS_s390x += s390x/sync_regs_test
>  TEST_GEN_PROGS_s390x += s390x/tprot
>  TEST_GEN_PROGS_s390x += s390x/cmma_test
>  TEST_GEN_PROGS_s390x += s390x/debug_test
> +TEST_GEN_PROGS_s390x += s390x/cpumodel_subfuncs_test
>  TEST_GEN_PROGS_s390x += s390x/shared_zeropage_test
>  TEST_GEN_PROGS_s390x += demand_paging_test
>  TEST_GEN_PROGS_s390x += dirty_log_test
> diff --git a/tools/testing/selftests/kvm/include/s390x/facility.h b/tools/testing/selftests/kvm/include/s390x/facility.h
> new file mode 100644
> index 000000000000..65eef9a722ba
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/include/s390x/facility.h
> @@ -0,0 +1,50 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright IBM Corp. 2024
> + *
> + * Authors:
> + *  Hariharan Mari <hari55@linux.ibm.com>
> + *
> + *  Get the facility bits with the STFLE instruction
> + */
> +
> +#ifndef SELFTEST_KVM_FACILITY_H
> +#define SELFTEST_KVM_FACILITY_H
> +
> +#include <linux/bitops.h>
> +
> +#define NB_STFL_DOUBLEWORDS 32 /* alt_stfle_fac_list[16] + stfle_fac_list[16] */

in general it would be better if the comment is before the variable or
define

> +
> +uint64_t stfl_doublewords[NB_STFL_DOUBLEWORDS];
> +bool stfle_flag;

I'm not very happy of global variables defined in headers; as we
discussed offline, there are several possible solutions:

* just make them static
* put them in a separate .c in lib/s390x/
* do not use them at all, and simply call stfle every time

and probably there are also more solutions I did not think of

> +
> +static inline bool test_bit_inv(unsigned long nr,
> +				const unsigned long *ptr)

if I'm not mistaken, the column limit is 100 also for the selftests;
please fix that throughout the series, it will be more readable

> +{
> +	return test_bit(nr ^ (BITS_PER_LONG - 1), ptr);
> +}
> +
> +static inline void stfle(uint64_t *fac, unsigned int nb_doublewords)
> +{
> +	register unsigned long r0 asm("0") = nb_doublewords - 1;
> +
> +	asm volatile("	.insn	s,0xb2b00000,0(%1)\n"
> +			: "+d" (r0)
> +			: "a" (fac)
> +			: "memory", "cc");
> +}
> +
> +static inline void setup_facilities(void)
> +{
> +	stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS);
> +	stfle_flag = true;
> +}
> +
> +static inline bool test_facility(int nr)
> +{
> +	if (!stfle_flag)
> +		setup_facilities();
> +	return test_bit_inv(nr, stfl_doublewords);
> +}
> +
> +#endif
> diff --git a/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
> new file mode 100644
> index 000000000000..ea03ce2010bb
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/s390x/cpumodel_subfuncs_test.c
> @@ -0,0 +1,115 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright IBM Corp. 2024
> + *
> + * Authors:
> + *  Hariharan Mari <hari55@linux.ibm.com>
> + *
> + * The tests compare the result of the KVM ioctl for obtaining CPU subfunction
> + * data with those from an ASM block performing the same CPU subfunction.
> + * Currently KVM doesn't mask instruction query data reported via the CPU Model,
> + * allowing us to directly compare it with the data acquired through executing
> + * the queries in the test.
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/ioctl.h>
> +#include "facility.h"
> +
> +#include "kvm_util.h"
> +
> +/**
> + * Query available CPU subfunctions
> + */
> +struct kvm_s390_vm_cpu_subfunc cpu_subfunc;
> +
> +static void get_cpu_machine_subfuntions(struct kvm_vm *vm,
> +					struct kvm_s390_vm_cpu_subfunc
> +					*cpu_subfunc)

here in particular you can see how ugly it looks with 80 columns :)

> +{
> +	int r;
> +
> +	r = __kvm_device_attr_get(vm->fd, KVM_S390_VM_CPU_MODEL,
> +				  KVM_S390_VM_CPU_MACHINE_SUBFUNC, cpu_subfunc);
> +
> +	TEST_ASSERT(!r, "Get cpu subfunctions failed r=%d errno=%d", r, errno);
> +}
> +
> +/*
> + * Testing Sort Lists (SORTL) CPU subfunction's ASM block
> + */
> +static void test_sortl_asm_block(u8 (*query)[32])
> +{
> +	asm volatile("	lghi	0,0\n"
> +			"	la	1,%[query]\n"
> +			"	.insn	rre,0xb9380000,2,4\n"
> +			: [query] "=R" (*query)
> +			:
> +			: "cc", "0", "1");
> +}
> +
> +/*
> + * Testing Deflate Conversion Call (DFLTCC) CPU subfunction's ASM block
> + */

there is no need to use multiline comments for a single line, unless
you want to use proper kdoc tags (which is definitely overkill for a
selftest)

> +static void test_dfltcc_asm_block(u8 (*query)[32])
> +{
> +	asm volatile("	lghi	0,0\n"
> +			"	la	1,%[query]\n"
> +			"	.insn	rrf,0xb9390000,2,4,6,0\n"
> +			: [query] "=R" (*query)
> +			:
> +			: "cc", "0", "1");
> +}
> +
> +typedef void (*testfunc_t)(u8 (*array)[]);
> +
> +struct testdef {
> +	const char *subfunc_name;
> +	u8 *subfunc_array;
> +	size_t array_size;
> +	testfunc_t test;
> +	int facility_bit;
> +} testlist[] = {
> +	/* SORTL - Facility bit 150 */
> +	{ "SORTL", cpu_subfunc.sortl, sizeof(cpu_subfunc.sortl),
> +		test_sortl_asm_block, 150 },

here as well, I think it fits in one line

> +	/* DFLTCC - Facility bit 151 */
> +	{ "DFLTCC", cpu_subfunc.dfltcc, sizeof(cpu_subfunc.dfltcc),
> +		test_dfltcc_asm_block, 151 },
> +};
> +
> +int main(int argc, char *argv[])
> +{
> +	struct kvm_vm *vm;
> +	int idx;
> +
> +	ksft_print_header();
> +
> +	vm = vm_create(1);
> +
> +	memset(&cpu_subfunc, 0, sizeof(cpu_subfunc));
> +	get_cpu_machine_subfuntions(vm, &cpu_subfunc);
> +
> +	ksft_set_plan(ARRAY_SIZE(testlist));
> +	for (idx = 0; idx < ARRAY_SIZE(testlist); idx++) {
> +		if (test_facility(testlist[idx].facility_bit)) {
> +			u8 *array = malloc(testlist[idx].array_size);
> +
> +			testlist[idx].test((u8 (*)[testlist[idx].array_size])array);
> +
> +			TEST_ASSERT_EQ(memcmp(testlist[idx].subfunc_array,
> +					      array, testlist[idx].array_size), 0);
> +
> +			ksft_test_result_pass("%s\n", testlist[idx].subfunc_name);
> +			free(array);
> +		} else {
> +			ksft_test_result_skip("%s feature is not avaialable\n",
> +					      testlist[idx].subfunc_name);
> +		}
> +	}
> +
> +	kvm_vm_free(vm);
> +	ksft_finished();
> +}


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

end of thread, other threads:[~2024-08-21 15:45 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-20  6:48 [PATCH v2 0/5] KVM: s390: selftests: Add regression tests for CPU subfunctions Hariharan Mari
2024-08-20  6:48 ` [PATCH v2 1/5] KVM: s390: selftests: Add regression tests for SORTL and DFLTCC " Hariharan Mari
2024-08-21  7:19   ` Christoph Schlameuss
2024-08-21 15:44   ` Claudio Imbrenda
2024-08-20  6:48 ` [PATCH v2 2/5] KVM: s390: selftests: Add regression tests for PRNO, KDSA and KMA crypto subfunctions Hariharan Mari
2024-08-21  7:21   ` Christoph Schlameuss
2024-08-20  6:48 ` [PATCH v2 3/5] KVM: s390: selftests: Add regression tests for KMCTR, KMF, KMO and PCC " Hariharan Mari
2024-08-21  7:22   ` Christoph Schlameuss
2024-08-20  6:48 ` [PATCH v2 4/5] KVM: s390: selftests: Add regression tests for KMAC, KMC, KM, KIMD and KLMD " Hariharan Mari
2024-08-21  7:23   ` Christoph Schlameuss
2024-08-20  6:48 ` [PATCH v2 5/5] KVM: s390: selftests: Add regression tests for PLO subfunctions Hariharan Mari
2024-08-21  7:25   ` Christoph Schlameuss
2024-08-21 15:40   ` Claudio Imbrenda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox