Skip to contentSkip to conversation

Introduce an errata framework

PATCH In review Andrew Jones 2 participants 17 messages Jan 13, 2017 – Mar 3, 2017

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

cover Introduce an errata framework

When using kvm-unit-tests to verify distributions (which use older, stable KVM and QEMU), it's possible to get FAILs for tests of features not implemented, or FAILs for fixes that are targeted for later releases. This framework empowers unit test developers to more generously apply report_skip and report_xfail by giving the user run-time modifiable booleans to control the flow of tests. For example, we can now do something like

  if (!ERRATA(PPC64_TM_01))
    report_skip("ERRATA_PPC64_TM_01 not set 'y', skipping...");
  else
    report(...);

ERRATA_PPC64_TM_01 is simply a unit test environment variable which can have its value changed easily. E.g.

  $ echo ERRATA_PPC64_TM_01=y > ppc64.env
  $ ENV=ppc64.env ./run_tests.sh

will run all ppc64 unit tests, and any test that checks ERRATA(PPC64_TM_01) will get a return value of true. Another example is

  report_xfail("APIC test", !ERRATA_RELAXED(X86_APIC_01), ...);

allowing an APIC test to report FAIL when ERRATA_X86_APIC_01 is 'y', or non-exist, and the test fails, or XFAIL when it fails with ERRATA_X86_APIC_01=n.

Getting report_skip/xfail patches upstream, and then using an environ with the appropriate errata set downstream, should help avoid automated test suites from flagging too many false alarms, and also avoid the need to carry too many downstream patches.

Thanks,
drew

Andrew Jones (15):
devicetree: improve dt_get_bootargs interface
devicetree: introduce dt_get_initrd
arm/arm64: better document setup
powerpc: better document setup
arm/arm64: import initrd
powerpc: import initrd
x86_64: mbi-cmdline is a 4 byte addr
x86: import initrd
lib/argv: fix coding style
lib/argv: introduce setup_env and getenv
arm/arm64: enable environ
powerpc: enable environ
x86: enable environ
README: reserve some environment variables
Introduce lib/errata.h

 arm/run             |   1 +
 powerpc/run         |   1 +
 x86/run             |   4 +-
 x86/Makefile.common |   1 +
 lib/devicetree.h    |  15 +++++-
 lib/errata.h        |  24 +++++++++
 lib/libcflat.h      |   1 +
 lib/argv.c          | 143 +++++++++++++++++++++++++++++++++++++++++-----------
 lib/arm/setup.c     |  55 +++++++++++++++++---
 lib/devicetree.c    |  39 ++++++++++++--
 lib/powerpc/setup.c |  55 +++++++++++++++++---
 lib/string.c        |  15 ++++++
 lib/x86/setup.c     |  47 +++++++++++++++++
 arm/cstart.S        |   1 +
 arm/cstart64.S      |   1 +
 powerpc/cstart64.S  |   5 +-
 x86/cstart.S        |   4 ++
 x86/cstart64.S      |   8 ++-
 README.md           |  24 +++++++++
 19 files changed, 391 insertions(+), 53 deletions(-)
 create mode 100644 lib/errata.h
 create mode 100644 lib/x86/setup.c
Signature · 1 line
2.9.3
#1 lore raw

PATCH 1/15 devicetree: improve dt_get_bootargs interface

Don't lie to callers when bootargs wasn't found, they can check for themselves. Also document that when a failure occurs @bootargs will be NULL.

---
 lib/devicetree.h    | 5 +++--
 lib/arm/setup.c     | 2 +-
 lib/devicetree.c    | 5 ++---
 lib/powerpc/setup.c | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
lib/devicetree.h +3 -2
index 0083587633d4..9a4d910b6450 100644
@@ -202,10 +202,11 @@ extern int dt_get_reg(int fdtnode, int regidx, struct dt_reg *reg);
  **********************************************************************/
 
 /*
- * dt_get_bootargs gets a pointer to /chosen/bootargs
+ * dt_get_bootargs gets the string pointer from /chosen/bootargs
  * returns
  *  - zero on success
- *  - a negative FDT_ERR_* value on failure
+ *  - a negative FDT_ERR_* value on failure, and @bootargs
+ *    will be set to NULL
  */
 extern int dt_get_bootargs(const char **bootargs);
 
lib/arm/setup.c +1 -1
index 68eae91286d6..dc94d312b262 100644
@@ -138,6 +138,6 @@ void setup(const void *fdt)
 	io_init();
 
 	ret = dt_get_bootargs(&bootargs);
-	assert(ret == 0);
+	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	setup_args_progname(bootargs);
 }
lib/devicetree.c +2 -3
index 671c64a2ca51..509649b917cf 100644
@@ -256,11 +256,10 @@ int dt_get_bootargs(const char **bootargs)
 		return node;
 
 	prop = fdt_get_property(fdt, node, "bootargs", &len);
-	if (prop)
-		*bootargs = prop->data;
-	else if (len < 0 && len != -FDT_ERR_NOTFOUND)
+	if (!prop)
 		return len;
 
+	*bootargs = prop->data;
 	return 0;
 }
 
lib/powerpc/setup.c +1 -1
index d56de36410c7..00969da8f12c 100644
@@ -176,6 +176,6 @@ void setup(const void *fdt)
 	io_init();
 
 	ret = dt_get_bootargs(&bootargs);
-	assert(ret == 0);
+	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	setup_args_progname(bootargs);
 }
Signature · 1 line
2.9.3
#4 lore raw

PATCH 4/15 powerpc: better document setup

In reply to Andrew Jones

To prepare for another region illustrate where we move the FDT. No functional change.

---
 lib/powerpc/setup.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)
lib/powerpc/setup.c +25 -5
index 00969da8f12c..f55b23fb5080 100644
@@ -153,28 +153,48 @@ static void mem_init(phys_addr_t freemem_start)
 
 void setup(const void *fdt)
 {
+	void *freemem = &stacktop;
 	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.
+	 * Before calling mem_init we need to move the fdt to a safe
+	 * location. We move it above the stack to construct the memory
+	 * map illustrated below:
+	 *
+	 * +----------------------+   <-- top of physical memory
+	 * |                      |
+	 * ~                      ~
+	 * |                      |
+	 * +----------------------+   <-- top of FDT
+	 * |                      |
+	 * +----------------------+   <-- top of cpu0's stack
+	 * |                      |
+	 * +----------------------+   <-- top of text/data/bss sections,
+	 * |                      |       see arm/flat.lds
+	 * |                      |
+	 * +----------------------+   <-- load address
+	 * |                      |
+	 * +----------------------+
 	 */
 	fdt_size = fdt_totalsize(fdt);
-	ret = fdt_move(fdt, &stacktop, fdt_size);
+	ret = fdt_move(fdt, freemem, fdt_size);
 	assert(ret == 0);
-	ret = dt_init(&stacktop);
+	ret = dt_init(freemem);
 	assert(ret == 0);
+	freemem += fdt_size;
 
+	/* call init functions */
 	cpu_init();
 
 	/* cpu_init must be called before mem_init */
-	mem_init(PAGE_ALIGN((unsigned long)&stacktop + fdt_size));
+	mem_init(PAGE_ALIGN((unsigned long)freemem));
 
 	/* mem_init must be called before io_init */
 	io_init();
 
+	/* finish setup */
 	ret = dt_get_bootargs(&bootargs);
 	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	setup_args_progname(bootargs);
Signature · 1 line
2.9.3
#5 lore raw

PATCH 5/15 arm/arm64: import initrd

In reply to Andrew Jones

If an initrd is provided on the qemu command line, then "import" it by copying it to a safe location during setup.

---
 lib/arm/setup.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
lib/arm/setup.c +16 -3
index dcf25c2f4365..c4d69ae2c143 100644
@@ -24,6 +24,9 @@ extern unsigned long stacktop;
 extern void io_init(void);
 extern void setup_args_progname(const char *args);
 
+char *initrd;
+u32 initrd_size;
+
 u64 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (u64)~0 };
 int nr_cpus;
 
@@ -113,19 +116,21 @@ static void mem_init(phys_addr_t freemem_start)
 void setup(const void *fdt)
 {
 	void *freemem = &stacktop;
-	const char *bootargs;
+	const char *bootargs, *tmp;
 	u32 fdt_size;
 	int ret;
 
 	/*
-	 * Before calling mem_init we need to move the fdt to a safe
-	 * location. We move it above the stack to construct the memory
+	 * Before calling mem_init we need to move the fdt and initrd
+	 * to safe locations. We move them to construct the memory
 	 * map illustrated below:
 	 *
 	 *    +----------------------+   <-- top of physical memory
 	 *    |                      |
 	 *    ~                      ~
 	 *    |                      |
+	 *    +----------------------+   <-- top of initrd
+	 *    |                      |
 	 *    +----------------------+   <-- top of FDT
 	 *    |                      |
 	 *    +----------------------+   <-- top of cpu0's stack
@@ -144,6 +149,14 @@ void setup(const void *fdt)
 	assert(ret == 0);
 	freemem += fdt_size;
 
+	ret = dt_get_initrd(&tmp, &initrd_size);
+	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
+	if (ret == 0) {
+		initrd = freemem;
+		memmove(initrd, tmp, initrd_size);
+		freemem += initrd_size;
+	}
+
 	/* call init functions */
 	cpu_init();
 
Signature · 1 line
2.9.3
#3 lore raw

PATCH 3/15 arm/arm64: better document setup

In reply to Andrew Jones

To prepare for another region illustrate where we move the FDT. No functional change.

---
 lib/arm/setup.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)
lib/arm/setup.c +25 -5
index dc94d312b262..dcf25c2f4365 100644
@@ -112,31 +112,51 @@ static void mem_init(phys_addr_t freemem_start)
 
 void setup(const void *fdt)
 {
+	void *freemem = &stacktop;
 	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.
+	 * Before calling mem_init we need to move the fdt to a safe
+	 * location. We move it above the stack to construct the memory
+	 * map illustrated below:
+	 *
+	 *    +----------------------+   <-- top of physical memory
+	 *    |                      |
+	 *    ~                      ~
+	 *    |                      |
+	 *    +----------------------+   <-- top of FDT
+	 *    |                      |
+	 *    +----------------------+   <-- top of cpu0's stack
+	 *    |                      |
+	 *    +----------------------+   <-- top of text/data/bss sections,
+	 *    |                      |       see arm/flat.lds
+	 *    |                      |
+	 *    +----------------------+   <-- load address
+	 *    |                      |
+	 *    +----------------------+
 	 */
 	fdt_size = fdt_totalsize(fdt);
-	ret = fdt_move(fdt, &stacktop, fdt_size);
+	ret = fdt_move(fdt, freemem, fdt_size);
 	assert(ret == 0);
-	ret = dt_init(&stacktop);
+	ret = dt_init(freemem);
 	assert(ret == 0);
+	freemem += fdt_size;
 
+	/* call init functions */
 	cpu_init();
 
 	/* cpu_init must be called before thread_info_init */
 	thread_info_init(current_thread_info(), 0);
 
 	/* thread_info_init must be called before mem_init */
-	mem_init(PAGE_ALIGN((unsigned long)&stacktop + fdt_size));
+	mem_init(PAGE_ALIGN((unsigned long)freemem));
 
 	/* mem_init must be called before io_init */
 	io_init();
 
+	/* finish setup */
 	ret = dt_get_bootargs(&bootargs);
 	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	setup_args_progname(bootargs);
Signature · 1 line
2.9.3
#6 lore raw

PATCH 6/15 powerpc: import initrd

In reply to Andrew Jones

If an initrd is provided on the qemu command line, then "import" it by copying it to a safe location during setup.

---
 lib/powerpc/setup.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
lib/powerpc/setup.c +16 -3
index f55b23fb5080..f2dc10e01352 100644
@@ -22,6 +22,9 @@ extern unsigned long stacktop;
 extern void io_init(void);
 extern void setup_args_progname(const char *args);
 
+char *initrd;
+u32 initrd_size;
+
 u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
 int nr_cpus;
 uint64_t tb_hz;
@@ -154,19 +157,21 @@ static void mem_init(phys_addr_t freemem_start)
 void setup(const void *fdt)
 {
 	void *freemem = &stacktop;
-	const char *bootargs;
+	const char *bootargs, *tmp;
 	u32 fdt_size;
 	int ret;
 
 	/*
-	 * Before calling mem_init we need to move the fdt to a safe
-	 * location. We move it above the stack to construct the memory
+	 * Before calling mem_init we need to move the fdt and initrd
+	 * to safe locations. We move them to construct the memory
 	 * map illustrated below:
 	 *
 	 * +----------------------+   <-- top of physical memory
 	 * |                      |
 	 * ~                      ~
 	 * |                      |
+	 * +----------------------+   <-- top of initrd
+	 * |                      |
 	 * +----------------------+   <-- top of FDT
 	 * |                      |
 	 * +----------------------+   <-- top of cpu0's stack
@@ -185,6 +190,14 @@ void setup(const void *fdt)
 	assert(ret == 0);
 	freemem += fdt_size;
 
+	ret = dt_get_initrd(&tmp, &initrd_size);
+	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
+	if (ret == 0) {
+		initrd = freemem;
+		memmove(initrd, tmp, initrd_size);
+		freemem += initrd_size;
+	}
+
 	/* call init functions */
 	cpu_init();
 
Signature · 1 line
2.9.3
#7 lore raw

PATCH 7/15 x86_64: mbi-cmdline is a 4 byte addr

In reply to Andrew Jones

Treating mbi-cmdline as an 8 byte addr includes mbi-mods-count, which only works as long as there are no mods.

---
 x86/cstart64.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
x86/cstart64.S +1 -1
index e94788832267..0240507519cd 100644
@@ -198,7 +198,7 @@ start64:
 	call smp_init
 	call enable_x2apic
 	mov mb_boot_info(%rip), %rax
-	mov mb_cmdline(%rax), %rax
+	mov mb_cmdline(%rax), %eax
 	mov %rax, __args(%rip)
 	call __setup_args
 	mov __argc(%rip), %edi
Signature · 1 line
2.9.3
#8 lore raw

PATCH 8/15 x86: import initrd

In reply to Andrew Jones

If an initrd is provided on the qemu command line, then set a pointer to it during setup.

---
 x86/Makefile.common |  1 +
 lib/x86/setup.c     | 31 +++++++++++++++++++++++++++++++
 x86/cstart.S        |  2 ++
 x86/cstart64.S      |  6 ++++--
 4 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 lib/x86/setup.c
x86/Makefile.common +1 -0
index 1dad18ba26e1..fbab82c85c00 100644
@@ -4,6 +4,7 @@ all: test_cases
 
 cflatobjs += lib/pci.o
 cflatobjs += lib/pci-edu.o
+cflatobjs += lib/x86/setup.o
 cflatobjs += lib/x86/io.o
 cflatobjs += lib/x86/smp.o
 cflatobjs += lib/x86/vm.o
lib/x86/setup.c new file +31 -0
new file mode 100644
index 000000000000..e5df6ce95b64
@@ -0,0 +1,31 @@
+/*
+ * Initialize machine setup information
+ *
+ * Copyright (C) 2017, Red Hat Inc, Andrew Jones <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include "libcflat.h"
+
+#define MBI_MODS_COUNT	20
+#define MBI_MODS_ADDR	24
+#define MB_MOD_START	 0
+#define MB_MOD_END	 4
+
+char *initrd;
+u32 initrd_size;
+
+void setup_get_initrd(u8 *bootinfo)
+{
+	u32 *mods_addr, *mod_start, *mod_end;
+
+	if (*((u32 *)&bootinfo[MBI_MODS_COUNT]) != 1)
+		return;
+
+	mods_addr = (u32 *)&bootinfo[MBI_MODS_ADDR];
+	mod_start = (u32 *)(ulong)(*mods_addr + MB_MOD_START);
+	mod_end = (u32 *)(ulong)(*mods_addr + MB_MOD_END);
+
+	initrd = (char *)(ulong)*mod_start;
+	initrd_size = *mod_end - *mod_start;
+}
x86/cstart.S +2 -0
index 3dc8e710925a..7ab99cd20b7f 100644
@@ -94,6 +94,8 @@ MSR_GS_BASE = 0xc0000101
 
 .globl start
 start:
+        push %ebx
+        call setup_get_initrd
         mov mb_cmdline(%ebx), %eax
         mov %eax, __args
         call __setup_args
x86/cstart64.S +4 -2
index 0240507519cd..1c5182043703 100644
@@ -197,8 +197,10 @@ start64:
 	call enable_apic
 	call smp_init
 	call enable_x2apic
-	mov mb_boot_info(%rip), %rax
-	mov mb_cmdline(%rax), %eax
+	mov mb_boot_info(%rip), %rbx
+	mov %rbx, %rdi
+	call setup_get_initrd
+	mov mb_cmdline(%rbx), %eax
 	mov %rax, __args(%rip)
 	call __setup_args
 	mov __argc(%rip), %edi
Signature · 1 line
2.9.3
#9 lore raw

PATCH 9/15 lib/argv: fix coding style

In reply to Andrew Jones

The next patch will double the amount of code in the file, so let's fix its coding style first. No functional change.

---
 lib/argv.c | 55 ++++++++++++++++++++++++++-----------------------------
 1 file changed, 26 insertions(+), 29 deletions(-)
lib/argv.c +26 -29
index 482ed004ee64..fe8826255c18 100644
@@ -8,49 +8,46 @@ char *__args;
 static char args_copy[1000];
 static char *copy_ptr = args_copy;
 
-static bool isblank(char p)
-{
-    return p == ' ' || p == '\t';
-}
+#define isblank(c) ((c) == ' ' || (c) == '\t')
 
 static char *skip_blanks(char *p)
 {
-    while (isblank(*p))
-        ++p;
-    return p;
+	while (isblank(*p))
+		++p;
+	return p;
 }
 
 void __setup_args(void)
 {
-    char *args = __args;
-    char **argv = __argv + __argc;
-
-    while (*(args = skip_blanks(args)) != '\0') {
-        *argv++ = copy_ptr;
-        while (*args != '\0' && !isblank(*args))
-            *copy_ptr++ = *args++;
-        *copy_ptr++ = '\0';
-    }
-    __argc = argv - __argv;
+	char *args = __args;
+	char **argv = __argv + __argc;
+
+	while (*(args = skip_blanks(args)) != '\0') {
+		*argv++ = copy_ptr;
+		while (*args != '\0' && !isblank(*args))
+			*copy_ptr++ = *args++;
+		*copy_ptr++ = '\0';
+	}
+	__argc = argv - __argv;
 }
 
 void setup_args(char *args)
 {
-    if (!args)
-        return;
+	if (!args)
+		return;
 
-    __args = args;
-    __setup_args();
+	__args = args;
+	__setup_args();
 }
 
 void setup_args_progname(char *args)
 {
-    __argv[0] = copy_ptr;
-    strcpy(__argv[0], auxinfo.progname);
-    copy_ptr += strlen(auxinfo.progname) + 1;
-    ++__argc;
-    if (args) {
-        __args = args;
-        __setup_args();
-    }
+	__argv[0] = copy_ptr;
+	strcpy(__argv[0], auxinfo.progname);
+	copy_ptr += strlen(auxinfo.progname) + 1;
+	++__argc;
+	if (args) {
+		__args = args;
+		__setup_args();
+	}
 }
Signature · 1 line
2.9.3
#10 lore raw

PATCH 10/15 lib/argv: introduce setup_env and getenv

In reply to Andrew Jones

Provide a function that imports an environ (a list of key=value environment variables). The list may be delimited by either '\0' or '\n'. If the list is delimited by '\n', then we assume it's user input and do additional sanity checking, as well as allow variables to be commented out with '#'. We also provide getenv() to lookup the variables.

---
 lib/libcflat.h |  1 +
 lib/argv.c     | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/string.c   | 15 ++++++++++
 3 files changed, 105 insertions(+), 1 deletion(-)
lib/libcflat.h +1 -0
index e80fc5071f61..96a37926f302 100644
@@ -85,6 +85,7 @@ extern void puts(const char *s);
 extern void exit(int code);
 extern void abort(void);
 extern long atol(const char *ptr);
+extern char *getenv(const char *name);
 
 extern int printf(const char *fmt, ...)
 					__attribute__((format(printf, 1, 2)));
lib/argv.c +89 -1

105 lines not on this page · raw message

lib/string.c +15 -0
index ee93e25e9821..833f22be48c5 100644
@@ -158,3 +158,18 @@ long atol(const char *ptr)
 
     return acc;
 }
+
+extern char **environ;
+
+char *getenv(const char *name)
+{
+    char **envp = environ, *delim;
+
+    while (*envp) {
+        delim = strchr(*envp, '=');
+        if (delim && strncmp(name, *envp, delim - *envp) == 0)
+            return delim + 1;
+        ++envp;
+    }
+    return NULL;
+}
Signature · 1 line
2.9.3
#2 lore raw

PATCH 2/15 devicetree: introduce dt_get_initrd

In reply to Andrew Jones

Allow DT users to find the initrd if one is passed on the QEMU command line.

---
 lib/devicetree.h | 10 ++++++++++
 lib/devicetree.c | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
lib/devicetree.h +10 -0
index 9a4d910b6450..93c7ebc63bd8 100644
@@ -220,6 +220,16 @@ extern int dt_get_bootargs(const char **bootargs);
 extern int dt_get_default_console_node(void);
 
 /*
+ * dt_get_initrd gets the physical address of the initrd and its
+ * size from /chosen
+ * returns
+ *  - zero on success
+ *  - a negative FDT_ERR_* value on failure, and @initrd will be
+ *    set to NULL and @size set to zero
+ */
+extern int dt_get_initrd(const char **initrd, u32 *size);
+
+/*
  * dt_get_memory_params gets the memory parameters from the /memory node(s)
  * storing each memory region ("address size" tuple) in consecutive entries
  * of @regs, up to @nr_regs
lib/devicetree.c +34 -0
index 509649b917cf..2b89178a109b 100644
@@ -282,6 +282,40 @@ int dt_get_default_console_node(void)
 	return fdt_path_offset(fdt, prop->data);
 }
 
+int dt_get_initrd(const char **initrd, u32 *size)
+{
+	const struct fdt_property *prop;
+	const char *start, *end;
+	int node, len;
+	u32 *data;
+
+	*initrd = NULL;
+	*size = 0;
+
+	node = fdt_path_offset(fdt, "/chosen");
+	if (node < 0)
+		return node;
+
+	prop = fdt_get_property(fdt, node, "linux,initrd-start", &len);
+	if (!prop)
+		return len;
+	data = (u32 *)prop->data;
+	start = (const char *)(unsigned long)fdt32_to_cpu(*data);
+
+	prop = fdt_get_property(fdt, node, "linux,initrd-end", &len);
+	if (!prop) {
+		assert(len != -FDT_ERR_NOTFOUND);
+		return len;
+	}
+	data = (u32 *)prop->data;
+	end = (const char *)(unsigned long)fdt32_to_cpu(*data);
+
+	*initrd = start;
+	*size = (unsigned long)end - (unsigned long)start;
+
+	return 0;
+}
+
 int dt_init(const void *fdt_ptr)
 {
 	int ret;
Signature · 1 line
2.9.3
#12 lore raw

PATCH 12/15 powerpc: enable environ

In reply to Andrew Jones

Give powerpc unit tests access to environment variables. The environment variables are passed to the unit test with '-initrd env-file'.

---
 powerpc/run         | 1 +
 lib/powerpc/setup.c | 8 ++++++++
 powerpc/cstart64.S  | 5 +++--
 3 files changed, 12 insertions(+), 2 deletions(-)
powerpc/run +1 -0
index afdd487bfc35..6269abb9fe7f 100755
@@ -44,6 +44,7 @@ fi
 M='-machine pseries'
 M+=",accel=$ACCEL"
 command="$qemu -nodefaults $M -bios $FIRMWARE"
+[ -f "$ENV" ] && command+=" -initrd $ENV"
 command+=" -display none -serial stdio -kernel"
 command="$(timeout_cmd) $command"
 echo $command "$@"
lib/powerpc/setup.c +8 -0
index f2dc10e01352..8d44311cac3b 100644
@@ -21,6 +21,7 @@
 extern unsigned long stacktop;
 extern void io_init(void);
 extern void setup_args_progname(const char *args);
+extern void setup_env(char *env, int size);
 
 char *initrd;
 u32 initrd_size;
@@ -211,4 +212,11 @@ void setup(const void *fdt)
 	ret = dt_get_bootargs(&bootargs);
 	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	setup_args_progname(bootargs);
+
+	if (initrd) {
+		/* environ is currently the only file in the initrd */
+		char *env = malloc(initrd_size);
+		memcpy(env, initrd, initrd_size);
+		setup_env(env, initrd_size);
+	}
 }
powerpc/cstart64.S +3 -2
index 2d660325e854..2204e3bbe44e 100644
@@ -94,9 +94,10 @@ start:
 	bl	setup
 
 	/* run the test */
-	LOAD_REG_ADDR(r5, __argc)
+	LOAD_REG_ADDR(r3, __argc)
 	LOAD_REG_ADDR(r4, __argv)
-	lwz	r3, 0(r5)
+	LOAD_REG_ADDR(r5, __environ)
+	lwz	r3, 0(r3)
 	bl	main
 	bl	exit
 	b	halt
Signature · 1 line
2.9.3
#13 lore raw

PATCH 13/15 x86: enable environ

In reply to Andrew Jones

Give x86 unit tests access to environment variables. The environment variables are passed to the unit test with '-initrd env-file'.

---
 x86/run         |  4 +++-
 lib/x86/setup.c | 16 ++++++++++++++++
 x86/cstart.S    |  2 ++
 x86/cstart64.S  |  2 ++
 4 files changed, 23 insertions(+), 1 deletion(-)
x86/run +3 -1
index 10a6e6d3421c..867a1cccd3ba 100755
@@ -42,7 +42,9 @@ else
 	pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out"
 fi
 
-command="${qemu} -nodefaults -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev -kernel"
+command="${qemu} -nodefaults -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev"
+[ -f "$ENV" ] && command+=" -initrd $ENV"
+command+=" -kernel"
 command="$(timeout_cmd) $command"
 echo ${command} "$@"
 
lib/x86/setup.c +16 -0
index e5df6ce95b64..804ba3a1b86e 100644
@@ -12,9 +12,15 @@
 #define MB_MOD_START	 0
 #define MB_MOD_END	 4
 
+#define ENV_SIZE 16384
+
+extern void setup_env(char *env, int size);
+
 char *initrd;
 u32 initrd_size;
 
+static char env[ENV_SIZE];
+
 void setup_get_initrd(u8 *bootinfo)
 {
 	u32 *mods_addr, *mod_start, *mod_end;
@@ -29,3 +35,13 @@ void setup_get_initrd(u8 *bootinfo)
 	initrd = (char *)(ulong)*mod_start;
 	initrd_size = *mod_end - *mod_start;
 }
+
+void setup_environ(void)
+{
+	if (initrd) {
+		/* environ is currently the only file in the initrd */
+		u32 size = MIN(initrd_size, ENV_SIZE);
+		memcpy(env, initrd, size);
+		setup_env(env, size);
+	}
+}
x86/cstart.S +2 -0
index 7ab99cd20b7f..69b5c332cbcc 100644
@@ -96,6 +96,7 @@ MSR_GS_BASE = 0xc0000101
 start:
         push %ebx
         call setup_get_initrd
+        call setup_environ
         mov mb_cmdline(%ebx), %eax
         mov %eax, __args
         call __setup_args
@@ -149,6 +150,7 @@ start32:
 	call enable_apic
 	call smp_init
 	call enable_x2apic
+        push $__environ
         push $__argv
         push __argc
         call main
x86/cstart64.S +2 -0
index 1c5182043703..004c014b5ba2 100644
@@ -200,11 +200,13 @@ start64:
 	mov mb_boot_info(%rip), %rbx
 	mov %rbx, %rdi
 	call setup_get_initrd
+	call setup_environ
 	mov mb_cmdline(%rbx), %eax
 	mov %rax, __args(%rip)
 	call __setup_args
 	mov __argc(%rip), %edi
 	lea __argv(%rip), %rsi
+	lea __environ(%rip), %rdx
 	call main
 	mov %eax, %edi
 	call exit
Signature · 1 line
2.9.3
#11 lore raw

PATCH 11/15 arm/arm64: enable environ

In reply to Andrew Jones

Give arm/arm64 unit tests access to environment variables. The environment variables are passed to the unit test with '-initrd env-file'.

---
 arm/run         | 1 +
 lib/arm/setup.c | 8 ++++++++
 arm/cstart.S    | 1 +
 arm/cstart64.S  | 1 +
 4 files changed, 11 insertions(+)
arm/run +1 -0
index 1c40ab02eb57..2134c9efb1bd 100755
@@ -79,6 +79,7 @@ fi
 
 M+=",accel=$ACCEL"
 command="$qemu -nodefaults $M -cpu $processor $chr_testdev $pci_testdev"
+[ -f "$ENV" ] && command+=" -initrd $ENV"
 command+=" -display none -serial stdio -kernel"
 command="$(timeout_cmd) $command"
 echo $command "$@"
lib/arm/setup.c +8 -0
index c4d69ae2c143..689c211d3018 100644
@@ -23,6 +23,7 @@
 extern unsigned long stacktop;
 extern void io_init(void);
 extern void setup_args_progname(const char *args);
+extern void setup_env(char *env, int size);
 
 char *initrd;
 u32 initrd_size;
@@ -173,4 +174,11 @@ void setup(const void *fdt)
 	ret = dt_get_bootargs(&bootargs);
 	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	setup_args_progname(bootargs);
+
+	if (initrd) {
+		/* environ is currently the only file in the initrd */
+		char *env = malloc(initrd_size);
+		memcpy(env, initrd, initrd_size);
+		setup_env(env, initrd_size);
+	}
 }
arm/cstart.S +1 -0
index 9822fb7ba637..12461d104dad 100644
@@ -62,6 +62,7 @@ start:
 	ldr	r0, =__argc
 	ldr	r0, [r0]
 	ldr	r1, =__argv
+	ldr	r2, =__environ
 	bl	main
 	bl	exit
 	b	halt
arm/cstart64.S +1 -0
index 44cff32d0f18..7738babc4109 100644
@@ -43,6 +43,7 @@ start:
 	adr	x0, __argc
 	ldr	x0, [x0]
 	adr	x1, __argv
+	adr	x2, __environ
 	bl	main
 	bl	exit
 	b	halt
Signature · 1 line
2.9.3
#14 lore raw

PATCH 14/15 README: reserve some environment variables

In reply to Andrew Jones
---
 README.md | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
README.md +24 -0
index b6f011d44568..49fbc9c50bce 100644
@@ -47,6 +47,30 @@ environment variable:
 
     QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat
 
+# Unit test inputs
+
+Unit tests use QEMU's '-append <args...>' parameter for command line
+inputs, i.e. all args will be available as argv strings in main().
+Additionally a file of the form
+
+KEY=VAL
+KEY2=VAL
+...
+
+may be passed with '-initrd <file>' to become the unit test's environ,
+which can then be accessed in the usual ways, e.g. VAL = getenv("KEY")
+Any key=val strings can be passed, but some have reserved meanings in
+the framework. The list of reserved environment variables is below
+
+ QEMU_ACCEL            ... either kvm or tcg
+ QEMU_VERSION_STRING   ... string of the form `qemu -h | head -1`
+ KERNEL_VERSION_STRING ... string of the form `uname -r`
+
+Additionally these self-explanatory variables are reserved
+
+ QEMU_MAJOR, QEMU_MINOR, QEMU_MICRO, KERNEL_VERSION, KERNEL_PATCHLEVEL,
+ KERNEL_SUBLEVEL, KERNEL_EXTRAVERSION
+
 # Contributing
 
 ## Directory structure
Signature · 1 line
2.9.3
#15 lore raw

PATCH 15/15 Introduce lib/errata.h

In reply to Andrew Jones

Now that we have environment variables we can apply them to defining errata booleans to determine behavior of report_skip or report_xfail in tests. lib/errata.h provides handy wrappers allowing one to do things like:

Only running dangerous tests (host crashers) when the errata has been applied

   if (!ERRATA(PPC64_TM_01))
     report_skip("ERRATA_PPC64_TM_01 not set 'y', skipping...");
   else
     report(...);

Trigger an XFAIL vs. a FAIL, when set to 'n'

   report_xfail("APIC test", !ERRATA_RELAXED(x86_APIC_01), ...);

The xfail example uses ERRATA_RELAXED to ensure we have the same behavior as now (assuming the software under test should pass, i.e output FAIL if it does not), when testing without the optional environ.

---
 lib/errata.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 lib/errata.h
lib/errata.h new file +24 -0
new file mode 100644
index 000000000000..5e63f73b3727
@@ -0,0 +1,24 @@
+#ifndef _ERRATA_H_
+#define _ERRATA_H_
+
+#define _ERRATA(erratum) errata("ERRATA_" # erratum)
+#define ERRATA(erratum) _ERRATA(erratum)
+
+#define _ERRATA_RELAXED(erratum) errata_relaxed("ERRATA_" # erratum)
+#define ERRATA_RELAXED(erratum) _ERRATA_RELAXED(erratum)
+
+static inline bool errata(const char *erratum)
+{
+	char *s = getenv(erratum);
+
+	return s && (*s == '1' || *s == 'y' || *s == 'Y');
+}
+
+static inline bool errata_relaxed(const char *erratum)
+{
+	char *s = getenv(erratum);
+
+	return !(s && (*s == '0' || *s == 'n' || *s == 'N'));
+}
+
+#endif
Signature · 1 line
2.9.3
#16 lore raw

Re: [PATCH kvm-unit-tests 15/15] Introduce lib/errata.h

2017-01-13 19:15+0100, Andrew Jones:

Quoted 8 lines

Now that we have environment variables we can apply them to defining errata booleans to determine behavior of report_skip or report_xfail in tests. lib/errata.h provides handy wrappers allowing one to do things like:

Only running dangerous tests (host crashers) when the errata has been applied

Quoted 8 lines
   if (!ERRATA(PPC64_TM_01))
     report_skip("ERRATA_PPC64_TM_01 not set 'y', skipping...");
   else
     report(...);

Trigger an XFAIL vs. a FAIL, when set to 'n'

   report_xfail("APIC test", !ERRATA_RELAXED(x86_APIC_01), ...);

I changed the examples to use commit hashes as errata IDs (as we agreed) and applied, thanks.

Quoted 44 lines

The xfail example uses ERRATA_RELAXED to ensure we have the same behavior as now (assuming the software under test should pass, i.e output FAIL if it does not), when testing without the optional environ.

---
 lib/errata.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 lib/errata.h
lib/errata.h new file +24 -0
new file mode 100644
index 000000000000..5e63f73b3727
@@ -0,0 +1,24 @@
+#ifndef _ERRATA_H_
+#define _ERRATA_H_
+
+#define _ERRATA(erratum) errata("ERRATA_" # erratum)
+#define ERRATA(erratum) _ERRATA(erratum)
+
+#define _ERRATA_RELAXED(erratum) errata_relaxed("ERRATA_" # erratum)
+#define ERRATA_RELAXED(erratum) _ERRATA_RELAXED(erratum)
+
+static inline bool errata(const char *erratum)
+{
+	char *s = getenv(erratum);
+
+	return s && (*s == '1' || *s == 'y' || *s == 'Y');
+}
+
+static inline bool errata_relaxed(const char *erratum)
+{
+	char *s = getenv(erratum);
+
+	return !(s && (*s == '0' || *s == 'n' || *s == 'N'));
+}
+
+#endif
Signature · 1 line
2.9.3