Skip to contentSkip to conversation

s390x: Interception tests

PATCH Superseded Thomas Huth 2 participants 6 messages Jun 2, 2017 – Jun 5, 2017 KVM

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 s390x: Interception tests

Certain CPU instructions will cause an exit of the virtual machine. Run some of these instructions to check whether they are emulated right by KVM (or QEMU).

---
Note: Test have been verified to pass with KVM of a 4.11 kernel. Running the tests with QEMU TCG emulation does not work yet ... QEMU first requires a bunch of fixes before this can pass there.

v2:
- Added entry in s390x/unittests.cfg
- Use low-core GEN_LC_STFL definition instead of hard-coded magic value
- Added lots of exception tests (thanks to David's interrupt framework!)
- Fixed constraints of inline assembler

(I haven't added a timing/iteration infrastructure like Paolo suggested yet - will do that later once the basic tests have been accepted)

 lib/s390x/asm/interrupt.h |   1 +
 lib/s390x/interrupt.c     |   5 ++
 s390x/Makefile            |   1 +
 s390x/intercept.c         | 170 ++++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg       |   3 +
 5 files changed, 180 insertions(+)
 create mode 100644 s390x/intercept.c
lib/s390x/asm/interrupt.h +1 -0
index 383d312..926f858 100644
@@ -14,5 +14,6 @@
 void handle_pgm_int(void);
 void expect_pgm_int(void);
 void check_pgm_int_code(uint16_t code);
+uint16_t get_pgm_int_code(void);
 
 #endif
lib/s390x/interrupt.c +5 -0
index 8d861a2..b5cc7ce 100644
@@ -23,6 +23,11 @@ void expect_pgm_int(void)
 	mb();
 }
 
+uint16_t get_pgm_int_code(void)
+{
+	return lc->pgm_int_code;
+}
+
 void check_pgm_int_code(uint16_t code)
 {
 	mb();
s390x/Makefile +1 -0
index b48f8ab..a61e163 100644
@@ -1,4 +1,5 @@
 tests = $(TEST_DIR)/selftest.elf
+tests += $(TEST_DIR)/intercept.elf
 
 all: directories test_cases
 
s390x/intercept.c new file +170 -0

170 lines not on this page · raw message

s390x/unittests.cfg +3 -0
index 92e01ab..3b6b892 100644
@@ -22,3 +22,6 @@
 file = selftest.elf
 groups = selftest
 extra_params = -append 'test 123'
+
+[intercept]
+file = intercept.elf
Signature · 1 line
1.8.3.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 84 lines · Thomas Huth

Certain CPU instructions will cause an exit of the virtual machine. Run some of these instructions to check whether they are emulated right by KVM (or QEMU).

---
Note: Test have been verified to pass with KVM of a 4.11 kernel. Running the tests with QEMU TCG emulation does not work yet ... QEMU first requires a bunch of fixes before this can pass there.

v2:
- Added entry in s390x/unittests.cfg
- Use low-core GEN_LC_STFL definition instead of hard-coded magic value
- Added lots of exception tests (thanks to David's interrupt framework!)
- Fixed constraints of inline assembler

(I haven't added a timing/iteration infrastructure like Paolo suggested yet - will do that later once the basic tests have been accepted)

 lib/s390x/asm/interrupt.h |   1 +
 lib/s390x/interrupt.c     |   5 ++
 s390x/Makefile            |   1 +
 s390x/intercept.c         | 170 ++++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg       |   3 +
 5 files changed, 180 insertions(+)
 create mode 100644 s390x/intercept.c
lib/s390x/asm/interrupt.h +1 -0
index 383d312..926f858 100644
@@ -14,5 +14,6 @@
 void handle_pgm_int(void);
 void expect_pgm_int(void);
 void check_pgm_int_code(uint16_t code);
+uint16_t get_pgm_int_code(void);
 
 #endif
lib/s390x/interrupt.c +5 -0
index 8d861a2..b5cc7ce 100644
@@ -23,6 +23,11 @@ void expect_pgm_int(void)
 	mb();
 }
 
+uint16_t get_pgm_int_code(void)
+{
+	return lc->pgm_int_code;
+}
+
 void check_pgm_int_code(uint16_t code)
 {
 	mb();
s390x/Makefile +1 -0
index b48f8ab..a61e163 100644
@@ -1,4 +1,5 @@
 tests = $(TEST_DIR)/selftest.elf
+tests += $(TEST_DIR)/intercept.elf
 
 all: directories test_cases
 
s390x/intercept.c new file +14 -0
new file mode 100644
index 0000000..4e3fb57
@@ -0,0 +1,170 @@
+/*
+ * Interception tests - for s390x CPU instruction that cause a VM exit
+ *
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  Thomas Huth <[email protected]>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+#include <libcflat.h>
+#include <asm/asm-offsets.h>
+#include <asm/interrupt.h>

s390x/intercept.c line 24

Quoted 10 lines
s390x/intercept.c new file +10 -0
+#include <asm/page.h>
+
+static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE)));
+
+/* Enable or disable low-address protection */
+static void set_low_prot(bool enable)
+{
+	uint64_t cr0;
+
+	asm volatile (" stctg 0,0,%0 " : : "Q"(cr0));

Use %c0 instead?

s390x/intercept.c line 29

Quoted 5 lines
s390x/intercept.c new file +5 -0
+	if (enable)
+		cr0 |= 1ULL << (63-35);
+	else
+		cr0 &= ~(1ULL << (63-35));
+	asm volatile (" lctlg 0,0,%0 " : : "Q"(cr0));

dito.

s390x/intercept.c line 30

Quoted 1 line
s390x/intercept.c new file +1 -0
+}

Think it makes sense to move this to interrupt.c / interrupt.h, so other tests can use it. But we can do this later.

Quoted 15 lines
s390x/intercept.c new file +15 -0
+
+/* Test the SET PREFIX and STORE PREFIX instructions */
+static void test_prefix(void)
+{
+	uint32_t old_prefix = -1U, tst_prefix = -1U;
+	uint32_t new_prefix = (uint32_t)(intptr_t)pagebuf;
+
+	memset(pagebuf, 0, PAGE_SIZE * 2);
+
+	/*
+	 * Temporarily change the prefix page to our buffer, and store
+	 * some facility bits there ... at least some of them should be
+	 * set in our buffer afterwards.
+	 */
+	asm volatile (

s390x/intercept.c line 55

Quoted 10 lines
s390x/intercept.c new file +10 -0
+		" stpx	%0\n"
+		" spx	%2\n"
+		" stfl	0\n"
+		" stpx	%1\n"
+		" spx	%0\n"
+		: "+Q"(old_prefix), "+Q"(tst_prefix)
+		: "Q"(new_prefix)
+		: "memory");
+	report("spx + stfl", pagebuf[GEN_LC_STFL] != 0 &&
+			     old_prefix == 0 && tst_prefix == new_prefix);

I would split this into two tests.

s390x/intercept.c line 60

Quoted 5 lines
s390x/intercept.c new file +5 -0
+
+	expect_pgm_int();
+	asm volatile(" spx 0(%0) " : : "r"(1));
+	report("spx alignment",
+	       get_pgm_int_code() == PGM_INT_CODE_SPECIFICATION);

Wonder if it makes sense to pass check_pgm_int_code() an string like "spx alignment", and let it handle the output. But this can also be changed later.

Quoted 46 lines
s390x/intercept.c new file +46 -0
+
+	expect_pgm_int();
+	asm volatile(" spx 0(%0) " : : "r"(-8));
+	report("spx addressing",
+	       get_pgm_int_code() == PGM_INT_CODE_ADDRESSING);
+
+	expect_pgm_int();
+	set_low_prot(true);
+	asm volatile(" stpx 0(%0) " : : "r"(8));
+	set_low_prot(false);
+	report("stpx low-address protection",
+	       get_pgm_int_code() == PGM_INT_CODE_PROTECTION);
+
+	expect_pgm_int();
+	asm volatile(" stpx 0(%0) " : : "r"(1));
+	report("stpx alignment",
+	       get_pgm_int_code() == PGM_INT_CODE_SPECIFICATION);
+
+	expect_pgm_int();
+	asm volatile(" stpx 0(%0) " : : "r"(-8));
+	report("stpx addressing",
+	       get_pgm_int_code() == PGM_INT_CODE_ADDRESSING);
+}
+
+/* Test the STORE CPU ADDRESS instruction */
+static void test_stap(void)
+{
+	uint16_t cpuid = 0xffff;
+
+	asm volatile ("stap %0\n" : "+Q"(cpuid));
+	report("get cpu id", cpuid != 0xffff);
+
+	expect_pgm_int();
+	set_low_prot(true);
+	asm volatile ("stap 0(%0)\n" : : "r"(8));
+	set_low_prot(false);
+	report("low-address protection",
+	       get_pgm_int_code() == PGM_INT_CODE_PROTECTION)> +
+	expect_pgm_int();
+	asm volatile ("stap 0(%0)\n" : : "r"(1));
+	report("alignment", get_pgm_int_code() == PGM_INT_CODE_SPECIFICATION);
+
+	expect_pgm_int();
+	asm volatile ("stap 0(%0)\n" : : "r"(-8));
+	report("addressing", get_pgm_int_code() == PGM_INT_CODE_ADDRESSING);
+}

s390x/intercept.c line 117

Quoted 10 lines
s390x/intercept.c new file +10 -0
+
+/* Test the TEST BLOCK instruction */
+static void test_testblock(void)
+{
+	int cc;
+
+	memset(pagebuf, 0xaa, PAGE_SIZE);
+
+	asm volatile (
+		" lghi	0,0\n"

%0,0 ?

Quoted 59 lines
s390x/intercept.c new file +53 -0
+		" tb	%1\n"
+		" ipm	%0\n"
+		" srl	%0,28\n"
+		: "=d" (cc)
+		: "a"(pagebuf + 0x123)
+		: "memory", "0", "cc");
+	report("page cleared",
+	       cc == 0 && pagebuf[0] == 0 &&  pagebuf[PAGE_SIZE - 1] == 0);
+
+	expect_pgm_int();
+	set_low_prot(true);
+	asm volatile (" tb %0 " : : "r"(4096));
+	set_low_prot(false);
+	report("low-address protection",
+	       get_pgm_int_code() == PGM_INT_CODE_PROTECTION);
+
+	expect_pgm_int();
+	asm volatile (" tb %0 " : : "r"(-4096));
+	report("addressing", get_pgm_int_code() == PGM_INT_CODE_ADDRESSING);
+}
+
+struct {
+	const char *name;
+	void (*func)(void);
+} tests[] = {
+	{ "prefix", test_prefix },
+	{ "stap", test_stap },
+	{ "testblock", test_testblock },
+	{ NULL, NULL }
+};
+
+int main(int argc, char **argv)
+{
+	int all = 0;
+	int i;
+
+	report_prefix_push("intercept");
+
+	if (argc < 2 || (argc == 2 && !strcmp(argv[1], "all")))
+		all = 1;
+
+	for (i = 0; tests[i].name != NULL; i++) {
+		report_prefix_push(tests[i].name);
+		if (all || strcmp(argv[1], tests[i].name) == 0) {
+			tests[i].func();
+		}
+		report_prefix_pop();
+	}
+
+	report_prefix_pop();
+
+	return report_summary();
+}
s390x/unittests.cfg +0 -0
index 92e01ab..3b6b892 100644

s390x/unittests.cfg line 27

Quoted 6 lines
s390x/unittests.cfg +3 -0
@@ -22,3 +22,6 @@
 file = selftest.elf
 groups = selftest
 extra_params = -append 'test 123'
+
+[intercept]
+file = intercept.elf

Nice! With or without these nits fixed.

Once upstream, I'll add a stidp test.

Signature · 3 lines
Thanks,

David
#2 lore raw
Quoted 89 lines · David Hildenbrand
Quoted 88 lines · Thomas Huth

Certain CPU instructions will cause an exit of the virtual machine. Run some of these instructions to check whether they are emulated right by KVM (or QEMU).

---
Note: Test have been verified to pass with KVM of a 4.11 kernel. Running the tests with QEMU TCG emulation does not work yet ... QEMU first requires a bunch of fixes before this can pass there.

v2:
- Added entry in s390x/unittests.cfg
- Use low-core GEN_LC_STFL definition instead of hard-coded magic value
- Added lots of exception tests (thanks to David's interrupt framework!)
- Fixed constraints of inline assembler

(I haven't added a timing/iteration infrastructure like Paolo suggested yet - will do that later once the basic tests have been accepted)

 lib/s390x/asm/interrupt.h |   1 +
 lib/s390x/interrupt.c     |   5 ++
 s390x/Makefile            |   1 +
 s390x/intercept.c         | 170 ++++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg       |   3 +
 5 files changed, 180 insertions(+)
 create mode 100644 s390x/intercept.c
lib/s390x/asm/interrupt.h +1 -0
index 383d312..926f858 100644
@@ -14,5 +14,6 @@
 void handle_pgm_int(void);
 void expect_pgm_int(void);
 void check_pgm_int_code(uint16_t code);
+uint16_t get_pgm_int_code(void);
 
 #endif
lib/s390x/interrupt.c +5 -0
index 8d861a2..b5cc7ce 100644
@@ -23,6 +23,11 @@ void expect_pgm_int(void)
 	mb();
 }
 
+uint16_t get_pgm_int_code(void)
+{
+	return lc->pgm_int_code;
+}
+
 void check_pgm_int_code(uint16_t code)
 {
 	mb();
s390x/Makefile +1 -0
index b48f8ab..a61e163 100644
@@ -1,4 +1,5 @@
 tests = $(TEST_DIR)/selftest.elf
+tests += $(TEST_DIR)/intercept.elf
 
 all: directories test_cases
 
s390x/intercept.c new file +18 -0
new file mode 100644
index 0000000..4e3fb57
@@ -0,0 +1,170 @@
+/*
+ * Interception tests - for s390x CPU instruction that cause a VM exit
+ *
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  Thomas Huth <[email protected]>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+#include <libcflat.h>
+#include <asm/asm-offsets.h>
+#include <asm/interrupt.h>
+#include <asm/page.h>
+
+static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE)));
+
Quoted 8 lines

s390x/intercept.c line 24

Quoted 6 lines
s390x/intercept.c new file +6 -0
+/* Enable or disable low-address protection */
+static void set_low_prot(bool enable)
+{
+	uint64_t cr0;
+
+	asm volatile (" stctg 0,0,%0 " : : "Q"(cr0));

Use %c0 instead?

It's got to be %%c0 ... not sure whether this looks really nicer here?

Quoted 8 lines

s390x/intercept.c line 29

Quoted 5 lines
s390x/intercept.c new file +5 -0
+	if (enable)
+		cr0 |= 1ULL << (63-35);
+	else
+		cr0 &= ~(1ULL << (63-35));
+	asm volatile (" lctlg 0,0,%0 " : : "Q"(cr0));

dito.

Quoted 4 lines

s390x/intercept.c line 30

Quoted 1 line
s390x/intercept.c new file +1 -0
+}

Think it makes sense to move this to interrupt.c / interrupt.h, so other tests can use it. But we can do this later.

OK, I can do that (I guess I have to respin anyway).

Quoted 19 lines
Quoted 19 lines
s390x/intercept.c new file +19 -0
+
+/* Test the SET PREFIX and STORE PREFIX instructions */
+static void test_prefix(void)
+{
+	uint32_t old_prefix = -1U, tst_prefix = -1U;
+	uint32_t new_prefix = (uint32_t)(intptr_t)pagebuf;
+
+	memset(pagebuf, 0, PAGE_SIZE * 2);
+
+	/*
+	 * Temporarily change the prefix page to our buffer, and store
+	 * some facility bits there ... at least some of them should be
+	 * set in our buffer afterwards.
+	 */
+	asm volatile (
+		" stpx	%0\n"
+		" spx	%2\n"
+		" stfl	0\n"
+		" stpx	%1\n"
Quoted 8 lines

s390x/intercept.c line 55

Quoted 6 lines
s390x/intercept.c new file +6 -0
+		" spx	%0\n"
+		: "+Q"(old_prefix), "+Q"(tst_prefix)
+		: "Q"(new_prefix)
+		: "memory");
+	report("spx + stfl", pagebuf[GEN_LC_STFL] != 0 &&
+			     old_prefix == 0 && tst_prefix == new_prefix);

I would split this into two tests.

Sorry, I can't follow you here ... Do you mean to just split the report() or the whole sequence of assembler instructions?

Quoted 9 lines

s390x/intercept.c line 60

Quoted 5 lines
s390x/intercept.c new file +5 -0
+
+	expect_pgm_int();
+	asm volatile(" spx 0(%0) " : : "r"(1));
+	report("spx alignment",
+	       get_pgm_int_code() == PGM_INT_CODE_SPECIFICATION);

Wonder if it makes sense to pass check_pgm_int_code() an string like "spx alignment", and let it handle the output. But this can also be changed later.

I guess I could also work with report_prefix_push() here ... not sure whether that looks nicer ... will give it a try...

Quoted 50 lines
Quoted 50 lines
s390x/intercept.c new file +50 -0
+
+	expect_pgm_int();
+	asm volatile(" spx 0(%0) " : : "r"(-8));
+	report("spx addressing",
+	       get_pgm_int_code() == PGM_INT_CODE_ADDRESSING);
+
+	expect_pgm_int();
+	set_low_prot(true);
+	asm volatile(" stpx 0(%0) " : : "r"(8));
+	set_low_prot(false);
+	report("stpx low-address protection",
+	       get_pgm_int_code() == PGM_INT_CODE_PROTECTION);
+
+	expect_pgm_int();
+	asm volatile(" stpx 0(%0) " : : "r"(1));
+	report("stpx alignment",
+	       get_pgm_int_code() == PGM_INT_CODE_SPECIFICATION);
+
+	expect_pgm_int();
+	asm volatile(" stpx 0(%0) " : : "r"(-8));
+	report("stpx addressing",
+	       get_pgm_int_code() == PGM_INT_CODE_ADDRESSING);
+}
+
+/* Test the STORE CPU ADDRESS instruction */
+static void test_stap(void)
+{
+	uint16_t cpuid = 0xffff;
+
+	asm volatile ("stap %0\n" : "+Q"(cpuid));
+	report("get cpu id", cpuid != 0xffff);
+
+	expect_pgm_int();
+	set_low_prot(true);
+	asm volatile ("stap 0(%0)\n" : : "r"(8));
+	set_low_prot(false);
+	report("low-address protection",
+	       get_pgm_int_code() == PGM_INT_CODE_PROTECTION)> +
+	expect_pgm_int();
+	asm volatile ("stap 0(%0)\n" : : "r"(1));
+	report("alignment", get_pgm_int_code() == PGM_INT_CODE_SPECIFICATION);
+
+	expect_pgm_int();
+	asm volatile ("stap 0(%0)\n" : : "r"(-8));
+	report("addressing", get_pgm_int_code() == PGM_INT_CODE_ADDRESSING);
+}
+
+/* Test the TEST BLOCK instruction */
+static void test_testblock(void)
+{
Quoted 8 lines

s390x/intercept.c line 117

Quoted 6 lines
s390x/intercept.c new file +6 -0
+	int cc;
+
+	memset(pagebuf, 0xaa, PAGE_SIZE);
+
+	asm volatile (
+		" lghi	0,0\n"

%0,0 ?

That's certainly wrong, since %0 is the reference to the first output parameter (cc). You likely mean %%0 or %%r0 ... and that looks rather cumbersome, too. I think I prefer the plain "0" here, what do you think?

Quoted 72 lines
Quoted 59 lines
s390x/intercept.c new file +53 -0
+		" tb	%1\n"
+		" ipm	%0\n"
+		" srl	%0,28\n"
+		: "=d" (cc)
+		: "a"(pagebuf + 0x123)
+		: "memory", "0", "cc");
+	report("page cleared",
+	       cc == 0 && pagebuf[0] == 0 &&  pagebuf[PAGE_SIZE - 1] == 0);
+
+	expect_pgm_int();
+	set_low_prot(true);
+	asm volatile (" tb %0 " : : "r"(4096));
+	set_low_prot(false);
+	report("low-address protection",
+	       get_pgm_int_code() == PGM_INT_CODE_PROTECTION);
+
+	expect_pgm_int();
+	asm volatile (" tb %0 " : : "r"(-4096));
+	report("addressing", get_pgm_int_code() == PGM_INT_CODE_ADDRESSING);
+}
+
+struct {
+	const char *name;
+	void (*func)(void);
+} tests[] = {
+	{ "prefix", test_prefix },
+	{ "stap", test_stap },
+	{ "testblock", test_testblock },
+	{ NULL, NULL }
+};
+
+int main(int argc, char **argv)
+{
+	int all = 0;
+	int i;
+
+	report_prefix_push("intercept");
+
+	if (argc < 2 || (argc == 2 && !strcmp(argv[1], "all")))
+		all = 1;
+
+	for (i = 0; tests[i].name != NULL; i++) {
+		report_prefix_push(tests[i].name);
+		if (all || strcmp(argv[1], tests[i].name) == 0) {
+			tests[i].func();
+		}
+		report_prefix_pop();
+	}
+
+	report_prefix_pop();
+
+	return report_summary();
+}
s390x/unittests.cfg +0 -0
index 92e01ab..3b6b892 100644

s390x/unittests.cfg line 27

Quoted 6 lines
s390x/unittests.cfg +3 -0
@@ -22,3 +22,6 @@
 file = selftest.elf
 groups = selftest
 extra_params = -append 'test 123'
+
+[intercept]
+file = intercept.elf

Nice! With or without these nits fixed.

Once upstream, I'll add a stidp test.

#3 lore raw
Quoted 12 lines
Quoted 11 lines

s390x/intercept.c line 24

Quoted 9 lines
s390x/intercept.c new file +8 -0
+static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE)));
+
+/* Enable or disable low-address protection */
+static void set_low_prot(bool enable)
+{
+	uint64_t cr0;
+
+	asm volatile (" stctg 0,0,%0 " : : "Q"(cr0));

Use %c0 instead?

Quoted 1 line

It's got to be %%c0 ... not sure whether this looks really nicer here?

%c0 should work, e.g. do a "git grep "%c0" in linux.git

arch/s390/kernel/base.S: lctlg %c0,%c0,0(%r4)
...

Quoted 7 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	report("spx + stfl", pagebuf[GEN_LC_STFL] != 0 &&
+			     );

I would split this into two tests.

Sorry, I can't follow you here ... Do you mean to just split the report() or the whole sequence of assembler instructions?

Sorry, I meant I would split it into:

report("spx + stpx", old_prefix == 0 && tst_prefix == new_prefix); report("spx + stfl", pagebuf[GEN_LC_STFL] != 0);

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
s390x/intercept.c new file +4 -0
+
+/* Test the TEST BLOCK instruction */
+static void test_testblock(void)
+{
Quoted 8 lines

s390x/intercept.c line 117

Quoted 6 lines
s390x/intercept.c new file +6 -0
+	int cc;
+
+	memset(pagebuf, 0xaa, PAGE_SIZE);
+
+	asm volatile (
+		" lghi	0,0\n"

%0,0 ?

Quoted 3 lines

That's certainly wrong, since %0 is the reference to the first output parameter (cc). You likely mean %%0 or %%r0 ... and that looks rather cumbersome, too. I think I prefer the plain "0" here, what do you think?

Sorry, of course I meant %r0. My keyboard ate one character ;)

(again, only one % is required, see e.g. arch/s390/kernel/entry.S)

Signature · 3 lines
Thanks,

David
#4 lore raw
Quoted 12 lines · David Hildenbrand
Quoted 12 lines
Quoted 11 lines

s390x/intercept.c line 24

Quoted 9 lines
s390x/intercept.c new file +8 -0
+static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE)));
+
+/* Enable or disable low-address protection */
+static void set_low_prot(bool enable)
+{
+	uint64_t cr0;
+
+	asm volatile (" stctg 0,0,%0 " : : "Q"(cr0));

Use %c0 instead?

Quoted 5 lines
Quoted 1 line

It's got to be %%c0 ... not sure whether this looks really nicer here?

%c0 should work, e.g. do a "git grep "%c0" in linux.git

arch/s390/kernel/base.S: lctlg %c0,%c0,0(%r4)

Well, that's a .S file ... for inline assembly in .c files, you need two percentage characters.

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

s390x/intercept.c line 117

Quoted 9 lines
s390x/intercept.c new file +9 -0
+/* Test the TEST BLOCK instruction */
+static void test_testblock(void)
+{
+	int cc;
+
+	memset(pagebuf, 0xaa, PAGE_SIZE);
+
+	asm volatile (
+		" lghi	0,0\n"

%0,0 ?

Quoted 7 lines
Quoted 3 lines

That's certainly wrong, since %0 is the reference to the first output parameter (cc). You likely mean %%0 or %%r0 ... and that looks rather cumbersome, too. I think I prefer the plain "0" here, what do you think?

Sorry, of course I meant %r0. My keyboard ate one character ;)

(again, only one % is required, see e.g. arch/s390/kernel/entry.S)

Dito, also %% required here, since we're not in a .S file.

Thomas

#5 lore raw
Quoted 13 lines · Thomas Huth
Quoted 12 lines · David Hildenbrand
Quoted 12 lines
Quoted 11 lines

s390x/intercept.c line 24

Quoted 9 lines
s390x/intercept.c new file +8 -0
+static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE)));
+
+/* Enable or disable low-address protection */
+static void set_low_prot(bool enable)
+{
+	uint64_t cr0;
+
+	asm volatile (" stctg 0,0,%0 " : : "Q"(cr0));

Use %c0 instead?

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

It's got to be %%c0 ... not sure whether this looks really nicer here?

%c0 should work, e.g. do a "git grep "%c0" in linux.git

arch/s390/kernel/base.S: lctlg %c0,%c0,0(%r4)

Well, that's a .S file ... for inline assembly in .c files, you need two percentage characters.

Oh right, wasn't aware of that! As I said, keep it like that if you prefer.

Signature · 3 lines
Thanks,

David