blob: 46a2edb694dbcd781dae992858ac84493d1e77e1 [file] [log] [blame]
Janosch Frankaa8794b2021-07-28 12:41:53 +00001/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Tests mvpg SIE partial execution intercepts.
4 *
5 * Copyright 2021 IBM Corp.
6 *
7 * Authors:
8 * Janosch Frank <frankja@linux.ibm.com>
9 */
Janosch Frank68200002021-05-20 07:44:38 +000010#include <libcflat.h>
11#include <asm/asm-offsets.h>
12#include <asm-generic/barrier.h>
13#include <asm/pgtable.h>
14#include <mmu.h>
15#include <asm/page.h>
16#include <asm/facility.h>
17#include <asm/mem.h>
18#include <alloc_page.h>
Janosch Frank68200002021-05-20 07:44:38 +000019#include <sclp.h>
20#include <sie.h>
Janosch Frankda967712021-10-08 09:06:27 +000021#include <snippet.h>
Janosch Frank68200002021-05-20 07:44:38 +000022
Janosch Frank68200002021-05-20 07:44:38 +000023static struct vm vm;
24
25static uint8_t *src;
26static uint8_t *dst;
27static uint8_t *cmp;
28
Janosch Frank68200002021-05-20 07:44:38 +000029static void test_mvpg_pei(void)
30{
31 uint64_t **pei_dst = (uint64_t **)((uintptr_t) vm.sblk + 0xc0);
32 uint64_t **pei_src = (uint64_t **)((uintptr_t) vm.sblk + 0xc8);
33
34 report_prefix_push("pei");
35
36 report_prefix_push("src");
37 memset(dst, 0, PAGE_SIZE);
38 protect_page(src, PAGE_ENTRY_I);
39 sie(&vm);
40 report(vm.sblk->icptcode == ICPT_PARTEXEC, "Partial execution");
41 report((uintptr_t)**pei_src == (uintptr_t)src + PAGE_ENTRY_I, "PEI_SRC correct");
42 report((uintptr_t)**pei_dst == (uintptr_t)dst, "PEI_DST correct");
43 unprotect_page(src, PAGE_ENTRY_I);
44 report(!memcmp(cmp, dst, PAGE_SIZE), "Destination intact");
45 /*
46 * We need to execute the diag44 which is used as a blocker
47 * behind the mvpg. It makes sure we fail the tests above if
48 * the mvpg wouldn't have intercepted.
49 */
50 sie(&vm);
51 /* Make sure we intercepted for the diag44 and nothing else */
52 assert(vm.sblk->icptcode == ICPT_INST &&
53 vm.sblk->ipa == 0x8300 && vm.sblk->ipb == 0x440000);
54 report_prefix_pop();
55
56 /* Clear PEI data for next check */
57 report_prefix_push("dst");
58 memset((uint64_t *)((uintptr_t) vm.sblk + 0xc0), 0, 16);
59 memset(dst, 0, PAGE_SIZE);
60 protect_page(dst, PAGE_ENTRY_I);
61 sie(&vm);
62 report(vm.sblk->icptcode == ICPT_PARTEXEC, "Partial execution");
63 report((uintptr_t)**pei_src == (uintptr_t)src, "PEI_SRC correct");
64 report((uintptr_t)**pei_dst == (uintptr_t)dst + PAGE_ENTRY_I, "PEI_DST correct");
65 /* Needed for the memcmp and general cleanup */
66 unprotect_page(dst, PAGE_ENTRY_I);
67 report(!memcmp(cmp, dst, PAGE_SIZE), "Destination intact");
68 report_prefix_pop();
69
70 report_prefix_pop();
71}
72
73static void test_mvpg(void)
74{
Janosch Frank68200002021-05-20 07:44:38 +000075 memset(src, 0x42, PAGE_SIZE);
76 memset(dst, 0x43, PAGE_SIZE);
77 sie(&vm);
78 report(!memcmp(src, dst, PAGE_SIZE) && *dst == 0x42, "Page moved");
79}
80
81static void setup_guest(void)
82{
Janosch Frank90cd8342021-12-06 11:05:22 +000083 extern const char SNIPPET_NAME_START(c, mvpg_snippet)[];
84 extern const char SNIPPET_NAME_END(c, mvpg_snippet)[];
85
Janosch Frank68200002021-05-20 07:44:38 +000086 setup_vm();
87
Janosch Frank90cd8342021-12-06 11:05:22 +000088 snippet_setup_guest(&vm, false);
89 snippet_init(&vm, SNIPPET_NAME_START(c, mvpg_snippet),
90 SNIPPET_LEN(c, mvpg_snippet), SNIPPET_OFF_C);
Janosch Frank68200002021-05-20 07:44:38 +000091
Janosch Frank68200002021-05-20 07:44:38 +000092 /* Enable MVPG interpretation as we want to test KVM and not ourselves */
93 vm.sblk->eca = ECA_MVPGI;
94
Janosch Frank90cd8342021-12-06 11:05:22 +000095 src = (uint8_t *) vm.sblk->mso + PAGE_SIZE * 6;
96 dst = (uint8_t *) vm.sblk->mso + PAGE_SIZE * 5;
Janosch Frank68200002021-05-20 07:44:38 +000097 cmp = alloc_page();
98 memset(cmp, 0, PAGE_SIZE);
99}
100
101int main(void)
102{
103 report_prefix_push("mvpg-sie");
104 if (!sclp_facilities.has_sief2) {
105 report_skip("SIEF2 facility unavailable");
106 goto done;
107 }
108
109 setup_guest();
110 test_mvpg();
111 test_mvpg_pei();
Janosch Franka58e5542021-04-15 11:58:17 +0000112 sie_guest_destroy(&vm);
Janosch Frank68200002021-05-20 07:44:38 +0000113
114done:
115 report_prefix_pop();
116 return report_summary();
117
118}