All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v2 0/6] s390x: basic test infrastructure
@ 2017-05-18 11:34 David Hildenbrand
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 1/6] s390x: initial infrastructure David Hildenbrand
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: David Hildenbrand @ 2017-05-18 11:34 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, david, Christian Borntraeger, Cornelia Huck

This adds the very basic infrastructure for s390x.

For now, only a basic self test is provided. This one will also run under
TCG.

Tested on KVM (on top of z/VM) and TCG.

The following, previously sent patches are required:
- [PATCH kvm-unit-tests] Makefile: drop "-lpthread -lrt"
- [kvm-unit-tests PATCH v2 0/3] provide asm-generic spinlock

Parts taken from a prototype by Thomas Huth.

v1 -> v2:
- enable AFP-register control, so GCC can use FPs and we can drop
  -msoft-float
- moved #include's into header guards
- beautified the selftest checks
- moved S390X section befor X86 section in MAINTAINERS file
- added a simple division test, that test if the FP unit is enabled and
  working (necesessary so GCC can use all FP registers)


David Hildenbrand (6):
  s390x: initial infrastructure
  s390x: basic self test
  s390x: copy sclp.h and sclp-ascii.c from QEMU
  s390x: compile sclp-ascii.c
  s390x: wire up sclp console output
  MAINTAINERS: add s390x maintainers

 MAINTAINERS              |   7 +++
 configure                |   2 +-
 lib/s390x/asm/barrier.h  |  16 +++++++
 lib/s390x/asm/io.h       |  18 ++++++++
 lib/s390x/asm/page.h     |  16 +++++++
 lib/s390x/asm/spinlock.h |  16 +++++++
 lib/s390x/asm/stack.h    |  21 +++++++++
 lib/s390x/io.c           |  49 +++++++++++++++++++++
 lib/s390x/sclp-ascii.c   |  68 +++++++++++++++++++++++++++++
 lib/s390x/sclp.h         | 108 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/s390x/stack.c        |  28 ++++++++++++
 s390x/Makefile           |  34 +++++++++++++++
 s390x/cstart64.S         |  44 +++++++++++++++++++
 s390x/flat.lds           |  42 ++++++++++++++++++
 s390x/run                |  56 ++++++++++++++++++++++++
 s390x/selftest.c         |  41 ++++++++++++++++++
 s390x/unittests.cfg      |  24 +++++++++++
 17 files changed, 589 insertions(+), 1 deletion(-)
 create mode 100644 lib/s390x/asm/barrier.h
 create mode 100644 lib/s390x/asm/io.h
 create mode 100644 lib/s390x/asm/page.h
 create mode 100644 lib/s390x/asm/spinlock.h
 create mode 100644 lib/s390x/asm/stack.h
 create mode 100644 lib/s390x/io.c
 create mode 100644 lib/s390x/sclp-ascii.c
 create mode 100644 lib/s390x/sclp.h
 create mode 100644 lib/s390x/stack.c
 create mode 100644 s390x/Makefile
 create mode 100644 s390x/cstart64.S
 create mode 100644 s390x/flat.lds
 create mode 100755 s390x/run
 create mode 100644 s390x/selftest.c
 create mode 100644 s390x/unittests.cfg

-- 
2.9.3

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH v2 1/6] s390x: initial infrastructure
  2017-05-18 11:34 [kvm-unit-tests PATCH v2 0/6] s390x: basic test infrastructure David Hildenbrand
@ 2017-05-18 11:34 ` David Hildenbrand
  2017-05-19  9:00   ` Thomas Huth
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 2/6] s390x: basic self test David Hildenbrand
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: David Hildenbrand @ 2017-05-18 11:34 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, david, Christian Borntraeger, Cornelia Huck

This adds the very basic infrastructure for s390x. As we compile for
z900, also QEMU tcg can be used.

To cross compile:

$./configure --arch=s390x --cross-prefix=/usr/bin/s390x-linux-gnu-
$ make

Please note that for now, nothing will be compiled, as there is no test
to compile. A basic self test will be added in the following patches.

smp and stack unwinding is not supported yet. sclp console output will
be added in the following patches.

Parts based on a prototype by Thomas Huth.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 configure                |  2 +-
 lib/s390x/asm/barrier.h  | 16 ++++++++++++++
 lib/s390x/asm/io.h       | 18 ++++++++++++++++
 lib/s390x/asm/page.h     | 16 ++++++++++++++
 lib/s390x/asm/spinlock.h | 16 ++++++++++++++
 lib/s390x/asm/stack.h    | 21 ++++++++++++++++++
 lib/s390x/io.c           | 48 +++++++++++++++++++++++++++++++++++++++++
 lib/s390x/stack.c        | 28 ++++++++++++++++++++++++
 s390x/Makefile           | 31 +++++++++++++++++++++++++++
 s390x/cstart64.S         | 44 +++++++++++++++++++++++++++++++++++++
 s390x/flat.lds           | 42 ++++++++++++++++++++++++++++++++++++
 s390x/run                | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg      | 19 ++++++++++++++++
 13 files changed, 356 insertions(+), 1 deletion(-)
 create mode 100644 lib/s390x/asm/barrier.h
 create mode 100644 lib/s390x/asm/io.h
 create mode 100644 lib/s390x/asm/page.h
 create mode 100644 lib/s390x/asm/spinlock.h
 create mode 100644 lib/s390x/asm/stack.h
 create mode 100644 lib/s390x/io.c
 create mode 100644 lib/s390x/stack.c
 create mode 100644 s390x/Makefile
 create mode 100644 s390x/cstart64.S
 create mode 100644 s390x/flat.lds
 create mode 100755 s390x/run
 create mode 100644 s390x/unittests.cfg

diff --git a/configure b/configure
index d152414..3690041 100755
--- a/configure
+++ b/configure
@@ -7,7 +7,7 @@ objcopy=objcopy
 objdump=objdump
 ar=ar
 addr2line=addr2line
-arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'`
+arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/;s/s390x.*/s390x/'`
 host=$arch
 cross_prefix=
 endian=""
diff --git a/lib/s390x/asm/barrier.h b/lib/s390x/asm/barrier.h
new file mode 100644
index 0000000..d862e78
--- /dev/null
+++ b/lib/s390x/asm/barrier.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  Thomas Huth <thuth@redhat.com>
+ *  David Hildenbrand <david@redhat.com>
+ *
+ * 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.
+ */
+#ifndef _ASM_S390X_BARRIER_H_
+#define _ASM_S390X_BARRIER_H_
+
+#include <asm-generic/barrier.h>
+
+#endif
diff --git a/lib/s390x/asm/io.h b/lib/s390x/asm/io.h
new file mode 100644
index 0000000..094dace
--- /dev/null
+++ b/lib/s390x/asm/io.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  Thomas Huth <thuth@redhat.com>
+ *  David Hildenbrand <david@redhat.com>
+ *
+ * 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.
+ */
+#ifndef _ASMS390X_IO_H_
+#define _ASMS390X_IO_H_
+
+#define __iomem
+
+#include <asm-generic/io.h>
+
+#endif
diff --git a/lib/s390x/asm/page.h b/lib/s390x/asm/page.h
new file mode 100644
index 0000000..141a456
--- /dev/null
+++ b/lib/s390x/asm/page.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  Thomas Huth <thuth@redhat.com>
+ *  David Hildenbrand <david@redhat.com>
+ *
+ * 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.
+ */
+#ifndef _ASMS390X_PAGE_H_
+#define _ASMS390X_PAGE_H_
+
+#include <asm-generic/page.h>
+
+#endif
diff --git a/lib/s390x/asm/spinlock.h b/lib/s390x/asm/spinlock.h
new file mode 100644
index 0000000..f7d3982
--- /dev/null
+++ b/lib/s390x/asm/spinlock.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  Thomas Huth <thuth@redhat.com>
+ *  David Hildenbrand <david@redhat.com>
+ *
+ * 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.
+ */
+#ifndef __ASMS390X_SPINLOCK_H
+#define __ASMS390X_SPINLOCK_H
+
+#include <asm-generic/spinlock.h>
+
+#endif
diff --git a/lib/s390x/asm/stack.h b/lib/s390x/asm/stack.h
new file mode 100644
index 0000000..e36d975
--- /dev/null
+++ b/lib/s390x/asm/stack.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  Thomas Huth <thuth@redhat.com>
+ *  David Hildenbrand <david@redhat.com>
+ *
+ * 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.
+ */
+#ifndef _ASMS390X_STACK_H_
+#define _ASMS390X_STACK_H_
+
+#ifndef _STACK_H_
+#error Do not directly include <asm/stack.h>. Just use <stack.h>.
+#endif
+
+#define HAVE_ARCH_BACKTRACE_FRAME
+#define HAVE_ARCH_BACKTRACE
+
+#endif
diff --git a/lib/s390x/io.c b/lib/s390x/io.c
new file mode 100644
index 0000000..a652124
--- /dev/null
+++ b/lib/s390x/io.c
@@ -0,0 +1,48 @@
+/*
+ * s390x io implementation
+ *
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  Thomas Huth <thuth@redhat.com>
+ *  David Hildenbrand <david@redhat.com>
+ *
+ * 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/spinlock.h>
+
+extern void setup_args_progname(const char *args);
+extern char ipl_args[];
+
+static struct spinlock lock;
+
+void puts(const char *s)
+{
+	spin_lock(&lock);
+	/* FIXME */
+	(void)s;
+	spin_unlock(&lock);
+}
+
+static void sigp_stop()
+{
+	register unsigned long status asm ("1") = 0;
+	register unsigned long cpu asm ("2") = 0;
+
+	asm volatile(
+		"	sigp %0,%1,0(%2)\n"
+		: "+d" (status)  : "d" (cpu), "d" (5) : "cc");
+}
+
+void setup()
+{
+	setup_args_progname(ipl_args);
+}
+
+void exit(int code)
+{
+	printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1);
+	sigp_stop();
+}
diff --git a/lib/s390x/stack.c b/lib/s390x/stack.c
new file mode 100644
index 0000000..cd34b20
--- /dev/null
+++ b/lib/s390x/stack.c
@@ -0,0 +1,28 @@
+/*
+ * s390x stack implementation
+ *
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  Thomas Huth <thuth@redhat.com>
+ *  David Hildenbrand <david@redhat.com>
+ *
+ * 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 <stack.h>
+
+int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
+{
+	printf("TODO: Implement backtrace_frame(%p, %p, %d) function!\n",
+	       frame, return_addrs, max_depth);
+	return 0;
+}
+
+int backtrace(const void **return_addrs, int max_depth)
+{
+	printf("TODO: Implement backtrace(%p, %d) function!\n",
+	       return_addrs, max_depth);
+	return 0;
+}
diff --git a/s390x/Makefile b/s390x/Makefile
new file mode 100644
index 0000000..193c3a0
--- /dev/null
+++ b/s390x/Makefile
@@ -0,0 +1,31 @@
+all: test_cases
+
+test_cases: $(tests)
+
+CFLAGS += -std=gnu99
+CFLAGS += -ffreestanding
+CFLAGS += -Wextra
+CFLAGS += -I lib
+CFLAGS += -O2
+CFLAGS += -march=z900
+LDFLAGS += -nostdlib
+
+# We want to keep intermediate files
+.PRECIOUS: %.o
+
+cflatobjs += lib/util.o
+cflatobjs += lib/alloc.o
+cflatobjs += lib/s390x/io.o
+cflatobjs += lib/s390x/stack.o
+
+cstart.o = $(TEST_DIR)/cstart64.o
+
+FLATLIBS = $(libcflat)
+%.elf: %.o $(FLATLIBS) s390x/flat.lds $(cstart.o)
+	$(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) lib/auxinfo.c -DPROGNAME=\"$@\"
+	$(CC) $(LDFLAGS) -o $@ -T s390x/flat.lds -Ttext=0x10000 \
+		$(filter %.o, $^) $(FLATLIBS) $(@:.elf=.aux.o)
+	$(RM) $(@:.elf=.aux.o)
+
+arch_clean:
+	$(RM) $(TEST_DIR)/*.{o,elf} $(TEST_DIR)/.*.d lib/s390x/.*.d
diff --git a/s390x/cstart64.S b/s390x/cstart64.S
new file mode 100644
index 0000000..28cd59d
--- /dev/null
+++ b/s390x/cstart64.S
@@ -0,0 +1,44 @@
+/*
+ * s390x startup code
+ *
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  Thomas Huth <thuth@redhat.com>
+ *  David Hildenbrand <david@redhat.com>
+ *
+ * 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.
+ */
+.section .init
+
+/* entry point - for KVM + TCG we directly start in 64 bit mode */
+	.globl start
+start:
+	/* setup stack */
+	larl	%r15, stacktop
+	/* setup initial PSW mask + control registers*/
+	larl	%r1, initital_psw
+	lpswe	0(%r1)
+init_psw_cont:
+	larl	%r1, initital_cr0
+	lctlg	%c0, %c0, 0(%r1)
+	/* call setup() */
+	brasl	%r14, setup
+	/* forward test parameter */
+	larl	%r2, __argc
+	llgf	%r2, 0(%r2)
+	larl	%r3, __argv
+	/* call to main() */
+	brasl	%r14, main
+	/* forward exit code */
+	lgr	%r3, %r2
+	/* call exit() */
+	j exit
+
+	.align	8
+initital_psw:
+	.quad	0x0000000180000000, init_psw_cont
+initital_cr0:
+	/* enable AFP-register control, so FP regs (+BFP instr) can be used */
+	.quad	0x0000000000040000
diff --git a/s390x/flat.lds b/s390x/flat.lds
new file mode 100644
index 0000000..b6e2172
--- /dev/null
+++ b/s390x/flat.lds
@@ -0,0 +1,42 @@
+SECTIONS
+{
+	.text : {
+		*(.init)
+		. = 0x480;
+		ipl_args = .;
+		. = 0x600;
+		*(.text)
+		*(.text.*)
+	}
+	. = ALIGN(64K);
+	etext = .;
+	.opd : { *(.opd) }
+	. = ALIGN(16);
+	.dynamic : {
+		dynamic_start = .;
+		*(.dynamic)
+	}
+	.dynsym : {
+		dynsym_start = .;
+		*(.dynsym)
+	}
+	.rela.dyn : { *(.rela*) }
+	. = ALIGN(16);
+	.data : {
+		*(.data)
+		*(.data.rel*)
+	}
+	. = ALIGN(16);
+	.rodata : { *(.rodata) *(.rodata.*) }
+	. = ALIGN(16);
+	.bss : { *(.bss) }
+	. = ALIGN(64K);
+	edata = .;
+	. += 64K;
+	. = ALIGN(64K);
+	/*
+	 * stackptr set with initial stack frame preallocated
+	 */
+	stackptr = . - 160;
+	stacktop = .;
+}
diff --git a/s390x/run b/s390x/run
new file mode 100755
index 0000000..cf333de
--- /dev/null
+++ b/s390x/run
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+
+if [ -z "$STANDALONE" ]; then
+	if [ ! -f config.mak ]; then
+		echo "run ./configure && make first. See ./configure -h"
+		exit 2
+	fi
+	source config.mak
+	source scripts/arch-run.bash
+fi
+
+if [ -c /dev/kvm ]; then
+	if [ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ]; then
+		kvm_available=yes
+	fi
+fi
+
+if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
+	echo "KVM is needed, but not available on this host"
+	exit 2
+fi
+
+if [ -z "$ACCEL" ]; then
+	if [ "$kvm_available" = "yes" ]; then
+		ACCEL="kvm"
+	else
+		ACCEL="tcg"
+	fi
+fi
+
+qemu=$(search_qemu_binary)
+
+M='-machine s390-ccw-virtio'
+M+=",accel=$ACCEL"
+command="$qemu -nodefaults -nographic $M"
+command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0"
+[ -f "$ENV" ] && command+=" -initrd $ENV"
+command+=" -kernel"
+command="$(timeout_cmd) $command"
+echo $command "$@"
+
+# We return the exit code via stdout, not via the QEMU return code
+lines=$(run_qemu $command "$@")
+ret=$?
+echo "$lines"
+if [ $ret -eq 1 ]; then
+	testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
+	if [ "$testret" ]; then
+		if [ $testret -eq 1 ]; then
+			ret=0
+		else
+			ret=$testret
+		fi
+	fi
+fi
+exit $ret
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
new file mode 100644
index 0000000..b1e0b1e
--- /dev/null
+++ b/s390x/unittests.cfg
@@ -0,0 +1,19 @@
+##############################################################################
+# unittest configuration
+#
+# [unittest_name]
+# file = <name>.elf		# Name of the elf file to be used.
+# extra_params = -append <params...>	# Additional parameters used.
+# groups = <group_name1> <group_name2> ... # Used to identify test cases
+#					   # with run_tests -g ...
+#					   # Specify group_name=nodefault
+#					   # to have test not run by default
+# accel = kvm|tcg		# Optionally specify if test must run with
+#				# kvm or tcg. If not specified, then kvm will
+#				# be used when available.
+# timeout = <duration>		# Optionally specify a timeout.
+# check = <path>=<value> # check a file for a particular value before running
+#			 # a test. The check line can contain multiple files
+#			 # to check separated by a space but each check
+#			 # parameter needs to be of the form <path>=<value>
+##############################################################################
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH v2 2/6] s390x: basic self test
  2017-05-18 11:34 [kvm-unit-tests PATCH v2 0/6] s390x: basic test infrastructure David Hildenbrand
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 1/6] s390x: initial infrastructure David Hildenbrand
@ 2017-05-18 11:34 ` David Hildenbrand
  2017-05-19  9:23   ` Thomas Huth
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 3/6] s390x: copy sclp.h and sclp-ascii.c from QEMU David Hildenbrand
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: David Hildenbrand @ 2017-05-18 11:34 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, david, Christian Borntraeger, Cornelia Huck

Test if the general infrastructure is working. The test will fail until
we have proper sclp console output.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 s390x/Makefile      |  2 ++
 s390x/selftest.c    | 41 +++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg |  5 +++++
 3 files changed, 48 insertions(+)
 create mode 100644 s390x/selftest.c

diff --git a/s390x/Makefile b/s390x/Makefile
index 193c3a0..4c6f9b5 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -1,3 +1,5 @@
+tests = $(TEST_DIR)/selftest.elf
+
 all: test_cases
 
 test_cases: $(tests)
diff --git a/s390x/selftest.c b/s390x/selftest.c
new file mode 100644
index 0000000..d6d4167
--- /dev/null
+++ b/s390x/selftest.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ *  Thomas Huth <thuth@redhat.com>
+ *  David Hildenbrand <david@redhat.com>
+ *
+ * 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 <util.h>
+
+static void test_fp(void)
+{
+	double a = 3.0;
+	double b = 2.0;
+	double c;
+
+	asm volatile(
+		"	ddb %1, %2\n"
+		"	std %1, %0\n"
+		: "=m" (c) : "f" (a), "m" (b) : );
+
+	report("3.0/2.0 == 1.5",	c == 1.5);
+}
+
+int main(int argc, char**argv)
+{
+	report_prefix_push("selftest");
+
+	report("true",			true);
+	report("argc == 3",		argc == 3);
+	report("argv[0] == PROGNAME",	!strcmp(argv[0], "s390x/selftest.elf"));
+	report("argv[1] == test",	!strcmp(argv[1], "test"));
+	report("argv[2] == 123",	!strcmp(argv[2], "123"));
+
+	test_fp();
+
+	return report_summary();
+}
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index b1e0b1e..92e01ab 100644
--- a/s390x/unittests.cfg
+++ b/s390x/unittests.cfg
@@ -17,3 +17,8 @@
 #			 # to check separated by a space but each check
 #			 # parameter needs to be of the form <path>=<value>
 ##############################################################################
+
+[selftest-setup]
+file = selftest.elf
+groups = selftest
+extra_params = -append 'test 123'
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH v2 3/6] s390x: copy sclp.h and sclp-ascii.c from QEMU
  2017-05-18 11:34 [kvm-unit-tests PATCH v2 0/6] s390x: basic test infrastructure David Hildenbrand
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 1/6] s390x: initial infrastructure David Hildenbrand
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 2/6] s390x: basic self test David Hildenbrand
@ 2017-05-18 11:34 ` David Hildenbrand
  2017-05-19  9:32   ` Thomas Huth
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 4/6] s390x: compile sclp-ascii.c David Hildenbrand
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: David Hildenbrand @ 2017-05-18 11:34 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, david, Christian Borntraeger, Cornelia Huck

The s390x-ccw pcbios already has what we need to print to the sclp
console. Let's copy the files and adjust them to our needs later.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 lib/s390x/sclp-ascii.c |  82 +++++++++++++++++++++++++++++++++++++
 lib/s390x/sclp.h       | 107 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 189 insertions(+)
 create mode 100644 lib/s390x/sclp-ascii.c
 create mode 100644 lib/s390x/sclp.h

diff --git a/lib/s390x/sclp-ascii.c b/lib/s390x/sclp-ascii.c
new file mode 100644
index 0000000..dc1c3e4
--- /dev/null
+++ b/lib/s390x/sclp-ascii.c
@@ -0,0 +1,82 @@
+/*
+ * SCLP ASCII access driver
+ *
+ * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "s390-ccw.h"
+#include "sclp.h"
+
+static char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096)));
+
+/* Perform service call. Return 0 on success, non-zero otherwise. */
+static int sclp_service_call(unsigned int command, void *sccb)
+{
+        int cc;
+
+        asm volatile(
+                "       .insn   rre,0xb2200000,%1,%2\n"  /* servc %1,%2 */
+                "       ipm     %0\n"
+                "       srl     %0,28"
+                : "=&d" (cc) : "d" (command), "a" (__pa(sccb))
+                : "cc", "memory");
+        consume_sclp_int();
+        if (cc == 3)
+                return -EIO;
+        if (cc == 2)
+                return -EBUSY;
+        return 0;
+}
+
+static void sclp_set_write_mask(void)
+{
+    WriteEventMask *sccb = (void *)_sccb;
+
+    sccb->h.length = sizeof(WriteEventMask);
+    sccb->mask_length = sizeof(unsigned int);
+    sccb->receive_mask = SCLP_EVENT_MASK_MSG_ASCII;
+    sccb->cp_receive_mask = SCLP_EVENT_MASK_MSG_ASCII;
+    sccb->send_mask = SCLP_EVENT_MASK_MSG_ASCII;
+    sccb->cp_send_mask = SCLP_EVENT_MASK_MSG_ASCII;
+
+    sclp_service_call(SCLP_CMD_WRITE_EVENT_MASK, sccb);
+}
+
+void sclp_setup(void)
+{
+    sclp_set_write_mask();
+}
+
+static int _strlen(const char *str)
+{
+    int i;
+    for (i = 0; *str; i++)
+        str++;
+    return i;
+}
+
+static void _memcpy(char *dest, const char *src, int len)
+{
+    int i;
+    for (i = 0; i < len; i++)
+        dest[i] = src[i];
+}
+
+void sclp_print(const char *str)
+{
+    int len = _strlen(str);
+    WriteEventData *sccb = (void *)_sccb;
+
+    sccb->h.length = sizeof(WriteEventData) + len;
+    sccb->h.function_code = SCLP_FC_NORMAL_WRITE;
+    sccb->ebh.length = sizeof(EventBufferHeader) + len;
+    sccb->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA;
+    sccb->ebh.flags = 0;
+    _memcpy(sccb->data, str, len);
+
+    sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb);
+}
diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h
new file mode 100644
index 0000000..3cbfb78
--- /dev/null
+++ b/lib/s390x/sclp.h
@@ -0,0 +1,107 @@
+/*
+ * SCLP ASCII access driver
+ *
+ * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#ifndef SCLP_H
+#define SCLP_H
+
+/* SCLP command codes */
+#define SCLP_CMDW_READ_SCP_INFO                 0x00020001
+#define SCLP_CMDW_READ_SCP_INFO_FORCED          0x00120001
+#define SCLP_CMD_READ_EVENT_DATA                0x00770005
+#define SCLP_CMD_WRITE_EVENT_DATA               0x00760005
+#define SCLP_CMD_READ_EVENT_DATA                0x00770005
+#define SCLP_CMD_WRITE_EVENT_DATA               0x00760005
+#define SCLP_CMD_WRITE_EVENT_MASK               0x00780005
+
+/* SCLP response codes */
+#define SCLP_RC_NORMAL_READ_COMPLETION          0x0010
+#define SCLP_RC_NORMAL_COMPLETION               0x0020
+#define SCLP_RC_INVALID_SCLP_COMMAND            0x01f0
+#define SCLP_RC_CONTAINED_EQUIPMENT_CHECK       0x0340
+#define SCLP_RC_INSUFFICIENT_SCCB_LENGTH        0x0300
+#define SCLP_RC_INVALID_FUNCTION                0x40f0
+#define SCLP_RC_NO_EVENT_BUFFERS_STORED         0x60f0
+#define SCLP_RC_INVALID_SELECTION_MASK          0x70f0
+#define SCLP_RC_INCONSISTENT_LENGTHS            0x72f0
+#define SCLP_RC_EVENT_BUFFER_SYNTAX_ERROR       0x73f0
+#define SCLP_RC_INVALID_MASK_LENGTH             0x74f0
+
+/* Service Call Control Block (SCCB) and its elements */
+
+#define SCCB_SIZE 4096
+
+#define SCLP_VARIABLE_LENGTH_RESPONSE           0x80
+#define SCLP_EVENT_BUFFER_ACCEPTED              0x80
+
+#define SCLP_FC_NORMAL_WRITE                    0
+
+typedef struct SCCBHeader {
+    uint16_t length;
+    uint8_t function_code;
+    uint8_t control_mask[3];
+    uint16_t response_code;
+} __attribute__((packed)) SCCBHeader;
+
+#define SCCB_DATA_LEN (SCCB_SIZE - sizeof(SCCBHeader))
+
+typedef struct ReadInfo {
+    SCCBHeader h;
+    uint16_t rnmax;
+    uint8_t rnsize;
+} __attribute__((packed)) ReadInfo;
+
+typedef struct SCCB {
+    SCCBHeader h;
+    char data[SCCB_DATA_LEN];
+ } __attribute__((packed)) SCCB;
+
+/* SCLP event types */
+#define SCLP_EVENT_ASCII_CONSOLE_DATA           0x1a
+#define SCLP_EVENT_SIGNAL_QUIESCE               0x1d
+
+/* SCLP event masks */
+#define SCLP_EVENT_MASK_SIGNAL_QUIESCE          0x00000008
+#define SCLP_EVENT_MASK_MSG_ASCII               0x00000040
+
+#define SCLP_UNCONDITIONAL_READ                 0x00
+#define SCLP_SELECTIVE_READ                     0x01
+
+typedef struct WriteEventMask {
+    SCCBHeader h;
+    uint16_t _reserved;
+    uint16_t mask_length;
+    uint32_t cp_receive_mask;
+    uint32_t cp_send_mask;
+    uint32_t send_mask;
+    uint32_t receive_mask;
+} __attribute__((packed)) WriteEventMask;
+
+typedef struct EventBufferHeader {
+    uint16_t length;
+    uint8_t  type;
+    uint8_t  flags;
+    uint16_t _reserved;
+} __attribute__((packed)) EventBufferHeader;
+
+typedef struct WriteEventData {
+    SCCBHeader h;
+    EventBufferHeader ebh;
+    char data[0];
+} __attribute__((packed)) WriteEventData;
+
+typedef struct ReadEventData {
+    SCCBHeader h;
+    EventBufferHeader ebh;
+    uint32_t mask;
+} __attribute__((packed)) ReadEventData;
+
+#define __pa(x) (x)
+
+#endif /* SCLP_H */
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH v2 4/6] s390x: compile sclp-ascii.c
  2017-05-18 11:34 [kvm-unit-tests PATCH v2 0/6] s390x: basic test infrastructure David Hildenbrand
                   ` (2 preceding siblings ...)
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 3/6] s390x: copy sclp.h and sclp-ascii.c from QEMU David Hildenbrand
@ 2017-05-18 11:34 ` David Hildenbrand
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 5/6] s390x: wire up sclp console output David Hildenbrand
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 6/6] MAINTAINERS: add s390x maintainers David Hildenbrand
  5 siblings, 0 replies; 15+ messages in thread
From: David Hildenbrand @ 2017-05-18 11:34 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, david, Christian Borntraeger, Cornelia Huck

We can reuse strlen and memcpy. __pa(x) is already defined in page.h
We don't have (and need) defines for error values and consuming sclp
irqs is not required, as we won't be passing control to some other OS.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 lib/s390x/sclp-ascii.c | 28 +++++++---------------------
 lib/s390x/sclp.h       |  2 --
 s390x/Makefile         |  1 +
 3 files changed, 8 insertions(+), 23 deletions(-)

diff --git a/lib/s390x/sclp-ascii.c b/lib/s390x/sclp-ascii.c
index dc1c3e4..dfb9e68 100644
--- a/lib/s390x/sclp-ascii.c
+++ b/lib/s390x/sclp-ascii.c
@@ -8,7 +8,9 @@
  * directory.
  */
 
-#include "s390-ccw.h"
+#include <libcflat.h>
+#include <string.h>
+#include <asm/page.h>
 #include "sclp.h"
 
 static char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096)));
@@ -24,11 +26,10 @@ static int sclp_service_call(unsigned int command, void *sccb)
                 "       srl     %0,28"
                 : "=&d" (cc) : "d" (command), "a" (__pa(sccb))
                 : "cc", "memory");
-        consume_sclp_int();
         if (cc == 3)
-                return -EIO;
+                return -1;
         if (cc == 2)
-                return -EBUSY;
+                return -1;
         return 0;
 }
 
@@ -51,24 +52,9 @@ void sclp_setup(void)
     sclp_set_write_mask();
 }
 
-static int _strlen(const char *str)
-{
-    int i;
-    for (i = 0; *str; i++)
-        str++;
-    return i;
-}
-
-static void _memcpy(char *dest, const char *src, int len)
-{
-    int i;
-    for (i = 0; i < len; i++)
-        dest[i] = src[i];
-}
-
 void sclp_print(const char *str)
 {
-    int len = _strlen(str);
+    int len = strlen(str);
     WriteEventData *sccb = (void *)_sccb;
 
     sccb->h.length = sizeof(WriteEventData) + len;
@@ -76,7 +62,7 @@ void sclp_print(const char *str)
     sccb->ebh.length = sizeof(EventBufferHeader) + len;
     sccb->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA;
     sccb->ebh.flags = 0;
-    _memcpy(sccb->data, str, len);
+    memcpy(sccb->data, str, len);
 
     sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb);
 }
diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h
index 3cbfb78..c48cc21 100644
--- a/lib/s390x/sclp.h
+++ b/lib/s390x/sclp.h
@@ -102,6 +102,4 @@ typedef struct ReadEventData {
     uint32_t mask;
 } __attribute__((packed)) ReadEventData;
 
-#define __pa(x) (x)
-
 #endif /* SCLP_H */
diff --git a/s390x/Makefile b/s390x/Makefile
index 4c6f9b5..c0998bb 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -19,6 +19,7 @@ cflatobjs += lib/util.o
 cflatobjs += lib/alloc.o
 cflatobjs += lib/s390x/io.o
 cflatobjs += lib/s390x/stack.o
+cflatobjs += lib/s390x/sclp-ascii.o
 
 cstart.o = $(TEST_DIR)/cstart64.o
 
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH v2 5/6] s390x: wire up sclp console output
  2017-05-18 11:34 [kvm-unit-tests PATCH v2 0/6] s390x: basic test infrastructure David Hildenbrand
                   ` (3 preceding siblings ...)
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 4/6] s390x: compile sclp-ascii.c David Hildenbrand
@ 2017-05-18 11:34 ` David Hildenbrand
  2017-05-19  9:33   ` Thomas Huth
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 6/6] MAINTAINERS: add s390x maintainers David Hildenbrand
  5 siblings, 1 reply; 15+ messages in thread
From: David Hildenbrand @ 2017-05-18 11:34 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, david, Christian Borntraeger, Cornelia Huck

Now the basics should be working and therefore the self test should
pass.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 lib/s390x/io.c   | 5 +++--
 lib/s390x/sclp.h | 3 +++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/s390x/io.c b/lib/s390x/io.c
index a652124..067ecf7 100644
--- a/lib/s390x/io.c
+++ b/lib/s390x/io.c
@@ -12,6 +12,7 @@
  */
 #include <libcflat.h>
 #include <asm/spinlock.h>
+#include "sclp.h"
 
 extern void setup_args_progname(const char *args);
 extern char ipl_args[];
@@ -21,8 +22,7 @@ static struct spinlock lock;
 void puts(const char *s)
 {
 	spin_lock(&lock);
-	/* FIXME */
-	(void)s;
+	sclp_print(s);
 	spin_unlock(&lock);
 }
 
@@ -39,6 +39,7 @@ static void sigp_stop()
 void setup()
 {
 	setup_args_progname(ipl_args);
+	sclp_setup();
 }
 
 void exit(int code)
diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h
index c48cc21..3f4c138 100644
--- a/lib/s390x/sclp.h
+++ b/lib/s390x/sclp.h
@@ -102,4 +102,7 @@ typedef struct ReadEventData {
     uint32_t mask;
 } __attribute__((packed)) ReadEventData;
 
+void sclp_setup(void);
+void sclp_print(const char *str);
+
 #endif /* SCLP_H */
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH v2 6/6] MAINTAINERS: add s390x maintainers
  2017-05-18 11:34 [kvm-unit-tests PATCH v2 0/6] s390x: basic test infrastructure David Hildenbrand
                   ` (4 preceding siblings ...)
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 5/6] s390x: wire up sclp console output David Hildenbrand
@ 2017-05-18 11:34 ` David Hildenbrand
  2017-05-19  9:35   ` Thomas Huth
  5 siblings, 1 reply; 15+ messages in thread
From: David Hildenbrand @ 2017-05-18 11:34 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Thomas Huth, david, Christian Borntraeger, Cornelia Huck

Add Thomas and myself as maintainers for now.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index b86dea7..d07a4cf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -76,6 +76,13 @@ F: powerpc/*
 F: lib/powerpc/*
 F: lib/ppc64/*
 
+S390X
+M: Thomas Huth <thuth@redhat.com>
+M: David Hildenbrand <david@redhat.com>
+L: kvm@vger.kernel.org
+F: s390x/*
+F: lib/s390x/*
+
 X86
 M: Paolo Bonzini <pbonzini@redhat.com>
 M: Radim Krčmář <rkrcmar@redhat.com>
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH v2 1/6] s390x: initial infrastructure
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 1/6] s390x: initial infrastructure David Hildenbrand
@ 2017-05-19  9:00   ` Thomas Huth
  2017-05-19 12:39     ` David Hildenbrand
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Huth @ 2017-05-19  9:00 UTC (permalink / raw)
  To: David Hildenbrand, kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Christian Borntraeger, Cornelia Huck

On 18.05.2017 13:34, David Hildenbrand wrote:
> This adds the very basic infrastructure for s390x. As we compile for
> z900, also QEMU tcg can be used.
> 
> To cross compile:
> 
> $./configure --arch=s390x --cross-prefix=/usr/bin/s390x-linux-gnu-
> $ make
> 
> Please note that for now, nothing will be compiled, as there is no test
> to compile. A basic self test will be added in the following patches.
> 
> smp and stack unwinding is not supported yet. sclp console output will
> be added in the following patches.
> 
> Parts based on a prototype by Thomas Huth.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  configure                |  2 +-
>  lib/s390x/asm/barrier.h  | 16 ++++++++++++++
>  lib/s390x/asm/io.h       | 18 ++++++++++++++++
>  lib/s390x/asm/page.h     | 16 ++++++++++++++
>  lib/s390x/asm/spinlock.h | 16 ++++++++++++++
>  lib/s390x/asm/stack.h    | 21 ++++++++++++++++++
>  lib/s390x/io.c           | 48 +++++++++++++++++++++++++++++++++++++++++
>  lib/s390x/stack.c        | 28 ++++++++++++++++++++++++
>  s390x/Makefile           | 31 +++++++++++++++++++++++++++
>  s390x/cstart64.S         | 44 +++++++++++++++++++++++++++++++++++++
>  s390x/flat.lds           | 42 ++++++++++++++++++++++++++++++++++++
>  s390x/run                | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
>  s390x/unittests.cfg      | 19 ++++++++++++++++
>  13 files changed, 356 insertions(+), 1 deletion(-)
>  create mode 100644 lib/s390x/asm/barrier.h
>  create mode 100644 lib/s390x/asm/io.h
>  create mode 100644 lib/s390x/asm/page.h
>  create mode 100644 lib/s390x/asm/spinlock.h
>  create mode 100644 lib/s390x/asm/stack.h
>  create mode 100644 lib/s390x/io.c
>  create mode 100644 lib/s390x/stack.c
>  create mode 100644 s390x/Makefile
>  create mode 100644 s390x/cstart64.S
>  create mode 100644 s390x/flat.lds
>  create mode 100755 s390x/run
>  create mode 100644 s390x/unittests.cfg
> 
> diff --git a/configure b/configure
> index d152414..3690041 100755
> --- a/configure
> +++ b/configure
> @@ -7,7 +7,7 @@ objcopy=objcopy
>  objdump=objdump
>  ar=ar
>  addr2line=addr2line
> -arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'`
> +arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/;s/s390x.*/s390x/'`
>  host=$arch
>  cross_prefix=
>  endian=""

I think we likely do not need this hunk on s390x, since we do not got
something like ppc64le there...?

[...]
> diff --git a/s390x/run b/s390x/run
> new file mode 100755
> index 0000000..cf333de
> --- /dev/null
> +++ b/s390x/run
> @@ -0,0 +1,56 @@
> +#!/usr/bin/env bash
> +
> +if [ -z "$STANDALONE" ]; then
> +	if [ ! -f config.mak ]; then
> +		echo "run ./configure && make first. See ./configure -h"
> +		exit 2
> +	fi
> +	source config.mak
> +	source scripts/arch-run.bash
> +fi
> +
> +if [ -c /dev/kvm ]; then
> +	if [ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ]; then
> +		kvm_available=yes
> +	fi
> +fi
> +
> +if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
> +	echo "KVM is needed, but not available on this host"
> +	exit 2
> +fi
> +
> +if [ -z "$ACCEL" ]; then
> +	if [ "$kvm_available" = "yes" ]; then
> +		ACCEL="kvm"
> +	else
> +		ACCEL="tcg"
> +	fi
> +fi
> +
> +qemu=$(search_qemu_binary)
> +
> +M='-machine s390-ccw-virtio'
> +M+=",accel=$ACCEL"

I'd maybe put the two above lines into one line only:

M="-M s390-ccw-virtio,accel=$ACCEL"

> +command="$qemu -nodefaults -nographic $M"
> +command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0"
> +[ -f "$ENV" ] && command+=" -initrd $ENV"
> +command+=" -kernel"
> +command="$(timeout_cmd) $command"
> +echo $command "$@"
> +
> +# We return the exit code via stdout, not via the QEMU return code
> +lines=$(run_qemu $command "$@")
> +ret=$?
> +echo "$lines"
> +if [ $ret -eq 1 ]; then
> +	testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
> +	if [ "$testret" ]; then
> +		if [ $testret -eq 1 ]; then
> +			ret=0
> +		else
> +			ret=$testret
> +		fi
> +	fi
> +fi
> +exit $ret

Apart from the two nits, patch looks fine to me, so feel free to add my:

Reviewed-by: Thomas Huth <thuth@redhat.com>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH v2 2/6] s390x: basic self test
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 2/6] s390x: basic self test David Hildenbrand
@ 2017-05-19  9:23   ` Thomas Huth
  2017-05-19 12:45     ` David Hildenbrand
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Huth @ 2017-05-19  9:23 UTC (permalink / raw)
  To: David Hildenbrand, kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Christian Borntraeger, Cornelia Huck

On 18.05.2017 13:34, David Hildenbrand wrote:
> Test if the general infrastructure is working. The test will fail until
> we have proper sclp console output.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  s390x/Makefile      |  2 ++
>  s390x/selftest.c    | 41 +++++++++++++++++++++++++++++++++++++++++
>  s390x/unittests.cfg |  5 +++++
>  3 files changed, 48 insertions(+)
>  create mode 100644 s390x/selftest.c
> 
> diff --git a/s390x/Makefile b/s390x/Makefile
> index 193c3a0..4c6f9b5 100644
> --- a/s390x/Makefile
> +++ b/s390x/Makefile
> @@ -1,3 +1,5 @@
> +tests = $(TEST_DIR)/selftest.elf
> +
>  all: test_cases
>  
>  test_cases: $(tests)
> diff --git a/s390x/selftest.c b/s390x/selftest.c
> new file mode 100644
> index 0000000..d6d4167
> --- /dev/null
> +++ b/s390x/selftest.c
> @@ -0,0 +1,41 @@
> +/*
> + * Copyright (c) 2017 Red Hat Inc
> + *
> + * Authors:
> + *  Thomas Huth <thuth@redhat.com>
> + *  David Hildenbrand <david@redhat.com>
> + *
> + * 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 <util.h>
> +
> +static void test_fp(void)
> +{
> +	double a = 3.0;
> +	double b = 2.0;
> +	double c;
> +
> +	asm volatile(
> +		"	ddb %1, %2\n"
> +		"	std %1, %0\n"
> +		: "=m" (c) : "f" (a), "m" (b) : );

You could omit the final ":" here.

> +
> +	report("3.0/2.0 == 1.5",	c == 1.5);

The indentation of the last parameter looks weird when only looking at
this function.

> +}
> +
> +int main(int argc, char**argv)
> +{
> +	report_prefix_push("selftest");
> +
> +	report("true",			true);
> +	report("argc == 3",		argc == 3);
> +	report("argv[0] == PROGNAME",	!strcmp(argv[0], "s390x/selftest.elf"));
> +	report("argv[1] == test",	!strcmp(argv[1], "test"));
> +	report("argv[2] == 123",	!strcmp(argv[2], "123"));

I think I'd also prefer if you could remove the indentation of the
second parameters here.
Also not sure whether we should really use the argv[1] and argv[2] test
here? ... that way, you hardly can run this test manually (without
unittests.cfg) ... I think it would be nicer if we'd had something like
in arm/selftest.c here one day ... but ok, for a start, it's likely ok.

> +	test_fp();
> +
> +	return report_summary();
> +}
> diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
> index b1e0b1e..92e01ab 100644
> --- a/s390x/unittests.cfg
> +++ b/s390x/unittests.cfg
> @@ -17,3 +17,8 @@
>  #			 # to check separated by a space but each check
>  #			 # parameter needs to be of the form <path>=<value>
>  ##############################################################################
> +
> +[selftest-setup]
> +file = selftest.elf
> +groups = selftest
> +extra_params = -append 'test 123'
> 

 Thomas

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH v2 3/6] s390x: copy sclp.h and sclp-ascii.c from QEMU
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 3/6] s390x: copy sclp.h and sclp-ascii.c from QEMU David Hildenbrand
@ 2017-05-19  9:32   ` Thomas Huth
  2017-05-19 12:48     ` David Hildenbrand
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Huth @ 2017-05-19  9:32 UTC (permalink / raw)
  To: David Hildenbrand, kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Christian Borntraeger, Cornelia Huck

On 18.05.2017 13:34, David Hildenbrand wrote:
> The s390x-ccw pcbios already has what we need to print to the sclp
> console. Let's copy the files and adjust them to our needs later.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  lib/s390x/sclp-ascii.c |  82 +++++++++++++++++++++++++++++++++++++
>  lib/s390x/sclp.h       | 107 +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 189 insertions(+)
>  create mode 100644 lib/s390x/sclp-ascii.c
>  create mode 100644 lib/s390x/sclp.h
> 
> diff --git a/lib/s390x/sclp-ascii.c b/lib/s390x/sclp-ascii.c
> new file mode 100644
> index 0000000..dc1c3e4
> --- /dev/null
> +++ b/lib/s390x/sclp-ascii.c

Looks like the file has been renamed to sclp.c in recent QEMU master ...
maybe we should use that name here, too?

 Thomas

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH v2 5/6] s390x: wire up sclp console output
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 5/6] s390x: wire up sclp console output David Hildenbrand
@ 2017-05-19  9:33   ` Thomas Huth
  0 siblings, 0 replies; 15+ messages in thread
From: Thomas Huth @ 2017-05-19  9:33 UTC (permalink / raw)
  To: David Hildenbrand, kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Christian Borntraeger, Cornelia Huck

On 18.05.2017 13:34, David Hildenbrand wrote:
> Now the basics should be working and therefore the self test should
> pass.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  lib/s390x/io.c   | 5 +++--
>  lib/s390x/sclp.h | 3 +++
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/s390x/io.c b/lib/s390x/io.c
> index a652124..067ecf7 100644
> --- a/lib/s390x/io.c
> +++ b/lib/s390x/io.c
> @@ -12,6 +12,7 @@
>   */
>  #include <libcflat.h>
>  #include <asm/spinlock.h>
> +#include "sclp.h"
>  
>  extern void setup_args_progname(const char *args);
>  extern char ipl_args[];
> @@ -21,8 +22,7 @@ static struct spinlock lock;
>  void puts(const char *s)
>  {
>  	spin_lock(&lock);
> -	/* FIXME */
> -	(void)s;
> +	sclp_print(s);
>  	spin_unlock(&lock);
>  }
>  
> @@ -39,6 +39,7 @@ static void sigp_stop()
>  void setup()
>  {
>  	setup_args_progname(ipl_args);
> +	sclp_setup();
>  }
>  
>  void exit(int code)
> diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h
> index c48cc21..3f4c138 100644
> --- a/lib/s390x/sclp.h
> +++ b/lib/s390x/sclp.h
> @@ -102,4 +102,7 @@ typedef struct ReadEventData {
>      uint32_t mask;
>  } __attribute__((packed)) ReadEventData;
>  
> +void sclp_setup(void);
> +void sclp_print(const char *str);
> +
>  #endif /* SCLP_H */

Reviewed-by: Thomas Huth <thuth@redhat.com>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH v2 6/6] MAINTAINERS: add s390x maintainers
  2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 6/6] MAINTAINERS: add s390x maintainers David Hildenbrand
@ 2017-05-19  9:35   ` Thomas Huth
  0 siblings, 0 replies; 15+ messages in thread
From: Thomas Huth @ 2017-05-19  9:35 UTC (permalink / raw)
  To: David Hildenbrand, kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Christian Borntraeger, Cornelia Huck

On 18.05.2017 13:34, David Hildenbrand wrote:
> Add Thomas and myself as maintainers for now.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  MAINTAINERS | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index b86dea7..d07a4cf 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -76,6 +76,13 @@ F: powerpc/*
>  F: lib/powerpc/*
>  F: lib/ppc64/*
>  
> +S390X
> +M: Thomas Huth <thuth@redhat.com>
> +M: David Hildenbrand <david@redhat.com>
> +L: kvm@vger.kernel.org
> +F: s390x/*
> +F: lib/s390x/*
> +
>  X86
>  M: Paolo Bonzini <pbonzini@redhat.com>
>  M: Radim Krčmář <rkrcmar@redhat.com>
> 

Acked-by: Thomas Huth <thuth@redhat.com>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH v2 1/6] s390x: initial infrastructure
  2017-05-19  9:00   ` Thomas Huth
@ 2017-05-19 12:39     ` David Hildenbrand
  0 siblings, 0 replies; 15+ messages in thread
From: David Hildenbrand @ 2017-05-19 12:39 UTC (permalink / raw)
  To: Thomas Huth, kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Christian Borntraeger, Cornelia Huck

On 19.05.2017 11:00, Thomas Huth wrote:
> On 18.05.2017 13:34, David Hildenbrand wrote:
>> This adds the very basic infrastructure for s390x. As we compile for
>> z900, also QEMU tcg can be used.
>>
>> To cross compile:
>>
>> $./configure --arch=s390x --cross-prefix=/usr/bin/s390x-linux-gnu-
>> $ make
>>
>> Please note that for now, nothing will be compiled, as there is no test
>> to compile. A basic self test will be added in the following patches.
>>
>> smp and stack unwinding is not supported yet. sclp console output will
>> be added in the following patches.
>>
>> Parts based on a prototype by Thomas Huth.
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>>  configure                |  2 +-
>>  lib/s390x/asm/barrier.h  | 16 ++++++++++++++
>>  lib/s390x/asm/io.h       | 18 ++++++++++++++++
>>  lib/s390x/asm/page.h     | 16 ++++++++++++++
>>  lib/s390x/asm/spinlock.h | 16 ++++++++++++++
>>  lib/s390x/asm/stack.h    | 21 ++++++++++++++++++
>>  lib/s390x/io.c           | 48 +++++++++++++++++++++++++++++++++++++++++
>>  lib/s390x/stack.c        | 28 ++++++++++++++++++++++++
>>  s390x/Makefile           | 31 +++++++++++++++++++++++++++
>>  s390x/cstart64.S         | 44 +++++++++++++++++++++++++++++++++++++
>>  s390x/flat.lds           | 42 ++++++++++++++++++++++++++++++++++++
>>  s390x/run                | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
>>  s390x/unittests.cfg      | 19 ++++++++++++++++
>>  13 files changed, 356 insertions(+), 1 deletion(-)
>>  create mode 100644 lib/s390x/asm/barrier.h
>>  create mode 100644 lib/s390x/asm/io.h
>>  create mode 100644 lib/s390x/asm/page.h
>>  create mode 100644 lib/s390x/asm/spinlock.h
>>  create mode 100644 lib/s390x/asm/stack.h
>>  create mode 100644 lib/s390x/io.c
>>  create mode 100644 lib/s390x/stack.c
>>  create mode 100644 s390x/Makefile
>>  create mode 100644 s390x/cstart64.S
>>  create mode 100644 s390x/flat.lds
>>  create mode 100755 s390x/run
>>  create mode 100644 s390x/unittests.cfg
>>
>> diff --git a/configure b/configure
>> index d152414..3690041 100755
>> --- a/configure
>> +++ b/configure
>> @@ -7,7 +7,7 @@ objcopy=objcopy
>>  objdump=objdump
>>  ar=ar
>>  addr2line=addr2line
>> -arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'`
>> +arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/;s/s390x.*/s390x/'`
>>  host=$arch
>>  cross_prefix=
>>  endian=""
> 
> I think we likely do not need this hunk on s390x, since we do not got
> something like ppc64le there...?

Correct, uname -m should return "s390x" only, will drop it.

> 
> [...]
>> diff --git a/s390x/run b/s390x/run
>> new file mode 100755
>> index 0000000..cf333de
>> --- /dev/null
>> +++ b/s390x/run
>> @@ -0,0 +1,56 @@
>> +#!/usr/bin/env bash
>> +
>> +if [ -z "$STANDALONE" ]; then
>> +	if [ ! -f config.mak ]; then
>> +		echo "run ./configure && make first. See ./configure -h"
>> +		exit 2
>> +	fi
>> +	source config.mak
>> +	source scripts/arch-run.bash
>> +fi
>> +
>> +if [ -c /dev/kvm ]; then
>> +	if [ "$HOST" = "s390x" ] && [ "$ARCH" = "s390x" ]; then
>> +		kvm_available=yes
>> +	fi
>> +fi
>> +
>> +if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
>> +	echo "KVM is needed, but not available on this host"
>> +	exit 2
>> +fi
>> +
>> +if [ -z "$ACCEL" ]; then
>> +	if [ "$kvm_available" = "yes" ]; then
>> +		ACCEL="kvm"
>> +	else
>> +		ACCEL="tcg"
>> +	fi
>> +fi
>> +
>> +qemu=$(search_qemu_binary)
>> +
>> +M='-machine s390-ccw-virtio'
>> +M+=",accel=$ACCEL"
> 
> I'd maybe put the two above lines into one line only:
> 
> M="-M s390-ccw-virtio,accel=$ACCEL"

This is similar to powerpc/run, so I'll leave it like that for now.

> 
>> +command="$qemu -nodefaults -nographic $M"
>> +command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0"
>> +[ -f "$ENV" ] && command+=" -initrd $ENV"
>> +command+=" -kernel"
>> +command="$(timeout_cmd) $command"
>> +echo $command "$@"
>> +
>> +# We return the exit code via stdout, not via the QEMU return code
>> +lines=$(run_qemu $command "$@")
>> +ret=$?
>> +echo "$lines"
>> +if [ $ret -eq 1 ]; then
>> +	testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
>> +	if [ "$testret" ]; then
>> +		if [ $testret -eq 1 ]; then
>> +			ret=0
>> +		else
>> +			ret=$testret
>> +		fi
>> +	fi
>> +fi
>> +exit $ret
> 
> Apart from the two nits, patch looks fine to me, so feel free to add my:
> 
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> 

Thanks!

-- 

Thanks,

David

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH v2 2/6] s390x: basic self test
  2017-05-19  9:23   ` Thomas Huth
@ 2017-05-19 12:45     ` David Hildenbrand
  0 siblings, 0 replies; 15+ messages in thread
From: David Hildenbrand @ 2017-05-19 12:45 UTC (permalink / raw)
  To: Thomas Huth, kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Christian Borntraeger, Cornelia Huck


>> +	asm volatile(
>> +		"	ddb %1, %2\n"
>> +		"	std %1, %0\n"
>> +		: "=m" (c) : "f" (a), "m" (b) : );
> 
> You could omit the final ":" here.

Yes, will drop it!

> 
>> +
>> +	report("3.0/2.0 == 1.5",	c == 1.5);
> 
> The indentation of the last parameter looks weird when only looking at
> this function.
> 
>> +}
>> +
>> +int main(int argc, char**argv)
>> +{
>> +	report_prefix_push("selftest");
>> +
>> +	report("true",			true);
>> +	report("argc == 3",		argc == 3);
>> +	report("argv[0] == PROGNAME",	!strcmp(argv[0], "s390x/selftest.elf"));
>> +	report("argv[1] == test",	!strcmp(argv[1], "test"));
>> +	report("argv[2] == 123",	!strcmp(argv[2], "123"));
> 
> I think I'd also prefer if you could remove the indentation of the
> second parameters here.

Me too, added it because Radim proposed it. Will simply drop the
indentation.

> Also not sure whether we should really use the argv[1] and argv[2] test
> here? ... that way, you hardly can run this test manually (without
> unittests.cfg) ... I think it would be nicer if we'd had something like
> in arm/selftest.c here one day ... but ok, for a start, it's likely ok.

Mixed feelings, for now I think this should be fine.

Testing frameworks will run it via unittests.cfg
The handful of people that actually execute the test manually either now
about this or should be able to figure out what is going on here.

So I agree, that we could change this later, once everything has been
running fine for a while.

> 
>> +	test_fp();
>> +
>> +	return report_summary();
>> +}
>> diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
>> index b1e0b1e..92e01ab 100644
>> --- a/s390x/unittests.cfg
>> +++ b/s390x/unittests.cfg
>> @@ -17,3 +17,8 @@
>>  #			 # to check separated by a space but each check
>>  #			 # parameter needs to be of the form <path>=<value>
>>  ##############################################################################
>> +
>> +[selftest-setup]
>> +file = selftest.elf
>> +groups = selftest
>> +extra_params = -append 'test 123'
>>
> 
>  Thomas
> 

Thanks!

-- 

Thanks,

David

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH v2 3/6] s390x: copy sclp.h and sclp-ascii.c from QEMU
  2017-05-19  9:32   ` Thomas Huth
@ 2017-05-19 12:48     ` David Hildenbrand
  0 siblings, 0 replies; 15+ messages in thread
From: David Hildenbrand @ 2017-05-19 12:48 UTC (permalink / raw)
  To: Thomas Huth, kvm
  Cc: Paolo Bonzini, Radim Krčmář,
	Christian Borntraeger, Cornelia Huck

On 19.05.2017 11:32, Thomas Huth wrote:
> On 18.05.2017 13:34, David Hildenbrand wrote:
>> The s390x-ccw pcbios already has what we need to print to the sclp
>> console. Let's copy the files and adjust them to our needs later.
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>>  lib/s390x/sclp-ascii.c |  82 +++++++++++++++++++++++++++++++++++++
>>  lib/s390x/sclp.h       | 107 +++++++++++++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 189 insertions(+)
>>  create mode 100644 lib/s390x/sclp-ascii.c
>>  create mode 100644 lib/s390x/sclp.h
>>
>> diff --git a/lib/s390x/sclp-ascii.c b/lib/s390x/sclp-ascii.c
>> new file mode 100644
>> index 0000000..dc1c3e4
>> --- /dev/null
>> +++ b/lib/s390x/sclp-ascii.c
> 
> Looks like the file has been renamed to sclp.c in recent QEMU master ...
> maybe we should use that name here, too?
> 

At the time I copied it, it was called sclp-ascii.c, so this should be
fine I think. Also, if we ever add new code related to sclp, we will
rather put it into a new file, which could then become sclp.c

>  Thomas
> 

Thanks


-- 

Thanks,

David

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-05-19 12:48 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-18 11:34 [kvm-unit-tests PATCH v2 0/6] s390x: basic test infrastructure David Hildenbrand
2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 1/6] s390x: initial infrastructure David Hildenbrand
2017-05-19  9:00   ` Thomas Huth
2017-05-19 12:39     ` David Hildenbrand
2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 2/6] s390x: basic self test David Hildenbrand
2017-05-19  9:23   ` Thomas Huth
2017-05-19 12:45     ` David Hildenbrand
2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 3/6] s390x: copy sclp.h and sclp-ascii.c from QEMU David Hildenbrand
2017-05-19  9:32   ` Thomas Huth
2017-05-19 12:48     ` David Hildenbrand
2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 4/6] s390x: compile sclp-ascii.c David Hildenbrand
2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 5/6] s390x: wire up sclp console output David Hildenbrand
2017-05-19  9:33   ` Thomas Huth
2017-05-18 11:34 ` [kvm-unit-tests PATCH v2 6/6] MAINTAINERS: add s390x maintainers David Hildenbrand
2017-05-19  9:35   ` Thomas Huth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.