xref: /kvm-unit-tests/s390x/cmm.c (revision 2352e986e4599bc4842c225762c78fa49f18648d)
1 /*
2  * CMM tests (ESSA)
3  *
4  * Copyright (c) 2018 IBM Corp
5  *
6  * Authors:
7  *  Janosch Frank <frankja@linux.vnet.ibm.com>
8  *
9  * This code is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Library General Public License version 2.
11  */
12 
13 #include <libcflat.h>
14 #include <asm/asm-offsets.h>
15 #include <asm/interrupt.h>
16 #include <asm/page.h>
17 
18 static uint8_t pagebuf[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
19 
20 static unsigned long essa(uint8_t state, unsigned long paddr)
21 {
22 	uint64_t extr_state;
23 
24 	asm volatile(".insn rrf,0xb9ab0000,%[extr_state],%[addr],%[new_state],0"
25 			: [extr_state] "=d" (extr_state)
26 			: [addr] "a" (paddr), [new_state] "i" (state));
27 	return (unsigned long)extr_state;
28 }
29 
30 static void test_params(void)
31 {
32 	expect_pgm_int();
33 	essa(8, (unsigned long)pagebuf);
34 	check_pgm_int_code(PGM_INT_CODE_SPECIFICATION);
35 }
36 
37 static void test_priv(void)
38 {
39 	expect_pgm_int();
40 	enter_pstate();
41 	essa(0, (unsigned long)pagebuf);
42 	check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION);
43 }
44 
45 /* Unfortunately the availability is not indicated by stfl bits, but
46  * we have to try to execute it and test for an operation exception.
47  */
48 static bool test_availability(void)
49 {
50 	expect_pgm_int();
51 	essa(0, (unsigned long)pagebuf);
52 	return clear_pgm_int() == 0;
53 }
54 
55 int main(void)
56 {
57 	bool has_essa = test_availability();
58 
59 	report_prefix_push("cmm");
60 	report_xfail("ESSA available", !has_essa, has_essa);
61 	if (!has_essa)
62 		goto done;
63 
64 	test_priv();
65 	test_params();
66 done:
67 	report_prefix_pop();
68 	return report_summary();
69 }
70