Skip to contentSkip to conversation

s390x: new maintainer, refactor linker scripts, tests for misalignments, execute-type instructions and vSIE epdx

GIT PULL Nico Boehr 2 participants 16 messages Apr 5, 2023 KVM

lore
Share & tools
lore

Nico Boehr

author
#0 lore raw

Hi Paolo and/or Thomas,

so, here's the <del>second</del><ins>third</ins> try of the first pull request from me :)

v2:
---
* fixup Nina's execute test to compile with Clang

v1:
---
* pick up a new version of Nina's spec_ex series to fix clang compiler issue and missing barrier.

Changes in this pull request:

* Marc contributed a series with a few fixes. Most importantly, it generates linker scripts for s390x with the assembler, permitting the use of defines in linker scripts.
It is worth noting that it also touches lib/linux/const.h to check for __ASSEMBLY__ and __ASSEMBLER__.
* Nina contributed quite a few tests for misalignments in various instructions. As well as tests for execute-type instructions. Note that a few of her tests will require recent QEMUs under TCG. Upstream fixes are available [1, 2].
* Thomas contributed a test for vSIE on s390x, where the g3 clock might sometimes we wrong after reboot. A kernel patch is required[3].
* And, finally, the patch where I get the honor to work as maintainer.

MERGE: https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/42

PIPELINE: https://gitlab.com/Nico-Boehr/kvm-unit-tests/-/pipelines/828580218

PULL: https://gitlab.com/Nico-Boehr/kvm-unit-tests.git s390x-2023-03

[1] https://lists.gnu.org/archive/html/qemu-devel/2023-03/msg04860.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2023-03/msg04896.html
[3] https://lore.kernel.org/kvm/[email protected]/

The following changes since commit 5b5d27da2973b20ec29b18df4d749fb2190458af:

memory: Skip tests for instructions that are absent (2023-04-03 18:44:24 +0200)

are available in the Git repository at:

https://gitlab.com/Nico-Boehr/kvm-unit-tests.git s390x-2023-03

for you to fetch changes up to f72ecf786b81aca39c26df43dba54e80f941770b:

s390x: sie: Test whether the epoch extension field is working as expected (2023-04-05 10:34:55 +0200)

Janosch Frank (1):
MAINTAINERS: Add Nico as s390x Maintainer and make Thomas reviewer

Marc Hartmayer (7):
.gitignore: ignore s390x/comm.key file s390x/Makefile: simplify %.hdr target rules s390x/Makefile: fix *.gbin target dependencies s390x/Makefile: refactor CPPFLAGS
s390x: use preprocessor for linker script generation
s390x: define a macro for the stack frame size lib/linux/const.h: test for __ASSEMBLER__ as well

Nina Schoetterl-Glausch (5):
s390x/spec_ex: Use PSW macro
s390x/spec_ex: Add test introducing odd address into PSW s390x/spec_ex: Add test of EXECUTE with odd target address
s390x: Add tests for execute-type instructions
s390x: spec_ex: Add test for misaligned load

Thomas Huth (1):
s390x: sie: Test whether the epoch extension field is working as
expected

 MAINTAINERS                                 |   3 +-
 s390x/Makefile                              |  28 +--
 lib/linux/const.h                           |   2 +-
 lib/s390x/asm-offsets.c                     |   1 +
 s390x/cstart64.S                            |   2 +-
 s390x/{flat.lds => flat.lds.S}              |   4 +-
 s390x/macros.S                              |   4 +-
 s390x/snippets/asm/{flat.lds => flat.lds.S} |   0
 s390x/snippets/c/{flat.lds => flat.lds.S}   |   6 +-
 s390x/ex.c                                  | 197 ++++++++++++++++++++
 s390x/gs.c                                  |  38 ++--
 s390x/sie.c                                 |  28 +++
 s390x/spec_ex.c                             | 106 +++++++++--
 s390x/unittests.cfg                         |   3 +
 .gitignore                                  |   2 +
 .gitlab-ci.yml                              |   1 +
 16 files changed, 379 insertions(+), 46 deletions(-)
 rename s390x/{flat.lds => flat.lds.S} (93%)
 rename s390x/snippets/asm/{flat.lds => flat.lds.S} (100%)
 rename s390x/snippets/c/{flat.lds => flat.lds.S} (88%)
 create mode 100644 s390x/ex.c
Signature · 1 line
2.39.2
author
#1 lore raw

[kvm-unit-tests GIT PULL v3 01/14] .gitignore: ignore `s390x/comm.key` file

From: Marc Hartmayer <[email protected]>

Ignore the Secure Execution Customer Communication Key file.

---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)
.gitignore +1 -0
index 33529b6..601822d 100644
@@ -28,5 +28,6 @@ cscope.*
 /s390x/*.bin
 /s390x/snippets/*/*.gbin
 /efi-tests/*
+/s390x/comm.key
 /s390x/snippets/*/*.hdr
 /s390x/snippets/*/*.*obj
Signature · 1 line
2.39.2
author
#2 lore raw

[kvm-unit-tests GIT PULL v3 02/14] s390x/Makefile: simplify `%.hdr` target rules

In reply to Nico Boehr

From: Marc Hartmayer <[email protected]>

Merge the two Makefile target rules $(SNIPPET_DIR)/asm/%.hdr and $(SNIPPET_DIR)/c/%.hdr into one target rule.

---
 s390x/Makefile | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
s390x/Makefile +1 -4
index 97a6161..660ff06 100644
@@ -145,10 +145,7 @@ $(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS)
 	$(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $@ $@
 	truncate -s '%4096' $@
 
-$(SNIPPET_DIR)/asm/%.hdr: $(SNIPPET_DIR)/asm/%.gbin $(HOST_KEY_DOCUMENT)
-	$(GEN_SE_HEADER) -k $(HOST_KEY_DOCUMENT) -c $<,0x0,0x00000000000000420000000000000000 --psw-addr 0x4000 -o $@
-
-$(SNIPPET_DIR)/c/%.hdr: $(SNIPPET_DIR)/c/%.gbin $(HOST_KEY_DOCUMENT)
+%.hdr: %.gbin $(HOST_KEY_DOCUMENT)
 	$(GEN_SE_HEADER) -k $(HOST_KEY_DOCUMENT) -c $<,0x0,0x00000000000000420000000000000000 --psw-addr 0x4000 -o $@
 
 .SECONDARY:
Signature · 1 line
2.39.2
author
#3 lore raw

[kvm-unit-tests GIT PULL v3 03/14] s390x/Makefile: fix `*.gbin` target dependencies

In reply to Nico Boehr

From: Marc Hartmayer <[email protected]>

If the linker scripts change, then the .gbin binaries must be rebuilt. While at it, replace $(SRCDIR)/s390x/snippets with $(SNIPPET_DIR) for these Makefile rules.

---
 s390x/Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
s390x/Makefile +4 -4
index 660ff06..71e6563 100644
@@ -135,13 +135,13 @@ $(SNIPPET_DIR)/asm/%.o: $(SNIPPET_DIR)/asm/%.S $(asm-offsets)
 $(SNIPPET_DIR)/c/%.o: $(SNIPPET_DIR)/c/%.c $(asm-offsets)
 	$(CC) $(CFLAGS) -c -nostdlib -o $@ $<
 
-$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o
-	$(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/snippets/asm/flat.lds $<
+$(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(SNIPPET_DIR)/asm/flat.lds
+	$(CC) $(LDFLAGS) -o $@ -T $(SNIPPET_DIR)/asm/flat.lds $<
 	$(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $@ $@
 	truncate -s '%4096' $@
 
-$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS)
-	$(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/snippets/c/flat.lds $< $(snippet_lib) $(FLATLIBS)
+$(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) $(SNIPPET_DIR)/c/flat.lds
+	$(CC) $(LDFLAGS) -o $@ -T $(SNIPPET_DIR)/c/flat.lds $< $(snippet_lib) $(FLATLIBS)
 	$(OBJCOPY) -O binary -j ".rodata" -j ".lowcore" -j ".text" -j ".data" -j ".bss" --set-section-flags .bss=alloc,load,contents $@ $@
 	truncate -s '%4096' $@
 
Signature · 1 line
2.39.2
author
#4 lore raw

[kvm-unit-tests GIT PULL v3 04/14] s390x/Makefile: refactor CPPFLAGS

In reply to Nico Boehr

From: Marc Hartmayer <[email protected]>

This change makes it easier to reuse them. While at it, add a comment why the lib include path is required.

---
 s390x/Makefile | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
s390x/Makefile +6 -1
index 71e6563..50171f3 100644
@@ -63,9 +63,14 @@ test_cases: $(tests)
 test_cases_binary: $(tests_binary)
 test_cases_pv: $(tests_pv_binary)
 
+INCLUDE_PATHS = $(SRCDIR)/lib $(SRCDIR)/lib/s390x
+# Include generated header files (e.g. in case of out-of-source builds)
+INCLUDE_PATHS += lib
+CPPFLAGS = $(addprefix -I,$(INCLUDE_PATHS))
+
 CFLAGS += -std=gnu99
 CFLAGS += -ffreestanding
-CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/s390x -I lib
+CFLAGS += $(CPPFLAGS)
 CFLAGS += -O2
 CFLAGS += -march=zEC12
 CFLAGS += -mbackchain
Signature · 1 line
2.39.2
author
#5 lore raw

[kvm-unit-tests GIT PULL v3 07/14] lib/linux/const.h: test for `__ASSEMBLER__` as well

In reply to Nico Boehr

From: Marc Hartmayer <[email protected]>

On s390x we're using the preprocessor for generating our linker scripts out of assembly files. The macro __ASSEMBLER__ is defined with value 1 when preprocessing assembly language using gcc. [1] Therefore, let's check for the macro __ASSEMBLER__ in lib/linux/const.h as well. Thus we can use macros that makes use of the _AC or _AT macro in the "linker scripts".

[1] https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html

---
 lib/linux/const.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/linux/const.h +1 -1
index c872bfd..be114dc 100644
@@ -12,7 +12,7 @@
  * leave it unchanged in asm.
  */
 
-#ifdef __ASSEMBLY__
+#if defined(__ASSEMBLY__) || defined(__ASSEMBLER__)
 #define _AC(X,Y)	X
 #define _AT(T,X)	X
 #else
Signature · 1 line
2.39.2
author
#6 lore raw

[kvm-unit-tests GIT PULL v3 08/14] s390x/spec_ex: Use PSW macro

In reply to Nico Boehr

From: Nina Schoetterl-Glausch <[email protected]>

Replace explicit psw definition by PSW macro.
No functional change intended.

---
 s390x/spec_ex.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
s390x/spec_ex.c +2 -8
index 42ecaed..2adc599 100644
@@ -105,10 +105,7 @@ static int check_invalid_psw(void)
 /* For normal PSWs bit 12 has to be 0 to be a valid PSW*/
 static int psw_bit_12_is_1(void)
 {
-	struct psw invalid = {
-		.mask = BIT(63 - 12),
-		.addr = 0x00000000deadbeee
-	};
+	struct psw invalid = PSW(BIT(63 - 12), 0x00000000deadbeee);
 
 	expect_invalid_psw(invalid);
 	load_psw(invalid);
@@ -118,10 +115,7 @@ static int psw_bit_12_is_1(void)
 /* A short PSW needs to have bit 12 set to be valid. */
 static int short_psw_bit_12_is_0(void)
 {
-	struct psw invalid = {
-		.mask = BIT(63 - 12),
-		.addr = 0x00000000deadbeee
-	};
+	struct psw invalid = PSW(BIT(63 - 12), 0x00000000deadbeee);
 	struct short_psw short_invalid = {
 		.mask = 0x0,
 		.addr = 0xdeadbeee
Signature · 1 line
2.39.2
author
#7 lore raw

[kvm-unit-tests GIT PULL v3 06/14] s390x: define a macro for the stack frame size

In reply to Nico Boehr

From: Marc Hartmayer <[email protected]>

Define and use a macro for the stack frame size. While at it, fix whitespace in the gs_handler_asm block.

---
 s390x/Makefile              |  2 +-
 lib/s390x/asm-offsets.c     |  1 +
 s390x/cstart64.S            |  2 +-
 s390x/flat.lds.S            |  4 +++-
 s390x/macros.S              |  4 ++--
 s390x/snippets/c/flat.lds.S |  6 ++++--
 s390x/gs.c                  | 38 +++++++++++++++++++++----------------
 7 files changed, 34 insertions(+), 23 deletions(-)
s390x/Makefile +1 -1
index 6732b48..ab146eb 100644
@@ -162,7 +162,7 @@ $(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) $(SNIPP
 	$(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@
 
 lds-autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d -MT $@
-%.lds: %.lds.S
+%.lds: %.lds.S $(asm-offsets)
 	$(CPP) $(lds-autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
 
 .SECONDEXPANSION:
lib/s390x/asm-offsets.c +1 -0
index f612f32..188dd2e 100644
@@ -87,6 +87,7 @@ int main(void)
 	OFFSET(STACK_FRAME_INT_GRS0, stack_frame_int, grs0);
 	OFFSET(STACK_FRAME_INT_GRS1, stack_frame_int, grs1);
 	DEFINE(STACK_FRAME_INT_SIZE, sizeof(struct stack_frame_int));
+	DEFINE(STACK_FRAME_SIZE, sizeof(struct stack_frame));
 
 	return 0;
 }
s390x/cstart64.S +1 -1
index 6f83da2..468ace3 100644
@@ -38,7 +38,7 @@ start:
 	/* setup stack */
 	larl	%r15, stackptr
 	/* Clear first stack frame */
-	xc      0(160,%r15), 0(%r15)
+	xc      0(STACK_FRAME_SIZE,%r15), 0(%r15)
 	/* setup initial PSW mask + control registers*/
 	larl	%r1, initial_psw
 	lpswe	0(%r1)
s390x/flat.lds.S +3 -1
index 952f6cd..0cb7e38 100644
@@ -1,3 +1,5 @@
+#include <asm/asm-offsets.h>
+
 SECTIONS
 {
 	.lowcore : {
@@ -44,6 +46,6 @@ SECTIONS
 	/*
 	 * stackptr set with initial stack frame preallocated
 	 */
-	stackptr = . - 160;
+	stackptr = . - STACK_FRAME_SIZE;
 	stacktop = .;
 }
s390x/macros.S +2 -2
index 13cff29..e2a56a3 100644
@@ -21,14 +21,14 @@
 	/* Save the stack address in GR2 which is the first function argument */
 	lgr     %r2, %r15
 	/* Allocate stack space for called C function, as specified in s390 ELF ABI */
-	slgfi   %r15, 160
+	slgfi   %r15, STACK_FRAME_SIZE
 	/*
 	 * Save the address of the interrupt stack into the back chain
 	 * of the called function.
 	 */
 	stg     %r2, STACK_FRAME_INT_BACKCHAIN(%r15)
 	brasl	%r14, \c_func
-	algfi   %r15, 160
+	algfi   %r15, STACK_FRAME_SIZE
 	RESTORE_REGS_STACK
 	lpswe	\old_psw
 	.endm
s390x/snippets/c/flat.lds.S +4 -2
index 9e5eb66..468b5f1 100644
@@ -1,3 +1,5 @@
+#include <asm/asm-offsets.h>
+
 SECTIONS
 {
 	.lowcore : {
@@ -18,9 +20,9 @@ SECTIONS
 	. = 0x4000;
 	/*
 	 * The stack grows down from 0x4000 to 0x2000, we pre-allocoate
-	 * a frame via the -160.
+	 * a frame via the -STACK_FRAME_SIZE.
 	 */
-	stackptr = . - 160;
+	stackptr = . - STACK_FRAME_SIZE;
 	stacktop = .;
 	/* Start text 0x4000 */
 	.text : {
s390x/gs.c +22 -16
index 4993eb8..9ae893e 100644
@@ -9,6 +9,7 @@
  *    Janosch Frank <[email protected]>
  */
 #include <libcflat.h>
+#include <asm/asm-offsets.h>
 #include <asm/page.h>
 #include <asm/facility.h>
 #include <asm/interrupt.h>
@@ -35,22 +36,27 @@ static inline unsigned long load_guarded(unsigned long *p)
 
 /* guarded-storage event handler and finally it calls gs_handler */
 extern void gs_handler_asm(void);
-	asm(".globl gs_handler_asm\n"
-	    "gs_handler_asm:\n"
-	    "	    lgr	    %r14,%r15\n" 		/* Save current stack address in r14 */
-	    "	    aghi    %r15,-320\n" 		/* Allocate stack frame */
-	    "	    stmg    %r0,%r13,192(%r15)\n" 	/* Store regs to save area */
-	    "	    stg	    %r14,312(%r15)\n"
-	    "	    la	    %r2,160(%r15)\n" 		/* Store gscb address in this_cb */
-	    "	    .insn   rxy,0xe30000000049,0,160(%r15)\n" /* stgsc */
-	    "	    lg	    %r14,24(%r2)\n" 		/* Get GSEPLA from GSCB*/
-	    "	    lg	    %r14,40(%r14)\n" 		/* Get GSERA from GSEPL*/
-	    "	    stg	    %r14,304(%r15)\n" 		/* Store GSERA in r14 of reg save area */
-	    "	    brasl   %r14,gs_handler\n" 		/* Jump to gs_handler */
-	    "	    lmg	    %r0,%r15,192(%r15)\n" 	/* Restore regs */
-	    "	    aghi    %r14, 6\n" 			/* Add lgg instr len to GSERA */
-	    "	    br	    %r14\n" 			/* Jump to next instruction after lgg */
-	    "	    .size gs_handler_asm,.-gs_handler_asm\n");
+	asm (          ".macro	STGSC	args:vararg\n"
+		"	.insn	rxy,0xe30000000049,\\args\n"
+		"	.endm\n"
+		"	.globl	gs_handler_asm\n"
+		"gs_handler_asm:\n"
+		"	lgr	%r14,%r15\n"				/* Save current stack address in r14 */
+		".Lgs_handler_frame = 16*8+32+" xstr(STACK_FRAME_SIZE) "\n"
+		"	aghi	%r15,-(.Lgs_handler_frame)\n"		/* Allocate stack frame */
+		"	stmg	%r0,%r13,192(%r15)\n"			/* Store regs to save area */
+		"	stg	%r14,312(%r15)\n"
+		"	la	%r2," xstr(STACK_FRAME_SIZE) "(%r15)\n"	/* Store gscb address in this_cb */
+		"	STGSC	%r0," xstr(STACK_FRAME_SIZE) "(%r15)\n"
+		"	lg	%r14,24(%r2)\n"				/* Get GSEPLA from GSCB*/
+		"	lg	%r14,40(%r14)\n"			/* Get GSERA from GSEPL*/
+		"	stg	%r14,304(%r15)\n"			/* Store GSERA in r14 of reg save area */
+		"	brasl	%r14,gs_handler\n"			/* Jump to gs_handler */
+		"	lmg	%r0,%r15,192(%r15)\n"			/* Restore regs */
+		"	aghi	%r14, 6\n"				/* Add lgg instr len to GSERA */
+		"	br	%r14\n"					/* Jump to next instruction after lgg */
+		".size gs_handler_asm,.-gs_handler_asm\n"
+	);
 
 void gs_handler(struct gs_cb *this_cb)
 {
Signature · 1 line
2.39.2
author
#8 lore raw

[kvm-unit-tests GIT PULL v3 05/14] s390x: use preprocessor for linker script generation

In reply to Nico Boehr

From: Marc Hartmayer <[email protected]>

The old .lds scripts are being renamed to .lds.S and the actual .lds scripts are being generated by the assembler preprocessor. This change allows us to use constants defined by macros in the .lds.S files.

---
 s390x/Makefile                              | 7 +++++--
 s390x/{flat.lds => flat.lds.S}              | 0
 s390x/snippets/asm/{flat.lds => flat.lds.S} | 0
 s390x/snippets/c/{flat.lds => flat.lds.S}   | 0
 .gitignore                                  | 1 +
 5 files changed, 6 insertions(+), 2 deletions(-)
 rename s390x/{flat.lds => flat.lds.S} (100%)
 rename s390x/snippets/asm/{flat.lds => flat.lds.S} (100%)
 rename s390x/snippets/c/{flat.lds => flat.lds.S} (100%)
s390x/Makefile +5 -2
index 50171f3..6732b48 100644
@@ -78,7 +78,7 @@ CFLAGS += -fno-delete-null-pointer-checks
 LDFLAGS += -nostdlib -Wl,--build-id=none
 
 # We want to keep intermediate files
-.PRECIOUS: %.o
+.PRECIOUS: %.o %.lds
 
 asm-offsets = lib/$(ARCH)/asm-offsets.h
 include $(SRCDIR)/scripts/asm-offsets.mak
@@ -161,6 +161,9 @@ $(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) $(SNIPP
 %.hdr.obj: %.hdr
 	$(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@
 
+lds-autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d -MT $@
+%.lds: %.lds.S
+	$(CPP) $(lds-autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
 
 .SECONDEXPANSION:
 %.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o
@@ -213,7 +216,7 @@ $(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets)
 
 
 arch_clean: asm_offsets_clean
-	$(RM) $(TEST_DIR)/*.{o,elf,bin} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d $(comm-key)
+	$(RM) $(TEST_DIR)/*.{o,elf,bin,lds} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr,lds} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d $(comm-key)
 
 generated-files = $(asm-offsets)
 $(tests:.elf=.o) $(asmlib) $(cflatobjs): $(generated-files)
s390x/flat.lds.S renamed from s390x/flat.lds +0 -0
similarity index 100%
rename from s390x/flat.lds
rename to s390x/flat.lds.S
s390x/snippets/asm/flat.lds.S renamed from s390x/snippets/asm/flat.lds +0 -0
similarity index 100%
rename from s390x/snippets/asm/flat.lds
rename to s390x/snippets/asm/flat.lds.S
s390x/snippets/c/flat.lds.S renamed from s390x/snippets/c/flat.lds +0 -0
similarity index 100%
rename from s390x/snippets/c/flat.lds
rename to s390x/snippets/c/flat.lds.S
.gitignore +1 -0
index 601822d..29f352c 100644
@@ -31,3 +31,4 @@ cscope.*
 /s390x/comm.key
 /s390x/snippets/*/*.hdr
 /s390x/snippets/*/*.*obj
+/s390x/**/*.lds
Signature · 1 line
2.39.2
author
#9 lore raw

[kvm-unit-tests GIT PULL v3 09/14] s390x/spec_ex: Add test introducing odd address into PSW

In reply to Nico Boehr

From: Nina Schoetterl-Glausch <[email protected]>

Instructions on s390 must be halfword aligned.
Introducing an odd instruction address into the PSW leads to a specification exception when attempting to execute the instruction at the odd address.
Add a test for this.

---
 s390x/spec_ex.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)
s390x/spec_ex.c +49 -1
index 2adc599..494d94c 100644
@@ -88,12 +88,23 @@ static void expect_invalid_psw(struct psw psw)
 	invalid_psw_expected = true;
 }
 
+static void clear_invalid_psw(void)
+{
+	expected_psw = PSW(0, 0);
+	invalid_psw_expected = false;
+}
+
 static int check_invalid_psw(void)
 {
 	/* Since the fixup sets this to false we check for false here. */
 	if (!invalid_psw_expected) {
+		/*
+		 * Early exception recognition: pgm_int_id == 0.
+		 * Late exception recognition: psw address has been
+		 *	incremented by pgm_int_id (unpredictable value)
+		 */
 		if (expected_psw.mask == invalid_psw.mask &&
-		    expected_psw.addr == invalid_psw.addr)
+		    expected_psw.addr == invalid_psw.addr - lowcore.pgm_int_id)
 			return 0;
 		report_fail("Wrong invalid PSW");
 	} else {
@@ -112,6 +123,42 @@ static int psw_bit_12_is_1(void)
 	return check_invalid_psw();
 }
 
+extern char misaligned_code_pre[];
+asm (  ".balign	2\n"
+"misaligned_code_pre:\n"
+"	. = . + 1\n"
+"	larl	%r0,0\n"
+"	br	%r1\n"
+);
+
+static int psw_odd_address(void)
+{
+	struct psw odd = PSW_WITH_CUR_MASK(((uint64_t)&misaligned_code_pre) + 1);
+	uint64_t executed_addr;
+
+	expect_invalid_psw(odd);
+	fixup_psw.mask = extract_psw_mask();
+	asm volatile ( "xgr	%%r0,%%r0\n"
+		"	larl	%%r1,0f\n"
+		"	stg	%%r1,%[fixup_addr]\n"
+		"	lpswe	%[odd_psw]\n"
+		"0:	lr	%[executed_addr],%%r0\n"
+	: [fixup_addr] "=&T" (fixup_psw.addr),
+	  [executed_addr] "=d" (executed_addr)
+	: [odd_psw] "Q" (odd)
+	: "cc", "%r0", "%r1", "memory" /* Compiler barrier like in load_psw */
+	);
+
+	if (!executed_addr) {
+		return check_invalid_psw();
+	} else {
+		assert(executed_addr == odd.addr);
+		clear_invalid_psw();
+		report_fail("did not execute unaligned instructions");
+		return 1;
+	}
+}
+
 /* A short PSW needs to have bit 12 set to be valid. */
 static int short_psw_bit_12_is_0(void)
 {
@@ -170,6 +217,7 @@ struct spec_ex_trigger {
 static const struct spec_ex_trigger spec_ex_triggers[] = {
 	{ "psw_bit_12_is_1", &psw_bit_12_is_1, false, &fixup_invalid_psw },
 	{ "short_psw_bit_12_is_0", &short_psw_bit_12_is_0, false, &fixup_invalid_psw },
+	{ "psw_odd_address", &psw_odd_address, false, &fixup_invalid_psw },
 	{ "bad_alignment", &bad_alignment, true, NULL },
 	{ "not_even", &not_even, true, NULL },
 	{ NULL, NULL, false, NULL },
Signature · 1 line
2.39.2
author
#10 lore raw

[kvm-unit-tests GIT PULL v3 10/14] s390x/spec_ex: Add test of EXECUTE with odd target address

In reply to Nico Boehr

From: Nina Schoetterl-Glausch <[email protected]>

The EXECUTE instruction executes the instruction at the given target address. This address must be halfword aligned, otherwise a specification exception occurs.
Add a test for this.

---
 s390x/spec_ex.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
s390x/spec_ex.c +25 -0
index 494d94c..e5f7b12 100644
@@ -177,6 +177,30 @@ static int short_psw_bit_12_is_0(void)
 	return 0;
 }
 
+static int odd_ex_target(void)
+{
+	uint64_t pre_target_addr;
+	int to = 0, from = 0x0dd;
+
+	asm volatile ( ".pushsection .text.ex_odd\n"
+		"	.balign	2\n"
+		"pre_odd_ex_target%=:\n"
+		"	. = . + 1\n"
+		"	lr	%[to],%[from]\n"
+		"	.popsection\n"
+
+		"	larl	%[pre_target_addr],pre_odd_ex_target%=\n"
+		"	ex	0,1(%[pre_target_addr])\n"
+		: [pre_target_addr] "=&a" (pre_target_addr),
+		  [to] "+d" (to)
+		: [from] "d" (from)
+	);
+
+	assert((pre_target_addr + 1) & 1);
+	report(to != from, "did not perform ex with odd target");
+	return 0;
+}
+
 static int bad_alignment(void)
 {
 	uint32_t words[5] __attribute__((aligned(16)));
@@ -218,6 +242,7 @@ static const struct spec_ex_trigger spec_ex_triggers[] = {
 	{ "psw_bit_12_is_1", &psw_bit_12_is_1, false, &fixup_invalid_psw },
 	{ "short_psw_bit_12_is_0", &short_psw_bit_12_is_0, false, &fixup_invalid_psw },
 	{ "psw_odd_address", &psw_odd_address, false, &fixup_invalid_psw },
+	{ "odd_ex_target", &odd_ex_target, true, NULL },
 	{ "bad_alignment", &bad_alignment, true, NULL },
 	{ "not_even", &not_even, true, NULL },
 	{ NULL, NULL, false, NULL },
Signature · 1 line
2.39.2
author
#11 lore raw

[kvm-unit-tests GIT PULL v3 11/14] s390x: Add tests for execute-type instructions

In reply to Nico Boehr

From: Nina Schoetterl-Glausch <[email protected]>

Test the instruction address used by targets of an execute instruction. When the target instruction calculates a relative address, the result is relative to the target instruction, not the execute instruction.

---
 s390x/Makefile      |   1 +
 s390x/ex.c          | 197 ++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg |   3 +
 .gitlab-ci.yml      |   1 +
 4 files changed, 202 insertions(+)
 create mode 100644 s390x/ex.c
s390x/Makefile +1 -0
index ab146eb..a80db53 100644
@@ -39,6 +39,7 @@ tests += $(TEST_DIR)/panic-loop-extint.elf
 tests += $(TEST_DIR)/panic-loop-pgm.elf
 tests += $(TEST_DIR)/migration-sck.elf
 tests += $(TEST_DIR)/exittime.elf
+tests += $(TEST_DIR)/ex.elf
 
 pv-tests += $(TEST_DIR)/pv-diags.elf
 
s390x/ex.c new file +197 -0

197 lines not on this page · raw message

s390x/unittests.cfg +3 -0
index d97eb5e..b61faf0 100644
@@ -215,3 +215,6 @@ file = migration-skey.elf
 smp = 2
 groups = migration
 extra_params = -append '--parallel'
+
+[execute]
+file = ex.elf
.gitlab-ci.yml +1 -0
index ad7949c..a999f64 100644
@@ -275,6 +275,7 @@ s390x-kvm:
   - ACCEL=kvm ./run_tests.sh
       selftest-setup intercept emulator sieve sthyi diag10 diag308 pfmf
       cmm vector gs iep cpumodel diag288 stsi sclp-1g sclp-3g css skrf sie
+      execute
       | tee results.txt
   - grep -q PASS results.txt && ! grep -q FAIL results.txt
  only:
Signature · 1 line
2.39.2
author
#12 lore raw

[kvm-unit-tests GIT PULL v3 13/14] MAINTAINERS: Add Nico as s390x Maintainer and make Thomas reviewer

In reply to Nico Boehr

From: Janosch Frank <[email protected]>

The circle of life continues as we bring in Nico as a s390x maintainer. Thomas moves from the maintainer position to reviewer but he's a general maintainer of the project anyway.

---
 MAINTAINERS | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
MAINTAINERS +2 -1
index 649de50..bd1761d 100644
@@ -85,11 +85,12 @@ F: lib/powerpc/
 F: lib/ppc64/
 
 S390X
-M: Thomas Huth <[email protected]>
 M: Janosch Frank <[email protected]>
 M: Claudio Imbrenda <[email protected]>
+M: Nico Böhr <[email protected]>
 S: Supported
 R: David Hildenbrand <[email protected]>
+R: Thomas Huth <[email protected]>
 L: [email protected]
 L: [email protected]
 F: s390x/
Signature · 1 line
2.39.2
author
#13 lore raw

[kvm-unit-tests GIT PULL v3 14/14] s390x: sie: Test whether the epoch extension field is working as expected

In reply to Nico Boehr

From: Thomas Huth <[email protected]>

We recently discovered a bug with the time management in nested scenarios which got fixed by kernel commit "KVM: s390: vsie: Fix the initialization of the epoch extension (epdx) field". This adds a simple test for this bug so that it is easier to determine whether the host kernel of a machine has already been fixed or not.

---
 s390x/sie.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
s390x/sie.c +28 -0
index 87575b2..cd3cea1 100644
@@ -58,6 +58,33 @@ static void test_diags(void)
 	}
 }
 
+static void test_epoch_ext(void)
+{
+	u32 instr[] = {
+		0xb2780000,	/* STCKE 0 */
+		0x83000044	/* DIAG 0x44 to intercept */
+	};
+
+	if (!test_facility(139)) {
+		report_skip("epdx: Multiple Epoch Facility is not available");
+		return;
+	}
+
+	guest[0] = 0x00;
+	memcpy(guest_instr, instr, sizeof(instr));
+
+	vm.sblk->gpsw.addr = PAGE_SIZE * 2;
+	vm.sblk->gpsw.mask = PSW_MASK_64;
+
+	vm.sblk->ecd |= ECD_MEF;
+	vm.sblk->epdx = 0x47;	/* Setting the epoch extension here ... */
+
+	sie(&vm);
+
+	/* ... should result in the same epoch extension here: */
+	report(guest[0] == 0x47, "epdx: different epoch is visible in the guest");
+}
+
 static void setup_guest(void)
 {
 	setup_vm();
@@ -80,6 +107,7 @@ int main(void)
 
 	setup_guest();
 	test_diags();
+	test_epoch_ext();
 	sie_guest_destroy(&vm);
 
 done:
Signature · 1 line
2.39.2
author
#14 lore raw

[kvm-unit-tests GIT PULL v3 12/14] s390x: spec_ex: Add test for misaligned load

In reply to Nico Boehr

From: Nina Schoetterl-Glausch <[email protected]>

The operand of LOAD RELATIVE LONG must be word aligned, otherwise a specification exception occurs. Test that this exception occurs.

---
 s390x/spec_ex.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
s390x/spec_ex.c +19 -2
index e5f7b12..e3dd85d 100644
@@ -201,7 +201,7 @@ static int odd_ex_target(void)
 	return 0;
 }
 
-static int bad_alignment(void)
+static int bad_alignment_lqp(void)
 {
 	uint32_t words[5] __attribute__((aligned(16)));
 	uint32_t (*bad_aligned)[4] = (uint32_t (*)[4])&words[1];
@@ -214,6 +214,22 @@ static int bad_alignment(void)
 	return 0;
 }
 
+static int bad_alignment_lrl(void)
+{
+	uint64_t r;
+
+	asm volatile ( ".pushsection .rodata\n"
+		"	.balign	4\n"
+		"	. = . + 2\n"
+		"0:	.fill	4\n"
+		"	.popsection\n"
+
+		"	lrl	%0,0b\n"
+		: "=d" (r)
+	);
+	return 0;
+}
+
 static int not_even(void)
 {
 	uint64_t quad[2] __attribute__((aligned(16))) = {0};
@@ -243,7 +259,8 @@ static const struct spec_ex_trigger spec_ex_triggers[] = {
 	{ "short_psw_bit_12_is_0", &short_psw_bit_12_is_0, false, &fixup_invalid_psw },
 	{ "psw_odd_address", &psw_odd_address, false, &fixup_invalid_psw },
 	{ "odd_ex_target", &odd_ex_target, true, NULL },
-	{ "bad_alignment", &bad_alignment, true, NULL },
+	{ "bad_alignment_lqp", &bad_alignment_lqp, true, NULL },
+	{ "bad_alignment_lrl", &bad_alignment_lrl, true, NULL },
 	{ "not_even", &not_even, true, NULL },
 	{ NULL, NULL, false, NULL },
 };
Signature · 1 line
2.39.2
#15 lore raw
In reply to Nico Boehr
Quoted 3 lines · Nico Boehr

Hi Paolo and/or Thomas,

so, here's the <del>second</del><ins>third</ins> try of the first pull request from me :)

Thanks, merged now!

Thomas