xref: /kvm-unit-tests/s390x/snippets/c/sie-dat.c (revision 1f08a91a41402b0e032ecce8ed1b5952cbfca0ea)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Snippet used by the sie-dat.c test to verify paging without MSO/MSL
4  *
5  * Copyright (c) 2023 IBM Corp
6  *
7  * Authors:
8  *  Nico Boehr <nrb@linux.ibm.com>
9  */
10 #include <libcflat.h>
11 #include <asm-generic/page.h>
12 #include <asm/mem.h>
13 #include <snippet-exit.h>
14 #include "sie-dat.h"
15 
16 static uint8_t test_pages[GUEST_TEST_PAGE_COUNT * PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
17 
main(void)18 int main(void)
19 {
20 	uint8_t *invalid_ptr;
21 
22 	memset(test_pages, 0, sizeof(test_pages));
23 	/* tell the host the page's physical address (we're running DAT off) */
24 	force_exit_value((uint64_t)test_pages);
25 
26 	/* write some value to the page so the host can verify it */
27 	for (size_t i = 0; i < GUEST_TEST_PAGE_COUNT; i++)
28 		test_pages[i * PAGE_SIZE] = 42 + i;
29 
30 	/* indicate we've written all pages */
31 	force_exit();
32 
33 	/* the first unmapped address */
34 	invalid_ptr = OPAQUE_PTR(GUEST_TOTAL_PAGE_COUNT * PAGE_SIZE);
35 	*invalid_ptr = 42;
36 
37 	/* indicate we've written the non-allowed page (should never get here) */
38 	force_exit();
39 
40 	return 0;
41 }
42