Skip to contentSkip to conversation

bunch of mostly trivial patches

PATCH Applied Andrew Jones 3 participants 44 messages Nov 6, 2015 – Nov 20, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover bunch of mostly trivial patches

Many of these patches were posted once. Some weren't, but anyway almost everything is pretty trivial. I'd like to get these in, or at least get definitive nacks on them (and then drop them) in order to clean my queue before more patches (coming from Alex Bennée and Chistopher are reposted).

All patches also available here
https://github.com/rhdrjones/kvm-unit-tests/commits/queue

Thanks,
drew

Alex Bennée (4):
README: add some CONTRIBUTING notes
configure: emit HOST=$host to config.mak
lib/printf: support the %u unsigned fmt field
lib/arm: add flush_tlb_page mmu function

Andrew Jones (13):
makefiles: use bash
trivial: lib: fail hard on failed mallocs
trivial: alloc: don't use 'top' outside spinlock
trivial: lib: missing extern in string.h
README: add pointer to new wiki page
run_tests: pass test name to run script arm/run: use ACCEL to choose between kvm and tcg
run_tests: probe for max-smp
arm/arm64: allow building a single test arm/arm64: generate map files
lib: link in linux kernel headers (uapi) Revert "arm/arm64: import include/uapi/linux/psci.h" arm/arm64: uart0_init: check /chosen/stdout-path

Christopher Covington (1):
arm: Fail on unknown subtest

 .gitignore                   |  2 ++
 Makefile                     |  6 ++--
 README                       | 32 +++++++++++++++++++
 arm/run                      | 43 ++++++++++++++++++++++----
 arm/selftest.c               |  3 ++
 arm/unittests.cfg            |  7 +++--
 config/config-arm-common.mak |  9 +++++-
 configure                    | 11 +++++++
 lib/alloc.c                  |  8 +++--
 lib/arm/asm/mmu.h            | 11 +++++++
 lib/arm/asm/page.h           |  2 +-
 lib/arm/asm/psci.h           |  2 +-
 lib/arm/asm/uapi-psci.h      | 73 --------------------------------------------
 lib/arm/io.c                 | 36 ++++++++++++++++------
 lib/arm64/asm/mmu.h          |  8 +++++
 lib/arm64/asm/page.h         |  2 +-
 lib/arm64/asm/psci.h         |  2 +-
 lib/arm64/asm/uapi-psci.h    |  1 -
 lib/asm-generic/page.h       |  2 +-
 lib/const.h                  | 11 -------
 lib/printf.c                 | 13 ++++++++
 lib/string.h                 |  2 +-
 lib/virtio-mmio.c            |  7 ++---
 run_tests.sh                 | 12 +++++++-
 scripts/functions.bash       |  8 +++--
 scripts/mkstandalone.sh      | 22 ++++++++++---
 x86/unittests.cfg            |  1 +
 27 files changed, 210 insertions(+), 126 deletions(-)
 delete mode 100644 lib/arm/asm/uapi-psci.h
 delete mode 100644 lib/arm64/asm/uapi-psci.h
 delete mode 100644 lib/const.h
Signature · 1 line
2.4.3
#1 lore raw

PATCH 1/18 makefiles: use bash

Use bash in the makefiles, like we do in the scripts. Without this some platforms using dash fail to execute make targets that use bash-isms.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +2 -0
index 0d5933474cd8c..3e60b4f8e4a57 100644
@@ -1,4 +1,6 @@
 
+SHELL := /bin/bash
+
 ifeq ($(wildcard config.mak),)
 $(error run ./configure first. See ./configure -h)
 endif
Signature · 1 line
2.4.3
maintainer
#2 lore raw

Re: [kvm-unit-tests PATCH 01/18] makefiles: use bash

Quoted 15 lines · Andrew Jones

Use bash in the makefiles, like we do in the scripts. Without this some platforms using dash fail to execute make targets that use bash-isms.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +0 -0
index 0d5933474cd8c..3e60b4f8e4a57 100644

Makefile line 6

Quoted 6 lines
Makefile +2 -0
@@ -1,4 +1,6 @@
 
+SHELL := /bin/bash
+
 ifeq ($(wildcard config.mak),)
 $(error run ./configure first. See ./configure -h)
 endif

Which bash-isms are actually present?

Paolo

#3 lore raw

Re: [kvm-unit-tests PATCH 01/18] makefiles: use bash

Quoted 18 lines · Paolo Bonzini
Quoted 15 lines · Andrew Jones

Use bash in the makefiles, like we do in the scripts. Without this some platforms using dash fail to execute make targets that use bash-isms.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +0 -0
index 0d5933474cd8c..3e60b4f8e4a57 100644
@@ -1,4 +1,6 @@
 
Quoted 8 lines

Makefile line 6

Quoted 6 lines
Makefile +2 -0
+SHELL := /bin/bash
+
 ifeq ($(wildcard config.mak),)
 $(error run ./configure first. See ./configure -h)
 endif

Which bash-isms are actually present?

config/config-arm-common.mak has $(RM) $(TEST_DIR)/*.{o,flat,elf,map} ...

I could certainly change that one, and that may be the only one... But, we require bash for other scripts anyway, so I think requiring make to use it is reasonable.

Thanks,
drew

Quoted 6 lines

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#4 lore raw

Re: [kvm-unit-tests PATCH 01/18] makefiles: use bash

Quoted 28 lines · Andrew Jones
Quoted 18 lines · Paolo Bonzini
Quoted 15 lines · Andrew Jones

Use bash in the makefiles, like we do in the scripts. Without this some platforms using dash fail to execute make targets that use bash-isms.

---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)
Makefile +0 -0
index 0d5933474cd8c..3e60b4f8e4a57 100644
@@ -1,4 +1,6 @@
 
Quoted 8 lines

Makefile line 6

Quoted 6 lines
Makefile +2 -0
+SHELL := /bin/bash
+
 ifeq ($(wildcard config.mak),)
 $(error run ./configure first. See ./configure -h)
 endif

Which bash-isms are actually present?

Quoted 5 lines

config/config-arm-common.mak has $(RM) $(TEST_DIR)/*.{o,flat,elf,map} ...

I could certainly change that one, and that may be the only one... But, we require bash for other scripts anyway, so I think requiring make to use it is reasonable.

One is enough to apply the patch. :)

Thanks,

Paolo

#5 lore raw

PATCH 2/18 trivial: lib: fail hard on failed mallocs

In reply to Andrew Jones

It's pretty safe to not even bother checking for NULL when using malloc and friends, but if we do check, then fail hard.

---
 lib/virtio-mmio.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
lib/virtio-mmio.c +2 -5
index 043832299174e..1b6f0cc378b79 100644
@@ -54,8 +54,7 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev,
 
 	vq = calloc(1, sizeof(*vq));
 	queue = memalign(PAGE_SIZE, VIRTIO_MMIO_QUEUE_SIZE_MIN);
-	if (!vq || !queue)
-		return NULL;
+	assert(vq && queue);
 
 	writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
 
@@ -161,9 +160,7 @@ static struct virtio_device *virtio_mmio_dt_bind(u32 devid)
 	if (node == -FDT_ERR_NOTFOUND)
 		return NULL;
 
-	vm_dev = calloc(1, sizeof(*vm_dev));
-	if (!vm_dev)
-		return NULL;
+	assert((vm_dev = calloc(1, sizeof(*vm_dev))) != NULL);
 
 	vm_dev->base = info.base;
 	vm_device_init(vm_dev);
Signature · 1 line
2.4.3
#6 lore raw

Re: [kvm-unit-tests PATCH 02/18] trivial: lib: fail hard on failed mallocs

Quoted 13 lines · Andrew Jones

It's pretty safe to not even bother checking for NULL when using malloc and friends, but if we do check, then fail hard.

---
 lib/virtio-mmio.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
lib/virtio-mmio.c +0 -0
index 043832299174e..1b6f0cc378b79 100644

...

lib/virtio-mmio.c static struct virtio_device *virtio_mmio_dt_bind(u32 devid) · line 163

Quoted 8 lines
lib/virtio-mmio.c +1 -3
@@ -161,9 +160,7 @@ static struct virtio_device *virtio_mmio_dt_bind(u32 devid)
 	if (node == -FDT_ERR_NOTFOUND)
 		return NULL;
 
-	vm_dev = calloc(1, sizeof(*vm_dev));
-	if (!vm_dev)
-		return NULL;
+	assert((vm_dev = calloc(1, sizeof(*vm_dev))) != NULL);

Could you maybe write that as two statements? assert() is classically a macro which could also be disabled, so if somebody introduces a switch to "#define assert(...) /*nothing*/" in the future, that calloc call would be completely gone!

Thomas

#7 lore raw

Re: [kvm-unit-tests PATCH 02/18] trivial: lib: fail hard on failed mallocs

Quoted 19 lines · Thomas Huth
Quoted 13 lines · Andrew Jones

It's pretty safe to not even bother checking for NULL when using malloc and friends, but if we do check, then fail hard.

---
 lib/virtio-mmio.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
lib/virtio-mmio.c +0 -0
index 043832299174e..1b6f0cc378b79 100644

...

Quoted 4 lines
lib/virtio-mmio.c +0 -0
@@ -161,9 +160,7 @@ static struct virtio_device *virtio_mmio_dt_bind(u32 devid)
 	if (node == -FDT_ERR_NOTFOUND)
 		return NULL;
 
Quoted 9 lines

lib/virtio-mmio.c static struct virtio_device *virtio_mmio_dt_bind(u32 devid) · line 163

Quoted 4 lines
lib/virtio-mmio.c +1 -3
-	vm_dev = calloc(1, sizeof(*vm_dev));
-	if (!vm_dev)
-		return NULL;
+	assert((vm_dev = calloc(1, sizeof(*vm_dev))) != NULL);

Could you maybe write that as two statements? assert() is classically a macro which could also be disabled, so if somebody introduces a switch to "#define assert(...) /*nothing*/" in the future, that calloc call would be completely gone!

That's a good point, and I'm happy to change this one. Unfortunately I've done things like this several times before, so if we decide to allow assert to be a noop, then we'll need to change those other places as well. I think it's pretty unlikely we ever will want to make it a noop for kvm-unit-tests though.

Thanks,
drew

Quoted 7 lines

Thomas

--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

PATCH v2 2/19 trivial: lib: fail hard on failed mallocs

In reply to Andrew Jones

It's pretty safe to not even bother checking for NULL when using malloc and friends, but if we do check, then fail hard.

---
v2: no code in asserts [Thomas Huth]

 lib/virtio-mmio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/virtio-mmio.c +2 -4
index 043832299174e..5ccbd193a264a 100644
@@ -54,8 +54,7 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev,
 
 	vq = calloc(1, sizeof(*vq));
 	queue = memalign(PAGE_SIZE, VIRTIO_MMIO_QUEUE_SIZE_MIN);
-	if (!vq || !queue)
-		return NULL;
+	assert(vq && queue);
 
 	writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
 
@@ -162,8 +161,7 @@ static struct virtio_device *virtio_mmio_dt_bind(u32 devid)
 		return NULL;
 
 	vm_dev = calloc(1, sizeof(*vm_dev));
-	if (!vm_dev)
-		return NULL;
+	assert(vm_dev != NULL);
 
 	vm_dev->base = info.base;
 	vm_device_init(vm_dev);
Signature · 1 line
2.4.3
Reviewed-by on v2 2/19
#9 lore raw

Re: [kvm-unit-tests PATCH v2 02/19] trivial: lib: fail hard on failed mallocs

Quoted 26 lines · Andrew Jones

It's pretty safe to not even bother checking for NULL when using malloc and friends, but if we do check, then fail hard.

---
v2: no code in asserts [Thomas Huth]

 lib/virtio-mmio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/virtio-mmio.c +1 -2
index 043832299174e..5ccbd193a264a 100644
@@ -54,8 +54,7 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev,
 
 	vq = calloc(1, sizeof(*vq));
 	queue = memalign(PAGE_SIZE, VIRTIO_MMIO_QUEUE_SIZE_MIN);
-	if (!vq || !queue)
-		return NULL;
+	assert(vq && queue);
 
 	writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
 

lib/virtio-mmio.c static struct virtio_device *virtio_mmio_dt_bind(u32 devid) · line 167

Quoted 9 lines
lib/virtio-mmio.c +1 -2
@@ -162,8 +161,7 @@ static struct virtio_device *virtio_mmio_dt_bind(u32 devid)
 		return NULL;
 
 	vm_dev = calloc(1, sizeof(*vm_dev));
-	if (!vm_dev)
-		return NULL;
+	assert(vm_dev != NULL);
 
 	vm_dev->base = info.base;
 	vm_device_init(vm_dev);
maintainer Applied
#10 lore raw

Re: [kvm-unit-tests PATCH v2 02/19] trivial: lib: fail hard on failed mallocs

In reply to Andrew Jones
Quoted 27 lines · Andrew Jones

It's pretty safe to not even bother checking for NULL when using malloc and friends, but if we do check, then fail hard.

---
v2: no code in asserts [Thomas Huth]

 lib/virtio-mmio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/virtio-mmio.c +1 -2
index 043832299174e..5ccbd193a264a 100644
@@ -54,8 +54,7 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev,
 
 	vq = calloc(1, sizeof(*vq));
 	queue = memalign(PAGE_SIZE, VIRTIO_MMIO_QUEUE_SIZE_MIN);
-	if (!vq || !queue)
-		return NULL;
+	assert(vq && queue);
 
 	writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
 

lib/virtio-mmio.c static struct virtio_device *virtio_mmio_dt_bind(u32 devid) · line 167

Quoted 9 lines
lib/virtio-mmio.c +1 -2
@@ -162,8 +161,7 @@ static struct virtio_device *virtio_mmio_dt_bind(u32 devid)
 		return NULL;
 
 	vm_dev = calloc(1, sizeof(*vm_dev));
-	if (!vm_dev)
-		return NULL;
+	assert(vm_dev != NULL);
 
 	vm_dev->base = info.base;
 	vm_device_init(vm_dev);

Applied, thanks.

Paolo

#11 lore raw

PATCH 3/18 trivial: alloc: don't use 'top' outside spinlock

In reply to Andrew Jones

This is a fix just due to being too much of a type-A person. I noticed the issue while reading over the function, and decided to fix it, even though it's unlikely to be a problem ever because top is read-mostly (like written once, then only read, type of mostly).

---
 lib/alloc.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
lib/alloc.c +5 -3
index ad6761430c965..34f71a337d868 100644
@@ -61,15 +61,17 @@ static phys_addr_t phys_alloc_aligned_safe(phys_addr_t size,
 {
 	static bool warned = false;
 	phys_addr_t addr, size_orig = size;
-	u64 top_safe = top;
+	u64 top_safe;
+
+	spin_lock(&lock);
+
+	top_safe = top;
 
 	if (safe && sizeof(long) == 4)
 		top_safe = MIN(top, 1ULL << 32);
 
 	align = MAX(align, align_min);
 
-	spin_lock(&lock);
-
 	addr = ALIGN(base, align);
 	size += addr - base;
 
Signature · 1 line
2.4.3
maintainer Applied
#12 lore raw

Re: [kvm-unit-tests PATCH 03/18] trivial: alloc: don't use 'top' outside spinlock

Quoted 27 lines · Andrew Jones

This is a fix just due to being too much of a type-A person. I noticed the issue while reading over the function, and decided to fix it, even though it's unlikely to be a problem ever because top is read-mostly (like written once, then only read, type of mostly).

---
 lib/alloc.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
lib/alloc.c +5 -1
index ad6761430c965..34f71a337d868 100644
@@ -61,15 +61,17 @@ static phys_addr_t phys_alloc_aligned_safe(phys_addr_t size,
 {
 	static bool warned = false;
 	phys_addr_t addr, size_orig = size;
-	u64 top_safe = top;
+	u64 top_safe;
+
+	spin_lock(&lock);
+
+	top_safe = top;
 

lib/alloc.c static phys_addr_t phys_alloc_aligned_safe(phys_addr_t size, · line 77

Quoted 10 lines
lib/alloc.c +0 -2
 	if (safe && sizeof(long) == 4)
 		top_safe = MIN(top, 1ULL << 32);
 
 	align = MAX(align, align_min);
 
-	spin_lock(&lock);
-
 	addr = ALIGN(base, align);
 	size += addr - base;
 

Applied, thanks.

Paolo

#13 lore raw

PATCH 4/18 trivial: lib: missing extern in string.h

In reply to Andrew Jones
---
 lib/string.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/string.h +1 -1
index 7820db86ee4e0..4e24f54d9e231 100644
@@ -6,7 +6,7 @@ extern char *strcat(char *dest, const char *src);
 extern char *strcpy(char *dest, const char *src);
 extern int strcmp(const char *a, const char *b);
 extern char *strchr(const char *s, int c);
-char *strstr(const char *haystack, const char *needle);
+extern char *strstr(const char *haystack, const char *needle);
 extern void *memset(void *s, int c, size_t n);
 extern void *memcpy(void *dest, const void *src, size_t n);
 extern int memcmp(const void *s1, const void *s2, size_t n);
Signature · 1 line
2.4.3
maintainer Applied
#14 lore raw

Re: [kvm-unit-tests PATCH 04/18] trivial: lib: missing extern in string.h

Quoted 11 lines · Andrew Jones
---
 lib/string.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/string.h +0 -0
index 7820db86ee4e0..4e24f54d9e231 100644

lib/string.h extern char *strcat(char *dest, const char *src); · line 12

Quoted 8 lines
lib/string.h +1 -1
@@ -6,7 +6,7 @@ extern char *strcat(char *dest, const char *src);
 extern char *strcpy(char *dest, const char *src);
 extern int strcmp(const char *a, const char *b);
 extern char *strchr(const char *s, int c);
-char *strstr(const char *haystack, const char *needle);
+extern char *strstr(const char *haystack, const char *needle);
 extern void *memset(void *s, int c, size_t n);
 extern void *memcpy(void *dest, const void *src, size_t n);
 extern int memcmp(const void *s1, const void *s2, size_t n);

Applied, thanks.

Paolo

#15 lore raw

PATCH 5/18 README: add pointer to new wiki page

In reply to Andrew Jones
---
 README | 6 ++++++
 1 file changed, 6 insertions(+)
README +6 -0
index eab5ea28f7fab..45587f2a97ec6 100644
@@ -1,3 +1,9 @@
+Welcome to kvm-unit-tests
+
+See http://www.linux-kvm.org/page/KVM-unit-tests for a high-level
+description of this project, as well as running tests and adding
+tests HOWTOs.
+
 This directory contains sources for a kvm test suite.
 
 To create the test images do
Signature · 1 line
2.4.3
maintainer Applied
#16 lore raw

Re: [kvm-unit-tests PATCH 05/18] README: add pointer to new wiki page

Quoted 11 lines · Andrew Jones
---
 README | 6 ++++++
 1 file changed, 6 insertions(+)
README +0 -0
index eab5ea28f7fab..45587f2a97ec6 100644

README line 9

Quoted 9 lines
README +6 -0
@@ -1,3 +1,9 @@
+Welcome to kvm-unit-tests
+
+See http://www.linux-kvm.org/page/KVM-unit-tests for a high-level
+description of this project, as well as running tests and adding
+tests HOWTOs.
+
 This directory contains sources for a kvm test suite.
 
 To create the test images do

Applied, thanks.

Paolo

#17 lore raw

PATCH 6/18 README: add some CONTRIBUTING notes

In reply to Andrew Jones

From: Alex Bennée <[email protected]>

---
 README | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
README +26 -0
index 45587f2a97ec6..457bd797362cf 100644
@@ -41,3 +41,29 @@ Directory structure:
 ./<ARCH>:	the sources of the tests and the created objects/images
 
 See <ARCH>/README for architecture specific documentation.
+
+CONTRIBUTING:
+=============
+
+Style
+-----
+
+Currently there is a mix of indentation styles so any changes to
+existing files should be consistent with the existing style. For new
+files:
+
+  - C: please use standard linux-with-tabs
+  - Shell: use TABs for indentation
+
+Patches
+-------
+
+Patches are welcome at the KVM mailing list <[email protected]>.
+
+Please prefix messages with: [kvm-unit-tests PATCH]
+
+You can add the following to .git/config to do this automatically for you:
+
+[format]
+	subjectprefix = kvm-unit-tests PATCH
+
Signature · 1 line
2.4.3
maintainer Applied
#18 lore raw

Re: [kvm-unit-tests PATCH 06/18] README: add some CONTRIBUTING notes

Quoted 19 lines · Andrew Jones

From: Alex Bennée <[email protected]>

---
 README | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
README +3 -0
index 45587f2a97ec6..457bd797362cf 100644
@@ -41,3 +41,29 @@ Directory structure:
 ./<ARCH>:	the sources of the tests and the created objects/images
 
 See <ARCH>/README for architecture specific documentation.
+
+CONTRIBUTING:
+=============

README Directory structure: · line 56

Quoted 10 lines
README +10 -0
+
+Style
+-----
+
+Currently there is a mix of indentation styles so any changes to
+existing files should be consistent with the existing style. For new
+files:
+
+  - C: please use standard linux-with-tabs
+  - Shell: use TABs for indentation

Which should be changed :)

README Directory structure: · line 69

Quoted 13 lines
README +12 -0
+Patches
+-------
+
+Patches are welcome at the KVM mailing list <[email protected]>.
+
+Please prefix messages with: [kvm-unit-tests PATCH]
+
+You can add the following to .git/config to do this automatically for you:
+
+[format]
+	subjectprefix = kvm-unit-tests PATCH
+

Applied, thanks.

Paolo

#19 lore raw

PATCH 7/18 configure: emit HOST=$host to config.mak

In reply to Andrew Jones

From: Alex Bennée <[email protected]>

This is useful information for the run scripts to know, especially if they want to drop to using TCG.

---
 configure | 2 ++
 1 file changed, 2 insertions(+)
configure +2 -0
index b2ad32a3e3a52..078b70ce096a6 100755
@@ -7,6 +7,7 @@ ld=ld
 objcopy=objcopy
 ar=ar
 arch=`uname -m | sed -e s/i.86/i386/ | sed -e 's/arm.*/arm/'`
+host=$arch
 cross_prefix=
 
 usage() {
@@ -122,6 +123,7 @@ ln -s $asm lib/asm
 cat <<EOF > config.mak
 PREFIX=$prefix
 KERNELDIR=$(readlink -f $kerneldir)
+HOST=$host
 ARCH=$arch
 ARCH_NAME=$arch_name
 PROCESSOR=$processor
Signature · 1 line
2.4.3
maintainer Applied
#20 lore raw

Re: [kvm-unit-tests PATCH 07/18] configure: emit HOST=$host to config.mak

Quoted 25 lines · Andrew Jones

From: Alex Bennée <[email protected]>

This is useful information for the run scripts to know, especially if they want to drop to using TCG.

---
 configure | 2 ++
 1 file changed, 2 insertions(+)
configure +1 -0
index b2ad32a3e3a52..078b70ce096a6 100755
@@ -7,6 +7,7 @@ ld=ld
 objcopy=objcopy
 ar=ar
 arch=`uname -m | sed -e s/i.86/i386/ | sed -e 's/arm.*/arm/'`
+host=$arch
 cross_prefix=
 
 usage() {

configure ln -s $asm lib/asm · line 129

Quoted 7 lines
configure +1 -0
@@ -122,6 +123,7 @@ ln -s $asm lib/asm
 cat <<EOF > config.mak
 PREFIX=$prefix
 KERNELDIR=$(readlink -f $kerneldir)
+HOST=$host
 ARCH=$arch
 ARCH_NAME=$arch_name
 PROCESSOR=$processor

Applied, thanks.

Paolo

#21 lore raw

PATCH 8/18 run_tests: pass test name to run script

In reply to Andrew Jones

With this $TEST_DIR/run can output test specific error messages.

---
 run_tests.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
run_tests.sh +1 -1
index ebb7e9fe6fdfc..80b87823c3358 100755
@@ -46,7 +46,7 @@ function run()
         fi
     done
 
-    cmdline="./$TEST_DIR-run $kernel -smp $smp $opts"
+    cmdline="TESTNAME=$testname ./$TEST_DIR-run $kernel -smp $smp $opts"
     if [ $verbose != 0 ]; then
         echo $cmdline
     fi
Signature · 1 line
2.4.3
maintainer Applied
#22 lore raw

Re: [kvm-unit-tests PATCH 08/18] run_tests: pass test name to run script

Quoted 13 lines · Andrew Jones

With this $TEST_DIR/run can output test specific error messages.

---
 run_tests.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
run_tests.sh +0 -0
index ebb7e9fe6fdfc..80b87823c3358 100755

run_tests.sh function run() · line 52

Quoted 8 lines
run_tests.sh +1 -1
@@ -46,7 +46,7 @@ function run()
         fi
     done
 
-    cmdline="./$TEST_DIR-run $kernel -smp $smp $opts"
+    cmdline="TESTNAME=$testname ./$TEST_DIR-run $kernel -smp $smp $opts"
     if [ $verbose != 0 ]; then
         echo $cmdline
     fi

Applied, thanks.

Paolo

#23 lore raw

PATCH 9/18 arm/run: use ACCEL to choose between kvm and tcg

In reply to Andrew Jones

Inspired by a patch by Alex Bennée. This version uses a new unittests.cfg variable and includes support for DRYRUN.

---
 arm/run                 | 43 +++++++++++++++++++++++++++++++++++++------
 arm/unittests.cfg       |  4 +++-
 run_tests.sh            |  3 ++-
 scripts/functions.bash  |  8 ++++++--
 scripts/mkstandalone.sh | 15 +++++++++++----
 5 files changed, 59 insertions(+), 14 deletions(-)
arm/run +37 -6
index 8cc2fa2571967..4a648697d7fb5 100755
@@ -7,6 +7,42 @@ fi
 source config.mak
 processor="$PROCESSOR"
 
+if [ -c /dev/kvm ]; then
+	if [ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]; then
+		kvm_available=yes
+	elif [ "$HOST" = "aarch64" ]; then
+		kvm_available=yes
+	fi
+fi
+
+if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ] &&
+		[ "$DRYRUN" != "yes" ]; then
+	printf "skip $TESTNAME (kvm only)\n\n"
+	exit 2
+fi
+
+if [ -z "$ACCEL" ]; then
+	if [ "$DRYRUN" = "yes" ]; then
+		# Output kvm with tcg fallback for dryrun (when both are
+		# allowed), since the command line we output may get used
+		# elsewhere.
+		ACCEL="kvm:tcg"
+	elif [ "$kvm_available" = "yes" ]; then
+		ACCEL="kvm"
+	else
+		ACCEL="tcg"
+	fi
+fi
+
+if [ "$ARCH" = "arm64" ]; then
+	if [[ $ACCEL =~ kvm ]]; then
+		# arm64 must use '-cpu host' with kvm, and we can't use
+		# '-cpu host' with tcg, so we force kvm-only (no fallback)
+		ACCEL="kvm"
+		processor="host"
+	fi
+fi
+
 qemu="${QEMU:-qemu-system-$ARCH_NAME}"
 qpath=$(which $qemu 2>/dev/null)
 
@@ -33,15 +69,10 @@ if $qemu $M -chardev testdev,id=id -initrd . 2>&1 \
 	exit 2
 fi
 
-M='-machine virt,accel=kvm:tcg'
 chr_testdev='-device virtio-serial-device'
 chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
 
-# arm64 must use '-cpu host' with kvm
-if [ "$(arch)" = "aarch64" ] && [ "$ARCH" = "arm64" ] && [ -c /dev/kvm ]; then
-	processor="host"
-fi
-
+M+=",accel=$ACCEL"
 command="$qemu $M -cpu $processor $chr_testdev"
 command+=" -display none -serial stdio -kernel"
 echo $command "$@"
arm/unittests.cfg +3 -1
index e068a0cdd9c1f..243c13301811b 100644
@@ -3,8 +3,10 @@
 # file = foo.flat # Name of the flat file to be used
 # smp  = 2        # Number of processors the VM will use during this test
 # extra_params = -append <params...> # Additional parameters used
-# arch = arm/arm64                   # Only if test case is specific to one
+# arch = arm|arm64                   # Only if test case is specific to one
 # groups = group1 group2 # Used to identify test cases with run_tests -g ...
+# accel = kvm|tcg # Optionally specify if test must run with kvm or tcg.
+#                 # If not specified, then kvm will be used when available.
 
 #
 # Test that the configured number of processors (smp = <num>), and
run_tests.sh +2 -1
index 80b87823c3358..b1b4c541ecaea 100755
@@ -20,6 +20,7 @@ function run()
     local opts="$5"
     local arch="$6"
     local check="$7"
+    local accel="$8"
 
     if [ -z "$testname" ]; then
         return
@@ -46,7 +47,7 @@ function run()
         fi
     done
 
-    cmdline="TESTNAME=$testname ./$TEST_DIR-run $kernel -smp $smp $opts"
+    cmdline="TESTNAME=$testname ACCEL=$accel ./$TEST_DIR-run $kernel -smp $smp $opts"
     if [ $verbose != 0 ]; then
         echo $cmdline
     fi
scripts/functions.bash +6 -2
index 7ed5a517250bc..f13fe6f88f23d 100644
@@ -10,12 +10,13 @@ function for_each_unittest()
 	local groups
 	local arch
 	local check
+	local accel
 
 	exec {fd}<"$unittests"
 
 	while read -u $fd line; do
 		if [[ "$line" =~ ^\[(.*)\]$ ]]; then
-			"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check"
+			"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel"
 			testname=${BASH_REMATCH[1]}
 			smp=1
 			kernel=""
@@ -23,6 +24,7 @@ function for_each_unittest()
 			groups=""
 			arch=""
 			check=""
+			accel=""
 		elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
 			kernel=$TEST_DIR/${BASH_REMATCH[1]}
 		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
@@ -35,8 +37,10 @@ function for_each_unittest()
 			arch=${BASH_REMATCH[1]}
 		elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then
 			check=${BASH_REMATCH[1]}
+		elif [[ $line =~ ^accel\ *=\ *(.*)$ ]]; then
+			accel=${BASH_REMATCH[1]}
 		fi
 	done
-	"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check"
+	"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel"
 	exec {fd}<&-
 }
scripts/mkstandalone.sh +11 -4
index 4cf346ab87d24..0c39451e538c9 100755
@@ -29,6 +29,7 @@ function mkstandalone()
 	local opts="$5"
 	local arch="$6"
 	local check="$7"
+	local accel="$8"
 
 	if [ -z "$testname" ]; then
 		return 1
@@ -39,7 +40,7 @@ function mkstandalone()
 	fi
 
 	standalone=tests/$testname
-	cmdline=$(DRYRUN=yes ./$TEST_DIR-run $kernel)
+	cmdline=$(DRYRUN=yes ACCEL=$accel ./$TEST_DIR-run $kernel)
 	if [ $? -ne 0 ]; then
 		echo $cmdline
 		exit 1
@@ -94,10 +95,16 @@ qemu="$qemu"
 if [ "\$QEMU" ]; then
 	qemu="\$QEMU"
 fi
-cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`"
 echo \$qemu $cmdline -smp $smp $opts
-\$qemu \$cmdline -smp $smp $opts
-ret=\$?
+
+cmdline="\`echo '$cmdline' | sed s%$kernel%_NO_FILE_4Uhere_%\`"
+if \$qemu \$cmdline 2>&1 | grep 'No accelerator found'; then
+        ret=2
+else
+	cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`"
+	\$qemu \$cmdline -smp $smp $opts
+	ret=\$?
+fi
 echo Return value from qemu: \$ret
 if [ \$ret -le 1 ]; then
 	echo PASS $testname 1>&2
Signature · 1 line
2.4.3
maintainer Applied
#24 lore raw

Re: [kvm-unit-tests PATCH 09/18] arm/run: use ACCEL to choose between kvm and tcg

Quoted 184 lines · Andrew Jones

Inspired by a patch by Alex Bennée. This version uses a new unittests.cfg variable and includes support for DRYRUN.

---
 arm/run                 | 43 +++++++++++++++++++++++++++++++++++++------
 arm/unittests.cfg       |  4 +++-
 run_tests.sh            |  3 ++-
 scripts/functions.bash  |  8 ++++++--
 scripts/mkstandalone.sh | 15 +++++++++++----
 5 files changed, 59 insertions(+), 14 deletions(-)
arm/run +37 -6
index 8cc2fa2571967..4a648697d7fb5 100755
@@ -7,6 +7,42 @@ fi
 source config.mak
 processor="$PROCESSOR"
 
+if [ -c /dev/kvm ]; then
+	if [ "$HOST" = "arm" ] && [ "$ARCH" = "arm" ]; then
+		kvm_available=yes
+	elif [ "$HOST" = "aarch64" ]; then
+		kvm_available=yes
+	fi
+fi
+
+if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ] &&
+		[ "$DRYRUN" != "yes" ]; then
+	printf "skip $TESTNAME (kvm only)\n\n"
+	exit 2
+fi
+
+if [ -z "$ACCEL" ]; then
+	if [ "$DRYRUN" = "yes" ]; then
+		# Output kvm with tcg fallback for dryrun (when both are
+		# allowed), since the command line we output may get used
+		# elsewhere.
+		ACCEL="kvm:tcg"
+	elif [ "$kvm_available" = "yes" ]; then
+		ACCEL="kvm"
+	else
+		ACCEL="tcg"
+	fi
+fi
+
+if [ "$ARCH" = "arm64" ]; then
+	if [[ $ACCEL =~ kvm ]]; then
+		# arm64 must use '-cpu host' with kvm, and we can't use
+		# '-cpu host' with tcg, so we force kvm-only (no fallback)
+		ACCEL="kvm"
+		processor="host"
+	fi
+fi
+
 qemu="${QEMU:-qemu-system-$ARCH_NAME}"
 qpath=$(which $qemu 2>/dev/null)
 
@@ -33,15 +69,10 @@ if $qemu $M -chardev testdev,id=id -initrd . 2>&1 \
 	exit 2
 fi
 
-M='-machine virt,accel=kvm:tcg'
 chr_testdev='-device virtio-serial-device'
 chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
 
-# arm64 must use '-cpu host' with kvm
-if [ "$(arch)" = "aarch64" ] && [ "$ARCH" = "arm64" ] && [ -c /dev/kvm ]; then
-	processor="host"
-fi
-
+M+=",accel=$ACCEL"
 command="$qemu $M -cpu $processor $chr_testdev"
 command+=" -display none -serial stdio -kernel"
 echo $command "$@"
arm/unittests.cfg +3 -1
index e068a0cdd9c1f..243c13301811b 100644
@@ -3,8 +3,10 @@
 # file = foo.flat # Name of the flat file to be used
 # smp  = 2        # Number of processors the VM will use during this test
 # extra_params = -append <params...> # Additional parameters used
-# arch = arm/arm64                   # Only if test case is specific to one
+# arch = arm|arm64                   # Only if test case is specific to one
 # groups = group1 group2 # Used to identify test cases with run_tests -g ...
+# accel = kvm|tcg # Optionally specify if test must run with kvm or tcg.
+#                 # If not specified, then kvm will be used when available.
 
 #
 # Test that the configured number of processors (smp = <num>), and
run_tests.sh +2 -1
index 80b87823c3358..b1b4c541ecaea 100755
@@ -20,6 +20,7 @@ function run()
     local opts="$5"
     local arch="$6"
     local check="$7"
+    local accel="$8"
 
     if [ -z "$testname" ]; then
         return
@@ -46,7 +47,7 @@ function run()
         fi
     done
 
-    cmdline="TESTNAME=$testname ./$TEST_DIR-run $kernel -smp $smp $opts"
+    cmdline="TESTNAME=$testname ACCEL=$accel ./$TEST_DIR-run $kernel -smp $smp $opts"
     if [ $verbose != 0 ]; then
         echo $cmdline
     fi
scripts/functions.bash +6 -2
index 7ed5a517250bc..f13fe6f88f23d 100644
@@ -10,12 +10,13 @@ function for_each_unittest()
 	local groups
 	local arch
 	local check
+	local accel
 
 	exec {fd}<"$unittests"
 
 	while read -u $fd line; do
 		if [[ "$line" =~ ^\[(.*)\]$ ]]; then
-			"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check"
+			"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel"
 			testname=${BASH_REMATCH[1]}
 			smp=1
 			kernel=""
@@ -23,6 +24,7 @@ function for_each_unittest()
 			groups=""
 			arch=""
 			check=""
+			accel=""
 		elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
 			kernel=$TEST_DIR/${BASH_REMATCH[1]}
 		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
@@ -35,8 +37,10 @@ function for_each_unittest()
 			arch=${BASH_REMATCH[1]}
 		elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then
 			check=${BASH_REMATCH[1]}
+		elif [[ $line =~ ^accel\ *=\ *(.*)$ ]]; then
+			accel=${BASH_REMATCH[1]}
 		fi
 	done
-	"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check"
+	"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel"
 	exec {fd}<&-
 }
scripts/mkstandalone.sh +4 -4
index 4cf346ab87d24..0c39451e538c9 100755
@@ -29,6 +29,7 @@ function mkstandalone()
 	local opts="$5"
 	local arch="$6"
 	local check="$7"
+	local accel="$8"
 
 	if [ -z "$testname" ]; then
 		return 1
@@ -39,7 +40,7 @@ function mkstandalone()
 	fi
 
 	standalone=tests/$testname
-	cmdline=$(DRYRUN=yes ./$TEST_DIR-run $kernel)
+	cmdline=$(DRYRUN=yes ACCEL=$accel ./$TEST_DIR-run $kernel)
 	if [ $? -ne 0 ]; then
 		echo $cmdline
 		exit 1
@@ -94,10 +95,16 @@ qemu="$qemu"
 if [ "\$QEMU" ]; then
 	qemu="\$QEMU"
 fi
-cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`"
 echo \$qemu $cmdline -smp $smp $opts
-\$qemu \$cmdline -smp $smp $opts
-ret=\$?
+
+cmdline="\`echo '$cmdline' | sed s%$kernel%_NO_FILE_4Uhere_%\`"

scripts/mkstandalone.sh qemu="$qemu" · line 110

Quoted 10 lines
scripts/mkstandalone.sh +7 -0
+if \$qemu \$cmdline 2>&1 | grep 'No accelerator found'; then
+        ret=2
+else
+	cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`"
+	\$qemu \$cmdline -smp $smp $opts
+	ret=\$?
+fi
 echo Return value from qemu: \$ret
 if [ \$ret -le 1 ]; then
 	echo PASS $testname 1>&2

Applied, thanks.

Paolo

#25 lore raw

PATCH 10/18 run_tests: probe for max-smp

In reply to Andrew Jones

KVM can be configured to only support a few vcpus. ARM and AArch64 currently have a default config of only 4. While it's nice to be able to write tests that use the maximum recommended, nr-host-cpus, we can't assume that nr-host-cpus == kvm-max-vcpus. This patch allows one to put $MAX_SMP in the smp = <num> line of a unittests.cfg file. That variable will then expand to the number of host cpus, or to the maximum vcpus allowed by KVM.

[Inspired by a patch from Alex Bennée solving the same issue.]

---
 arm/unittests.cfg       | 3 ++-
 run_tests.sh            | 9 +++++++++
 scripts/mkstandalone.sh | 9 ++++++++-
 x86/unittests.cfg       | 1 +
 4 files changed, 20 insertions(+), 2 deletions(-)
arm/unittests.cfg +2 -1
index 243c13301811b..5e26da1a8c1bc 100644
@@ -2,6 +2,7 @@
 # [unittest_name]
 # file = foo.flat # Name of the flat file to be used
 # smp  = 2        # Number of processors the VM will use during this test
+#                 # Use $MAX_SMP to use the maximum the host supports.
 # extra_params = -append <params...> # Additional parameters used
 # arch = arm|arm64                   # Only if test case is specific to one
 # groups = group1 group2 # Used to identify test cases with run_tests -g ...
@@ -34,6 +35,6 @@ groups = selftest
 # Test SMP support
 [selftest-smp]
 file = selftest.flat
-smp = `getconf _NPROCESSORS_CONF`
+smp = $MAX_SMP
 extra_params = -append 'smp'
 groups = selftest
run_tests.sh +9 -0
index b1b4c541ecaea..fad22a935b007 100755
@@ -98,4 +98,13 @@ while getopts "g:hv" opt; do
     esac
 done
 
+#
+# Probe for MAX_SMP
+#
+MAX_SMP=$(getconf _NPROCESSORS_CONF)
+while ./$TEST_DIR-run _NO_FILE_4Uhere_ -smp $MAX_SMP \
+		|& grep -q 'exceeds max cpus'; do
+	((--MAX_SMP))
+done
+
 for_each_unittest $config run
scripts/mkstandalone.sh +8 -1
index 0c39451e538c9..3ce244aff67b9 100755
@@ -95,12 +95,19 @@ qemu="$qemu"
 if [ "\$QEMU" ]; then
 	qemu="\$QEMU"
 fi
+
+MAX_SMP="MAX_SMP"
 echo \$qemu $cmdline -smp $smp $opts
 
 cmdline="\`echo '$cmdline' | sed s%$kernel%_NO_FILE_4Uhere_%\`"
 if \$qemu \$cmdline 2>&1 | grep 'No accelerator found'; then
-        ret=2
+	ret=2
 else
+	MAX_SMP=\`getconf _NPROCESSORS_CONF\`
+	while \$qemu \$cmdline -smp \$MAX_SMP 2>&1 | grep 'exceeds max cpus' > /dev/null; do
+		MAX_SMP=\`expr \$MAX_SMP - 1\`
+	done
+
 	cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`"
 	\$qemu \$cmdline -smp $smp $opts
 	ret=\$?
x86/unittests.cfg +1 -0
index a38544f77c056..337cc19d3d19d 100644
@@ -2,6 +2,7 @@
 # [unittest_name]
 # file = foo.flat # Name of the flat file to be used
 # smp = 2 # Number of processors the VM will use during this test
+#         # Use $MAX_SMP to use the maximum the host supports.
 # extra_params = -cpu qemu64,+x2apic # Additional parameters used
 # arch = i386/x86_64 # Only if the test case works only on one of them
 # groups = group1 group2 # Used to identify test cases with run_tests -g ...
Signature · 1 line
2.4.3
maintainer Applied
#26 lore raw

Re: [kvm-unit-tests PATCH 10/18] run_tests: probe for max-smp

Quoted 87 lines · Andrew Jones

KVM can be configured to only support a few vcpus. ARM and AArch64 currently have a default config of only 4. While it's nice to be able to write tests that use the maximum recommended, nr-host-cpus, we can't assume that nr-host-cpus == kvm-max-vcpus. This patch allows one to put $MAX_SMP in the smp = <num> line of a unittests.cfg file. That variable will then expand to the number of host cpus, or to the maximum vcpus allowed by KVM.

[Inspired by a patch from Alex Bennée solving the same issue.]

---
 arm/unittests.cfg       | 3 ++-
 run_tests.sh            | 9 +++++++++
 scripts/mkstandalone.sh | 9 ++++++++-
 x86/unittests.cfg       | 1 +
 4 files changed, 20 insertions(+), 2 deletions(-)
arm/unittests.cfg +2 -1
index 243c13301811b..5e26da1a8c1bc 100644
@@ -2,6 +2,7 @@
 # [unittest_name]
 # file = foo.flat # Name of the flat file to be used
 # smp  = 2        # Number of processors the VM will use during this test
+#                 # Use $MAX_SMP to use the maximum the host supports.
 # extra_params = -append <params...> # Additional parameters used
 # arch = arm|arm64                   # Only if test case is specific to one
 # groups = group1 group2 # Used to identify test cases with run_tests -g ...
@@ -34,6 +35,6 @@ groups = selftest
 # Test SMP support
 [selftest-smp]
 file = selftest.flat
-smp = `getconf _NPROCESSORS_CONF`
+smp = $MAX_SMP
 extra_params = -append 'smp'
 groups = selftest
run_tests.sh +9 -0
index b1b4c541ecaea..fad22a935b007 100755
@@ -98,4 +98,13 @@ while getopts "g:hv" opt; do
     esac
 done
 
+#
+# Probe for MAX_SMP
+#
+MAX_SMP=$(getconf _NPROCESSORS_CONF)
+while ./$TEST_DIR-run _NO_FILE_4Uhere_ -smp $MAX_SMP \
+		|& grep -q 'exceeds max cpus'; do
+	((--MAX_SMP))
+done
+
 for_each_unittest $config run
scripts/mkstandalone.sh +8 -1
index 0c39451e538c9..3ce244aff67b9 100755
@@ -95,12 +95,19 @@ qemu="$qemu"
 if [ "\$QEMU" ]; then
 	qemu="\$QEMU"
 fi
+
+MAX_SMP="MAX_SMP"
 echo \$qemu $cmdline -smp $smp $opts
 
 cmdline="\`echo '$cmdline' | sed s%$kernel%_NO_FILE_4Uhere_%\`"
 if \$qemu \$cmdline 2>&1 | grep 'No accelerator found'; then
-        ret=2
+	ret=2
 else
+	MAX_SMP=\`getconf _NPROCESSORS_CONF\`
+	while \$qemu \$cmdline -smp \$MAX_SMP 2>&1 | grep 'exceeds max cpus' > /dev/null; do
+		MAX_SMP=\`expr \$MAX_SMP - 1\`
+	done
+
 	cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`"
 	\$qemu \$cmdline -smp $smp $opts
 	ret=\$?
x86/unittests.cfg +0 -0
index a38544f77c056..337cc19d3d19d 100644

x86/unittests.cfg line 8

Quoted 7 lines
x86/unittests.cfg +1 -0
@@ -2,6 +2,7 @@
 # [unittest_name]
 # file = foo.flat # Name of the flat file to be used
 # smp = 2 # Number of processors the VM will use during this test
+#         # Use $MAX_SMP to use the maximum the host supports.
 # extra_params = -cpu qemu64,+x2apic # Additional parameters used
 # arch = i386/x86_64 # Only if the test case works only on one of them
 # groups = group1 group2 # Used to identify test cases with run_tests -g ...

Applied, thanks.

Paolo

#27 lore raw

PATCH 11/18 lib/printf: support the %u unsigned fmt field

In reply to Andrew Jones

From: Alex Bennée <[email protected]>

---
 lib/printf.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
lib/printf.c +13 -0
index 89308fb26b7d2..5d83605afe829 100644
@@ -180,6 +180,19 @@ int vsnprintf(char *buf, int size, const char *fmt, va_list va)
 		break;
 	    }
 	    break;
+	case 'u':
+	    switch (nlong) {
+	    case 0:
+		print_unsigned(&s, va_arg(va, unsigned), 10, props);
+		break;
+	    case 1:
+		print_unsigned(&s, va_arg(va, unsigned long), 10, props);
+		break;
+	    default:
+		print_unsigned(&s, va_arg(va, unsigned long long), 10, props);
+		break;
+	    }
+	    break;
 	case 'x':
 	    switch (nlong) {
 	    case 0:
Signature · 1 line
2.4.3
maintainer Applied
#28 lore raw

Re: [kvm-unit-tests PATCH 11/18] lib/printf: support the %u unsigned fmt field

Quoted 23 lines · Andrew Jones

From: Alex Bennée <[email protected]>

---
 lib/printf.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
lib/printf.c +6 -0
index 89308fb26b7d2..5d83605afe829 100644
@@ -180,6 +180,19 @@ int vsnprintf(char *buf, int size, const char *fmt, va_list va)
 		break;
 	    }
 	    break;
+	case 'u':
+	    switch (nlong) {
+	    case 0:
+		print_unsigned(&s, va_arg(va, unsigned), 10, props);
+		break;
+	    case 1:

lib/printf.c int vsnprintf(char *buf, int size, const char *fmt, va_list va) · line 198

Quoted 10 lines
lib/printf.c +7 -0
+		print_unsigned(&s, va_arg(va, unsigned long), 10, props);
+		break;
+	    default:
+		print_unsigned(&s, va_arg(va, unsigned long long), 10, props);
+		break;
+	    }
+	    break;
 	case 'x':
 	    switch (nlong) {
 	    case 0:

Applied, thanks.

Paolo

#29 lore raw

PATCH 12/18 lib/arm: add flush_tlb_page mmu function

In reply to Andrew Jones

From: Alex Bennée <[email protected]>

This introduces a new flush_tlb_page function which does exactly what you expect. It's going to be useful for the future TLB torture test.

---
 lib/arm/asm/mmu.h   | 11 +++++++++++
 lib/arm64/asm/mmu.h |  8 ++++++++
 2 files changed, 19 insertions(+)
lib/arm/asm/mmu.h +11 -0
index c1bd01c9ee1b9..2bb0cde820f8a 100644
@@ -14,8 +14,11 @@
 #define PTE_AF			PTE_EXT_AF
 #define PTE_WBWA		L_PTE_MT_WRITEALLOC
 
+/* See B3.18.7 TLB maintenance operations */
+
 static inline void local_flush_tlb_all(void)
 {
+	/* TLBIALL */
 	asm volatile("mcr p15, 0, %0, c8, c7, 0" :: "r" (0));
 	dsb();
 	isb();
@@ -27,6 +30,14 @@ static inline void flush_tlb_all(void)
 	local_flush_tlb_all();
 }
 
+static inline void flush_tlb_page(unsigned long vaddr)
+{
+	/* TLBIMVAA */
+	asm volatile("mcr p15, 0, %0, c8, c7, 3" :: "r" (vaddr));
+	dsb();
+	isb();
+}
+
 #include <asm/mmu-api.h>
 
 #endif /* __ASMARM_MMU_H_ */
lib/arm64/asm/mmu.h +8 -0
index 18b4d6be18fae..3bc31c91c36f8 100644
@@ -19,6 +19,14 @@ static inline void flush_tlb_all(void)
 	isb();
 }
 
+static inline void flush_tlb_page(unsigned long vaddr)
+{
+	unsigned long page = vaddr >> 12;
+	dsb(ishst);
+	asm("tlbi	vaae1is, %0" :: "r" (page));
+	dsb(ish);
+}
+
 #include <asm/mmu-api.h>
 
 #endif /* __ASMARM64_MMU_H_ */
Signature · 1 line
2.4.3
maintainer Applied
#30 lore raw

Re: [kvm-unit-tests PATCH 12/18] lib/arm: add flush_tlb_page mmu function

Quoted 53 lines · Andrew Jones

From: Alex Bennée <[email protected]>

This introduces a new flush_tlb_page function which does exactly what you expect. It's going to be useful for the future TLB torture test.

---
 lib/arm/asm/mmu.h   | 11 +++++++++++
 lib/arm64/asm/mmu.h |  8 ++++++++
 2 files changed, 19 insertions(+)
lib/arm/asm/mmu.h +11 -0
index c1bd01c9ee1b9..2bb0cde820f8a 100644
@@ -14,8 +14,11 @@
 #define PTE_AF			PTE_EXT_AF
 #define PTE_WBWA		L_PTE_MT_WRITEALLOC
 
+/* See B3.18.7 TLB maintenance operations */
+
 static inline void local_flush_tlb_all(void)
 {
+	/* TLBIALL */
 	asm volatile("mcr p15, 0, %0, c8, c7, 0" :: "r" (0));
 	dsb();
 	isb();
@@ -27,6 +30,14 @@ static inline void flush_tlb_all(void)
 	local_flush_tlb_all();
 }
 
+static inline void flush_tlb_page(unsigned long vaddr)
+{
+	/* TLBIMVAA */
+	asm volatile("mcr p15, 0, %0, c8, c7, 3" :: "r" (vaddr));
+	dsb();
+	isb();
+}
+
 #include <asm/mmu-api.h>
 
 #endif /* __ASMARM_MMU_H_ */
lib/arm64/asm/mmu.h +1 -0
index 18b4d6be18fae..3bc31c91c36f8 100644
@@ -19,6 +19,14 @@ static inline void flush_tlb_all(void)
 	isb();
 }
 
+static inline void flush_tlb_page(unsigned long vaddr)

lib/arm64/asm/mmu.h static inline void flush_tlb_all(void) · line 32

Quoted 10 lines
lib/arm64/asm/mmu.h +7 -0
+{
+	unsigned long page = vaddr >> 12;
+	dsb(ishst);
+	asm("tlbi	vaae1is, %0" :: "r" (page));
+	dsb(ish);
+}
+
 #include <asm/mmu-api.h>
 
 #endif /* __ASMARM64_MMU_H_ */

Applied, thanks.

Paolo

#31 lore raw

PATCH 13/18 arm: Fail on unknown subtest

In reply to Andrew Jones

From: Christopher Covington <[email protected]>

---
 arm/selftest.c | 3 +++
 1 file changed, 3 insertions(+)
arm/selftest.c +3 -0
index fc9ec609d875e..f4a503079e464 100644
@@ -376,6 +376,9 @@ int main(int argc, char **argv)
 		cpumask_set_cpu(0, &smp_reported);
 		while (!cpumask_full(&smp_reported))
 			cpu_relax();
+	} else {
+		printf("Unknown subtest\n");
+		abort();
 	}
 
 	return report_summary();
Signature · 1 line
2.4.3
maintainer Applied
#32 lore raw

Re: [kvm-unit-tests PATCH 13/18] arm: Fail on unknown subtest

Quoted 14 lines · Andrew Jones

From: Christopher Covington <[email protected]>

---
 arm/selftest.c | 3 +++
 1 file changed, 3 insertions(+)
arm/selftest.c +0 -0
index fc9ec609d875e..f4a503079e464 100644

arm/selftest.c int main(int argc, char **argv) · line 384

Quoted 9 lines
arm/selftest.c +3 -0
@@ -376,6 +376,9 @@ int main(int argc, char **argv)
 		cpumask_set_cpu(0, &smp_reported);
 		while (!cpumask_full(&smp_reported))
 			cpu_relax();
+	} else {
+		printf("Unknown subtest\n");
+		abort();
 	}
 
 	return report_summary();

Applied, thanks.

Paolo

#33 lore raw

PATCH 14/18 arm/arm64: allow building a single test

In reply to Andrew Jones

This is mostly useful for building new tests that don't yet (and may never) have entries in the makefiles (config-arm*.mak). Of course it can be used to build tests that do have entries as well, in order to avoid building all tests, if the plan is to run just the one.

Just do 'make TEST=some-test' to use it, where "some-test" matches the name of the source file, i.e. arm/some-test.c

---
 config/config-arm-common.mak | 6 ++++++
 1 file changed, 6 insertions(+)
config/config-arm-common.mak +6 -0
index 698555d6a676f..937d408574751 100644
@@ -13,6 +13,11 @@ tests-common = \
 	$(TEST_DIR)/selftest.flat \
 	$(TEST_DIR)/spinlock-test.flat
 
+ifneq ($(TEST),)
+	tests = $(TEST_DIR)/$(TEST).flat
+	tests-common =
+endif
+
 all: test_cases
 
 ##################################################################
@@ -68,5 +73,6 @@ generated_files = $(asm-offsets)
 
 test_cases: $(generated_files) $(tests-common) $(tests)
 
+$(TEST_DIR)/$(TEST).elf: $(cstart.o) $(TEST_DIR)/$(TEST).o
 $(TEST_DIR)/selftest.elf: $(cstart.o) $(TEST_DIR)/selftest.o
 $(TEST_DIR)/spinlock-test.elf: $(cstart.o) $(TEST_DIR)/spinlock-test.o
Signature · 1 line
2.4.3
#34 lore raw

PATCH 15/18 arm/arm64: generate map files

In reply to Andrew Jones
---
 .gitignore                   | 1 +
 config/config-arm-common.mak | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
.gitignore +1 -0
index 242fae475094c..acbb9055212aa 100644
@@ -4,6 +4,7 @@
 *.o
 *.flat
 *.elf
+*.map
 .pc
 patches
 .stgit-*
config/config-arm-common.mak +2 -1
index 937d408574751..54cca5663d275 100644
@@ -55,6 +55,7 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi)
 %.elf: %.o $(FLATLIBS) arm/flat.lds
 	$(CC) $(LDFLAGS) -o $@ \
 		-Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
+		-Wl,-Map,$(basename $@).map \
 		$(filter %.o, $^) $(FLATLIBS)
 
 %.flat: %.elf
@@ -64,7 +65,7 @@ $(libeabi): $(eabiobjs)
 	$(AR) rcs $@ $^
 
 arm_clean: libfdt_clean asm_offsets_clean
-	$(RM) $(TEST_DIR)/*.{o,flat,elf} $(libeabi) $(eabiobjs) \
+	$(RM) $(TEST_DIR)/*.{o,flat,elf,map} $(libeabi) $(eabiobjs) \
 	      $(TEST_DIR)/.*.d lib/arm/.*.d
 
 ##################################################################
Signature · 1 line
2.4.3
#35 lore raw

PATCH 16/18 lib: link in linux kernel headers (uapi)

In reply to Andrew Jones

Rather than import uapi headers, e.g. lib/arm/asm/uapi-psci.h, just include them. For cross compilation we'll need the headers explicitly added to the include path, but doing -I /usr/include won't work, as some of our local header names will collide with /usr/include names. Even just doing -I /usr/include/linux would leave too many potential name collisions. So we create a lib/linux link, and do *not* add -I lib/linux. Doing it this way requires code to include the uapi headers with <linux/header.h>, putting them in their own "linux" namespace.

---
 .gitignore             |  1 +
 Makefile               |  4 ++--
 configure              |  9 +++++++++
 lib/arm/asm/page.h     |  2 +-
 lib/arm/asm/psci.h     |  2 +-
 lib/arm64/asm/page.h   |  2 +-
 lib/arm64/asm/psci.h   |  2 +-
 lib/asm-generic/page.h |  2 +-
 lib/const.h            | 11 -----------
 9 files changed, 17 insertions(+), 18 deletions(-)
 delete mode 100644 lib/const.h
.gitignore +1 -0
index acbb9055212aa..b193802488003 100644
@@ -11,6 +11,7 @@ patches
 cscope.*
 *.swp
 /lib/asm
+/lib/linux
 /config.mak
 /*-run
 /test.log
Makefile +2 -2
index 3e60b4f8e4a57..2e76c90bdcea5 100644
@@ -82,10 +82,10 @@ libfdt_clean:
 	$(LIBFDT_objdir)/.*.d
 
 distclean: clean libfdt_clean
-	$(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.*
+	$(RM) lib/linux lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.*
 	$(RM) -r tests
 
-cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic
+cscope: common_dirs = lib lib/libfdt lib/linux lib/asm lib/asm-generic
 cscope:
 	$(RM) ./cscope.*
 	find -L $(TEST_DIR) lib/$(TEST_DIR) lib/$(ARCH) $(common_dirs) -maxdepth 1 \
configure +9 -0
index 078b70ce096a6..667cc1b30e119 100755
@@ -91,6 +91,15 @@ if [ -f $testdir/run ]; then
     ln -fs $testdir/run $testdir-run
 fi
 
+# link uapi/linux
+rm -f lib/linux
+if [ ! -d /usr/include/linux ]; then
+    echo kernel-headers not installed, aborting...
+    exit 1
+else
+    ln -s /usr/include/linux lib/linux
+fi
+
 # check for dependent 32 bit libraries
 if [ "$arch" != "arm" ]; then
 cat << EOF > lib_test.c
lib/arm/asm/page.h +1 -1
index 039e2ddfb8e0f..df76969964ed3 100644
@@ -6,7 +6,7 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 
-#include <const.h>
+#include <linux/const.h>
 
 #define PAGE_SHIFT		12
 #define PAGE_SIZE		(_AC(1,UL) << PAGE_SHIFT)
lib/arm/asm/psci.h +1 -1
index c5fe78184b5ac..11ac45028d787 100644
@@ -1,7 +1,7 @@
 #ifndef _ASMARM_PSCI_H_
 #define _ASMARM_PSCI_H_
 #include <libcflat.h>
-#include <asm/uapi-psci.h>
+#include <linux/psci.h>
 
 #define PSCI_INVOKE_ARG_TYPE	u32
 #define PSCI_FN_CPU_ON		PSCI_0_2_FN_CPU_ON
lib/arm64/asm/page.h +1 -1
index 29ad1f1f720c4..3144e8efcc7ae 100644
@@ -11,7 +11,7 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 
-#include <const.h>
+#include <linux/const.h>
 
 #define PGTABLE_LEVELS		2
 #define VA_BITS			42
lib/arm64/asm/psci.h +1 -1
index 940d61d34c05d..0a7d7c854e2b3 100644
@@ -1,7 +1,7 @@
 #ifndef _ASMARM64_PSCI_H_
 #define _ASMARM64_PSCI_H_
 #include <libcflat.h>
-#include <asm/uapi-psci.h>
+#include <linux/psci.h>
 
 #define PSCI_INVOKE_ARG_TYPE	u64
 #define PSCI_FN_CPU_ON		PSCI_0_2_FN64_CPU_ON
lib/asm-generic/page.h +1 -1
index 66c72a62bb0f7..f872f6fa0dad2 100644
@@ -9,7 +9,7 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 
-#include "const.h"
+#include <linux/const.h>
 
 #define PAGE_SHIFT		12
 #define PAGE_SIZE		(_AC(1,UL) << PAGE_SHIFT)
lib/const.h deleted +0 -11
deleted file mode 100644
index 5cd94d7067541..0000000000000
@@ -1,11 +0,0 @@
-#ifndef _CONST_H_
-#define _CONST_H_
-#ifdef __ASSEMBLY__
-#define _AC(X,Y)	X
-#define _AT(T,X)	X
-#else
-#define __AC(X,Y)	(X##Y)
-#define _AC(X,Y)	__AC(X,Y)
-#define _AT(T,X)	((T)(X))
-#endif
-#endif
Signature · 1 line
2.4.3
#36 lore raw

PATCH 17/18 Revert "arm/arm64: import include/uapi/linux/psci.h"

In reply to Andrew Jones

The previous patch allows us to "unimport" this header now.

This reverts commit 7bc9f5e757bfa5c5a5202816404444fcf47a14b3.

---
 lib/arm/asm/uapi-psci.h   | 73 -----------------------------------------------
 lib/arm64/asm/uapi-psci.h |  1 -
 2 files changed, 74 deletions(-)
 delete mode 100644 lib/arm/asm/uapi-psci.h
 delete mode 100644 lib/arm64/asm/uapi-psci.h
lib/arm/asm/uapi-psci.h deleted +0 -73
deleted file mode 100644
index 5c6fada2b5105..0000000000000
@@ -1,73 +0,0 @@
-#ifndef _ASMARM_UAPI_PSCI_H_
-#define _ASMARM_UAPI_PSCI_H_
-/*
- * From include/uapi/linux/psci.h
- */
-
-/* PSCI v0.2 interface */
-#define PSCI_0_2_FN_BASE			0x84000000
-#define PSCI_0_2_FN(n)				(PSCI_0_2_FN_BASE + (n))
-#define PSCI_0_2_64BIT				0x40000000
-#define PSCI_0_2_FN64_BASE			\
-					(PSCI_0_2_FN_BASE + PSCI_0_2_64BIT)
-#define PSCI_0_2_FN64(n)			(PSCI_0_2_FN64_BASE + (n))
-
-#define PSCI_0_2_FN_PSCI_VERSION		PSCI_0_2_FN(0)
-#define PSCI_0_2_FN_CPU_SUSPEND			PSCI_0_2_FN(1)
-#define PSCI_0_2_FN_CPU_OFF			PSCI_0_2_FN(2)
-#define PSCI_0_2_FN_CPU_ON			PSCI_0_2_FN(3)
-#define PSCI_0_2_FN_AFFINITY_INFO		PSCI_0_2_FN(4)
-#define PSCI_0_2_FN_MIGRATE			PSCI_0_2_FN(5)
-#define PSCI_0_2_FN_MIGRATE_INFO_TYPE		PSCI_0_2_FN(6)
-#define PSCI_0_2_FN_MIGRATE_INFO_UP_CPU		PSCI_0_2_FN(7)
-#define PSCI_0_2_FN_SYSTEM_OFF			PSCI_0_2_FN(8)
-#define PSCI_0_2_FN_SYSTEM_RESET		PSCI_0_2_FN(9)
-
-#define PSCI_0_2_FN64_CPU_SUSPEND		PSCI_0_2_FN64(1)
-#define PSCI_0_2_FN64_CPU_ON			PSCI_0_2_FN64(3)
-#define PSCI_0_2_FN64_AFFINITY_INFO		PSCI_0_2_FN64(4)
-#define PSCI_0_2_FN64_MIGRATE			PSCI_0_2_FN64(5)
-#define PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU	PSCI_0_2_FN64(7)
-
-/* PSCI v0.2 power state encoding for CPU_SUSPEND function */
-#define PSCI_0_2_POWER_STATE_ID_MASK		0xffff
-#define PSCI_0_2_POWER_STATE_ID_SHIFT		0
-#define PSCI_0_2_POWER_STATE_TYPE_SHIFT		16
-#define PSCI_0_2_POWER_STATE_TYPE_MASK		\
-				(0x1 << PSCI_0_2_POWER_STATE_TYPE_SHIFT)
-#define PSCI_0_2_POWER_STATE_AFFL_SHIFT		24
-#define PSCI_0_2_POWER_STATE_AFFL_MASK		\
-				(0x3 << PSCI_0_2_POWER_STATE_AFFL_SHIFT)
-
-/* PSCI v0.2 affinity level state returned by AFFINITY_INFO */
-#define PSCI_0_2_AFFINITY_LEVEL_ON		0
-#define PSCI_0_2_AFFINITY_LEVEL_OFF		1
-#define PSCI_0_2_AFFINITY_LEVEL_ON_PENDING	2
-
-/* PSCI v0.2 multicore support in Trusted OS returned by MIGRATE_INFO_TYPE */
-#define PSCI_0_2_TOS_UP_MIGRATE			0
-#define PSCI_0_2_TOS_UP_NO_MIGRATE		1
-#define PSCI_0_2_TOS_MP				2
-
-/* PSCI version decoding (independent of PSCI version) */
-#define PSCI_VERSION_MAJOR_SHIFT		16
-#define PSCI_VERSION_MINOR_MASK			\
-		((1U << PSCI_VERSION_MAJOR_SHIFT) - 1)
-#define PSCI_VERSION_MAJOR_MASK			~PSCI_VERSION_MINOR_MASK
-#define PSCI_VERSION_MAJOR(ver)			\
-		(((ver) & PSCI_VERSION_MAJOR_MASK) >> PSCI_VERSION_MAJOR_SHIFT)
-#define PSCI_VERSION_MINOR(ver)			\
-		((ver) & PSCI_VERSION_MINOR_MASK)
-
-/* PSCI return values (inclusive of all PSCI versions) */
-#define PSCI_RET_SUCCESS			0
-#define PSCI_RET_NOT_SUPPORTED			-1
-#define PSCI_RET_INVALID_PARAMS			-2
-#define PSCI_RET_DENIED				-3
-#define PSCI_RET_ALREADY_ON			-4
-#define PSCI_RET_ON_PENDING			-5
-#define PSCI_RET_INTERNAL_FAILURE		-6
-#define PSCI_RET_NOT_PRESENT			-7
-#define PSCI_RET_DISABLED			-8
-
-#endif /* _ASMARM_UAPI_PSCI_H_ */
lib/arm64/asm/uapi-psci.h deleted +0 -1
deleted file mode 100644
index 83d018f954e4c..0000000000000
@@ -1 +0,0 @@
-#include "../../arm/asm/uapi-psci.h"
Signature · 1 line
2.4.3
#37 lore raw

PATCH 18/18 arm/arm64: uart0_init: check /chosen/stdout-path

In reply to Andrew Jones

Arguably all of uart0_init() is unnecessary, as we're pretty sure that the address we initialize uart0_base to is correct. We go through the motions of finding the uart anyway though, because it's easy. It's also easy to check chosen/stdout-path first, so let's do that too. But, just to make all this stuff is a little less unnecessary, let's add a warning when we do actually find an address that doesn't match our initializer.

---
 lib/arm/io.c | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)
lib/arm/io.c +27 -9
index 8b1501886736a..a08d394e4aa1c 100644
@@ -19,12 +19,14 @@ extern void halt(int code);
 /*
  * Use this guess for the pl011 base in order to make an attempt at
  * having earlier printf support. We'll overwrite it with the real
- * base address that we read from the device tree later.
+ * base address that we read from the device tree later. This is
+ * the address we expect QEMU's mach-virt machine type to put in
+ * its generated device tree.
  */
-#define QEMU_MACH_VIRT_PL011_BASE 0x09000000UL
+#define UART_EARLY_BASE 0x09000000UL
 
 static struct spinlock uart_lock;
-static volatile u8 *uart0_base = (u8 *)QEMU_MACH_VIRT_PL011_BASE;
+static volatile u8 *uart0_base = (u8 *)UART_EARLY_BASE;
 
 static void uart0_init(void)
 {
@@ -32,16 +34,32 @@ static void uart0_init(void)
 	struct dt_pbus_reg base;
 	int ret;
 
-	ret = dt_pbus_get_base_compatible(compatible, &base);
-	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
+	ret = dt_get_default_console_node();
+	assert(ret >= 0 || ret == -FDT_ERR_NOTFOUND);
 
-	if (ret) {
-		printf("%s: %s not found in the device tree, aborting...\n",
-			__func__, compatible);
-		abort();
+	if (ret == -FDT_ERR_NOTFOUND) {
+
+		ret = dt_pbus_get_base_compatible(compatible, &base);
+		assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
+
+		if (ret) {
+			printf("%s: %s not found in the device tree, "
+				"aborting...\n",
+				__func__, compatible);
+			abort();
+		}
+
+	} else {
+		assert(dt_pbus_translate_node(ret, 0, &base) == 0);
 	}
 
 	uart0_base = ioremap(base.addr, base.size);
+
+	if (uart0_base != (u8 *)UART_EARLY_BASE) {
+		printf("WARNING: early print support may not work. "
+		       "Found uart at %p, but early base is %p.\n",
+			uart0_base, (u8 *)UART_EARLY_BASE);
+	}
 }
 
 void io_init(void)
Signature · 1 line
2.4.3
maintainer Applied
#38 lore raw

Re: [kvm-unit-tests PATCH 18/18] arm/arm64: uart0_init: check /chosen/stdout-path

Quoted 65 lines · Andrew Jones

Arguably all of uart0_init() is unnecessary, as we're pretty sure that the address we initialize uart0_base to is correct. We go through the motions of finding the uart anyway though, because it's easy. It's also easy to check chosen/stdout-path first, so let's do that too. But, just to make all this stuff is a little less unnecessary, let's add a warning when we do actually find an address that doesn't match our initializer.

---
 lib/arm/io.c | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)
lib/arm/io.c +21 -9
index 8b1501886736a..a08d394e4aa1c 100644
@@ -19,12 +19,14 @@ extern void halt(int code);
 /*
  * Use this guess for the pl011 base in order to make an attempt at
  * having earlier printf support. We'll overwrite it with the real
- * base address that we read from the device tree later.
+ * base address that we read from the device tree later. This is
+ * the address we expect QEMU's mach-virt machine type to put in
+ * its generated device tree.
  */
-#define QEMU_MACH_VIRT_PL011_BASE 0x09000000UL
+#define UART_EARLY_BASE 0x09000000UL
 
 static struct spinlock uart_lock;
-static volatile u8 *uart0_base = (u8 *)QEMU_MACH_VIRT_PL011_BASE;
+static volatile u8 *uart0_base = (u8 *)UART_EARLY_BASE;
 
 static void uart0_init(void)
 {
@@ -32,16 +34,32 @@ static void uart0_init(void)
 	struct dt_pbus_reg base;
 	int ret;
 
-	ret = dt_pbus_get_base_compatible(compatible, &base);
-	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
+	ret = dt_get_default_console_node();
+	assert(ret >= 0 || ret == -FDT_ERR_NOTFOUND);
 
-	if (ret) {
-		printf("%s: %s not found in the device tree, aborting...\n",
-			__func__, compatible);
-		abort();
+	if (ret == -FDT_ERR_NOTFOUND) {
+
+		ret = dt_pbus_get_base_compatible(compatible, &base);
+		assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
+
+		if (ret) {
+			printf("%s: %s not found in the device tree, "
+				"aborting...\n",
+				__func__, compatible);
+			abort();
+		}
+
+	} else {
+		assert(dt_pbus_translate_node(ret, 0, &base) == 0);
 	}
 

lib/arm/io.c static void uart0_init(void) · line 65

Quoted 10 lines
lib/arm/io.c +6 -0
 	uart0_base = ioremap(base.addr, base.size);
+
+	if (uart0_base != (u8 *)UART_EARLY_BASE) {
+		printf("WARNING: early print support may not work. "
+		       "Found uart at %p, but early base is %p.\n",
+			uart0_base, (u8 *)UART_EARLY_BASE);
+	}
 }
 
 void io_init(void)

Applied, thanks.

Paolo

#39 lore raw

[kvm-unit-tests PATCH 19/18] don't embed code inside asserts

In reply to Andrew Jones

assert() is classically a macro which could also be disabled, so if somebody introduces a switch to "#define assert(...) /*nothing*/" in the future, we'd lose code.

---
 lib/arm/setup.c   | 19 ++++++++++++++-----
 lib/arm/smp.c     |  4 +++-
 lib/virtio-mmio.c |  4 +++-
 3 files changed, 20 insertions(+), 7 deletions(-)
lib/arm/setup.c +14 -5
index 02e81a689a8a6..da6edc1f9d8ff 100644
@@ -39,8 +39,11 @@ static void cpu_set(int fdtnode __unused, u32 regval, void *info __unused)
 
 static void cpu_init(void)
 {
+	int ret;
+
 	nr_cpus = 0;
-	assert(dt_for_each_cpu_node(cpu_set, NULL) == 0);
+	ret = dt_for_each_cpu_node(cpu_set, NULL);
+	assert(ret == 0);
 	set_cpu_online(0, true);
 }
 
@@ -49,8 +52,10 @@ static void mem_init(phys_addr_t freemem_start)
 	/* we only expect one membank to be defined in the DT */
 	struct dt_pbus_reg regs[1];
 	phys_addr_t mem_start, mem_end;
+	int ret;
 
-	assert(dt_get_memory_params(regs, 1));
+	ret = dt_get_memory_params(regs, 1);
+	assert(ret != 0);
 
 	mem_start = regs[0].addr;
 	mem_end = mem_start + regs[0].size;
@@ -71,14 +76,17 @@ void setup(const void *fdt)
 {
 	const char *bootargs;
 	u32 fdt_size;
+	int ret;
 
 	/*
 	 * Move the fdt to just above the stack. The free memory
 	 * then starts just after the fdt.
 	 */
 	fdt_size = fdt_totalsize(fdt);
-	assert(fdt_move(fdt, &stacktop, fdt_size) == 0);
-	assert(dt_init(&stacktop) == 0);
+	ret = fdt_move(fdt, &stacktop, fdt_size);
+	assert(ret == 0);
+	ret = dt_init(&stacktop);
+	assert(ret == 0);
 
 	mem_init(PAGE_ALIGN((unsigned long)&stacktop + fdt_size));
 	io_init();
@@ -86,6 +94,7 @@ void setup(const void *fdt)
 
 	thread_info_init(current_thread_info(), 0);
 
-	assert(dt_get_bootargs(&bootargs) == 0);
+	ret = dt_get_bootargs(&bootargs);
+	assert(ret == 0);
 	setup_args(bootargs);
 }
lib/arm/smp.c +3 -1
index 3cfc6d5ddedd0..390c53b5d84c3 100644
@@ -44,11 +44,13 @@ secondary_entry_fn secondary_cinit(void)
 void smp_boot_secondary(int cpu, secondary_entry_fn entry)
 {
 	void *stack_base = memalign(THREAD_SIZE, THREAD_SIZE);
+	int ret;
 
 	secondary_data.stack = stack_base + THREAD_START_SP;
 	secondary_data.entry = entry;
 	mmu_mark_disabled(cpu);
-	assert(cpu_psci_cpu_boot(cpu) == 0);
+	ret = cpu_psci_cpu_boot(cpu);
+	assert(ret == 0);
 
 	while (!cpu_online(cpu))
 		wfe();
lib/virtio-mmio.c +3 -1
index 5ccbd193a264a..fa8dd5b8d484d 100644
@@ -123,10 +123,12 @@ static int vm_dt_match(const struct dt_device *dev, int fdtnode)
 	struct vm_dt_info *info = (struct vm_dt_info *)dev->info;
 	struct dt_pbus_reg base;
 	u32 magic;
+	int ret;
 
 	dt_device_bind_node((struct dt_device *)dev, fdtnode);
 
-	assert(dt_pbus_get_base(dev, &base) == 0);
+	ret = dt_pbus_get_base(dev, &base);
+	assert(ret == 0);
 	info->base = ioremap(base.addr, base.size);
 
 	magic = readl(info->base + VIRTIO_MMIO_MAGIC_VALUE);
Signature · 1 line
2.4.3
maintainer Applied
#40 lore raw

Re: [kvm-unit-tests PATCH 19/18] don't embed code inside asserts

Quoted 98 lines · Andrew Jones

assert() is classically a macro which could also be disabled, so if somebody introduces a switch to "#define assert(...) /*nothing*/" in the future, we'd lose code.

---
 lib/arm/setup.c   | 19 ++++++++++++++-----
 lib/arm/smp.c     |  4 +++-
 lib/virtio-mmio.c |  4 +++-
 3 files changed, 20 insertions(+), 7 deletions(-)
lib/arm/setup.c +14 -5
index 02e81a689a8a6..da6edc1f9d8ff 100644
@@ -39,8 +39,11 @@ static void cpu_set(int fdtnode __unused, u32 regval, void *info __unused)
 
 static void cpu_init(void)
 {
+	int ret;
+
 	nr_cpus = 0;
-	assert(dt_for_each_cpu_node(cpu_set, NULL) == 0);
+	ret = dt_for_each_cpu_node(cpu_set, NULL);
+	assert(ret == 0);
 	set_cpu_online(0, true);
 }
 
@@ -49,8 +52,10 @@ static void mem_init(phys_addr_t freemem_start)
 	/* we only expect one membank to be defined in the DT */
 	struct dt_pbus_reg regs[1];
 	phys_addr_t mem_start, mem_end;
+	int ret;
 
-	assert(dt_get_memory_params(regs, 1));
+	ret = dt_get_memory_params(regs, 1);
+	assert(ret != 0);
 
 	mem_start = regs[0].addr;
 	mem_end = mem_start + regs[0].size;
@@ -71,14 +76,17 @@ void setup(const void *fdt)
 {
 	const char *bootargs;
 	u32 fdt_size;
+	int ret;
 
 	/*
 	 * Move the fdt to just above the stack. The free memory
 	 * then starts just after the fdt.
 	 */
 	fdt_size = fdt_totalsize(fdt);
-	assert(fdt_move(fdt, &stacktop, fdt_size) == 0);
-	assert(dt_init(&stacktop) == 0);
+	ret = fdt_move(fdt, &stacktop, fdt_size);
+	assert(ret == 0);
+	ret = dt_init(&stacktop);
+	assert(ret == 0);
 
 	mem_init(PAGE_ALIGN((unsigned long)&stacktop + fdt_size));
 	io_init();
@@ -86,6 +94,7 @@ void setup(const void *fdt)
 
 	thread_info_init(current_thread_info(), 0);
 
-	assert(dt_get_bootargs(&bootargs) == 0);
+	ret = dt_get_bootargs(&bootargs);
+	assert(ret == 0);
 	setup_args(bootargs);
 }
lib/arm/smp.c +3 -1
index 3cfc6d5ddedd0..390c53b5d84c3 100644
@@ -44,11 +44,13 @@ secondary_entry_fn secondary_cinit(void)
 void smp_boot_secondary(int cpu, secondary_entry_fn entry)
 {
 	void *stack_base = memalign(THREAD_SIZE, THREAD_SIZE);
+	int ret;
 
 	secondary_data.stack = stack_base + THREAD_START_SP;
 	secondary_data.entry = entry;
 	mmu_mark_disabled(cpu);
-	assert(cpu_psci_cpu_boot(cpu) == 0);
+	ret = cpu_psci_cpu_boot(cpu);
+	assert(ret == 0);
 
 	while (!cpu_online(cpu))
 		wfe();
lib/virtio-mmio.c +0 -0
index 5ccbd193a264a..fa8dd5b8d484d 100644
@@ -123,10 +123,12 @@ static int vm_dt_match(const struct dt_device *dev, int fdtnode)
 	struct vm_dt_info *info = (struct vm_dt_info *)dev->info;
 	struct dt_pbus_reg base;
 	u32 magic;

lib/virtio-mmio.c static int vm_dt_match(const struct dt_device *dev, int fdtnode) · line 134

Quoted 10 lines
lib/virtio-mmio.c +3 -1
+	int ret;
 
 	dt_device_bind_node((struct dt_device *)dev, fdtnode);
 
-	assert(dt_pbus_get_base(dev, &base) == 0);
+	ret = dt_pbus_get_base(dev, &base);
+	assert(ret == 0);
 	info->base = ioremap(base.addr, base.size);
 
 	magic = readl(info->base + VIRTIO_MMIO_MAGIC_VALUE);

Applied, thanks.

Paolo

maintainer
#41 lore raw
In reply to Andrew Jones
Quoted 8 lines · Andrew Jones

Many of these patches were posted once. Some weren't, but anyway almost everything is pretty trivial. I'd like to get these in, or at least get definitive nacks on them (and then drop them) in order to clean my queue before more patches (coming from Alex Bennée and Chistopher are reposted).

All patches also available here
https://github.com/rhdrjones/kvm-unit-tests/commits/queue

I applied all of these except 1 (question asked) and 14/15/16/17 (not sure I like the idea).

Paolo

Quoted 60 lines

Thanks,
drew

Alex Bennée (4):
README: add some CONTRIBUTING notes
configure: emit HOST=$host to config.mak
lib/printf: support the %u unsigned fmt field
lib/arm: add flush_tlb_page mmu function

Andrew Jones (13):
makefiles: use bash
trivial: lib: fail hard on failed mallocs
trivial: alloc: don't use 'top' outside spinlock
trivial: lib: missing extern in string.h
README: add pointer to new wiki page
run_tests: pass test name to run script arm/run: use ACCEL to choose between kvm and tcg
run_tests: probe for max-smp
arm/arm64: allow building a single test arm/arm64: generate map files
lib: link in linux kernel headers (uapi) Revert "arm/arm64: import include/uapi/linux/psci.h" arm/arm64: uart0_init: check /chosen/stdout-path

Christopher Covington (1):
arm: Fail on unknown subtest

 .gitignore                   |  2 ++
 Makefile                     |  6 ++--
 README                       | 32 +++++++++++++++++++
 arm/run                      | 43 ++++++++++++++++++++++----
 arm/selftest.c               |  3 ++
 arm/unittests.cfg            |  7 +++--
 config/config-arm-common.mak |  9 +++++-
 configure                    | 11 +++++++
 lib/alloc.c                  |  8 +++--
 lib/arm/asm/mmu.h            | 11 +++++++
 lib/arm/asm/page.h           |  2 +-
 lib/arm/asm/psci.h           |  2 +-
 lib/arm/asm/uapi-psci.h      | 73 --------------------------------------------
 lib/arm/io.c                 | 36 ++++++++++++++++------
 lib/arm64/asm/mmu.h          |  8 +++++
 lib/arm64/asm/page.h         |  2 +-
 lib/arm64/asm/psci.h         |  2 +-
 lib/arm64/asm/uapi-psci.h    |  1 -
 lib/asm-generic/page.h       |  2 +-
 lib/const.h                  | 11 -------
 lib/printf.c                 | 13 ++++++++
 lib/string.h                 |  2 +-
 lib/virtio-mmio.c            |  7 ++---
 run_tests.sh                 | 12 +++++++-
 scripts/functions.bash       |  8 +++--
 scripts/mkstandalone.sh      | 22 ++++++++++---
 x86/unittests.cfg            |  1 +
 27 files changed, 210 insertions(+), 126 deletions(-)
 delete mode 100644 lib/arm/asm/uapi-psci.h
 delete mode 100644 lib/arm64/asm/uapi-psci.h
 delete mode 100644 lib/const.h
#42 lore raw
Quoted 9 lines · Paolo Bonzini
Quoted 6 lines · Andrew Jones

Many of these patches were posted once. Some weren't, but anyway almost everything is pretty trivial. I'd like to get these in, or at least get definitive nacks on them (and then drop them) in order to clean my queue before more patches (coming from Alex Bennée and Chistopher are reposted).

Quoted 4 lines
Quoted 2 lines

All patches also available here
https://github.com/rhdrjones/kvm-unit-tests/commits/queue

I applied all of these

Thanks!

Quoted 1 line

except 1 (question asked) and 14/15/16/17 (not sure I like the idea).

At one point I recall that you liked the uapi patches, although I'm not 100% married to it myself, as it does add a new dependency. I'm open to suggestions.

I'm not sure what you're opposed to wrt to map files (patch 15). They aren't 100% necessary, but don't really hurt either to generate either. I won't fight for them though.

The TEST= patch is quite useful. I find it annoying to always have to modify a makefile whenever I throw together a few line test. It may not be for everyone, but then it doesn't do anything when it's not used, so it shouldn't hurt that it exists. I would agree that maybe the patch should also document it though, if you argued that. Or, that fact that it's undocumented, and does nothing when not used, could be an argument to just commit it :-)

Thanks,
drew

Quoted 67 lines

Paolo

Quoted 51 lines

Thanks,
drew

Alex Bennée (4):
README: add some CONTRIBUTING notes
configure: emit HOST=$host to config.mak
lib/printf: support the %u unsigned fmt field
lib/arm: add flush_tlb_page mmu function

Andrew Jones (13):
makefiles: use bash
trivial: lib: fail hard on failed mallocs
trivial: alloc: don't use 'top' outside spinlock
trivial: lib: missing extern in string.h
README: add pointer to new wiki page
run_tests: pass test name to run script arm/run: use ACCEL to choose between kvm and tcg
run_tests: probe for max-smp
arm/arm64: allow building a single test arm/arm64: generate map files
lib: link in linux kernel headers (uapi) Revert "arm/arm64: import include/uapi/linux/psci.h" arm/arm64: uart0_init: check /chosen/stdout-path

Christopher Covington (1):
arm: Fail on unknown subtest

 .gitignore                   |  2 ++
 Makefile                     |  6 ++--
 README                       | 32 +++++++++++++++++++
 arm/run                      | 43 ++++++++++++++++++++++----
 arm/selftest.c               |  3 ++
 arm/unittests.cfg            |  7 +++--
 config/config-arm-common.mak |  9 +++++-
 configure                    | 11 +++++++
 lib/alloc.c                  |  8 +++--
 lib/arm/asm/mmu.h            | 11 +++++++
 lib/arm/asm/page.h           |  2 +-
 lib/arm/asm/psci.h           |  2 +-
 lib/arm/asm/uapi-psci.h      | 73 --------------------------------------------
 lib/arm/io.c                 | 36 ++++++++++++++++------
 lib/arm64/asm/mmu.h          |  8 +++++
 lib/arm64/asm/page.h         |  2 +-
 lib/arm64/asm/psci.h         |  2 +-
 lib/arm64/asm/uapi-psci.h    |  1 -
 lib/asm-generic/page.h       |  2 +-
 lib/const.h                  | 11 -------
 lib/printf.c                 | 13 ++++++++
 lib/string.h                 |  2 +-
 lib/virtio-mmio.c            |  7 ++---
Quoted 9 lines
 run_tests.sh                 | 12 +++++++-
 scripts/functions.bash       |  8 +++--
 scripts/mkstandalone.sh      | 22 ++++++++++---
 x86/unittests.cfg            |  1 +
 27 files changed, 210 insertions(+), 126 deletions(-)
 delete mode 100644 lib/arm/asm/uapi-psci.h
 delete mode 100644 lib/arm64/asm/uapi-psci.h
 delete mode 100644 lib/const.h

--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#43 lore raw
Quoted 10 lines · Andrew Jones
Quoted 9 lines · Paolo Bonzini
Quoted 6 lines · Andrew Jones

Many of these patches were posted once. Some weren't, but anyway almost everything is pretty trivial. I'd like to get these in, or at least get definitive nacks on them (and then drop them) in order to clean my queue before more patches (coming from Alex Bennée and Chistopher are reposted).

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

All patches also available here
https://github.com/rhdrjones/kvm-unit-tests/commits/queue

I applied all of these

Thanks!

Quoted 1 line

except 1 (question asked) and 14/15/16/17 (not sure I like the idea).

Hi Paolo,

Any more thoughts on these? I parsed "not sure I like" as "still thinking". Or should I parse it as a "no" and drop them from my queue?

Quoted 4 lines

At one point I recall that you liked the uapi patches, although I'm not 100% married to it myself, as it does add a new dependency. I'm open to suggestions.

Another argument for the uapi patches is that we're working on adding support for the mach-virt pcie host bridge in order to use pci-testdev in arm unit tests. We'll need to either use this series or import pci[_regs].h for that.

Quoted 4 lines

I'm not sure what you're opposed to wrt to map files (patch 15). They aren't 100% necessary, but don't really hurt either to generate either. I won't fight for them though.

I'm OK with dropping this one. The map files were useful to me once, but as rare as they would be, I agree cluttering things with them isn't a great idea.

Quoted 8 lines

The TEST= patch is quite useful. I find it annoying to always have to modify a makefile whenever I throw together a few line test. It may not be for everyone, but then it doesn't do anything when it's not used, so it shouldn't hurt that it exists. I would agree that maybe the patch should also document it though, if you argued that. Or, that fact that it's undocumented, and does nothing when not used, could be an argument to just commit it :-)

I still like this one. I'll buy you a beer for it :-)

Thanks,
drew