mbox series

[v2,0/5] KVM: s390: selftests: Add regression tests for CPU subfunctions

Message ID 20240820065623.1140399-1-hari55@linux.ibm.com
Headers show
Series KVM: s390: selftests: Add regression tests for CPU subfunctions | expand

Message

Hariharan Mari Aug. 20, 2024, 6:48 a.m. UTC
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

Comments

Christoph Schlameuss Aug. 21, 2024, 7:19 a.m. UTC | #1
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

[...]
Christoph Schlameuss Aug. 21, 2024, 7:22 a.m. UTC | #2
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(+)

[...]
Christoph Schlameuss Aug. 21, 2024, 7:25 a.m. UTC | #3
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 },
Claudio Imbrenda Aug. 21, 2024, 3:40 p.m. UTC | #4
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 },