All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests 00/15] arm64: initial drop
@ 2014-12-10 19:59 Andrew Jones
  2014-12-10 19:59 ` [PATCH 01/15] arm: fix run script testdev probing Andrew Jones
                   ` (15 more replies)
  0 siblings, 16 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 19:59 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

This series adds support for aarch64 to the kvm-unit-tests framework,
bringing it to the same level as the arm support. In the process a
few tweaks to the arm support were made, as one of the main goals
was to share as much code as possible between the two.

Patches
01   : A fix for the script runner. We need this one for arm
       regardless of the aarch64 support.
02-03: Fixes to the arm support. The bugs fixed weren't visible
       until running on aarch64.
04-07: Prep the arm framework for the bare minimal initial drop
08   : The bare minimal initial drop
09   : Add vector support to the minimal drop
10-12: Prep the arm framework for enabling the mmu on aarch64
13-14: Prep the aarch64 framework for enabling the mmu
15   : Enables the mmu on aarch64

These patches are also available here
https://github.com/rhdrjones/kvm-unit-tests/tree/arm64/initial-drop

Thanks,
drew


Andrew Jones (15):
  arm: fix run script testdev probing
  virtio: don't use size_t
  arm: setup: fix type mismatch
  Makefile: cscope may need to look in lib/$ARCH
  arm: use absolute headers
  arm: setup: drop unused arguments
  arm: selftest: rename svc mode to kernel mode
  arm64: initial drop
  arm64: vectors support
  arm: get PHYS_MASK from pgtable-hwdef.h
  arm: import more linux page table api
  arm: prepare mmu code for arm64
  arm64: import some Linux page table API
  arm64: prepare for 64k pages
  arm64: enable mmu

 Makefile                      |   4 +-
 arm/cstart.S                  |  18 ++-
 arm/cstart64.S                | 252 ++++++++++++++++++++++++++++++++++++++++++
 arm/flat.lds                  |  11 +-
 arm/run                       |  12 +-
 arm/selftest.c                | 141 +++++++++++++++++++++--
 arm/unittests.cfg             |  12 +-
 config/config-arm-common.mak  |  69 ++++++++++++
 config/config-arm.mak         |  74 ++-----------
 config/config-arm64.mak       |  21 ++++
 configure                     |  12 +-
 lib/arm/asm-offsets.c         |  11 +-
 lib/arm/asm/asm-offsets.h     |   2 +-
 lib/arm/asm/io.h              |   8 +-
 lib/arm/asm/mmu-api.h         |  14 +++
 lib/arm/asm/mmu.h             |  27 ++---
 lib/arm/asm/page.h            |   7 +-
 lib/arm/asm/pgtable-hwdef.h   |  44 +++++++-
 lib/arm/asm/pgtable.h         |  91 +++++++++++++++
 lib/arm/asm/processor.h       |   2 +-
 lib/arm/asm/ptrace.h          |   2 +-
 lib/arm/asm/setup.h           |  11 +-
 lib/arm/eabi_compat.c         |   2 +-
 lib/arm/io.c                  |  10 +-
 lib/arm/mmu.c                 |  82 ++++++++++----
 lib/arm/processor.c           |   6 +-
 lib/arm/setup.c               |  19 ++--
 lib/arm/spinlock.c            |   8 +-
 lib/arm64/.gitignore          |   1 +
 lib/arm64/asm-offsets.c       |  30 +++++
 lib/arm64/asm/asm-offsets.h   |   1 +
 lib/arm64/asm/barrier.h       |  17 +++
 lib/arm64/asm/esr.h           |  43 +++++++
 lib/arm64/asm/io.h            |  84 ++++++++++++++
 lib/arm64/asm/mmu-api.h       |   1 +
 lib/arm64/asm/mmu.h           |  24 ++++
 lib/arm64/asm/page.h          |  65 +++++++++++
 lib/arm64/asm/pgtable-hwdef.h | 136 +++++++++++++++++++++++
 lib/arm64/asm/pgtable.h       |  69 ++++++++++++
 lib/arm64/asm/processor.h     |  66 +++++++++++
 lib/arm64/asm/ptrace.h        |  95 ++++++++++++++++
 lib/arm64/asm/setup.h         |   1 +
 lib/arm64/asm/spinlock.h      |  15 +++
 lib/arm64/processor.c         | 192 ++++++++++++++++++++++++++++++++
 lib/chr-testdev.c             |   4 +-
 lib/kbuild.h                  |   8 ++
 lib/virtio.c                  |   2 +-
 lib/virtio.h                  |   3 +-
 48 files changed, 1638 insertions(+), 191 deletions(-)
 create mode 100644 arm/cstart64.S
 create mode 100644 config/config-arm-common.mak
 create mode 100644 config/config-arm64.mak
 create mode 100644 lib/arm/asm/mmu-api.h
 create mode 100644 lib/arm/asm/pgtable.h
 create mode 100644 lib/arm64/.gitignore
 create mode 100644 lib/arm64/asm-offsets.c
 create mode 100644 lib/arm64/asm/asm-offsets.h
 create mode 100644 lib/arm64/asm/barrier.h
 create mode 100644 lib/arm64/asm/esr.h
 create mode 100644 lib/arm64/asm/io.h
 create mode 100644 lib/arm64/asm/mmu-api.h
 create mode 100644 lib/arm64/asm/mmu.h
 create mode 100644 lib/arm64/asm/page.h
 create mode 100644 lib/arm64/asm/pgtable-hwdef.h
 create mode 100644 lib/arm64/asm/pgtable.h
 create mode 100644 lib/arm64/asm/processor.h
 create mode 100644 lib/arm64/asm/ptrace.h
 create mode 100644 lib/arm64/asm/setup.h
 create mode 100644 lib/arm64/asm/spinlock.h
 create mode 100644 lib/arm64/processor.c
 create mode 100644 lib/kbuild.h

-- 
1.9.3


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

* [PATCH 01/15] arm: fix run script testdev probing
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
@ 2014-12-10 19:59 ` Andrew Jones
  2014-12-10 19:59 ` [PATCH 02/15] virtio: don't use size_t Andrew Jones
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 19:59 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

Using -kernel doesn't force qemu to exit immediately,
and thus we "hang" when trying to run arm/run. Using
-initrd works though.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/run | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arm/run b/arm/run
index a714350225597..4c5e52525d687 100755
--- a/arm/run
+++ b/arm/run
@@ -26,7 +26,7 @@ if ! $qemu $M -device '?' 2>&1 | grep virtconsole > /dev/null; then
 	exit 2
 fi
 
-if $qemu $M -chardev testdev,id=id -kernel . 2>&1 \
+if $qemu $M -chardev testdev,id=id -initrd . 2>&1 \
 		| grep backend > /dev/null; then
 	echo "$qpath doesn't support chr-testdev. Exiting."
 	exit 2
-- 
1.9.3


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

* [PATCH 02/15] virtio: don't use size_t
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
  2014-12-10 19:59 ` [PATCH 01/15] arm: fix run script testdev probing Andrew Jones
@ 2014-12-10 19:59 ` Andrew Jones
  2014-12-10 19:59 ` [PATCH 03/15] arm: setup: fix type mismatch Andrew Jones
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 19:59 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

A size_t can have a different size when compiled as
64-bit vs. 32-bit. When unsigned int is what we want,
then make sure unsigned int is what we use.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/chr-testdev.c | 4 ++--
 lib/virtio.c      | 2 +-
 lib/virtio.h      | 3 ++-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/chr-testdev.c b/lib/chr-testdev.c
index 0c9a173a04886..c19424fd44b20 100644
--- a/lib/chr-testdev.c
+++ b/lib/chr-testdev.c
@@ -13,7 +13,7 @@ static struct virtio_device *vcon;
 static struct virtqueue *in_vq, *out_vq;
 static struct spinlock lock;
 
-static void __testdev_send(char *buf, size_t len)
+static void __testdev_send(char *buf, unsigned int len)
 {
 	int ret;
 
@@ -29,8 +29,8 @@ static void __testdev_send(char *buf, size_t len)
 
 void chr_testdev_exit(int code)
 {
+	unsigned int len;
 	char buf[8];
-	int len;
 
 	snprintf(buf, sizeof(buf), "%dq", code);
 	len = strlen(buf);
diff --git a/lib/virtio.c b/lib/virtio.c
index cb496ff2eabd5..9532d1aeb1707 100644
--- a/lib/virtio.c
+++ b/lib/virtio.c
@@ -47,7 +47,7 @@ void vring_init_virtqueue(struct vring_virtqueue *vq, unsigned index,
 	vq->data[i] = NULL;
 }
 
-int virtqueue_add_outbuf(struct virtqueue *_vq, char *buf, size_t len)
+int virtqueue_add_outbuf(struct virtqueue *_vq, char *buf, unsigned int len)
 {
 	struct vring_virtqueue *vq = to_vvq(_vq);
 	unsigned avail;
diff --git a/lib/virtio.h b/lib/virtio.h
index b51899ab998b6..4801e204a469d 100644
--- a/lib/virtio.h
+++ b/lib/virtio.h
@@ -139,7 +139,8 @@ extern void vring_init_virtqueue(struct vring_virtqueue *vq, unsigned index,
 				 bool (*notify)(struct virtqueue *),
 				 void (*callback)(struct virtqueue *),
 				 const char *name);
-extern int virtqueue_add_outbuf(struct virtqueue *vq, char *buf, size_t len);
+extern int virtqueue_add_outbuf(struct virtqueue *vq, char *buf,
+				unsigned int len);
 extern bool virtqueue_kick(struct virtqueue *vq);
 extern void detach_buf(struct vring_virtqueue *vq, unsigned head);
 extern void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len);
-- 
1.9.3


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

* [PATCH 03/15] arm: setup: fix type mismatch
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
  2014-12-10 19:59 ` [PATCH 01/15] arm: fix run script testdev probing Andrew Jones
  2014-12-10 19:59 ` [PATCH 02/15] virtio: don't use size_t Andrew Jones
@ 2014-12-10 19:59 ` Andrew Jones
  2014-12-10 19:59 ` [PATCH 04/15] Makefile: cscope may need to look in lib/$ARCH Andrew Jones
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 19:59 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

Correct a type mismatch in the cpus initialization.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index 5fa37ca35f383..50ca4cb9ff99e 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -22,7 +22,7 @@ extern unsigned long stacktop;
 extern void io_init(void);
 extern void setup_args(const char *args);
 
-u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0UL) };
+u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
 int nr_cpus;
 
 phys_addr_t __phys_offset, __phys_end;
-- 
1.9.3


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

* [PATCH 04/15] Makefile: cscope may need to look in lib/$ARCH
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (2 preceding siblings ...)
  2014-12-10 19:59 ` [PATCH 03/15] arm: setup: fix type mismatch Andrew Jones
@ 2014-12-10 19:59 ` Andrew Jones
  2014-12-10 19:59 ` [PATCH 05/15] arm: use absolute headers Andrew Jones
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 19:59 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

When $ARCH != $TEST_DIR we should look there too. This patch cheats
though and makes cscope always look there, but then gets rid of the
duplicates generated when $ARCH == $TEST_DIR.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index dd7e6e94bfe7b..4f28f072ae3d7 100644
--- a/Makefile
+++ b/Makefile
@@ -82,6 +82,6 @@ distclean: clean libfdt_clean
 cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic
 cscope:
 	$(RM) ./cscope.*
-	find -L $(TEST_DIR) lib/$(TEST_DIR) $(common_dirs) -maxdepth 1 \
-		-name '*.[chsS]' -print | sed 's,^\./,,' > ./cscope.files
+	find -L $(TEST_DIR) lib/$(TEST_DIR) lib/$(ARCH) $(common_dirs) -maxdepth 1 \
+		-name '*.[chsS]' -print | sed 's,^\./,,' | sort -u > ./cscope.files
 	cscope -bk
-- 
1.9.3


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

* [PATCH 05/15] arm: use absolute headers
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (3 preceding siblings ...)
  2014-12-10 19:59 ` [PATCH 04/15] Makefile: cscope may need to look in lib/$ARCH Andrew Jones
@ 2014-12-10 19:59 ` Andrew Jones
  2014-12-10 19:59 ` [PATCH 06/15] arm: setup: drop unused arguments Andrew Jones
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 19:59 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

Files in lib/arm including "asm/someheader.h" will get
lib/arm/asm/someheader.h, not lib/asm/someheader.h. So we
need to use <> instead of "" in order to prepare for headers
of the same name, but for a different arch. We change all
'#include's of all arm files, as consistency looks better.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/cstart.S              |  6 +++---
 arm/selftest.c            | 14 +++++++-------
 lib/arm/asm-offsets.c     |  4 ++--
 lib/arm/asm/asm-offsets.h |  2 +-
 lib/arm/asm/io.h          |  8 ++++----
 lib/arm/asm/mmu.h         |  6 +++---
 lib/arm/asm/page.h        |  2 +-
 lib/arm/asm/processor.h   |  2 +-
 lib/arm/asm/ptrace.h      |  2 +-
 lib/arm/asm/setup.h       |  4 ++--
 lib/arm/eabi_compat.c     |  2 +-
 lib/arm/io.c              | 10 +++++-----
 lib/arm/mmu.c             |  6 +++---
 lib/arm/processor.c       |  6 +++---
 lib/arm/setup.c           | 14 +++++++-------
 lib/arm/spinlock.c        |  8 ++++----
 16 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/arm/cstart.S b/arm/cstart.S
index a1ccfb24bb4e0..1e3c3a32375fd 100644
--- a/arm/cstart.S
+++ b/arm/cstart.S
@@ -6,9 +6,9 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 #define __ASSEMBLY__
-#include "asm/asm-offsets.h"
-#include "asm/ptrace.h"
-#include "asm/cp15.h"
+#include <asm/asm-offsets.h>
+#include <asm/ptrace.h>
+#include <asm/cp15.h>
 
 .arm
 
diff --git a/arm/selftest.c b/arm/selftest.c
index 0f70e1dcb3b0e..0de794ea7d696 100644
--- a/arm/selftest.c
+++ b/arm/selftest.c
@@ -5,13 +5,13 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
-#include "libcflat.h"
-#include "alloc.h"
-#include "asm/setup.h"
-#include "asm/ptrace.h"
-#include "asm/asm-offsets.h"
-#include "asm/processor.h"
-#include "asm/page.h"
+#include <libcflat.h>
+#include <alloc.h>
+#include <asm/setup.h>
+#include <asm/ptrace.h>
+#include <asm/asm-offsets.h>
+#include <asm/processor.h>
+#include <asm/page.h>
 
 #define TESTGRP "selftest"
 
diff --git a/lib/arm/asm-offsets.c b/lib/arm/asm-offsets.c
index a9c349d2d427c..76380dfa15ab8 100644
--- a/lib/arm/asm-offsets.c
+++ b/lib/arm/asm-offsets.c
@@ -5,8 +5,8 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
-#include "libcflat.h"
-#include "asm/ptrace.h"
+#include <libcflat.h>
+#include <asm/ptrace.h>
 
 #define DEFINE(sym, val) \
 	asm volatile("\n->" #sym " %0 " #val : : "i" (val))
diff --git a/lib/arm/asm/asm-offsets.h b/lib/arm/asm/asm-offsets.h
index c2ff2ba6ec417..d370ee36a182b 100644
--- a/lib/arm/asm/asm-offsets.h
+++ b/lib/arm/asm/asm-offsets.h
@@ -1 +1 @@
-#include "generated/asm-offsets.h"
+#include <generated/asm-offsets.h>
diff --git a/lib/arm/asm/io.h b/lib/arm/asm/io.h
index bbcbcd0542490..ba3b0b2412adb 100644
--- a/lib/arm/asm/io.h
+++ b/lib/arm/asm/io.h
@@ -1,8 +1,8 @@
 #ifndef _ASMARM_IO_H_
 #define _ASMARM_IO_H_
-#include "libcflat.h"
-#include "asm/barrier.h"
-#include "asm/page.h"
+#include <libcflat.h>
+#include <asm/barrier.h>
+#include <asm/page.h>
 
 #define __iomem
 #define __force
@@ -89,6 +89,6 @@ static inline void *phys_to_virt(phys_addr_t x)
 	return (void *)__phys_to_virt(x);
 }
 
-#include "asm-generic/io.h"
+#include <asm-generic/io.h>
 
 #endif /* _ASMARM_IO_H_ */
diff --git a/lib/arm/asm/mmu.h b/lib/arm/asm/mmu.h
index 451c7493c2aba..1117aeaf06a57 100644
--- a/lib/arm/asm/mmu.h
+++ b/lib/arm/asm/mmu.h
@@ -5,9 +5,9 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
-#include "asm/page.h"
-#include "asm/barrier.h"
-#include "alloc.h"
+#include <asm/page.h>
+#include <asm/barrier.h>
+#include <alloc.h>
 
 #define PTRS_PER_PGD	4
 #define PGDIR_SHIFT	30
diff --git a/lib/arm/asm/page.h b/lib/arm/asm/page.h
index 6ff849a0c0e3b..304c80b9ddfd7 100644
--- a/lib/arm/asm/page.h
+++ b/lib/arm/asm/page.h
@@ -6,7 +6,7 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 
-#include "const.h"
+#include <const.h>
 
 #define PAGE_SHIFT		12
 #define PAGE_SIZE		(_AC(1,UL) << PAGE_SHIFT)
diff --git a/lib/arm/asm/processor.h b/lib/arm/asm/processor.h
index 883cab89622f7..a56f8d1fc9797 100644
--- a/lib/arm/asm/processor.h
+++ b/lib/arm/asm/processor.h
@@ -5,7 +5,7 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
-#include "ptrace.h"
+#include <asm/ptrace.h>
 
 enum vector {
 	EXCPTN_RST,
diff --git a/lib/arm/asm/ptrace.h b/lib/arm/asm/ptrace.h
index 3a4c7532258f6..9ee71c760d22f 100644
--- a/lib/arm/asm/ptrace.h
+++ b/lib/arm/asm/ptrace.h
@@ -49,7 +49,7 @@
 #define PSR_ENDIAN_MASK	0x00000200	/* Endianness state mask */
 
 #ifndef __ASSEMBLY__
-#include "libcflat.h"
+#include <libcflat.h>
 
 struct pt_regs {
 	unsigned long uregs[18];
diff --git a/lib/arm/asm/setup.h b/lib/arm/asm/setup.h
index 21445ef2085fc..3ef3b2c99a9de 100644
--- a/lib/arm/asm/setup.h
+++ b/lib/arm/asm/setup.h
@@ -5,8 +5,8 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
-#include "libcflat.h"
-#include "alloc.h"
+#include <libcflat.h>
+#include <alloc.h>
 
 #define NR_CPUS			8
 extern u32 cpus[NR_CPUS];
diff --git a/lib/arm/eabi_compat.c b/lib/arm/eabi_compat.c
index 59d624dcd9277..8133ce7995cb0 100644
--- a/lib/arm/eabi_compat.c
+++ b/lib/arm/eabi_compat.c
@@ -1,7 +1,7 @@
 /*
  * Adapted from u-boot's arch/arm/lib/eabi_compat.c
  */
-#include "libcflat.h"
+#include <libcflat.h>
 
 int raise(int signum __unused)
 {
diff --git a/lib/arm/io.c b/lib/arm/io.c
index 60c0fdba2bff6..8b1501886736a 100644
--- a/lib/arm/io.c
+++ b/lib/arm/io.c
@@ -8,11 +8,11 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
-#include "libcflat.h"
-#include "devicetree.h"
-#include "chr-testdev.h"
-#include "asm/spinlock.h"
-#include "asm/io.h"
+#include <libcflat.h>
+#include <devicetree.h>
+#include <chr-testdev.h>
+#include <asm/spinlock.h>
+#include <asm/io.h>
 
 extern void halt(int code);
 
diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
index c9d39bf6464b8..a42ae84bcec1f 100644
--- a/lib/arm/mmu.c
+++ b/lib/arm/mmu.c
@@ -5,9 +5,9 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
-#include "asm/setup.h"
-#include "asm/mmu.h"
-#include "asm/pgtable-hwdef.h"
+#include <asm/setup.h>
+#include <asm/mmu.h>
+#include <asm/pgtable-hwdef.h>
 
 static bool mmu_on;
 static pgd_t idmap[PTRS_PER_PGD] __attribute__((aligned(L1_CACHE_BYTES)));
diff --git a/lib/arm/processor.c b/lib/arm/processor.c
index 866d11975b23b..da4163664a835 100644
--- a/lib/arm/processor.c
+++ b/lib/arm/processor.c
@@ -5,9 +5,9 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
-#include "libcflat.h"
-#include "asm/ptrace.h"
-#include "asm/processor.h"
+#include <libcflat.h>
+#include <asm/ptrace.h>
+#include <asm/processor.h>
 
 static const char *processor_modes[] = {
 	"USER_26", "FIQ_26" , "IRQ_26" , "SVC_26" ,
diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index 50ca4cb9ff99e..9d2094da8a29c 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -10,13 +10,13 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
-#include "libcflat.h"
-#include "libfdt/libfdt.h"
-#include "devicetree.h"
-#include "alloc.h"
-#include "asm/setup.h"
-#include "asm/page.h"
-#include "asm/mmu.h"
+#include <libcflat.h>
+#include <libfdt/libfdt.h>
+#include <devicetree.h>
+#include <alloc.h>
+#include <asm/setup.h>
+#include <asm/page.h>
+#include <asm/mmu.h>
 
 extern unsigned long stacktop;
 extern void io_init(void);
diff --git a/lib/arm/spinlock.c b/lib/arm/spinlock.c
index e2bb1ace43c4e..3b023ceaebf71 100644
--- a/lib/arm/spinlock.c
+++ b/lib/arm/spinlock.c
@@ -1,7 +1,7 @@
-#include "libcflat.h"
-#include "asm/spinlock.h"
-#include "asm/barrier.h"
-#include "asm/mmu.h"
+#include <libcflat.h>
+#include <asm/spinlock.h>
+#include <asm/barrier.h>
+#include <asm/mmu.h>
 
 void spin_lock(struct spinlock *lock)
 {
-- 
1.9.3


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

* [PATCH 06/15] arm: setup: drop unused arguments
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (4 preceding siblings ...)
  2014-12-10 19:59 ` [PATCH 05/15] arm: use absolute headers Andrew Jones
@ 2014-12-10 19:59 ` Andrew Jones
  2014-12-10 20:00 ` [PATCH 07/15] arm: selftest: rename svc mode to kernel mode Andrew Jones
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 19:59 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

Drop the unused arguments from setup(), passing only the fdt.
This allows setup() to be more easily shared with arm64.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/cstart.S    | 12 ++++++++++--
 lib/arm/setup.c |  3 +--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/arm/cstart.S b/arm/cstart.S
index 1e3c3a32375fd..da496e9eae7e0 100644
--- a/arm/cstart.S
+++ b/arm/cstart.S
@@ -19,15 +19,23 @@ start:
 	/*
 	 * bootloader params are in r0-r2
 	 * See the kernel doc Documentation/arm/Booting
+	 *   r0 = 0
+	 *   r1 = machine type number
+	 *   r2 = physical address of the dtb
+	 *
+	 * As we have no need for r0's nor r1's value, then
+	 * put the dtb in r0. This allows setup to be consistent
+	 * with arm64.
 	 */
 	ldr	sp, =stacktop
-	push	{r0-r3}
+	mov	r0, r2
+	push	{r0-r1}
 
 	/* set up vector table and mode stacks */
 	bl	exceptions_init
 
 	/* complete setup */
-	pop	{r0-r3}
+	pop	{r0-r1}
 	bl	setup
 
 	/* run the test */
diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index 9d2094da8a29c..8f58802e958ac 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -62,8 +62,7 @@ static void mem_init(phys_addr_t freemem_start)
 	mmu_enable_idmap();
 }
 
-void setup(unsigned long arg __unused, unsigned long id __unused,
-	   const void *fdt)
+void setup(const void *fdt)
 {
 	const char *bootargs;
 	u32 fdt_size;
-- 
1.9.3


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

* [PATCH 07/15] arm: selftest: rename svc mode to kernel mode
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (5 preceding siblings ...)
  2014-12-10 19:59 ` [PATCH 06/15] arm: setup: drop unused arguments Andrew Jones
@ 2014-12-10 20:00 ` Andrew Jones
  2014-12-10 20:00 ` [PATCH 08/15] arm64: initial drop Andrew Jones
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 20:00 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

Separate the concepts of an 'svc', the syscall instruction present
on both arm and arm64, and 'svc mode', which is arm's kernel mode,
and doesn't exist on arm64. kernel mode on arm64 is modeled with
exception level 1 (el1).

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/selftest.c    |  4 ++--
 arm/unittests.cfg | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arm/selftest.c b/arm/selftest.c
index 0de794ea7d696..885a54fee0e4a 100644
--- a/arm/selftest.c
+++ b/arm/selftest.c
@@ -195,11 +195,11 @@ int main(int argc, char **argv)
 
 		check_setup(argc-1, &argv[1]);
 
-	} else if (strcmp(argv[0], "vectors-svc") == 0) {
+	} else if (strcmp(argv[0], "vectors-kernel") == 0) {
 
 		check_vectors(NULL);
 
-	} else if (strcmp(argv[0], "vectors-usr") == 0) {
+	} else if (strcmp(argv[0], "vectors-user") == 0) {
 
 		void *sp = memalign(PAGE_SIZE, PAGE_SIZE);
 		memset(sp, 0, PAGE_SIZE);
diff --git a/arm/unittests.cfg b/arm/unittests.cfg
index 57f5f90f3e808..efcca6bf24af6 100644
--- a/arm/unittests.cfg
+++ b/arm/unittests.cfg
@@ -17,14 +17,14 @@ smp  = 1
 extra_params = -m 256 -append 'setup smp=1 mem=256'
 groups = selftest
 
-# Test vector setup and exception handling (svc mode).
-[selftest::vectors-svc]
+# Test vector setup and exception handling (kernel mode).
+[selftest::vectors-kernel]
 file = selftest.flat
-extra_params = -append 'vectors-svc'
+extra_params = -append 'vectors-kernel'
 groups = selftest
 
-# Test vector setup and exception handling (usr mode).
-[selftest::vectors-usr]
+# Test vector setup and exception handling (user mode).
+[selftest::vectors-user]
 file = selftest.flat
-extra_params = -append 'vectors-usr'
+extra_params = -append 'vectors-user'
 groups = selftest
-- 
1.9.3


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

* [PATCH 08/15] arm64: initial drop
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (6 preceding siblings ...)
  2014-12-10 20:00 ` [PATCH 07/15] arm: selftest: rename svc mode to kernel mode Andrew Jones
@ 2014-12-10 20:00 ` Andrew Jones
  2014-12-10 20:00 ` [PATCH 09/15] arm64: vectors support Andrew Jones
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 20:00 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

This is the initial drop of the arm64 test framework and a first test
that just checks that setup completed (a selftest). kvm isn't needed
to run this test unless testing with smp > 1.

Try it out with
  yum install gcc-aarch64-linux-gnu
  ./configure --cross-prefix=aarch64-linux-gnu- --arch=arm64
  make
  QEMU=[qemu with aarch64, mach-virt, and chr-testdev] ./run_tests.sh

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/cstart64.S               | 48 +++++++++++++++++++++++++
 arm/run                      | 10 ++++--
 arm/selftest.c               |  6 ++++
 arm/unittests.cfg            |  2 ++
 config/config-arm-common.mak | 68 +++++++++++++++++++++++++++++++++++
 config/config-arm.mak        | 75 +++++----------------------------------
 config/config-arm64.mak      | 20 +++++++++++
 configure                    | 12 ++++++-
 lib/arm/asm-offsets.c        |  7 +---
 lib/arm64/.gitignore         |  1 +
 lib/arm64/asm-offsets.c      | 14 ++++++++
 lib/arm64/asm/asm-offsets.h  |  1 +
 lib/arm64/asm/barrier.h      | 17 +++++++++
 lib/arm64/asm/io.h           | 84 ++++++++++++++++++++++++++++++++++++++++++++
 lib/arm64/asm/mmu.h          | 18 ++++++++++
 lib/arm64/asm/page.h         |  1 +
 lib/arm64/asm/setup.h        |  1 +
 lib/arm64/asm/spinlock.h     | 15 ++++++++
 lib/kbuild.h                 |  8 +++++
 19 files changed, 333 insertions(+), 75 deletions(-)
 create mode 100644 arm/cstart64.S
 create mode 100644 config/config-arm-common.mak
 create mode 100644 config/config-arm64.mak
 create mode 100644 lib/arm64/.gitignore
 create mode 100644 lib/arm64/asm-offsets.c
 create mode 100644 lib/arm64/asm/asm-offsets.h
 create mode 100644 lib/arm64/asm/barrier.h
 create mode 100644 lib/arm64/asm/io.h
 create mode 100644 lib/arm64/asm/mmu.h
 create mode 100644 lib/arm64/asm/page.h
 create mode 100644 lib/arm64/asm/setup.h
 create mode 100644 lib/arm64/asm/spinlock.h
 create mode 100644 lib/kbuild.h

diff --git a/arm/cstart64.S b/arm/cstart64.S
new file mode 100644
index 0000000000000..1d98066d0e187
--- /dev/null
+++ b/arm/cstart64.S
@@ -0,0 +1,48 @@
+/*
+ * Boot entry point and assembler functions for aarch64 tests.
+ *
+ * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#define __ASSEMBLY__
+#include <asm/asm-offsets.h>
+
+.section .init
+
+.globl start
+start:
+	/*
+	 * bootloader params are in x0-x3
+	 * The physical address of the dtb is in x0, x1-x3 are reserved
+	 * See the kernel doc Documentation/arm64/booting.txt
+	 */
+	adr     x4, stacktop
+	mov	sp, x4
+	stp	x0, x1, [sp, #-16]!
+
+	/* Enable FP/ASIMD */
+	mov	x0, #(3 << 20)
+	msr	cpacr_el1, x0
+
+	/* set up exception handling */
+//	bl	exceptions_init
+
+	/* complete setup */
+	ldp	x0, x1, [sp], #16
+	bl	setup
+
+	/* run the test */
+	adr	x0, __argc
+	ldr	x0, [x0]
+	adr	x1, __argv
+	bl	main
+	bl	exit
+	b	halt
+
+.text
+
+.globl halt
+halt:
+1:	wfi
+	b	1b
diff --git a/arm/run b/arm/run
index 4c5e52525d687..662a8564674a3 100755
--- a/arm/run
+++ b/arm/run
@@ -5,8 +5,9 @@ if [ ! -f config.mak ]; then
 	exit 2
 fi
 source config.mak
+processor="$PROCESSOR"
 
-qemu="${QEMU:-qemu-system-arm}"
+qemu="${QEMU:-qemu-system-$ARCH_NAME}"
 qpath=$(which $qemu 2>/dev/null)
 
 if [ -z "$qpath" ]; then
@@ -36,7 +37,12 @@ M='-machine virt,accel=kvm:tcg'
 chr_testdev='-device virtio-serial-device'
 chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
 
-command="$qemu $M -cpu $PROCESSOR $chr_testdev"
+# arm64 must use '-cpu host' with kvm
+if [ "$(arch)" = "aarch64" ] && [ "$ARCH" = "arm64" ] && [ -c /dev/kvm ]; then
+	processor="host"
+fi
+
+command="$qemu $M -cpu $processor $chr_testdev"
 command+=" -display none -serial stdio -kernel"
 
 echo $command "$@"
diff --git a/arm/selftest.c b/arm/selftest.c
index 885a54fee0e4a..30f44261d47db 100644
--- a/arm/selftest.c
+++ b/arm/selftest.c
@@ -8,10 +8,12 @@
 #include <libcflat.h>
 #include <alloc.h>
 #include <asm/setup.h>
+#ifdef __arm__
 #include <asm/ptrace.h>
 #include <asm/asm-offsets.h>
 #include <asm/processor.h>
 #include <asm/page.h>
+#endif
 
 #define TESTGRP "selftest"
 
@@ -78,6 +80,7 @@ static void check_setup(int argc, char **argv)
 	assert_args(nr_tests, 2);
 }
 
+#ifdef __arm__
 static struct pt_regs expected_regs;
 /*
  * Capture the current register state and execute an instruction
@@ -184,6 +187,7 @@ static void check_vectors(void *arg __unused)
 	report("%s", check_und() && check_svc(), testname);
 	exit(report_summary());
 }
+#endif
 
 int main(int argc, char **argv)
 {
@@ -195,6 +199,7 @@ int main(int argc, char **argv)
 
 		check_setup(argc-1, &argv[1]);
 
+#ifdef __arm__
 	} else if (strcmp(argv[0], "vectors-kernel") == 0) {
 
 		check_vectors(NULL);
@@ -204,6 +209,7 @@ int main(int argc, char **argv)
 		void *sp = memalign(PAGE_SIZE, PAGE_SIZE);
 		memset(sp, 0, PAGE_SIZE);
 		start_usr(check_vectors, NULL, (unsigned long)sp + PAGE_SIZE);
+#endif
 	}
 
 	return report_summary();
diff --git a/arm/unittests.cfg b/arm/unittests.cfg
index efcca6bf24af6..9ac6ecaa55d3b 100644
--- a/arm/unittests.cfg
+++ b/arm/unittests.cfg
@@ -22,9 +22,11 @@ groups = selftest
 file = selftest.flat
 extra_params = -append 'vectors-kernel'
 groups = selftest
+arch = arm
 
 # Test vector setup and exception handling (user mode).
 [selftest::vectors-user]
 file = selftest.flat
 extra_params = -append 'vectors-user'
 groups = selftest
+arch = arm
diff --git a/config/config-arm-common.mak b/config/config-arm-common.mak
new file mode 100644
index 0000000000000..b61a2a6044ab2
--- /dev/null
+++ b/config/config-arm-common.mak
@@ -0,0 +1,68 @@
+#
+# arm common makefile
+#
+# Authors: Andrew Jones <drjones@redhat.com>
+#
+
+ifeq ($(LOADADDR),)
+	# qemu mach-virt default load address
+	LOADADDR = 0x40000000
+endif
+
+tests-common = \
+	$(TEST_DIR)/selftest.flat
+
+all: test_cases
+
+##################################################################
+phys_base = $(LOADADDR)
+
+CFLAGS += -std=gnu99
+CFLAGS += -ffreestanding
+CFLAGS += -Wextra
+CFLAGS += -O2
+CFLAGS += -I lib -I lib/libfdt
+
+asm-offsets = lib/$(ARCH)/asm-offsets.h
+include config/asm-offsets.mak
+
+cflatobjs += lib/alloc.o
+cflatobjs += lib/devicetree.o
+cflatobjs += lib/virtio.o
+cflatobjs += lib/virtio-mmio.o
+cflatobjs += lib/chr-testdev.o
+cflatobjs += lib/arm/io.o
+cflatobjs += lib/arm/setup.o
+
+libeabi = lib/arm/libeabi.a
+eabiobjs = lib/arm/eabi_compat.o
+
+libgcc := $(shell $(CC) $(machine) --print-libgcc-file-name)
+start_addr := $(shell printf "%x\n" $$(( $(phys_base) + $(kernel_offset) )))
+
+FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi)
+%.elf: LDFLAGS = $(CFLAGS) -nostdlib
+%.elf: %.o $(FLATLIBS) arm/flat.lds
+	$(CC) $(LDFLAGS) -o $@ \
+		-Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
+		$(filter %.o, $^) $(FLATLIBS)
+
+%.flat: %.elf
+	$(OBJCOPY) -O binary $^ $@
+
+$(libeabi): $(eabiobjs)
+	$(AR) rcs $@ $^
+
+arm_clean: libfdt_clean asm_offsets_clean
+	$(RM) $(TEST_DIR)/*.{o,flat,elf} $(libeabi) $(eabiobjs) \
+	      $(TEST_DIR)/.*.d lib/arm/.*.d
+
+##################################################################
+
+tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg
+
+generated_files = $(asm-offsets)
+
+test_cases: $(generated_files) $(tests-common) $(tests)
+
+$(TEST_DIR)/selftest.elf: $(cstart.o) $(TEST_DIR)/selftest.o
diff --git a/config/config-arm.mak b/config/config-arm.mak
index 86e1d75169b59..96686fb639d2d 100644
--- a/config/config-arm.mak
+++ b/config/config-arm.mak
@@ -3,80 +3,23 @@
 #
 # Authors: Andrew Jones <drjones@redhat.com>
 #
-
-tests-common = \
-	$(TEST_DIR)/selftest.flat
-
-tests =
-
-all: test_cases
-
-##################################################################
 bits = 32
 ldarch = elf32-littlearm
-
-ifeq ($(LOADADDR),)
-	LOADADDR = 0x40000000
-endif
-phys_base = $(LOADADDR)
 kernel_offset = 0x10000
+machine = -marm
 
 CFLAGS += -D__arm__
-CFLAGS += -marm
+CFLAGS += $(machine)
 CFLAGS += -mcpu=$(PROCESSOR)
-CFLAGS += -std=gnu99
-CFLAGS += -ffreestanding
-CFLAGS += -Wextra
-CFLAGS += -O2
-CFLAGS += -I lib -I lib/libfdt
-
-asm-offsets = lib/arm/asm-offsets.h
-include config/asm-offsets.mak
-
-cflatobjs += \
-	lib/alloc.o \
-	lib/devicetree.o \
-	lib/virtio.o \
-	lib/virtio-mmio.o \
-	lib/chr-testdev.o \
-	lib/arm/io.o \
-	lib/arm/setup.o \
-	lib/arm/spinlock.o \
-	lib/arm/processor.o \
-	lib/arm/mmu.o
-
-libeabi = lib/arm/libeabi.a
-eabiobjs = lib/arm/eabi_compat.o
-
-libgcc := $(shell $(CC) -m$(ARCH) --print-libgcc-file-name)
-start_addr := $(shell printf "%x\n" $$(( $(phys_base) + $(kernel_offset) )))
-
-FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi)
-%.elf: LDFLAGS = $(CFLAGS) -nostdlib
-%.elf: %.o $(FLATLIBS) arm/flat.lds
-	$(CC) $(LDFLAGS) -o $@ \
-		-Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
-		$(filter %.o, $^) $(FLATLIBS)
-
-%.flat: %.elf
-	$(OBJCOPY) -O binary $^ $@
-
-$(libeabi): $(eabiobjs)
-	$(AR) rcs $@ $^
-
-arch_clean: libfdt_clean asm_offsets_clean
-	$(RM) $(TEST_DIR)/*.{o,flat,elf} $(libeabi) $(eabiobjs) \
-	      $(TEST_DIR)/.*.d lib/arm/.*.d
-
-##################################################################
-
-tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg
 
 cstart.o = $(TEST_DIR)/cstart.o
+cflatobjs += lib/arm/spinlock.o
+cflatobjs += lib/arm/processor.o
+cflatobjs += lib/arm/mmu.o
 
-generated_files = $(asm-offsets)
-
-test_cases: $(generated_files) $(tests-common) $(tests)
+# arm specific tests
+tests =
 
-$(TEST_DIR)/selftest.elf: $(cstart.o) $(TEST_DIR)/selftest.o
+include config/config-arm-common.mak
 
+arch_clean: arm_clean
diff --git a/config/config-arm64.mak b/config/config-arm64.mak
new file mode 100644
index 0000000000000..37db3d6026424
--- /dev/null
+++ b/config/config-arm64.mak
@@ -0,0 +1,20 @@
+#
+# arm64 makefile
+#
+# Authors: Andrew Jones <drjones@redhat.com>
+#
+bits = 64
+ldarch = elf64-littleaarch64
+kernel_offset = 0x80000
+
+CFLAGS += -D__aarch64__
+
+cstart.o = $(TEST_DIR)/cstart64.o
+
+# arm64 specific tests
+tests =
+
+include config/config-arm-common.mak
+
+arch_clean: arm_clean
+	$(RM) lib/arm64/.*.d
diff --git a/configure b/configure
index afdd62800f56e..b2ad32a3e3a52 100755
--- a/configure
+++ b/configure
@@ -62,14 +62,23 @@ while [[ "$1" = -* ]]; do
 	    ;;
     esac
 done
+
+arch_name=$arch
+[ "$arch" = "aarch64" ] && arch="arm64"
+[ "$arch_name" = "arm64" ] && arch_name="aarch64"
+
 [ -z "$processor" ] && processor="$arch"
 
-if [ "$processor" = "arm" ]; then
+if [ "$processor" = "arm64" ]; then
+    processor="cortex-a57"
+elif [ "$processor" = "arm" ]; then
     processor="cortex-a15"
 fi
 
 if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then
     testdir=x86
+elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then
+    testdir=arm
 else
     testdir=$arch
 fi
@@ -114,6 +123,7 @@ cat <<EOF > config.mak
 PREFIX=$prefix
 KERNELDIR=$(readlink -f $kerneldir)
 ARCH=$arch
+ARCH_NAME=$arch_name
 PROCESSOR=$processor
 CC=$cross_prefix$cc
 LD=$cross_prefix$ld
diff --git a/lib/arm/asm-offsets.c b/lib/arm/asm-offsets.c
index 76380dfa15ab8..1ee9da070f609 100644
--- a/lib/arm/asm-offsets.c
+++ b/lib/arm/asm-offsets.c
@@ -6,14 +6,9 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 #include <libcflat.h>
+#include <kbuild.h>
 #include <asm/ptrace.h>
 
-#define DEFINE(sym, val) \
-	asm volatile("\n->" #sym " %0 " #val : : "i" (val))
-#define OFFSET(sym, str, mem)	DEFINE(sym, offsetof(struct str, mem))
-#define COMMENT(x)		asm volatile("\n->#" x)
-#define BLANK()			asm volatile("\n->" : : )
-
 int main(void)
 {
 	OFFSET(S_R0, pt_regs, ARM_r0);
diff --git a/lib/arm64/.gitignore b/lib/arm64/.gitignore
new file mode 100644
index 0000000000000..84872bf197c67
--- /dev/null
+++ b/lib/arm64/.gitignore
@@ -0,0 +1 @@
+asm-offsets.[hs]
diff --git a/lib/arm64/asm-offsets.c b/lib/arm64/asm-offsets.c
new file mode 100644
index 0000000000000..c85b9a1e97e44
--- /dev/null
+++ b/lib/arm64/asm-offsets.c
@@ -0,0 +1,14 @@
+/*
+ * Adapted from arch/arm64/kernel/asm-offsets.c
+ *
+ * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include <libcflat.h>
+#include <kbuild.h>
+
+int main(void)
+{
+	return 0;
+}
diff --git a/lib/arm64/asm/asm-offsets.h b/lib/arm64/asm/asm-offsets.h
new file mode 100644
index 0000000000000..d370ee36a182b
--- /dev/null
+++ b/lib/arm64/asm/asm-offsets.h
@@ -0,0 +1 @@
+#include <generated/asm-offsets.h>
diff --git a/lib/arm64/asm/barrier.h b/lib/arm64/asm/barrier.h
new file mode 100644
index 0000000000000..8ebdfdf7f1037
--- /dev/null
+++ b/lib/arm64/asm/barrier.h
@@ -0,0 +1,17 @@
+#ifndef _ASMARM64_BARRIER_H_
+#define _ASMARM64_BARRIER_H_
+/*
+ * From Linux arch/arm64/include/asm/barrier.h
+ */
+
+#define isb()		asm volatile("isb" : : : "memory")
+#define dmb(opt)	asm volatile("dmb " #opt : : : "memory")
+#define dsb(opt)	asm volatile("dsb " #opt : : : "memory")
+#define mb()		dsb(sy)
+#define rmb()		dsb(ld)
+#define wmb()		dsb(st)
+#define smp_mb()	dmb(ish)
+#define smp_rmb()	dmb(ishld)
+#define smp_wmb()	dmb(ishst)
+
+#endif /* _ASMARM64_BARRIER_H_ */
diff --git a/lib/arm64/asm/io.h b/lib/arm64/asm/io.h
new file mode 100644
index 0000000000000..07b82cb9d8695
--- /dev/null
+++ b/lib/arm64/asm/io.h
@@ -0,0 +1,84 @@
+#ifndef _ASMARM64_IO_H_
+#define _ASMARM64_IO_H_
+/*
+ * From Linux arch/arm64/include/asm/io.h
+ * Generic IO read/write.  These perform native-endian accesses.
+ */
+#include <libcflat.h>
+#include <asm/barrier.h>
+#include <asm/page.h>
+
+#define __iomem
+#define __force
+
+#define __raw_writeb __raw_writeb
+static inline void __raw_writeb(u8 val, volatile void __iomem *addr)
+{
+	asm volatile("strb %w0, [%1]" : : "r" (val), "r" (addr));
+}
+
+#define __raw_writew __raw_writew
+static inline void __raw_writew(u16 val, volatile void __iomem *addr)
+{
+	asm volatile("strh %w0, [%1]" : : "r" (val), "r" (addr));
+}
+
+#define __raw_writel __raw_writel
+static inline void __raw_writel(u32 val, volatile void __iomem *addr)
+{
+	asm volatile("str %w0, [%1]" : : "r" (val), "r" (addr));
+}
+
+#define __raw_writeq __raw_writeq
+static inline void __raw_writeq(u64 val, volatile void __iomem *addr)
+{
+	asm volatile("str %0, [%1]" : : "r" (val), "r" (addr));
+}
+
+#define __raw_readb __raw_readb
+static inline u8 __raw_readb(const volatile void __iomem *addr)
+{
+	u8 val;
+	asm volatile("ldrb %w0, [%1]" : "=r" (val) : "r" (addr));
+	return val;
+}
+
+#define __raw_readw __raw_readw
+static inline u16 __raw_readw(const volatile void __iomem *addr)
+{
+	u16 val;
+	asm volatile("ldrh %w0, [%1]" : "=r" (val) : "r" (addr));
+	return val;
+}
+
+#define __raw_readl __raw_readl
+static inline u32 __raw_readl(const volatile void __iomem *addr)
+{
+	u32 val;
+	asm volatile("ldr %w0, [%1]" : "=r" (val) : "r" (addr));
+	return val;
+}
+
+#define __raw_readq __raw_readq
+static inline u64 __raw_readq(const volatile void __iomem *addr)
+{
+	u64 val;
+	asm volatile("ldr %0, [%1]" : "=r" (val) : "r" (addr));
+	return val;
+}
+
+#define virt_to_phys virt_to_phys
+static inline phys_addr_t virt_to_phys(const volatile void *x)
+{
+	return __virt_to_phys((unsigned long)(x));
+}
+
+#define phys_to_virt phys_to_virt
+static inline void *phys_to_virt(phys_addr_t x)
+{
+	return (void *)__phys_to_virt(x);
+}
+
+#include <asm-generic/io.h>
+
+#endif /* _ASMARM64_IO_H_ */
diff --git a/lib/arm64/asm/mmu.h b/lib/arm64/asm/mmu.h
new file mode 100644
index 0000000000000..cbafbca6701e7
--- /dev/null
+++ b/lib/arm64/asm/mmu.h
@@ -0,0 +1,18 @@
+#ifndef __ASMARM64_MMU_H_
+#define __ASMARM64_MMU_H_
+/*
+ * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+
+static inline bool mmu_enabled(void)
+{
+	return false;
+}
+
+static inline void mmu_enable_idmap(void)
+{
+}
+
+#endif /* __ASMARM64_MMU_H_ */
diff --git a/lib/arm64/asm/page.h b/lib/arm64/asm/page.h
new file mode 100644
index 0000000000000..395760cad5f82
--- /dev/null
+++ b/lib/arm64/asm/page.h
@@ -0,0 +1 @@
+#include "../../arm/asm/page.h"
diff --git a/lib/arm64/asm/setup.h b/lib/arm64/asm/setup.h
new file mode 100644
index 0000000000000..e3b4702716c6b
--- /dev/null
+++ b/lib/arm64/asm/setup.h
@@ -0,0 +1 @@
+#include "../../arm/asm/setup.h"
diff --git a/lib/arm64/asm/spinlock.h b/lib/arm64/asm/spinlock.h
new file mode 100644
index 0000000000000..36b7b44fa4edf
--- /dev/null
+++ b/lib/arm64/asm/spinlock.h
@@ -0,0 +1,15 @@
+#ifndef _ASMARM64_SPINLOCK_H_
+#define _ASMARM64_SPINLOCK_H_
+
+struct spinlock {
+	int v;
+};
+
+static inline void spin_lock(struct spinlock *lock __unused)
+{
+}
+static inline void spin_unlock(struct spinlock *lock __unused)
+{
+}
+
+#endif /* _ASMARM64_SPINLOCK_H_ */
diff --git a/lib/kbuild.h b/lib/kbuild.h
new file mode 100644
index 0000000000000..ab99db6770efa
--- /dev/null
+++ b/lib/kbuild.h
@@ -0,0 +1,8 @@
+#ifndef _KBUILD_H_
+#define _KBUILD_H_
+#define DEFINE(sym, val) \
+	asm volatile("\n->" #sym " %0 " #val : : "i" (val))
+#define OFFSET(sym, str, mem)	DEFINE(sym, offsetof(struct str, mem))
+#define COMMENT(x)		asm volatile("\n->#" x)
+#define BLANK()			asm volatile("\n->" : : )
+#endif
-- 
1.9.3


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

* [PATCH 09/15] arm64: vectors support
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (7 preceding siblings ...)
  2014-12-10 20:00 ` [PATCH 08/15] arm64: initial drop Andrew Jones
@ 2014-12-10 20:00 ` Andrew Jones
  2014-12-10 20:00 ` [PATCH 10/15] arm: get PHYS_MASK from pgtable-hwdef.h Andrew Jones
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 20:00 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/cstart64.S            | 142 ++++++++++++++++++++++++++++++++++++++-
 arm/selftest.c            | 129 ++++++++++++++++++++++++++++++++---
 arm/unittests.cfg         |   2 -
 config/config-arm64.mak   |   1 +
 lib/arm64/asm-offsets.c   |  16 +++++
 lib/arm64/asm/esr.h       |  43 ++++++++++++
 lib/arm64/asm/processor.h |  52 ++++++++++++++
 lib/arm64/asm/ptrace.h    |  95 ++++++++++++++++++++++++++
 lib/arm64/processor.c     | 168 ++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 637 insertions(+), 11 deletions(-)
 create mode 100644 lib/arm64/asm/esr.h
 create mode 100644 lib/arm64/asm/processor.h
 create mode 100644 lib/arm64/asm/ptrace.h
 create mode 100644 lib/arm64/processor.c

diff --git a/arm/cstart64.S b/arm/cstart64.S
index 1d98066d0e187..d1860a94fb2d3 100644
--- a/arm/cstart64.S
+++ b/arm/cstart64.S
@@ -7,6 +7,7 @@
  */
 #define __ASSEMBLY__
 #include <asm/asm-offsets.h>
+#include <asm/ptrace.h>
 
 .section .init
 
@@ -26,7 +27,7 @@ start:
 	msr	cpacr_el1, x0
 
 	/* set up exception handling */
-//	bl	exceptions_init
+	bl	exceptions_init
 
 	/* complete setup */
 	ldp	x0, x1, [sp], #16
@@ -40,9 +41,148 @@ start:
 	bl	exit
 	b	halt
 
+exceptions_init:
+	adr	x0, vector_table
+	msr	vbar_el1, x0
+	isb
+	ret
+
 .text
 
 .globl halt
 halt:
 1:	wfi
 	b	1b
+
+/*
+ * Vectors
+ * Adapted from arch/arm64/kernel/entry.S
+ */
+.macro vector_stub, name, vec
+\name:
+	stp	 x0,  x1, [sp, #-S_FRAME_SIZE]!
+	stp	 x2,  x3, [sp,  #16]
+	stp	 x4,  x5, [sp,  #32]
+	stp	 x6,  x7, [sp,  #48]
+	stp	 x8,  x9, [sp,  #64]
+	stp	x10, x11, [sp,  #80]
+	stp	x12, x13, [sp,  #96]
+	stp	x14, x15, [sp, #112]
+	stp	x16, x17, [sp, #128]
+	stp	x18, x19, [sp, #144]
+	stp	x20, x21, [sp, #160]
+	stp	x22, x23, [sp, #176]
+	stp	x24, x25, [sp, #192]
+	stp	x26, x27, [sp, #208]
+	stp	x28, x29, [sp, #224]
+
+	str	x30, [sp, #S_LR]
+
+	.if \vec >= 8
+	mrs	x1, sp_el0
+	.else
+	add	x1, sp, #S_FRAME_SIZE
+	.endif
+	str	x1, [sp, #S_SP]
+
+	mrs	x1, elr_el1
+	mrs	x2, spsr_el1
+	stp	x1, x2, [sp, #S_PC]
+
+	and	x2, x2, #PSR_MODE_MASK
+	cmp	x2, #PSR_MODE_EL0t
+	b.ne	1f
+	adr	x2, user_mode
+	str	xzr, [x2]		/* we're in kernel mode now */
+
+1:	mov	x0, \vec
+	mov	x1, sp
+	mrs	x2, esr_el1
+	bl	do_handle_exception
+
+	ldp	x1, x2, [sp, #S_PC]
+	msr	spsr_el1, x2
+	msr	elr_el1, x1
+
+	and	x2, x2, #PSR_MODE_MASK
+	cmp	x2, #PSR_MODE_EL0t
+	b.ne	1f
+	adr	x2, user_mode
+	mov	x1, #1
+	str	x1, [x2]		/* we're going back to user mode */
+
+1:
+	.if \vec >= 8
+	ldr	x1, [sp, #S_SP]
+	msr	sp_el0, x1
+	.endif
+
+	ldr	x30, [sp, #S_LR]
+
+	ldp	x28, x29, [sp, #224]
+	ldp	x26, x27, [sp, #208]
+	ldp	x24, x25, [sp, #192]
+	ldp	x22, x23, [sp, #176]
+	ldp	x20, x21, [sp, #160]
+	ldp	x18, x19, [sp, #144]
+	ldp	x16, x17, [sp, #128]
+	ldp	x14, x15, [sp, #112]
+	ldp	x12, x13, [sp,  #96]
+	ldp	x10, x11, [sp,  #80]
+	ldp	 x8,  x9, [sp,  #64]
+	ldp	 x6,  x7, [sp,  #48]
+	ldp	 x4,  x5, [sp,  #32]
+	ldp	 x2,  x3, [sp,  #16]
+	ldp	 x0,  x1, [sp], #S_FRAME_SIZE
+
+	eret
+.endm
+
+vector_stub	el1t_sync,     0
+vector_stub	el1t_irq,      1
+vector_stub	el1t_fiq,      2
+vector_stub	el1t_error,    3
+
+vector_stub	el1h_sync,     4
+vector_stub	el1h_irq,      5
+vector_stub	el1h_fiq,      6
+vector_stub	el1h_error,    7
+
+vector_stub	el0_sync_64,   8
+vector_stub	el0_irq_64,    9
+vector_stub	el0_fiq_64,   10
+vector_stub	el0_error_64, 11
+
+vector_stub	el0_sync_32,  12
+vector_stub	el0_irq_32,   13
+vector_stub	el0_fiq_32,   14
+vector_stub	el0_error_32, 15
+
+.section .text.ex
+
+.macro ventry, label
+.align 7
+	b	\label
+.endm
+
+.align 11
+vector_table:
+	ventry	el1t_sync			// Synchronous EL1t
+	ventry	el1t_irq			// IRQ EL1t
+	ventry	el1t_fiq			// FIQ EL1t
+	ventry	el1t_error			// Error EL1t
+
+	ventry	el1h_sync			// Synchronous EL1h
+	ventry	el1h_irq			// IRQ EL1h
+	ventry	el1h_fiq			// FIQ EL1h
+	ventry	el1h_error			// Error EL1h
+
+	ventry	el0_sync_64			// Synchronous 64-bit EL0
+	ventry	el0_irq_64			// IRQ 64-bit EL0
+	ventry	el0_fiq_64			// FIQ 64-bit EL0
+	ventry	el0_error_64			// Error 64-bit EL0
+
+	ventry	el0_sync_32			// Synchronous 32-bit EL0
+	ventry	el0_irq_32			// IRQ 32-bit EL0
+	ventry	el0_fiq_32			// FIQ 32-bit EL0
+	ventry	el0_error_32			// Error 32-bit EL0
diff --git a/arm/selftest.c b/arm/selftest.c
index 30f44261d47db..824af2f3c15af 100644
--- a/arm/selftest.c
+++ b/arm/selftest.c
@@ -8,12 +8,10 @@
 #include <libcflat.h>
 #include <alloc.h>
 #include <asm/setup.h>
-#ifdef __arm__
 #include <asm/ptrace.h>
 #include <asm/asm-offsets.h>
 #include <asm/processor.h>
 #include <asm/page.h>
-#endif
 
 #define TESTGRP "selftest"
 
@@ -80,8 +78,10 @@ static void check_setup(int argc, char **argv)
 	assert_args(nr_tests, 2);
 }
 
-#ifdef __arm__
 static struct pt_regs expected_regs;
+static bool und_works;
+static bool svc_works;
+#if defined(__arm__)
 /*
  * Capture the current register state and execute an instruction
  * that causes an exception. The test handler will check that its
@@ -122,7 +122,6 @@ static bool check_regs(struct pt_regs *regs)
 	return true;
 }
 
-static bool und_works;
 static void und_handler(struct pt_regs *regs)
 {
 	und_works = check_regs(regs);
@@ -140,7 +139,6 @@ static bool check_und(void)
 	return und_works;
 }
 
-static bool svc_works;
 static void svc_handler(struct pt_regs *regs)
 {
 	u32 svc = *(u32 *)(regs->ARM_pc - 4) & 0xffffff;
@@ -181,13 +179,130 @@ static bool check_svc(void)
 
 	return svc_works;
 }
+#elif defined(__aarch64__)
+#include <asm/esr.h>
+
+/*
+ * Capture the current register state and execute an instruction
+ * that causes an exception. The test handler will check that its
+ * capture of the current register state matches the capture done
+ * here.
+ *
+ * NOTE: update clobber list if passed insns needs more than x0,x1
+ */
+#define test_exception(pre_insns, excptn_insn, post_insns)	\
+	asm volatile(						\
+		pre_insns "\n"					\
+		"mov	x1, %0\n"				\
+		"ldr	x0, [x1, #" xstr(S_PSTATE) "]\n"	\
+		"mrs	x1, nzcv\n"				\
+		"orr	w0, w0, w1\n"				\
+		"mov	x1, %0\n"				\
+		"str	w0, [x1, #" xstr(S_PSTATE) "]\n"	\
+		"mov	x0, sp\n"				\
+		"str	x0, [x1, #" xstr(S_SP) "]\n"		\
+		"adr	x0, 1f\n"				\
+		"str	x0, [x1, #" xstr(S_PC) "]\n"		\
+		"stp	 x2,  x3, [x1,  #16]\n"			\
+		"stp	 x4,  x5, [x1,  #32]\n"			\
+		"stp	 x6,  x7, [x1,  #48]\n"			\
+		"stp	 x8,  x9, [x1,  #64]\n"			\
+		"stp	x10, x11, [x1,  #80]\n"			\
+		"stp	x12, x13, [x1,  #96]\n"			\
+		"stp	x14, x15, [x1, #112]\n"			\
+		"stp	x16, x17, [x1, #128]\n"			\
+		"stp	x18, x19, [x1, #144]\n"			\
+		"stp	x20, x21, [x1, #160]\n"			\
+		"stp	x22, x23, [x1, #176]\n"			\
+		"stp	x24, x25, [x1, #192]\n"			\
+		"stp	x26, x27, [x1, #208]\n"			\
+		"stp	x28, x29, [x1, #224]\n"			\
+		"str	x30, [x1, #" xstr(S_LR) "]\n"		\
+		"stp	 x0,  x1, [x1]\n"			\
+	"1:"	excptn_insn "\n"				\
+		post_insns "\n"					\
+	:: "r" (&expected_regs) : "x0", "x1")
+
+static bool check_regs(struct pt_regs *regs)
+{
+	unsigned i;
+
+	/* exception handlers should always run in EL1 */
+	if (current_level() != CurrentEL_EL1)
+		return false;
+
+	for (i = 0; i < ARRAY_SIZE(regs->regs); ++i) {
+		if (regs->regs[i] != expected_regs.regs[i])
+			return false;
+	}
+
+	regs->pstate &= 0xf0000000 /* NZCV */ | 0x3c0 /* DAIF */
+			| PSR_MODE_MASK;
+
+	return regs->sp == expected_regs.sp
+		&& regs->pc == expected_regs.pc
+		&& regs->pstate == expected_regs.pstate;
+}
+
+static enum vector check_vector_prep(void)
+{
+	unsigned long daif;
+
+	if (user_mode)
+		return EL0_SYNC_64;
+
+	asm volatile("mrs %0, daif" : "=r" (daif) ::);
+	expected_regs.pstate = daif | PSR_MODE_EL1h;
+	return EL1H_SYNC;
+}
+
+static void unknown_handler(struct pt_regs *regs, unsigned int esr __unused)
+{
+	und_works = check_regs(regs);
+	regs->pc += 4;
+}
+
+static bool check_und(void)
+{
+	enum vector v = check_vector_prep();
+
+	install_exception_handler(v, ESR_EL1_EC_UNKNOWN, unknown_handler);
+
+	/* try to read an el2 sysreg from el0/1 */
+	test_exception("", "mrs x0, sctlr_el2", "");
+
+	install_exception_handler(v, ESR_EL1_EC_UNKNOWN, NULL);
+
+	return und_works;
+}
+
+static void svc_handler(struct pt_regs *regs, unsigned int esr)
+{
+	u16 svc = esr & 0xffff;
+
+	expected_regs.pc += 4;
+	svc_works = check_regs(regs) && svc == 123;
+}
+
+static bool check_svc(void)
+{
+	enum vector v = check_vector_prep();
+
+	install_exception_handler(v, ESR_EL1_EC_SVC64, svc_handler);
+
+	test_exception("", "svc #123", "");
+
+	install_exception_handler(v, ESR_EL1_EC_SVC64, NULL);
+
+	return svc_works;
+}
+#endif
 
 static void check_vectors(void *arg __unused)
 {
 	report("%s", check_und() && check_svc(), testname);
 	exit(report_summary());
 }
-#endif
 
 int main(int argc, char **argv)
 {
@@ -199,7 +314,6 @@ int main(int argc, char **argv)
 
 		check_setup(argc-1, &argv[1]);
 
-#ifdef __arm__
 	} else if (strcmp(argv[0], "vectors-kernel") == 0) {
 
 		check_vectors(NULL);
@@ -209,7 +323,6 @@ int main(int argc, char **argv)
 		void *sp = memalign(PAGE_SIZE, PAGE_SIZE);
 		memset(sp, 0, PAGE_SIZE);
 		start_usr(check_vectors, NULL, (unsigned long)sp + PAGE_SIZE);
-#endif
 	}
 
 	return report_summary();
diff --git a/arm/unittests.cfg b/arm/unittests.cfg
index 9ac6ecaa55d3b..efcca6bf24af6 100644
--- a/arm/unittests.cfg
+++ b/arm/unittests.cfg
@@ -22,11 +22,9 @@ groups = selftest
 file = selftest.flat
 extra_params = -append 'vectors-kernel'
 groups = selftest
-arch = arm
 
 # Test vector setup and exception handling (user mode).
 [selftest::vectors-user]
 file = selftest.flat
 extra_params = -append 'vectors-user'
 groups = selftest
-arch = arm
diff --git a/config/config-arm64.mak b/config/config-arm64.mak
index 37db3d6026424..91255e7d01432 100644
--- a/config/config-arm64.mak
+++ b/config/config-arm64.mak
@@ -10,6 +10,7 @@ kernel_offset = 0x80000
 CFLAGS += -D__aarch64__
 
 cstart.o = $(TEST_DIR)/cstart64.o
+cflatobjs += lib/arm64/processor.o
 
 # arm64 specific tests
 tests =
diff --git a/lib/arm64/asm-offsets.c b/lib/arm64/asm-offsets.c
index c85b9a1e97e44..d7d33f4d917ab 100644
--- a/lib/arm64/asm-offsets.c
+++ b/lib/arm64/asm-offsets.c
@@ -7,8 +7,24 @@
  */
 #include <libcflat.h>
 #include <kbuild.h>
+#include <asm/ptrace.h>
 
 int main(void)
 {
+	OFFSET(S_X0, pt_regs, regs[0]);
+	OFFSET(S_X1, pt_regs, regs[1]);
+	OFFSET(S_X2, pt_regs, regs[2]);
+	OFFSET(S_X3, pt_regs, regs[3]);
+	OFFSET(S_X4, pt_regs, regs[4]);
+	OFFSET(S_X5, pt_regs, regs[5]);
+	OFFSET(S_X6, pt_regs, regs[6]);
+	OFFSET(S_X7, pt_regs, regs[7]);
+	OFFSET(S_LR, pt_regs, regs[30]);
+	OFFSET(S_SP, pt_regs, sp);
+	OFFSET(S_PC, pt_regs, pc);
+	OFFSET(S_PSTATE, pt_regs, pstate);
+	OFFSET(S_ORIG_X0, pt_regs, orig_x0);
+	OFFSET(S_SYSCALLNO, pt_regs, syscallno);
+	DEFINE(S_FRAME_SIZE, sizeof(struct pt_regs));
 	return 0;
 }
diff --git a/lib/arm64/asm/esr.h b/lib/arm64/asm/esr.h
new file mode 100644
index 0000000000000..8407b003afa7f
--- /dev/null
+++ b/lib/arm64/asm/esr.h
@@ -0,0 +1,43 @@
+/*
+ * From Linux kernel arch/arm64/include/asm/esr.h
+ */
+#ifndef _ASMARM64_ESR_H_
+#define _ASMARM64_ESR_H_
+
+#define ESR_EL1_WRITE		(1 << 6)
+#define ESR_EL1_CM		(1 << 8)
+#define ESR_EL1_IL		(1 << 25)
+
+#define ESR_EL1_EC_SHIFT	(26)
+#define ESR_EL1_EC_UNKNOWN	(0x00)
+#define ESR_EL1_EC_WFI		(0x01)
+#define ESR_EL1_EC_CP15_32	(0x03)
+#define ESR_EL1_EC_CP15_64	(0x04)
+#define ESR_EL1_EC_CP14_MR	(0x05)
+#define ESR_EL1_EC_CP14_LS	(0x06)
+#define ESR_EL1_EC_FP_ASIMD	(0x07)
+#define ESR_EL1_EC_CP10_ID	(0x08)
+#define ESR_EL1_EC_CP14_64	(0x0C)
+#define ESR_EL1_EC_ILL_ISS	(0x0E)
+#define ESR_EL1_EC_SVC32	(0x11)
+#define ESR_EL1_EC_SVC64	(0x15)
+#define ESR_EL1_EC_SYS64	(0x18)
+#define ESR_EL1_EC_IABT_EL0	(0x20)
+#define ESR_EL1_EC_IABT_EL1	(0x21)
+#define ESR_EL1_EC_PC_ALIGN	(0x22)
+#define ESR_EL1_EC_DABT_EL0	(0x24)
+#define ESR_EL1_EC_DABT_EL1	(0x25)
+#define ESR_EL1_EC_SP_ALIGN	(0x26)
+#define ESR_EL1_EC_FP_EXC32	(0x28)
+#define ESR_EL1_EC_FP_EXC64	(0x2C)
+#define ESR_EL1_EC_SERROR	(0x2F)
+#define ESR_EL1_EC_BREAKPT_EL0	(0x30)
+#define ESR_EL1_EC_BREAKPT_EL1	(0x31)
+#define ESR_EL1_EC_SOFTSTP_EL0	(0x32)
+#define ESR_EL1_EC_SOFTSTP_EL1	(0x33)
+#define ESR_EL1_EC_WATCHPT_EL0	(0x34)
+#define ESR_EL1_EC_WATCHPT_EL1	(0x35)
+#define ESR_EL1_EC_BKPT32	(0x38)
+#define ESR_EL1_EC_BRK64	(0x3C)
+
+#endif /* _ASMARM64_ESR_H_ */
diff --git a/lib/arm64/asm/processor.h b/lib/arm64/asm/processor.h
new file mode 100644
index 0000000000000..66296f549f87e
--- /dev/null
+++ b/lib/arm64/asm/processor.h
@@ -0,0 +1,52 @@
+#ifndef _ASMARM64_PROCESSOR_H_
+#define _ASMARM64_PROCESSOR_H_
+/*
+ * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include <asm/ptrace.h>
+
+enum vector {
+	EL1T_SYNC,
+	EL1T_IRQ,
+	EL1T_FIQ,
+	EL1T_ERROR,
+	EL1H_SYNC,
+	EL1H_IRQ,
+	EL1H_FIQ,
+	EL1H_ERROR,
+	EL0_SYNC_64,
+	EL0_IRQ_64,
+	EL0_FIQ_64,
+	EL0_ERROR_64,
+	EL0_SYNC_32,
+	EL0_IRQ_32,
+	EL0_FIQ_32,
+	EL0_ERROR_32,
+	VECTOR_MAX,
+};
+
+#define EC_MAX 64
+
+typedef void (*vector_fn)(enum vector v, struct pt_regs *regs,
+			  unsigned int esr);
+typedef void (*exception_fn)(struct pt_regs *regs, unsigned int esr);
+extern void install_vector_handler(enum vector v, vector_fn fn);
+extern void install_exception_handler(enum vector v, unsigned int ec,
+				      exception_fn fn);
+
+extern void show_regs(struct pt_regs *regs);
+extern void *get_sp(void);
+
+static inline unsigned long current_level(void)
+{
+	unsigned long el;
+	asm volatile("mrs %0, CurrentEL" : "=r" (el));
+	return el & 0xc;
+}
+
+extern bool user_mode;
+extern void start_usr(void (*func)(void *arg), void *arg, unsigned long sp_usr);
+
+#endif /* _ASMARM64_PROCESSOR_H_ */
diff --git a/lib/arm64/asm/ptrace.h b/lib/arm64/asm/ptrace.h
new file mode 100644
index 0000000000000..dd89d82063b1d
--- /dev/null
+++ b/lib/arm64/asm/ptrace.h
@@ -0,0 +1,95 @@
+#ifndef _ASMARM64_PTRACE_H_
+#define _ASMARM64_PTRACE_H_
+/*
+ * Adapted from Linux kernel headers
+ * arch/arm64/include/asm/ptrace.h
+ * arch/arm64/include/uapi/asm/ptrace.h
+ */
+
+/* Current Exception Level values, as contained in CurrentEL */
+#define CurrentEL_EL1	(1 << 2)
+#define CurrentEL_EL2	(2 << 2)
+
+/*
+ * PSR bits
+ */
+#define PSR_MODE_EL0t	0x00000000
+#define PSR_MODE_EL1t	0x00000004
+#define PSR_MODE_EL1h	0x00000005
+#define PSR_MODE_EL2t	0x00000008
+#define PSR_MODE_EL2h	0x00000009
+#define PSR_MODE_EL3t	0x0000000c
+#define PSR_MODE_EL3h	0x0000000d
+#define PSR_MODE_MASK	0x0000000f
+
+/* AArch32 CPSR bits */
+#define PSR_MODE32_BIT	0x00000010
+
+/* AArch64 SPSR bits */
+#define PSR_F_BIT	0x00000040
+#define PSR_I_BIT	0x00000080
+#define PSR_A_BIT	0x00000100
+#define PSR_D_BIT	0x00000200
+#define PSR_Q_BIT	0x08000000
+#define PSR_V_BIT	0x10000000
+#define PSR_C_BIT	0x20000000
+#define PSR_Z_BIT	0x40000000
+#define PSR_N_BIT	0x80000000
+
+/*
+ * Groups of PSR bits
+ */
+#define PSR_f		0xff000000	/* Flags                */
+#define PSR_s		0x00ff0000	/* Status               */
+#define PSR_x		0x0000ff00	/* Extension            */
+#define PSR_c		0x000000ff	/* Control              */
+
+#ifndef __ASSEMBLY__
+#include <libcflat.h>
+
+struct user_pt_regs {
+	u64		regs[31];
+	u64		sp;
+	u64		pc;
+	u64		pstate;
+};
+
+struct user_fpsimd_state {
+	__uint128_t	vregs[32];
+	u32		fpsr;
+	u32		fpcr;
+};
+
+/*
+ * This struct defines the way the registers are stored on the stack during an
+ * exception. Note that sizeof(struct pt_regs) has to be a multiple of 16 (for
+ * stack alignment). struct user_pt_regs must form a prefix of struct pt_regs.
+ */
+struct pt_regs {
+	union {
+		struct user_pt_regs user_regs;
+		struct {
+			u64 regs[31];
+			u64 sp;
+			u64 pc;
+			u64 pstate;
+		};
+	};
+	u64 orig_x0;
+	u64 syscallno;
+};
+
+#define user_mode(regs) \
+	(((regs)->pstate & PSR_MODE_MASK) == PSR_MODE_EL0t)
+
+#define processor_mode(regs) \
+	((regs)->pstate & PSR_MODE_MASK)
+
+#define interrupts_enabled(regs) \
+	(!((regs)->pstate & PSR_I_BIT))
+
+#define fast_interrupts_enabled(regs) \
+	(!((regs)->pstate & PSR_F_BIT))
+
+#endif /* !__ASSEMBLY__ */
+#endif /* _ASMARM64_PTRACE_H_ */
diff --git a/lib/arm64/processor.c b/lib/arm64/processor.c
new file mode 100644
index 0000000000000..7230a8ab3f702
--- /dev/null
+++ b/lib/arm64/processor.c
@@ -0,0 +1,168 @@
+/*
+ * processor control and status functions
+ *
+ * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include <libcflat.h>
+#include <asm/ptrace.h>
+#include <asm/processor.h>
+#include <asm/esr.h>
+
+static char *vector_names[] = {
+	"el1t_sync",
+	"el1t_irq",
+	"el1t_fiq",
+	"el1t_error",
+	"el1h_sync",
+	"el1h_irq",
+	"el1h_fiq",
+	"el1h_error",
+	"el0_sync_64",
+	"el0_irq_64",
+	"el0_fiq_64",
+	"el0_error_64",
+	"el0_sync_32",
+	"el0_irq_32",
+	"el0_fiq_32",
+	"el0_error_32",
+};
+
+static char *ec_names[EC_MAX] = {
+	[ESR_EL1_EC_UNKNOWN]		= "UNKNOWN",
+	[ESR_EL1_EC_WFI]		= "WFI",
+	[ESR_EL1_EC_CP15_32]		= "CP15_32",
+	[ESR_EL1_EC_CP15_64]		= "CP15_64",
+	[ESR_EL1_EC_CP14_MR]		= "CP14_MR",
+	[ESR_EL1_EC_CP14_LS]		= "CP14_LS",
+	[ESR_EL1_EC_FP_ASIMD]		= "FP_ASMID",
+	[ESR_EL1_EC_CP10_ID]		= "CP10_ID",
+	[ESR_EL1_EC_CP14_64]		= "CP14_64",
+	[ESR_EL1_EC_ILL_ISS]		= "ILL_ISS",
+	[ESR_EL1_EC_SVC32]		= "SVC32",
+	[ESR_EL1_EC_SVC64]		= "SVC64",
+	[ESR_EL1_EC_SYS64]		= "SYS64",
+	[ESR_EL1_EC_IABT_EL0]		= "IABT_EL0",
+	[ESR_EL1_EC_IABT_EL1]		= "IABT_EL1",
+	[ESR_EL1_EC_PC_ALIGN]		= "PC_ALIGN",
+	[ESR_EL1_EC_DABT_EL0]		= "DABT_EL0",
+	[ESR_EL1_EC_DABT_EL1]		= "DABT_EL1",
+	[ESR_EL1_EC_SP_ALIGN]		= "SP_ALIGN",
+	[ESR_EL1_EC_FP_EXC32]		= "FP_EXC32",
+	[ESR_EL1_EC_FP_EXC64]		= "FP_EXC64",
+	[ESR_EL1_EC_SERROR]		= "SERROR",
+	[ESR_EL1_EC_BREAKPT_EL0]	= "BREAKPT_EL0",
+	[ESR_EL1_EC_BREAKPT_EL1]	= "BREAKPT_EL1",
+	[ESR_EL1_EC_SOFTSTP_EL0]	= "SOFTSTP_EL0",
+	[ESR_EL1_EC_SOFTSTP_EL1]	= "SOFTSTP_EL1",
+	[ESR_EL1_EC_WATCHPT_EL0]	= "WATCHPT_EL0",
+	[ESR_EL1_EC_WATCHPT_EL1]	= "WATCHPT_EL1",
+	[ESR_EL1_EC_BKPT32]		= "BKPT32",
+	[ESR_EL1_EC_BRK64]		= "BRK64",
+};
+
+void show_regs(struct pt_regs *regs)
+{
+	int i;
+
+	printf("pc : [<%016llx>] lr : [<%016llx>] pstate: %08llx\n",
+			regs->pc, regs->regs[30], regs->pstate);
+	printf("sp : %016llx\n", regs->sp);
+
+	for (i = 29; i >= 0; --i) {
+		printf("x%-2d: %016llx ", i, regs->regs[i]);
+		if (i % 2 == 0)
+			printf("\n");
+	}
+	printf("\n");
+}
+
+void *get_sp(void)
+{
+	register unsigned long sp asm("sp");
+	return (void *)sp;
+}
+
+static void bad_exception(enum vector v, struct pt_regs *regs,
+			  unsigned int esr, bool bad_vector)
+{
+	unsigned int ec = esr >> ESR_EL1_EC_SHIFT;
+
+	if (bad_vector) {
+		if (v < VECTOR_MAX)
+			printf("Unhandled vector %d (%s)\n", v,
+					vector_names[v]);
+		else
+			printf("Got bad vector=%d\n", v);
+	} else {
+		if (ec_names[ec])
+			printf("Unhandled exception ec=0x%x (%s)\n", ec,
+					ec_names[ec]);
+		else
+			printf("Got bad ec=0x%x\n", ec);
+	}
+
+	printf("Vector: %d (%s)\n", v, vector_names[v]);
+	printf("ESR_EL1: %08lx, ec=0x%x (%s)\n", esr, ec, ec_names[ec]);
+	printf("Exception frame registers:\n");
+	show_regs(regs);
+	abort();
+}
+
+static exception_fn exception_handlers[VECTOR_MAX][EC_MAX];
+
+void install_exception_handler(enum vector v, unsigned int ec, exception_fn fn)
+{
+	if (v < VECTOR_MAX && ec < EC_MAX)
+		exception_handlers[v][ec] = fn;
+}
+
+static void default_vector_handler(enum vector v, struct pt_regs *regs,
+				   unsigned int esr)
+{
+	unsigned int ec = esr >> ESR_EL1_EC_SHIFT;
+
+	if (ec < EC_MAX && exception_handlers[v][ec])
+		exception_handlers[v][ec](regs, esr);
+	else
+		bad_exception(v, regs, esr, false);
+}
+
+static vector_fn vector_handlers[VECTOR_MAX] = {
+	[EL1H_SYNC]	= default_vector_handler,
+	[EL1H_IRQ]	= default_vector_handler,
+	[EL0_SYNC_64]	= default_vector_handler,
+	[EL0_IRQ_64]	= default_vector_handler,
+};
+
+void do_handle_exception(enum vector v, struct pt_regs *regs, unsigned int esr)
+{
+	if (v < VECTOR_MAX && vector_handlers[v])
+		vector_handlers[v](v, regs, esr);
+	else
+		bad_exception(v, regs, esr, true);
+}
+
+void install_vector_handler(enum vector v, vector_fn fn)
+{
+	if (v < VECTOR_MAX)
+		vector_handlers[v] = fn;
+}
+
+bool user_mode;
+void start_usr(void (*func)(void *arg), void *arg, unsigned long sp_usr)
+{
+	sp_usr &= (~15UL); /* stack ptr needs 16-byte alignment */
+
+	user_mode = true;
+
+	asm volatile(
+		"mov	x0, %0\n"
+		"msr	sp_el0, %1\n"
+		"msr	elr_el1, %2\n"
+		"mov	x3, xzr\n"	/* clear and "set" PSR_MODE_EL0t */
+		"msr	spsr_el1, x3\n"
+		"eret\n"
+	:: "r" (arg), "r" (sp_usr), "r" (func) : "x0", "x3");
+}
-- 
1.9.3


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

* [PATCH 10/15] arm: get PHYS_MASK from pgtable-hwdef.h
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (8 preceding siblings ...)
  2014-12-10 20:00 ` [PATCH 09/15] arm64: vectors support Andrew Jones
@ 2014-12-10 20:00 ` Andrew Jones
  2014-12-10 20:00 ` [PATCH 11/15] arm: import more linux page table api Andrew Jones
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 20:00 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

This allows it to be different for arm64, even with setup.h
shared.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/asm/mmu.h           | 2 +-
 lib/arm/asm/page.h          | 5 ++---
 lib/arm/asm/pgtable-hwdef.h | 6 ++++++
 lib/arm/asm/setup.h         | 6 ++----
 lib/arm/mmu.c               | 1 -
 5 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/lib/arm/asm/mmu.h b/lib/arm/asm/mmu.h
index 1117aeaf06a57..8090a1b554820 100644
--- a/lib/arm/asm/mmu.h
+++ b/lib/arm/asm/mmu.h
@@ -5,7 +5,7 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
-#include <asm/page.h>
+#include <asm/setup.h>
 #include <asm/barrier.h>
 #include <alloc.h>
 
diff --git a/lib/arm/asm/page.h b/lib/arm/asm/page.h
index 304c80b9ddfd7..039e2ddfb8e0f 100644
--- a/lib/arm/asm/page.h
+++ b/lib/arm/asm/page.h
@@ -16,7 +16,7 @@
 
 #define PAGE_ALIGN(addr)	ALIGN(addr, PAGE_SIZE)
 
-#include <asm/setup.h>
+#include <alloc.h>
 
 typedef u64 pteval_t;
 typedef u64 pmdval_t;
@@ -51,6 +51,5 @@ typedef struct { pgd_t pgd; } pud_t;
 #define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
 #define pfn_to_virt(pfn)	__va((pfn) << PAGE_SHIFT)
 
-#endif /* __ASSEMBLY__ */
-
+#endif /* !__ASSEMBLY__ */
 #endif /* _ASMARM_PAGE_H_ */
diff --git a/lib/arm/asm/pgtable-hwdef.h b/lib/arm/asm/pgtable-hwdef.h
index a2564aaca05a3..b6850f64b0f52 100644
--- a/lib/arm/asm/pgtable-hwdef.h
+++ b/lib/arm/asm/pgtable-hwdef.h
@@ -62,4 +62,10 @@
 #define PTE_EXT_NG		(_AT(pteval_t, 1) << 11)	/* nG */
 #define PTE_EXT_XN		(_AT(pteval_t, 1) << 54)	/* XN */
 
+/*
+ * 40-bit physical address supported.
+ */
+#define PHYS_MASK_SHIFT		(40)
+#define PHYS_MASK		((_AC(1, ULL) << PHYS_MASK_SHIFT) - 1)
+
 #endif /* _ASMARM_PGTABLE_HWDEF_H_ */
diff --git a/lib/arm/asm/setup.h b/lib/arm/asm/setup.h
index 3ef3b2c99a9de..450501cc6e8e3 100644
--- a/lib/arm/asm/setup.h
+++ b/lib/arm/asm/setup.h
@@ -6,7 +6,8 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 #include <libcflat.h>
-#include <alloc.h>
+#include <asm/page.h>
+#include <asm/pgtable-hwdef.h>
 
 #define NR_CPUS			8
 extern u32 cpus[NR_CPUS];
@@ -16,9 +17,6 @@ extern phys_addr_t __phys_offset, __phys_end;
 
 #define PHYS_OFFSET		(__phys_offset)
 #define PHYS_END		(__phys_end)
-#define PHYS_SHIFT		40
-#define PHYS_SIZE		(1ULL << PHYS_SHIFT)
-#define PHYS_MASK		(PHYS_SIZE - 1ULL)
 
 #define L1_CACHE_SHIFT		6
 #define L1_CACHE_BYTES		(1 << L1_CACHE_SHIFT)
diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
index a42ae84bcec1f..7a975c6708de4 100644
--- a/lib/arm/mmu.c
+++ b/lib/arm/mmu.c
@@ -7,7 +7,6 @@
  */
 #include <asm/setup.h>
 #include <asm/mmu.h>
-#include <asm/pgtable-hwdef.h>
 
 static bool mmu_on;
 static pgd_t idmap[PTRS_PER_PGD] __attribute__((aligned(L1_CACHE_BYTES)));
-- 
1.9.3


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

* [PATCH 11/15] arm: import more linux page table api
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (9 preceding siblings ...)
  2014-12-10 20:00 ` [PATCH 10/15] arm: get PHYS_MASK from pgtable-hwdef.h Andrew Jones
@ 2014-12-10 20:00 ` Andrew Jones
  2014-12-10 20:00 ` [PATCH 12/15] arm: prepare mmu code for arm64 Andrew Jones
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 20:00 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

To use page level descriptors we need some pgd/pud/pmd/pte
methods, and a few more flags defined.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/asm/mmu.h           | 16 +-------
 lib/arm/asm/pgtable-hwdef.h | 38 ++++++++++++++++++-
 lib/arm/asm/pgtable.h       | 91 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 129 insertions(+), 16 deletions(-)
 create mode 100644 lib/arm/asm/pgtable.h

diff --git a/lib/arm/asm/mmu.h b/lib/arm/asm/mmu.h
index 8090a1b554820..254c29f84fe6f 100644
--- a/lib/arm/asm/mmu.h
+++ b/lib/arm/asm/mmu.h
@@ -5,22 +5,8 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
-#include <asm/setup.h>
+#include <asm/pgtable.h>
 #include <asm/barrier.h>
-#include <alloc.h>
-
-#define PTRS_PER_PGD	4
-#define PGDIR_SHIFT	30
-#define PGDIR_SIZE	(1UL << PGDIR_SHIFT)
-#define PGDIR_MASK	(~((1 << PGDIR_SHIFT) - 1))
-
-#define pgd_free(pgd) free(pgd)
-static inline pgd_t *pgd_alloc(void)
-{
-	pgd_t *pgd = memalign(L1_CACHE_BYTES, PTRS_PER_PGD * sizeof(pgd_t));
-	memset(pgd, 0, PTRS_PER_PGD * sizeof(pgd_t));
-	return pgd;
-}
 
 static inline void local_flush_tlb_all(void)
 {
diff --git a/lib/arm/asm/pgtable-hwdef.h b/lib/arm/asm/pgtable-hwdef.h
index b6850f64b0f52..13a273d36e8fe 100644
--- a/lib/arm/asm/pgtable-hwdef.h
+++ b/lib/arm/asm/pgtable-hwdef.h
@@ -1,9 +1,45 @@
 #ifndef _ASMARM_PGTABLE_HWDEF_H_
 #define _ASMARM_PGTABLE_HWDEF_H_
 /*
- * From arch/arm/include/asm/pgtable-3level-hwdef.h
+ * From arch/arm/include/asm/pgtable-3level.h
+ *      arch/arm/include/asm/pgtable-3level-hwdef.h
  */
 
+#define PTRS_PER_PGD		4
+#define PGDIR_SHIFT		30
+#define PGDIR_SIZE		(_AC(1,UL) << PGDIR_SHIFT)
+#define PGDIR_MASK		(~((1 << PGDIR_SHIFT) - 1))
+
+#define PTRS_PER_PTE		512
+#define PTRS_PER_PMD		512
+
+#define PMD_SHIFT		21
+#define PMD_SIZE		(_AC(1,UL) << PMD_SHIFT)
+#define PMD_MASK		(~((1 << PMD_SHIFT) - 1))
+
+#define L_PMD_SECT_VALID	(_AT(pmdval_t, 1) << 0)
+
+#define L_PTE_VALID		(_AT(pteval_t, 1) << 0)		/* Valid */
+#define L_PTE_PRESENT		(_AT(pteval_t, 3) << 0)		/* Present */
+#define L_PTE_USER		(_AT(pteval_t, 1) << 6)		/* AP[1] */
+#define L_PTE_SHARED		(_AT(pteval_t, 3) << 8)		/* SH[1:0], inner shareable */
+#define L_PTE_YOUNG		(_AT(pteval_t, 1) << 10)	/* AF */
+#define L_PTE_XN		(_AT(pteval_t, 1) << 54)	/* XN */
+
+/*
+ * AttrIndx[2:0] encoding (mapping attributes defined in the MAIR* registers).
+ */
+#define L_PTE_MT_UNCACHED	(_AT(pteval_t, 0) << 2)	/* strongly ordered */
+#define L_PTE_MT_BUFFERABLE	(_AT(pteval_t, 1) << 2)	/* normal non-cacheable */
+#define L_PTE_MT_WRITETHROUGH	(_AT(pteval_t, 2) << 2)	/* normal inner write-through */
+#define L_PTE_MT_WRITEBACK	(_AT(pteval_t, 3) << 2)	/* normal inner write-back */
+#define L_PTE_MT_WRITEALLOC	(_AT(pteval_t, 7) << 2)	/* normal inner write-alloc */
+#define L_PTE_MT_DEV_SHARED	(_AT(pteval_t, 4) << 2)	/* device */
+#define L_PTE_MT_DEV_NONSHARED	(_AT(pteval_t, 4) << 2)	/* device */
+#define L_PTE_MT_DEV_WC		(_AT(pteval_t, 1) << 2)	/* normal non-cacheable */
+#define L_PTE_MT_DEV_CACHED	(_AT(pteval_t, 3) << 2)	/* normal inner write-back */
+#define L_PTE_MT_MASK		(_AT(pteval_t, 7) << 2)
+
 /*
  * Hardware page table definitions.
  *
diff --git a/lib/arm/asm/pgtable.h b/lib/arm/asm/pgtable.h
new file mode 100644
index 0000000000000..8a730f44e537b
--- /dev/null
+++ b/lib/arm/asm/pgtable.h
@@ -0,0 +1,91 @@
+#ifndef _ASMARM_PGTABLE_H_
+#define _ASMARM_PGTABLE_H_
+/*
+ * Adapted from arch/arm/include/asm/pgtable.h
+ *              arch/arm/include/asm/pgtable-3level.h
+ *              arch/arm/include/asm/pgalloc.h
+ *              include/asm-generic/pgtable-nopud.h
+ *
+ * Note: some Linux function APIs have been modified. Nothing crazy,
+ *       but if a function took, for example, an mm_struct, then
+ *       that was either removed or replaced.
+ */
+#include <alloc.h>
+#include <asm/setup.h>
+#include <asm/page.h>
+#include <asm/pgtable-hwdef.h>
+
+#define pgd_none(pgd)		(!pgd_val(pgd))
+#define pud_none(pud)		(!pud_val(pud))
+#define pmd_none(pmd)		(!pmd_val(pmd))
+#define pte_none(pte)		(!pte_val(pte))
+
+#define pgd_index(addr) \
+	(((addr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
+#define pgd_offset(pgtable, addr) ((pgtable) + pgd_index(addr))
+
+#define pgd_free(pgd) free(pgd)
+static inline pgd_t *pgd_alloc(void)
+{
+	pgd_t *pgd = memalign(L1_CACHE_BYTES, PTRS_PER_PGD * sizeof(pgd_t));
+	memset(pgd, 0, PTRS_PER_PGD * sizeof(pgd_t));
+	return pgd;
+}
+
+#define pud_offset(pgd, addr)	((pud_t *)pgd)
+#define pud_free(pud)
+#define pud_alloc(pgd, addr)	pud_offset(pgd, addr)
+
+static inline pmd_t *pud_page_vaddr(pud_t pud)
+{
+	return __va(pud_val(pud) & PHYS_MASK & (s32)PAGE_MASK);
+}
+
+#define pmd_index(addr) \
+	(((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
+#define pmd_offset(pud, addr) \
+	(pud_page_vaddr(*(pud)) + pmd_index(addr))
+
+#define pmd_free(pmd) free(pmd)
+static inline pmd_t *pmd_alloc_one(void)
+{
+	pmd_t *pmd = memalign(PAGE_SIZE, PTRS_PER_PMD * sizeof(pmd_t));
+	memset(pmd, 0, PTRS_PER_PMD * sizeof(pmd_t));
+	return pmd;
+}
+static inline pmd_t *pmd_alloc(pud_t *pud, unsigned long addr)
+{
+	if (pud_none(*pud)) {
+		pmd_t *pmd = pmd_alloc_one();
+		pud_val(*pud) = __pa(pmd) | PMD_TYPE_TABLE;
+	}
+	return pmd_offset(pud, addr);
+}
+
+static inline pte_t *pmd_page_vaddr(pmd_t pmd)
+{
+	return __va(pmd_val(pmd) & PHYS_MASK & (s32)PAGE_MASK);
+}
+
+#define pte_index(addr) \
+	(((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
+#define pte_offset(pmd, addr) \
+	(pmd_page_vaddr(*(pmd)) + pte_index(addr))
+
+#define pte_free(pte) free(pte)
+static inline pte_t *pte_alloc_one(void)
+{
+	pte_t *pte = memalign(PAGE_SIZE, PTRS_PER_PTE * sizeof(pte_t));
+	memset(pte, 0, PTRS_PER_PTE * sizeof(pte_t));
+	return pte;
+}
+static inline pte_t *pte_alloc(pmd_t *pmd, unsigned long addr)
+{
+	if (pmd_none(*pmd)) {
+		pte_t *pte = pte_alloc_one();
+		pmd_val(*pmd) = __pa(pte) | PMD_TYPE_TABLE;
+	}
+	return pte_offset(pmd, addr);
+}
+
+#endif /* _ASMARM_PGTABLE_H_ */
-- 
1.9.3


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

* [PATCH 12/15] arm: prepare mmu code for arm64
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (10 preceding siblings ...)
  2014-12-10 20:00 ` [PATCH 11/15] arm: import more linux page table api Andrew Jones
@ 2014-12-10 20:00 ` Andrew Jones
  2014-12-10 20:00 ` [PATCH 13/15] arm64: import some Linux page table API Andrew Jones
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 20:00 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

* don't assume 1G PGDIR_SIZE or L1_CACHE_BYTES pgd alignment
* use page level descriptors for non-I/O memory
* apply new pgd/pud/pmd/pte methods
* split mmu.h to share function declarations
* use more generic flag names in mmu.c

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/asm/mmu-api.h | 14 +++++++++++
 lib/arm/asm/mmu.h     | 10 +++++---
 lib/arm/asm/setup.h   |  3 +++
 lib/arm/mmu.c         | 69 +++++++++++++++++++++++++++++++++++++--------------
 4 files changed, 74 insertions(+), 22 deletions(-)
 create mode 100644 lib/arm/asm/mmu-api.h

diff --git a/lib/arm/asm/mmu-api.h b/lib/arm/asm/mmu-api.h
new file mode 100644
index 0000000000000..f2511e3dc7dee
--- /dev/null
+++ b/lib/arm/asm/mmu-api.h
@@ -0,0 +1,14 @@
+#ifndef __ASMARM_MMU_API_H_
+#define __ASMARM_MMU_API_H_
+extern pgd_t *mmu_idmap;
+extern bool mmu_enabled(void);
+extern void mmu_enable(pgd_t *pgtable);
+extern void mmu_enable_idmap(void);
+extern void mmu_init_io_sect(pgd_t *pgtable, unsigned long virt_offset);
+extern void mmu_set_range_sect(pgd_t *pgtable, unsigned long virt_offset,
+			       unsigned long phys_start, unsigned long phys_end,
+			       pgprot_t prot);
+extern void mmu_set_range_ptes(pgd_t *pgtable, unsigned long virt_offset,
+			       unsigned long phys_start, unsigned long phys_end,
+			       pgprot_t prot);
+#endif
diff --git a/lib/arm/asm/mmu.h b/lib/arm/asm/mmu.h
index 254c29f84fe6f..5ec7a6ce5886b 100644
--- a/lib/arm/asm/mmu.h
+++ b/lib/arm/asm/mmu.h
@@ -8,6 +8,11 @@
 #include <asm/pgtable.h>
 #include <asm/barrier.h>
 
+#define PTE_USER		L_PTE_USER
+#define PTE_SHARED		L_PTE_SHARED
+#define PTE_AF			PTE_EXT_AF
+#define PTE_WBWA		L_PTE_MT_WRITEALLOC
+
 static inline void local_flush_tlb_all(void)
 {
 	asm volatile("mcr p15, 0, %0, c8, c7, 0" :: "r" (0));
@@ -21,9 +26,6 @@ static inline void flush_tlb_all(void)
 	local_flush_tlb_all();
 }
 
-extern bool mmu_enabled(void);
-extern void mmu_enable(pgd_t *pgtable);
-extern void mmu_enable_idmap(void);
-extern void mmu_init_io_sect(pgd_t *pgtable);
+#include <asm/mmu-api.h>
 
 #endif /* __ASMARM_MMU_H_ */
diff --git a/lib/arm/asm/setup.h b/lib/arm/asm/setup.h
index 450501cc6e8e3..02b668672fca4 100644
--- a/lib/arm/asm/setup.h
+++ b/lib/arm/asm/setup.h
@@ -17,6 +17,9 @@ extern phys_addr_t __phys_offset, __phys_end;
 
 #define PHYS_OFFSET		(__phys_offset)
 #define PHYS_END		(__phys_end)
+/* mach-virt reserves the first 1G section for I/O */
+#define PHYS_IO_OFFSET		(0UL)
+#define PHYS_IO_END		(1UL << 30)
 
 #define L1_CACHE_SHIFT		6
 #define L1_CACHE_BYTES		(1 << L1_CACHE_SHIFT)
diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
index 7a975c6708de4..55d18a10e1ebd 100644
--- a/lib/arm/mmu.c
+++ b/lib/arm/mmu.c
@@ -8,9 +8,9 @@
 #include <asm/setup.h>
 #include <asm/mmu.h>
 
-static bool mmu_on;
-static pgd_t idmap[PTRS_PER_PGD] __attribute__((aligned(L1_CACHE_BYTES)));
+pgd_t *mmu_idmap;
 
+static bool mmu_on;
 bool mmu_enabled(void)
 {
 	return mmu_on;
@@ -24,29 +24,62 @@ void mmu_enable(pgd_t *pgtable)
 	mmu_on = true;
 }
 
-void mmu_init_io_sect(pgd_t *pgtable)
+void mmu_set_range_ptes(pgd_t *pgtable, unsigned long virt_offset,
+			unsigned long phys_start, unsigned long phys_end,
+			pgprot_t prot)
 {
-	/*
-	 * mach-virt reserves the first 1G section for I/O
-	 */
-	pgd_val(pgtable[0]) = PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_USER;
-	pgd_val(pgtable[0]) |= PMD_SECT_UNCACHED;
+	unsigned long vaddr = virt_offset & PAGE_MASK;
+	unsigned long paddr = phys_start & PAGE_MASK;
+	unsigned long virt_end = phys_end - paddr + vaddr;
+
+	for (; vaddr < virt_end; vaddr += PAGE_SIZE, paddr += PAGE_SIZE) {
+		pgd_t *pgd = pgd_offset(pgtable, vaddr);
+		pud_t *pud = pud_alloc(pgd, vaddr);
+		pmd_t *pmd = pmd_alloc(pud, vaddr);
+		pte_t *pte = pte_alloc(pmd, vaddr);
+
+		pte_val(*pte) = paddr;
+		pte_val(*pte) |= PTE_TYPE_PAGE | PTE_AF | PTE_SHARED;
+		pte_val(*pte) |= pgprot_val(prot);
+	}
+}
+
+void mmu_set_range_sect(pgd_t *pgtable, unsigned long virt_offset,
+			unsigned long phys_start, unsigned long phys_end,
+			pgprot_t prot)
+{
+	unsigned long vaddr = virt_offset & PGDIR_MASK;
+	unsigned long paddr = phys_start & PGDIR_MASK;
+	unsigned long virt_end = phys_end - paddr + vaddr;
+
+	for (; vaddr < virt_end; vaddr += PGDIR_SIZE, paddr += PGDIR_SIZE) {
+		pgd_t *pgd = pgd_offset(pgtable, vaddr);
+		pgd_val(*pgd) = paddr;
+		pgd_val(*pgd) |= PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S;
+		pgd_val(*pgd) |= pgprot_val(prot);
+	}
+}
+
+
+void mmu_init_io_sect(pgd_t *pgtable, unsigned long virt_offset)
+{
+	mmu_set_range_sect(pgtable, virt_offset,
+		PHYS_IO_OFFSET, PHYS_IO_END,
+		__pgprot(PMD_SECT_UNCACHED | PMD_SECT_USER));
 }
 
 void mmu_enable_idmap(void)
 {
-	unsigned long sect, end;
+	unsigned long phys_end = sizeof(long) == 8 || !(PHYS_END >> 32)
+						? PHYS_END : 0xfffff000;
 
-	mmu_init_io_sect(idmap);
+	mmu_idmap = pgd_alloc();
 
-	end = sizeof(long) == 8 || !(PHYS_END >> 32) ? PHYS_END : 0xfffff000;
+	mmu_init_io_sect(mmu_idmap, PHYS_IO_OFFSET);
 
-	for (sect = PHYS_OFFSET & PGDIR_MASK; sect < end; sect += PGDIR_SIZE) {
-		int i = sect >> PGDIR_SHIFT;
-		pgd_val(idmap[i]) = sect;
-		pgd_val(idmap[i]) |= PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_USER;
-		pgd_val(idmap[i]) |= PMD_SECT_S | PMD_SECT_WBWA;
-	}
+	mmu_set_range_ptes(mmu_idmap, PHYS_OFFSET,
+		PHYS_OFFSET, phys_end,
+		__pgprot(PTE_WBWA | PTE_USER));
 
-	mmu_enable(idmap);
+	mmu_enable(mmu_idmap);
 }
-- 
1.9.3


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

* [PATCH 13/15] arm64: import some Linux page table API
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (11 preceding siblings ...)
  2014-12-10 20:00 ` [PATCH 12/15] arm: prepare mmu code for arm64 Andrew Jones
@ 2014-12-10 20:00 ` Andrew Jones
  2014-12-10 20:00 ` [PATCH 14/15] arm64: prepare for 64k pages Andrew Jones
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 20:00 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm64/asm/page.h          |  66 +++++++++++++++++++-
 lib/arm64/asm/pgtable-hwdef.h | 136 ++++++++++++++++++++++++++++++++++++++++++
 lib/arm64/asm/pgtable.h       |  69 +++++++++++++++++++++
 3 files changed, 270 insertions(+), 1 deletion(-)
 create mode 100644 lib/arm64/asm/pgtable-hwdef.h
 create mode 100644 lib/arm64/asm/pgtable.h

diff --git a/lib/arm64/asm/page.h b/lib/arm64/asm/page.h
index 395760cad5f82..29ad1f1f720c4 100644
--- a/lib/arm64/asm/page.h
+++ b/lib/arm64/asm/page.h
@@ -1 +1,65 @@
-#include "../../arm/asm/page.h"
+#ifndef _ASMARM64_PAGE_H_
+#define _ASMARM64_PAGE_H_
+/*
+ * Adapted from
+ *   arch/arm64/include/asm/pgtable-types.h
+ *   include/asm-generic/pgtable-nopud.h
+ *   include/asm-generic/pgtable-nopmd.h
+ *
+ * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+
+#include <const.h>
+
+#define PGTABLE_LEVELS		2
+#define VA_BITS			42
+
+#define PAGE_SHIFT		16
+#define PAGE_SIZE		(_AC(1,UL) << PAGE_SHIFT)
+#define PAGE_MASK		(~(PAGE_SIZE-1))
+
+#ifndef __ASSEMBLY__
+
+#define PAGE_ALIGN(addr)	ALIGN(addr, PAGE_SIZE)
+
+#include <alloc.h>
+
+typedef u64 pteval_t;
+typedef u64 pmdval_t;
+typedef u64 pudval_t;
+typedef u64 pgdval_t;
+typedef struct { pteval_t pte; } pte_t;
+typedef struct { pgdval_t pgd; } pgd_t;
+typedef struct { pteval_t pgprot; } pgprot_t;
+
+#define pte_val(x)		((x).pte)
+#define pgd_val(x)		((x).pgd)
+#define pgprot_val(x)		((x).pgprot)
+
+#define __pte(x)		((pte_t) { (x) } )
+#define __pgd(x)		((pgd_t) { (x) } )
+#define __pgprot(x)		((pgprot_t) { (x) } )
+
+typedef struct { pgd_t pgd; } pud_t;
+#define pud_val(x)		(pgd_val((x).pgd))
+#define __pud(x)		((pud_t) { __pgd(x) } )
+
+typedef struct { pud_t pud; } pmd_t;
+#define pmd_val(x)		(pud_val((x).pud))
+#define __pmd(x)		((pmd_t) { __pud(x) } )
+
+#ifndef __virt_to_phys
+#define __phys_to_virt(x)	((unsigned long) (x))
+#define __virt_to_phys(x)	(x)
+#endif
+
+#define __va(x)			((void *)__phys_to_virt((phys_addr_t)(x)))
+#define __pa(x)			__virt_to_phys((unsigned long)(x))
+
+#define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
+#define pfn_to_virt(pfn)	__va((pfn) << PAGE_SHIFT)
+
+#endif /* !__ASSEMBLY__ */
+#endif /* _ASMARM64_PAGE_H_ */
diff --git a/lib/arm64/asm/pgtable-hwdef.h b/lib/arm64/asm/pgtable-hwdef.h
new file mode 100644
index 0000000000000..20ac9fa402987
--- /dev/null
+++ b/lib/arm64/asm/pgtable-hwdef.h
@@ -0,0 +1,136 @@
+#ifndef _ASMARM64_PGTABLE_HWDEF_H_
+#define _ASMARM64_PGTABLE_HWDEF_H_
+/*
+ * From arch/arm64/include/asm/pgtable-hwdef.h
+ *      arch/arm64/include/asm/memory.h
+ */
+#define UL(x) _AC(x, UL)
+
+#define PTRS_PER_PTE		(1 << (PAGE_SHIFT - 3))
+
+/*
+ * PGDIR_SHIFT determines the size a top-level page table entry can map
+ * (depending on the configuration, this level can be 0, 1 or 2).
+ */
+#define PGDIR_SHIFT		((PAGE_SHIFT - 3) * PGTABLE_LEVELS + 3)
+#define PGDIR_SIZE		(_AC(1, UL) << PGDIR_SHIFT)
+#define PGDIR_MASK		(~(PGDIR_SIZE-1))
+#define PTRS_PER_PGD		(1 << (VA_BITS - PGDIR_SHIFT))
+
+/* From include/asm-generic/pgtable-nopud.h */
+#define PUD_SHIFT		PGDIR_SHIFT
+#define PTRS_PER_PUD		1
+#define PUD_SIZE		(UL(1) << PUD_SHIFT)
+#define PUD_MASK		(~(PUD_SIZE-1))
+/* From include/asm-generic/pgtable-nopmd.h */
+#define PMD_SHIFT		PUD_SHIFT
+#define PTRS_PER_PMD		1
+#define PMD_SIZE		(UL(1) << PMD_SHIFT)
+#define PMD_MASK		(~(PMD_SIZE-1))
+
+/*
+ * Section address mask and size definitions.
+ */
+#define SECTION_SHIFT		PMD_SHIFT
+#define SECTION_SIZE		(_AC(1, UL) << SECTION_SHIFT)
+#define SECTION_MASK		(~(SECTION_SIZE-1))
+
+/*
+ * Hardware page table definitions.
+ *
+ * Level 1 descriptor (PUD).
+ */
+#define PUD_TYPE_TABLE		(_AT(pudval_t, 3) << 0)
+#define PUD_TABLE_BIT		(_AT(pgdval_t, 1) << 1)
+#define PUD_TYPE_MASK		(_AT(pgdval_t, 3) << 0)
+#define PUD_TYPE_SECT		(_AT(pgdval_t, 1) << 0)
+
+/*
+ * Level 2 descriptor (PMD).
+ */
+#define PMD_TYPE_MASK		(_AT(pmdval_t, 3) << 0)
+#define PMD_TYPE_FAULT		(_AT(pmdval_t, 0) << 0)
+#define PMD_TYPE_TABLE		(_AT(pmdval_t, 3) << 0)
+#define PMD_TYPE_SECT		(_AT(pmdval_t, 1) << 0)
+#define PMD_TABLE_BIT		(_AT(pmdval_t, 1) << 1)
+
+/*
+ * Section
+ */
+#define PMD_SECT_VALID		(_AT(pmdval_t, 1) << 0)
+#define PMD_SECT_PROT_NONE	(_AT(pmdval_t, 1) << 58)
+#define PMD_SECT_USER		(_AT(pmdval_t, 1) << 6)		/* AP[1] */
+#define PMD_SECT_RDONLY		(_AT(pmdval_t, 1) << 7)		/* AP[2] */
+#define PMD_SECT_S		(_AT(pmdval_t, 3) << 8)
+#define PMD_SECT_AF		(_AT(pmdval_t, 1) << 10)
+#define PMD_SECT_NG		(_AT(pmdval_t, 1) << 11)
+#define PMD_SECT_PXN		(_AT(pmdval_t, 1) << 53)
+#define PMD_SECT_UXN		(_AT(pmdval_t, 1) << 54)
+
+/*
+ * AttrIndx[2:0] encoding (mapping attributes defined in the MAIR* registers).
+ */
+#define PMD_ATTRINDX(t)		(_AT(pmdval_t, (t)) << 2)
+#define PMD_ATTRINDX_MASK	(_AT(pmdval_t, 7) << 2)
+
+/*
+ * Level 3 descriptor (PTE).
+ */
+#define PTE_TYPE_MASK		(_AT(pteval_t, 3) << 0)
+#define PTE_TYPE_FAULT		(_AT(pteval_t, 0) << 0)
+#define PTE_TYPE_PAGE		(_AT(pteval_t, 3) << 0)
+#define PTE_TABLE_BIT		(_AT(pteval_t, 1) << 1)
+#define PTE_USER		(_AT(pteval_t, 1) << 6)		/* AP[1] */
+#define PTE_RDONLY		(_AT(pteval_t, 1) << 7)		/* AP[2] */
+#define PTE_SHARED		(_AT(pteval_t, 3) << 8)		/* SH[1:0], inner shareable */
+#define PTE_AF			(_AT(pteval_t, 1) << 10)	/* Access Flag */
+#define PTE_NG			(_AT(pteval_t, 1) << 11)	/* nG */
+#define PTE_PXN			(_AT(pteval_t, 1) << 53)	/* Privileged XN */
+#define PTE_UXN			(_AT(pteval_t, 1) << 54)	/* User XN */
+
+/*
+ * AttrIndx[2:0] encoding (mapping attributes defined in the MAIR* registers).
+ */
+#define PTE_ATTRINDX(t)		(_AT(pteval_t, (t)) << 2)
+#define PTE_ATTRINDX_MASK	(_AT(pteval_t, 7) << 2)
+
+/*
+ * Highest possible physical address supported.
+ */
+#define PHYS_MASK_SHIFT		(48)
+#define PHYS_MASK		((UL(1) << PHYS_MASK_SHIFT) - 1)
+
+/*
+ * TCR flags.
+ */
+#define TCR_TxSZ(x)		(((UL(64) - (x)) << 16) | ((UL(64) - (x)) << 0))
+#define TCR_IRGN_NC		((UL(0) << 8) | (UL(0) << 24))
+#define TCR_IRGN_WBWA		((UL(1) << 8) | (UL(1) << 24))
+#define TCR_IRGN_WT		((UL(2) << 8) | (UL(2) << 24))
+#define TCR_IRGN_WBnWA		((UL(3) << 8) | (UL(3) << 24))
+#define TCR_IRGN_MASK		((UL(3) << 8) | (UL(3) << 24))
+#define TCR_ORGN_NC		((UL(0) << 10) | (UL(0) << 26))
+#define TCR_ORGN_WBWA		((UL(1) << 10) | (UL(1) << 26))
+#define TCR_ORGN_WT		((UL(2) << 10) | (UL(2) << 26))
+#define TCR_ORGN_WBnWA		((UL(3) << 10) | (UL(3) << 26))
+#define TCR_ORGN_MASK		((UL(3) << 10) | (UL(3) << 26))
+#define TCR_SHARED		((UL(3) << 12) | (UL(3) << 28))
+#define TCR_TG0_4K		(UL(0) << 14)
+#define TCR_TG0_64K		(UL(1) << 14)
+#define TCR_TG0_16K		(UL(2) << 14)
+#define TCR_TG1_16K		(UL(1) << 30)
+#define TCR_TG1_4K		(UL(2) << 30)
+#define TCR_TG1_64K		(UL(3) << 30)
+#define TCR_ASID16		(UL(1) << 36)
+#define TCR_TBI0		(UL(1) << 37)
+
+/*
+ * Memory types available.
+ */
+#define MT_DEVICE_nGnRnE	0	/* noncached */
+#define MT_DEVICE_nGnRE		1	/* device */
+#define MT_DEVICE_GRE		2
+#define MT_NORMAL_NC		3	/* writecombine */
+#define MT_NORMAL		4
+
+#endif /* _ASMARM64_PGTABLE_HWDEF_H_ */
diff --git a/lib/arm64/asm/pgtable.h b/lib/arm64/asm/pgtable.h
new file mode 100644
index 0000000000000..3635b075682ad
--- /dev/null
+++ b/lib/arm64/asm/pgtable.h
@@ -0,0 +1,69 @@
+#ifndef _ASMARM64_PGTABLE_H_
+#define _ASMARM64_PGTABLE_H_
+/*
+ * Adapted from arch/arm64/include/asm/pgtable.h
+ *              include/asm-generic/pgtable-nopmd.h
+ *              include/asm-generic/pgtable-nopud.h
+ *              include/linux/mm.h
+ *
+ * Note: some Linux function APIs have been modified. Nothing crazy,
+ *       but if a function took, for example, an mm_struct, then
+ *       that was either removed or replaced.
+ */
+#include <alloc.h>
+#include <asm/setup.h>
+#include <asm/page.h>
+#include <asm/pgtable-hwdef.h>
+
+#define pgd_none(pgd)		(!pgd_val(pgd))
+#define pud_none(pud)		(!pud_val(pud))
+#define pmd_none(pmd)		(!pmd_val(pmd))
+#define pte_none(pte)		(!pte_val(pte))
+
+#define pgd_index(addr) \
+	(((addr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
+#define pgd_offset(pgtable, addr) ((pgtable) + pgd_index(addr))
+
+#define pgd_free(pgd) free(pgd)
+static inline pgd_t *pgd_alloc(void)
+{
+	pgd_t *pgd = memalign(PAGE_SIZE, PTRS_PER_PGD * sizeof(pgd_t));
+	memset(pgd, 0, PTRS_PER_PGD * sizeof(pgd_t));
+	return pgd;
+}
+
+#define pud_offset(pgd, addr)	((pud_t *)pgd)
+#define pud_free(pud)
+#define pud_alloc(pgd, addr)	pud_offset(pgd, addr)
+
+#define pmd_offset(pud, addr)	((pmd_t *)pud)
+#define pmd_free(pmd)
+#define pmd_alloc(pud, addr)	pmd_offset(pud, addr)
+
+static inline pte_t *pmd_page_vaddr(pmd_t pmd)
+{
+	return __va(pmd_val(pmd) & PHYS_MASK & (s32)PAGE_MASK);
+}
+
+#define pte_index(addr) \
+	(((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
+#define pte_offset(pmd, addr) \
+	(pmd_page_vaddr(*(pmd)) + pte_index(addr))
+
+#define pte_free(pte) free(pte)
+static inline pte_t *pte_alloc_one(void)
+{
+	pte_t *pte = memalign(PAGE_SIZE, PTRS_PER_PTE * sizeof(pte_t));
+	memset(pte, 0, PTRS_PER_PTE * sizeof(pte_t));
+	return pte;
+}
+static inline pte_t *pte_alloc(pmd_t *pmd, unsigned long addr)
+{
+	if (pmd_none(*pmd)) {
+		pte_t *pte = pte_alloc_one();
+		pmd_val(*pmd) = __pa(pte) | PMD_TYPE_TABLE;
+	}
+	return pte_offset(pmd, addr);
+}
+
+#endif /* _ASMARM64_PGTABLE_H_ */
-- 
1.9.3


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

* [PATCH 14/15] arm64: prepare for 64k pages
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (12 preceding siblings ...)
  2014-12-10 20:00 ` [PATCH 13/15] arm64: import some Linux page table API Andrew Jones
@ 2014-12-10 20:00 ` Andrew Jones
  2014-12-10 20:00 ` [PATCH 15/15] arm64: enable mmu Andrew Jones
  2014-12-12 12:44 ` [PATCH kvm-unit-tests 00/15] arm64: initial drop Paolo Bonzini
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 20:00 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

This changes the layout for arm too, but that's fine. The only
thing to keep in mind is that while arm64 will have a single
64k page for its stack, arm will have 16 4k pages. If the number
of stack pages matters, then unit tests that want to work for
both arm and arm64, may need to avoid using more than one page,
even though the memory is there.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/flat.lds | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arm/flat.lds b/arm/flat.lds
index ee9fc0ab79abc..89a55720d728f 100644
--- a/arm/flat.lds
+++ b/arm/flat.lds
@@ -2,10 +2,10 @@
 SECTIONS
 {
     .text : { *(.init) *(.text) *(.text.*) }
-    . = ALIGN(4K);
+    . = ALIGN(64K);
     .data : {
         exception_stacks = .;
-        . += 4K;
+        . += 64K;
         exception_stacks_end = .;
         *(.data)
     }
@@ -13,10 +13,10 @@ SECTIONS
     .rodata : { *(.rodata) }
     . = ALIGN(16);
     .bss : { *(.bss) }
-    . = ALIGN(4K);
+    . = ALIGN(64K);
     edata = .;
-    . += 8K;
-    . = ALIGN(4K);
+    . += 64K;
+    . = ALIGN(64K);
     stacktop = .;
 }
 
-- 
1.9.3


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

* [PATCH 15/15] arm64: enable mmu
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (13 preceding siblings ...)
  2014-12-10 20:00 ` [PATCH 14/15] arm64: prepare for 64k pages Andrew Jones
@ 2014-12-10 20:00 ` Andrew Jones
  2014-12-12 12:44 ` [PATCH kvm-unit-tests 00/15] arm64: initial drop Paolo Bonzini
  15 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2014-12-10 20:00 UTC (permalink / raw)
  To: kvmarm, kvm; +Cc: christoffer.dall, pbonzini, alex.bennee

Implement asm_mmu_enable and flush_tlb_all, and then make a final
change to mmu.c in order to link it into arm64. The final change
is to map the code read-only. This is necessary because armv8
forces all writable code shared between EL1 and EL0 to be PXN.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/cstart64.S               | 64 ++++++++++++++++++++++++++++++++++++++++++++
 arm/flat.lds                 |  1 +
 config/config-arm-common.mak |  1 +
 config/config-arm.mak        |  1 -
 lib/arm/asm/mmu.h            |  1 +
 lib/arm/mmu.c                | 10 ++++++-
 lib/arm64/asm/mmu-api.h      |  1 +
 lib/arm64/asm/mmu.h          | 16 +++++++----
 lib/arm64/asm/processor.h    | 14 ++++++++++
 lib/arm64/processor.c        | 26 +++++++++++++++++-
 10 files changed, 127 insertions(+), 8 deletions(-)
 create mode 100644 lib/arm64/asm/mmu-api.h

diff --git a/arm/cstart64.S b/arm/cstart64.S
index d1860a94fb2d3..5151f4c77d745 100644
--- a/arm/cstart64.S
+++ b/arm/cstart64.S
@@ -8,6 +8,9 @@
 #define __ASSEMBLY__
 #include <asm/asm-offsets.h>
 #include <asm/ptrace.h>
+#include <asm/processor.h>
+#include <asm/page.h>
+#include <asm/pgtable-hwdef.h>
 
 .section .init
 
@@ -55,6 +58,67 @@ halt:
 	b	1b
 
 /*
+ * asm_mmu_enable
+ *   Inputs:
+ *     x0 is the base address of the translation table
+ *   Outputs: none
+ *
+ * Adapted from
+ *   arch/arm64/kernel/head.S
+ *   arch/arm64/mm/proc.S
+ */
+
+/*
+ * Memory region attributes for LPAE:
+ *
+ *   n = AttrIndx[2:0]
+ *                      n       MAIR
+ *   DEVICE_nGnRnE      000     00000000
+ *   DEVICE_nGnRE       001     00000100
+ *   DEVICE_GRE         010     00001100
+ *   NORMAL_NC          011     01000100
+ *   NORMAL             100     11111111
+ */
+#define MAIR(attr, mt) ((attr) << ((mt) * 8))
+
+.globl asm_mmu_enable
+asm_mmu_enable:
+	ic	iallu			// I+BTB cache invalidate
+	tlbi	vmalle1is		// invalidate I + D TLBs
+	dsb	ish
+
+	/* TCR */
+	ldr	x1, =TCR_TxSZ(VA_BITS) |		\
+		     TCR_TG0_64K | TCR_TG1_64K |	\
+		     TCR_IRGN_WBWA | TCR_ORGN_WBWA |	\
+		     TCR_SHARED
+	mov	x2, #3			// 011 is 42 bits
+	bfi	x1, x2, #32, #3
+	msr	tcr_el1, x1
+
+	/* MAIR */
+	ldr	x1, =MAIR(0x00, MT_DEVICE_nGnRnE) |	\
+		     MAIR(0x04, MT_DEVICE_nGnRE) |	\
+		     MAIR(0x0c, MT_DEVICE_GRE) |	\
+		     MAIR(0x44, MT_NORMAL_NC) |		\
+		     MAIR(0xff, MT_NORMAL)
+	msr	mair_el1, x1
+
+	/* TTBR0 */
+	msr	ttbr0_el1, x0
+	isb
+
+	/* SCTLR */
+	mrs	x1, sctlr_el1
+	orr	x1, x1, SCTLR_EL1_C
+	orr	x1, x1, SCTLR_EL1_I
+	orr	x1, x1, SCTLR_EL1_M
+	msr	sctlr_el1, x1
+	isb
+
+	ret
+
+/*
  * Vectors
  * Adapted from arch/arm64/kernel/entry.S
  */
diff --git a/arm/flat.lds b/arm/flat.lds
index 89a55720d728f..a8849ee0939a8 100644
--- a/arm/flat.lds
+++ b/arm/flat.lds
@@ -3,6 +3,7 @@ SECTIONS
 {
     .text : { *(.init) *(.text) *(.text.*) }
     . = ALIGN(64K);
+    etext = .;
     .data : {
         exception_stacks = .;
         . += 64K;
diff --git a/config/config-arm-common.mak b/config/config-arm-common.mak
index b61a2a6044ab2..b01e9ab836b2d 100644
--- a/config/config-arm-common.mak
+++ b/config/config-arm-common.mak
@@ -33,6 +33,7 @@ cflatobjs += lib/virtio-mmio.o
 cflatobjs += lib/chr-testdev.o
 cflatobjs += lib/arm/io.o
 cflatobjs += lib/arm/setup.o
+cflatobjs += lib/arm/mmu.o
 
 libeabi = lib/arm/libeabi.a
 eabiobjs = lib/arm/eabi_compat.o
diff --git a/config/config-arm.mak b/config/config-arm.mak
index 96686fb639d2d..16e2cb5c103a3 100644
--- a/config/config-arm.mak
+++ b/config/config-arm.mak
@@ -15,7 +15,6 @@ CFLAGS += -mcpu=$(PROCESSOR)
 cstart.o = $(TEST_DIR)/cstart.o
 cflatobjs += lib/arm/spinlock.o
 cflatobjs += lib/arm/processor.o
-cflatobjs += lib/arm/mmu.o
 
 # arm specific tests
 tests =
diff --git a/lib/arm/asm/mmu.h b/lib/arm/asm/mmu.h
index 5ec7a6ce5886b..c1bd01c9ee1b9 100644
--- a/lib/arm/asm/mmu.h
+++ b/lib/arm/asm/mmu.h
@@ -9,6 +9,7 @@
 #include <asm/barrier.h>
 
 #define PTE_USER		L_PTE_USER
+#define PTE_RDONLY		PTE_AP2
 #define PTE_SHARED		L_PTE_SHARED
 #define PTE_AF			PTE_EXT_AF
 #define PTE_WBWA		L_PTE_MT_WRITEALLOC
diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
index 55d18a10e1ebd..1c024538663ce 100644
--- a/lib/arm/mmu.c
+++ b/lib/arm/mmu.c
@@ -8,6 +8,8 @@
 #include <asm/setup.h>
 #include <asm/mmu.h>
 
+extern unsigned long etext;
+
 pgd_t *mmu_idmap;
 
 static bool mmu_on;
@@ -72,13 +74,19 @@ void mmu_enable_idmap(void)
 {
 	unsigned long phys_end = sizeof(long) == 8 || !(PHYS_END >> 32)
 						? PHYS_END : 0xfffff000;
+	unsigned long code_end = (unsigned long)&etext;
 
 	mmu_idmap = pgd_alloc();
 
 	mmu_init_io_sect(mmu_idmap, PHYS_IO_OFFSET);
 
+	/* armv8 requires code shared between EL1 and EL0 to be read-only */
 	mmu_set_range_ptes(mmu_idmap, PHYS_OFFSET,
-		PHYS_OFFSET, phys_end,
+		PHYS_OFFSET, code_end,
+		__pgprot(PTE_WBWA | PTE_RDONLY | PTE_USER));
+
+	mmu_set_range_ptes(mmu_idmap, code_end,
+		code_end, phys_end,
 		__pgprot(PTE_WBWA | PTE_USER));
 
 	mmu_enable(mmu_idmap);
diff --git a/lib/arm64/asm/mmu-api.h b/lib/arm64/asm/mmu-api.h
new file mode 100644
index 0000000000000..7cd7096a93553
--- /dev/null
+++ b/lib/arm64/asm/mmu-api.h
@@ -0,0 +1 @@
+#include "../../arm/asm/mmu-api.h"
diff --git a/lib/arm64/asm/mmu.h b/lib/arm64/asm/mmu.h
index cbafbca6701e7..18b4d6be18fae 100644
--- a/lib/arm64/asm/mmu.h
+++ b/lib/arm64/asm/mmu.h
@@ -5,14 +5,20 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
+#include <asm/pgtable.h>
+#include <asm/barrier.h>
 
-static inline bool mmu_enabled(void)
-{
-	return false;
-}
+#define PMD_SECT_UNCACHED	PMD_ATTRINDX(MT_DEVICE_nGnRE)
+#define PTE_WBWA		PTE_ATTRINDX(MT_NORMAL)
 
-static inline void mmu_enable_idmap(void)
+static inline void flush_tlb_all(void)
 {
+	dsb(ishst);
+	asm("tlbi	vmalle1is");
+	dsb(ish);
+	isb();
 }
 
+#include <asm/mmu-api.h>
+
 #endif /* __ASMARM64_MMU_H_ */
diff --git a/lib/arm64/asm/processor.h b/lib/arm64/asm/processor.h
index 66296f549f87e..f73ffb5e4bc95 100644
--- a/lib/arm64/asm/processor.h
+++ b/lib/arm64/asm/processor.h
@@ -5,6 +5,18 @@
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
+
+/* System Control Register (SCTLR_EL1) bits */
+#define SCTLR_EL1_EE	(1 << 25)
+#define SCTLR_EL1_WXN	(1 << 19)
+#define SCTLR_EL1_I	(1 << 12)
+#define SCTLR_EL1_SA0	(1 << 4)
+#define SCTLR_EL1_SA	(1 << 3)
+#define SCTLR_EL1_C	(1 << 2)
+#define SCTLR_EL1_A	(1 << 1)
+#define SCTLR_EL1_M	(1 << 0)
+
+#ifndef __ASSEMBLY__
 #include <asm/ptrace.h>
 
 enum vector {
@@ -38,6 +50,7 @@ extern void install_exception_handler(enum vector v, unsigned int ec,
 
 extern void show_regs(struct pt_regs *regs);
 extern void *get_sp(void);
+extern bool get_far(unsigned int esr, unsigned long *far);
 
 static inline unsigned long current_level(void)
 {
@@ -49,4 +62,5 @@ static inline unsigned long current_level(void)
 extern bool user_mode;
 extern void start_usr(void (*func)(void *arg), void *arg, unsigned long sp_usr);
 
+#endif /* !__ASSEMBLY__ */
 #endif /* _ASMARM64_PROCESSOR_H_ */
diff --git a/lib/arm64/processor.c b/lib/arm64/processor.c
index 7230a8ab3f702..7dc0b2e026134 100644
--- a/lib/arm64/processor.c
+++ b/lib/arm64/processor.c
@@ -84,9 +84,32 @@ void *get_sp(void)
 	return (void *)sp;
 }
 
+bool get_far(unsigned int esr, unsigned long *far)
+{
+	unsigned int ec = esr >> ESR_EL1_EC_SHIFT;
+
+	asm volatile("mrs %0, far_el1": "=r" (*far));
+
+	switch (ec) {
+	case ESR_EL1_EC_IABT_EL0:
+	case ESR_EL1_EC_IABT_EL1:
+	case ESR_EL1_EC_PC_ALIGN:
+	case ESR_EL1_EC_DABT_EL0:
+	case ESR_EL1_EC_DABT_EL1:
+	case ESR_EL1_EC_WATCHPT_EL0:
+	case ESR_EL1_EC_WATCHPT_EL1:
+		if ((esr & 0x3f /* DFSC */) != 0x10
+				|| !(esr & 0x400 /* FnV */))
+			return true;
+	}
+	return false;
+}
+
 static void bad_exception(enum vector v, struct pt_regs *regs,
 			  unsigned int esr, bool bad_vector)
 {
+	unsigned long far;
+	bool far_valid = get_far(esr, &far);
 	unsigned int ec = esr >> ESR_EL1_EC_SHIFT;
 
 	if (bad_vector) {
@@ -104,7 +127,8 @@ static void bad_exception(enum vector v, struct pt_regs *regs,
 	}
 
 	printf("Vector: %d (%s)\n", v, vector_names[v]);
-	printf("ESR_EL1: %08lx, ec=0x%x (%s)\n", esr, ec, ec_names[ec]);
+	printf("ESR_EL1: %8s%08lx, ec=0x%x (%s)\n", "", esr, ec, ec_names[ec]);
+	printf("FAR_EL1: %016lx (%svalid)\n", far, far_valid ? "" : "not ");
 	printf("Exception frame registers:\n");
 	show_regs(regs);
 	abort();
-- 
1.9.3


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

* Re: [PATCH kvm-unit-tests 00/15] arm64: initial drop
  2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
                   ` (14 preceding siblings ...)
  2014-12-10 20:00 ` [PATCH 15/15] arm64: enable mmu Andrew Jones
@ 2014-12-12 12:44 ` Paolo Bonzini
  2015-01-02 17:46   ` Andrew Jones
  15 siblings, 1 reply; 20+ messages in thread
From: Paolo Bonzini @ 2014-12-12 12:44 UTC (permalink / raw)
  To: Andrew Jones, kvmarm, kvm; +Cc: christoffer.dall, alex.bennee



On 10/12/2014 20:59, Andrew Jones wrote:
> This series adds support for aarch64 to the kvm-unit-tests framework,
> bringing it to the same level as the arm support. In the process a
> few tweaks to the arm support were made, as one of the main goals
> was to share as much code as possible between the two.
> 
> Patches
> 01   : A fix for the script runner. We need this one for arm
>        regardless of the aarch64 support.
> 02-03: Fixes to the arm support. The bugs fixed weren't visible
>        until running on aarch64.
> 04-07: Prep the arm framework for the bare minimal initial drop
> 08   : The bare minimal initial drop
> 09   : Add vector support to the minimal drop
> 10-12: Prep the arm framework for enabling the mmu on aarch64
> 13-14: Prep the aarch64 framework for enabling the mmu
> 15   : Enables the mmu on aarch64
> 
> These patches are also available here
> https://github.com/rhdrjones/kvm-unit-tests/tree/arm64/initial-drop
> 
> Thanks,
> drew
> 
> 
> Andrew Jones (15):
>   arm: fix run script testdev probing
>   virtio: don't use size_t
>   arm: setup: fix type mismatch
>   Makefile: cscope may need to look in lib/$ARCH
>   arm: use absolute headers
>   arm: setup: drop unused arguments
>   arm: selftest: rename svc mode to kernel mode
>   arm64: initial drop
>   arm64: vectors support
>   arm: get PHYS_MASK from pgtable-hwdef.h
>   arm: import more linux page table api
>   arm: prepare mmu code for arm64
>   arm64: import some Linux page table API
>   arm64: prepare for 64k pages
>   arm64: enable mmu
> 
>  Makefile                      |   4 +-
>  arm/cstart.S                  |  18 ++-
>  arm/cstart64.S                | 252 ++++++++++++++++++++++++++++++++++++++++++
>  arm/flat.lds                  |  11 +-
>  arm/run                       |  12 +-
>  arm/selftest.c                | 141 +++++++++++++++++++++--
>  arm/unittests.cfg             |  12 +-
>  config/config-arm-common.mak  |  69 ++++++++++++
>  config/config-arm.mak         |  74 ++-----------
>  config/config-arm64.mak       |  21 ++++
>  configure                     |  12 +-
>  lib/arm/asm-offsets.c         |  11 +-
>  lib/arm/asm/asm-offsets.h     |   2 +-
>  lib/arm/asm/io.h              |   8 +-
>  lib/arm/asm/mmu-api.h         |  14 +++
>  lib/arm/asm/mmu.h             |  27 ++---
>  lib/arm/asm/page.h            |   7 +-
>  lib/arm/asm/pgtable-hwdef.h   |  44 +++++++-
>  lib/arm/asm/pgtable.h         |  91 +++++++++++++++
>  lib/arm/asm/processor.h       |   2 +-
>  lib/arm/asm/ptrace.h          |   2 +-
>  lib/arm/asm/setup.h           |  11 +-
>  lib/arm/eabi_compat.c         |   2 +-
>  lib/arm/io.c                  |  10 +-
>  lib/arm/mmu.c                 |  82 ++++++++++----
>  lib/arm/processor.c           |   6 +-
>  lib/arm/setup.c               |  19 ++--
>  lib/arm/spinlock.c            |   8 +-
>  lib/arm64/.gitignore          |   1 +
>  lib/arm64/asm-offsets.c       |  30 +++++
>  lib/arm64/asm/asm-offsets.h   |   1 +
>  lib/arm64/asm/barrier.h       |  17 +++
>  lib/arm64/asm/esr.h           |  43 +++++++
>  lib/arm64/asm/io.h            |  84 ++++++++++++++
>  lib/arm64/asm/mmu-api.h       |   1 +
>  lib/arm64/asm/mmu.h           |  24 ++++
>  lib/arm64/asm/page.h          |  65 +++++++++++
>  lib/arm64/asm/pgtable-hwdef.h | 136 +++++++++++++++++++++++
>  lib/arm64/asm/pgtable.h       |  69 ++++++++++++
>  lib/arm64/asm/processor.h     |  66 +++++++++++
>  lib/arm64/asm/ptrace.h        |  95 ++++++++++++++++
>  lib/arm64/asm/setup.h         |   1 +
>  lib/arm64/asm/spinlock.h      |  15 +++
>  lib/arm64/processor.c         | 192 ++++++++++++++++++++++++++++++++
>  lib/chr-testdev.c             |   4 +-
>  lib/kbuild.h                  |   8 ++
>  lib/virtio.c                  |   2 +-
>  lib/virtio.h                  |   3 +-
>  48 files changed, 1638 insertions(+), 191 deletions(-)
>  create mode 100644 arm/cstart64.S
>  create mode 100644 config/config-arm-common.mak
>  create mode 100644 config/config-arm64.mak
>  create mode 100644 lib/arm/asm/mmu-api.h
>  create mode 100644 lib/arm/asm/pgtable.h
>  create mode 100644 lib/arm64/.gitignore
>  create mode 100644 lib/arm64/asm-offsets.c
>  create mode 100644 lib/arm64/asm/asm-offsets.h
>  create mode 100644 lib/arm64/asm/barrier.h
>  create mode 100644 lib/arm64/asm/esr.h
>  create mode 100644 lib/arm64/asm/io.h
>  create mode 100644 lib/arm64/asm/mmu-api.h
>  create mode 100644 lib/arm64/asm/mmu.h
>  create mode 100644 lib/arm64/asm/page.h
>  create mode 100644 lib/arm64/asm/pgtable-hwdef.h
>  create mode 100644 lib/arm64/asm/pgtable.h
>  create mode 100644 lib/arm64/asm/processor.h
>  create mode 100644 lib/arm64/asm/ptrace.h
>  create mode 100644 lib/arm64/asm/setup.h
>  create mode 100644 lib/arm64/asm/spinlock.h
>  create mode 100644 lib/arm64/processor.c
>  create mode 100644 lib/kbuild.h
> 

Thanks, looks good.  Only applied locally until I find some time to
retest 32-bit ARM with this changes.

Paolo

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

* Re: [PATCH kvm-unit-tests 00/15] arm64: initial drop
  2014-12-12 12:44 ` [PATCH kvm-unit-tests 00/15] arm64: initial drop Paolo Bonzini
@ 2015-01-02 17:46   ` Andrew Jones
  2015-01-03  8:54     ` Paolo Bonzini
  2015-01-06  9:03     ` Alex Bennée
  0 siblings, 2 replies; 20+ messages in thread
From: Andrew Jones @ 2015-01-02 17:46 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvmarm, kvm, christoffer.dall, alex.bennee

On Fri, Dec 12, 2014 at 01:44:52PM +0100, Paolo Bonzini wrote:
> 
> 
> On 10/12/2014 20:59, Andrew Jones wrote:
> > This series adds support for aarch64 to the kvm-unit-tests framework,
> > bringing it to the same level as the arm support. In the process a
> > few tweaks to the arm support were made, as one of the main goals
> > was to share as much code as possible between the two.
> > 
> > Patches
> > 01   : A fix for the script runner. We need this one for arm
> >        regardless of the aarch64 support.
> > 02-03: Fixes to the arm support. The bugs fixed weren't visible
> >        until running on aarch64.
> > 04-07: Prep the arm framework for the bare minimal initial drop
> > 08   : The bare minimal initial drop
> > 09   : Add vector support to the minimal drop
> > 10-12: Prep the arm framework for enabling the mmu on aarch64
> > 13-14: Prep the aarch64 framework for enabling the mmu
> > 15   : Enables the mmu on aarch64
> > 
> > These patches are also available here
> > https://github.com/rhdrjones/kvm-unit-tests/tree/arm64/initial-drop
> > 
> > Thanks,
> > drew
> > 
> > 
> > Andrew Jones (15):
> >   arm: fix run script testdev probing
> >   virtio: don't use size_t
> >   arm: setup: fix type mismatch
> >   Makefile: cscope may need to look in lib/$ARCH
> >   arm: use absolute headers
> >   arm: setup: drop unused arguments
> >   arm: selftest: rename svc mode to kernel mode
> >   arm64: initial drop
> >   arm64: vectors support
> >   arm: get PHYS_MASK from pgtable-hwdef.h
> >   arm: import more linux page table api
> >   arm: prepare mmu code for arm64
> >   arm64: import some Linux page table API
> >   arm64: prepare for 64k pages
> >   arm64: enable mmu
> > 
> >  Makefile                      |   4 +-
> >  arm/cstart.S                  |  18 ++-
> >  arm/cstart64.S                | 252 ++++++++++++++++++++++++++++++++++++++++++
> >  arm/flat.lds                  |  11 +-
> >  arm/run                       |  12 +-
> >  arm/selftest.c                | 141 +++++++++++++++++++++--
> >  arm/unittests.cfg             |  12 +-
> >  config/config-arm-common.mak  |  69 ++++++++++++
> >  config/config-arm.mak         |  74 ++-----------
> >  config/config-arm64.mak       |  21 ++++
> >  configure                     |  12 +-
> >  lib/arm/asm-offsets.c         |  11 +-
> >  lib/arm/asm/asm-offsets.h     |   2 +-
> >  lib/arm/asm/io.h              |   8 +-
> >  lib/arm/asm/mmu-api.h         |  14 +++
> >  lib/arm/asm/mmu.h             |  27 ++---
> >  lib/arm/asm/page.h            |   7 +-
> >  lib/arm/asm/pgtable-hwdef.h   |  44 +++++++-
> >  lib/arm/asm/pgtable.h         |  91 +++++++++++++++
> >  lib/arm/asm/processor.h       |   2 +-
> >  lib/arm/asm/ptrace.h          |   2 +-
> >  lib/arm/asm/setup.h           |  11 +-
> >  lib/arm/eabi_compat.c         |   2 +-
> >  lib/arm/io.c                  |  10 +-
> >  lib/arm/mmu.c                 |  82 ++++++++++----
> >  lib/arm/processor.c           |   6 +-
> >  lib/arm/setup.c               |  19 ++--
> >  lib/arm/spinlock.c            |   8 +-
> >  lib/arm64/.gitignore          |   1 +
> >  lib/arm64/asm-offsets.c       |  30 +++++
> >  lib/arm64/asm/asm-offsets.h   |   1 +
> >  lib/arm64/asm/barrier.h       |  17 +++
> >  lib/arm64/asm/esr.h           |  43 +++++++
> >  lib/arm64/asm/io.h            |  84 ++++++++++++++
> >  lib/arm64/asm/mmu-api.h       |   1 +
> >  lib/arm64/asm/mmu.h           |  24 ++++
> >  lib/arm64/asm/page.h          |  65 +++++++++++
> >  lib/arm64/asm/pgtable-hwdef.h | 136 +++++++++++++++++++++++
> >  lib/arm64/asm/pgtable.h       |  69 ++++++++++++
> >  lib/arm64/asm/processor.h     |  66 +++++++++++
> >  lib/arm64/asm/ptrace.h        |  95 ++++++++++++++++
> >  lib/arm64/asm/setup.h         |   1 +
> >  lib/arm64/asm/spinlock.h      |  15 +++
> >  lib/arm64/processor.c         | 192 ++++++++++++++++++++++++++++++++
> >  lib/chr-testdev.c             |   4 +-
> >  lib/kbuild.h                  |   8 ++
> >  lib/virtio.c                  |   2 +-
> >  lib/virtio.h                  |   3 +-
> >  48 files changed, 1638 insertions(+), 191 deletions(-)
> >  create mode 100644 arm/cstart64.S
> >  create mode 100644 config/config-arm-common.mak
> >  create mode 100644 config/config-arm64.mak
> >  create mode 100644 lib/arm/asm/mmu-api.h
> >  create mode 100644 lib/arm/asm/pgtable.h
> >  create mode 100644 lib/arm64/.gitignore
> >  create mode 100644 lib/arm64/asm-offsets.c
> >  create mode 100644 lib/arm64/asm/asm-offsets.h
> >  create mode 100644 lib/arm64/asm/barrier.h
> >  create mode 100644 lib/arm64/asm/esr.h
> >  create mode 100644 lib/arm64/asm/io.h
> >  create mode 100644 lib/arm64/asm/mmu-api.h
> >  create mode 100644 lib/arm64/asm/mmu.h
> >  create mode 100644 lib/arm64/asm/page.h
> >  create mode 100644 lib/arm64/asm/pgtable-hwdef.h
> >  create mode 100644 lib/arm64/asm/pgtable.h
> >  create mode 100644 lib/arm64/asm/processor.h
> >  create mode 100644 lib/arm64/asm/ptrace.h
> >  create mode 100644 lib/arm64/asm/setup.h
> >  create mode 100644 lib/arm64/asm/spinlock.h
> >  create mode 100644 lib/arm64/processor.c
> >  create mode 100644 lib/kbuild.h
> > 
> 
> Thanks, looks good.  Only applied locally until I find some time to
> retest 32-bit ARM with this changes.
> 

Ping? I'd like to send more patches building on this series soon.
Hopefully others (/me looks at Alex Bennee) do too :-)

drew

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

* Re: [PATCH kvm-unit-tests 00/15] arm64: initial drop
  2015-01-02 17:46   ` Andrew Jones
@ 2015-01-03  8:54     ` Paolo Bonzini
  2015-01-06  9:03     ` Alex Bennée
  1 sibling, 0 replies; 20+ messages in thread
From: Paolo Bonzini @ 2015-01-03  8:54 UTC (permalink / raw)
  To: Andrew Jones; +Cc: kvmarm, kvm, christoffer.dall, alex.bennee



On 02/01/2015 18:46, Andrew Jones wrote:
> On Fri, Dec 12, 2014 at 01:44:52PM +0100, Paolo Bonzini wrote:
>>
>>
>> On 10/12/2014 20:59, Andrew Jones wrote:
>>> This series adds support for aarch64 to the kvm-unit-tests framework,
>>> bringing it to the same level as the arm support. In the process a
>>> few tweaks to the arm support were made, as one of the main goals
>>> was to share as much code as possible between the two.
>>>
>>> Patches
>>> 01   : A fix for the script runner. We need this one for arm
>>>        regardless of the aarch64 support.
>>> 02-03: Fixes to the arm support. The bugs fixed weren't visible
>>>        until running on aarch64.
>>> 04-07: Prep the arm framework for the bare minimal initial drop
>>> 08   : The bare minimal initial drop
>>> 09   : Add vector support to the minimal drop
>>> 10-12: Prep the arm framework for enabling the mmu on aarch64
>>> 13-14: Prep the aarch64 framework for enabling the mmu
>>> 15   : Enables the mmu on aarch64
>>>
>>> These patches are also available here
>>> https://github.com/rhdrjones/kvm-unit-tests/tree/arm64/initial-drop
>>>
>>> Thanks,
>>> drew
>>>
>>>
>>> Andrew Jones (15):
>>>   arm: fix run script testdev probing
>>>   virtio: don't use size_t
>>>   arm: setup: fix type mismatch
>>>   Makefile: cscope may need to look in lib/$ARCH
>>>   arm: use absolute headers
>>>   arm: setup: drop unused arguments
>>>   arm: selftest: rename svc mode to kernel mode
>>>   arm64: initial drop
>>>   arm64: vectors support
>>>   arm: get PHYS_MASK from pgtable-hwdef.h
>>>   arm: import more linux page table api
>>>   arm: prepare mmu code for arm64
>>>   arm64: import some Linux page table API
>>>   arm64: prepare for 64k pages
>>>   arm64: enable mmu
>>>
>>>  Makefile                      |   4 +-
>>>  arm/cstart.S                  |  18 ++-
>>>  arm/cstart64.S                | 252 ++++++++++++++++++++++++++++++++++++++++++
>>>  arm/flat.lds                  |  11 +-
>>>  arm/run                       |  12 +-
>>>  arm/selftest.c                | 141 +++++++++++++++++++++--
>>>  arm/unittests.cfg             |  12 +-
>>>  config/config-arm-common.mak  |  69 ++++++++++++
>>>  config/config-arm.mak         |  74 ++-----------
>>>  config/config-arm64.mak       |  21 ++++
>>>  configure                     |  12 +-
>>>  lib/arm/asm-offsets.c         |  11 +-
>>>  lib/arm/asm/asm-offsets.h     |   2 +-
>>>  lib/arm/asm/io.h              |   8 +-
>>>  lib/arm/asm/mmu-api.h         |  14 +++
>>>  lib/arm/asm/mmu.h             |  27 ++---
>>>  lib/arm/asm/page.h            |   7 +-
>>>  lib/arm/asm/pgtable-hwdef.h   |  44 +++++++-
>>>  lib/arm/asm/pgtable.h         |  91 +++++++++++++++
>>>  lib/arm/asm/processor.h       |   2 +-
>>>  lib/arm/asm/ptrace.h          |   2 +-
>>>  lib/arm/asm/setup.h           |  11 +-
>>>  lib/arm/eabi_compat.c         |   2 +-
>>>  lib/arm/io.c                  |  10 +-
>>>  lib/arm/mmu.c                 |  82 ++++++++++----
>>>  lib/arm/processor.c           |   6 +-
>>>  lib/arm/setup.c               |  19 ++--
>>>  lib/arm/spinlock.c            |   8 +-
>>>  lib/arm64/.gitignore          |   1 +
>>>  lib/arm64/asm-offsets.c       |  30 +++++
>>>  lib/arm64/asm/asm-offsets.h   |   1 +
>>>  lib/arm64/asm/barrier.h       |  17 +++
>>>  lib/arm64/asm/esr.h           |  43 +++++++
>>>  lib/arm64/asm/io.h            |  84 ++++++++++++++
>>>  lib/arm64/asm/mmu-api.h       |   1 +
>>>  lib/arm64/asm/mmu.h           |  24 ++++
>>>  lib/arm64/asm/page.h          |  65 +++++++++++
>>>  lib/arm64/asm/pgtable-hwdef.h | 136 +++++++++++++++++++++++
>>>  lib/arm64/asm/pgtable.h       |  69 ++++++++++++
>>>  lib/arm64/asm/processor.h     |  66 +++++++++++
>>>  lib/arm64/asm/ptrace.h        |  95 ++++++++++++++++
>>>  lib/arm64/asm/setup.h         |   1 +
>>>  lib/arm64/asm/spinlock.h      |  15 +++
>>>  lib/arm64/processor.c         | 192 ++++++++++++++++++++++++++++++++
>>>  lib/chr-testdev.c             |   4 +-
>>>  lib/kbuild.h                  |   8 ++
>>>  lib/virtio.c                  |   2 +-
>>>  lib/virtio.h                  |   3 +-
>>>  48 files changed, 1638 insertions(+), 191 deletions(-)
>>>  create mode 100644 arm/cstart64.S
>>>  create mode 100644 config/config-arm-common.mak
>>>  create mode 100644 config/config-arm64.mak
>>>  create mode 100644 lib/arm/asm/mmu-api.h
>>>  create mode 100644 lib/arm/asm/pgtable.h
>>>  create mode 100644 lib/arm64/.gitignore
>>>  create mode 100644 lib/arm64/asm-offsets.c
>>>  create mode 100644 lib/arm64/asm/asm-offsets.h
>>>  create mode 100644 lib/arm64/asm/barrier.h
>>>  create mode 100644 lib/arm64/asm/esr.h
>>>  create mode 100644 lib/arm64/asm/io.h
>>>  create mode 100644 lib/arm64/asm/mmu-api.h
>>>  create mode 100644 lib/arm64/asm/mmu.h
>>>  create mode 100644 lib/arm64/asm/page.h
>>>  create mode 100644 lib/arm64/asm/pgtable-hwdef.h
>>>  create mode 100644 lib/arm64/asm/pgtable.h
>>>  create mode 100644 lib/arm64/asm/processor.h
>>>  create mode 100644 lib/arm64/asm/ptrace.h
>>>  create mode 100644 lib/arm64/asm/setup.h
>>>  create mode 100644 lib/arm64/asm/spinlock.h
>>>  create mode 100644 lib/arm64/processor.c
>>>  create mode 100644 lib/kbuild.h
>>>
>>
>> Thanks, looks good.  Only applied locally until I find some time to
>> retest 32-bit ARM with this changes.
>>
> 
> Ping? I'd like to send more patches building on this series soon.
> Hopefully others (/me looks at Alex Bennee) do too :-)

Pushed, thanks.

Paolo

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

* Re: [PATCH kvm-unit-tests 00/15] arm64: initial drop
  2015-01-02 17:46   ` Andrew Jones
  2015-01-03  8:54     ` Paolo Bonzini
@ 2015-01-06  9:03     ` Alex Bennée
  1 sibling, 0 replies; 20+ messages in thread
From: Alex Bennée @ 2015-01-06  9:03 UTC (permalink / raw)
  To: Andrew Jones; +Cc: Paolo Bonzini, kvmarm, kvm, christoffer.dall


Andrew Jones <drjones@redhat.com> writes:

> On Fri, Dec 12, 2014 at 01:44:52PM +0100, Paolo Bonzini wrote:
<snip>
>> On 10/12/2014 20:59, Andrew Jones wrote:
>> > This series adds support for aarch64 to the kvm-unit-tests framework,
>> > bringing it to the same level as the arm support. In the process a
>> > few tweaks to the arm support were made, as one of the main goals
>> > was to share as much code as possible between the two.
>> > 
>> > Patches
>> > 01   : A fix for the script runner. We need this one for arm
>> >        regardless of the aarch64 support.
>> > 02-03: Fixes to the arm support. The bugs fixed weren't visible
>> >        until running on aarch64.
>> > 04-07: Prep the arm framework for the bare minimal initial drop
>> > 08   : The bare minimal initial drop
>> > 09   : Add vector support to the minimal drop
>> > 10-12: Prep the arm framework for enabling the mmu on aarch64
>> > 13-14: Prep the aarch64 framework for enabling the mmu
>> > 15   : Enables the mmu on aarch64
>> > 
>> > These patches are also available here
>> > https://github.com/rhdrjones/kvm-unit-tests/tree/arm64/initial-drop
<snip>
>
> Ping? I'd like to send more patches building on this series soon.
> Hopefully others (/me looks at Alex Bennee) do too :-)

I am looking at them now.

-- 
Alex Bennée

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

end of thread, other threads:[~2015-01-06  9:23 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-10 19:59 [PATCH kvm-unit-tests 00/15] arm64: initial drop Andrew Jones
2014-12-10 19:59 ` [PATCH 01/15] arm: fix run script testdev probing Andrew Jones
2014-12-10 19:59 ` [PATCH 02/15] virtio: don't use size_t Andrew Jones
2014-12-10 19:59 ` [PATCH 03/15] arm: setup: fix type mismatch Andrew Jones
2014-12-10 19:59 ` [PATCH 04/15] Makefile: cscope may need to look in lib/$ARCH Andrew Jones
2014-12-10 19:59 ` [PATCH 05/15] arm: use absolute headers Andrew Jones
2014-12-10 19:59 ` [PATCH 06/15] arm: setup: drop unused arguments Andrew Jones
2014-12-10 20:00 ` [PATCH 07/15] arm: selftest: rename svc mode to kernel mode Andrew Jones
2014-12-10 20:00 ` [PATCH 08/15] arm64: initial drop Andrew Jones
2014-12-10 20:00 ` [PATCH 09/15] arm64: vectors support Andrew Jones
2014-12-10 20:00 ` [PATCH 10/15] arm: get PHYS_MASK from pgtable-hwdef.h Andrew Jones
2014-12-10 20:00 ` [PATCH 11/15] arm: import more linux page table api Andrew Jones
2014-12-10 20:00 ` [PATCH 12/15] arm: prepare mmu code for arm64 Andrew Jones
2014-12-10 20:00 ` [PATCH 13/15] arm64: import some Linux page table API Andrew Jones
2014-12-10 20:00 ` [PATCH 14/15] arm64: prepare for 64k pages Andrew Jones
2014-12-10 20:00 ` [PATCH 15/15] arm64: enable mmu Andrew Jones
2014-12-12 12:44 ` [PATCH kvm-unit-tests 00/15] arm64: initial drop Paolo Bonzini
2015-01-02 17:46   ` Andrew Jones
2015-01-03  8:54     ` Paolo Bonzini
2015-01-06  9:03     ` Alex Bennée

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.