Skip to contentSkip to conversation

Small fixes and improvements

PATCH New Pawel Wieczorkiewicz 1 participant 5 messages Apr 23, 2020 x86

lore
Share & tools
lore
#0 lore raw

v2 cover Small fixes and improvements

This is the first series of XTF patches I intend to send. It covers some relatively small changes displaying Xen version on test start, as well as adding serial consol support for HVM guests..

Paul Semel (1):
Enabled serial writing for hvm guests

Pawel Wieczorkiewicz (3):
lib: Add XEN_MAJOR() and XEN_MINOR() macros
lib: always append CR after LF in vsnprintf()
setup: Detect and display Xen version on test startup

 arch/x86/setup.c        | 22 +++++++++++++++++++++-
 common/console.c        |  3 ++-
 common/libc/vsnprintf.c | 10 ++++++++++
 common/setup.c          |  6 +++++-
 include/xtf/framework.h |  2 +-
 include/xtf/lib.h       |  3 +++
 tests/xsa-213/main.c    |  4 ++--
 7 files changed, 44 insertions(+), 6 deletions(-)
Signature · 12 lines
2.16.6




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
#1 lore raw

PATCH v2 1/4 lib: Add XEN_MAJOR() and XEN_MINOR() macros

These are just a simple macros obtaining major, minor values as returned by xen_version hypercall.

---
 include/xtf/lib.h    | 3 +++
 tests/xsa-213/main.c | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)
include/xtf/lib.h +3 -0
index 3348464..40e5731 100644
@@ -20,6 +20,9 @@
 
 #define ACCESS_ONCE(x)   (*(volatile typeof(x) *)&(x))
 
+#define XEN_MAJOR(v) (((v) >> 16) & 0xFFFF)
+#define XEN_MINOR(v) ((v) & 0xFFFF)
+
 void __noreturn panic(const char *fmt, ...) __printf(1, 2);
 
 #define ASSERT(cond)                                    \
tests/xsa-213/main.c +2 -2
index 64e7065..0353168 100644
@@ -121,8 +121,8 @@ void test_main(void)
 {
     long rc, xen_version = hypercall_xen_version(XENVER_version, NULL);
 
-    printk("Found Xen %ld.%ld\n",
-           (xen_version >> 16) & 0xffff, xen_version & 0xffff);
+    printk("Found Xen %ld.%ld\n", XEN_MAJOR(xen_version),
+           XEN_MINOR(xen_version));
 
     xtf_set_idte(X86_VEC_AVAIL, &idte);
 
Signature · 12 lines
2.16.6




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
#2 lore raw

PATCH v2 2/4 lib: always append CR after LF in vsnprintf()

In reply to Pawel Wieczorkiewicz

The explicit LFCR sequence guarantees proper line by line formatting in the output.
The '\n' character alone on some terminals is not automatically converted to LFCR.

---
Changed since v1:
* Emit CRLF instead of LFCR

 common/libc/vsnprintf.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
common/libc/vsnprintf.c +10 -0
index a49fd30..b9a4fab 100644
@@ -284,7 +284,17 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
         /* Put regular characters into the destination. */
         if ( *fmt != '%' )
         {
+            /*
+             * The '\n' character alone on some terminals is not automatically
+             * converted to CRLF.
+             * The explicit CRLF sequence guarantees proper line by line
+             * formatting in the output.
+             */
+            if ( *fmt == '\n' && str < end )
+                PUT('\r');
+
             PUT(*fmt);
+
             continue;
         }
 
Signature · 12 lines
2.16.6




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
#3 lore raw

PATCH v2 3/4 Enabled serial writing for hvm guests

In reply to Pawel Wieczorkiewicz

From: Paul Semel <[email protected]>

setup.c: PV console writing is not working in Xen 4.2 for hvm guests, so we make xtf write to COM1 serial port to get its output

---
Changed since v1:
* Increase callbacks array

 arch/x86/setup.c | 14 ++++++++++++++
 common/console.c |  3 ++-
 2 files changed, 16 insertions(+), 1 deletion(-)
arch/x86/setup.c +14 -0
index 3c84e96..f6fa4df 100644
@@ -238,6 +238,13 @@ static void qemu_console_write(const char *buf, size_t len)
                  : "d" (0x12));
 }
 
+static void com1_write(const char *buf, size_t len)
+{
+    asm volatile("rep; outsb"
+                 : "+S" (buf), "+c" (len)
+                 : "d" (0x3f8));
+}
+
 static void xen_console_write(const char *buf, size_t len)
 {
     hypercall_console_write(buf, len);
@@ -246,7 +253,14 @@ static void xen_console_write(const char *buf, size_t len)
 void arch_setup(void)
 {
     if ( IS_DEFINED(CONFIG_HVM) && !pvh_start_info )
+    {
         register_console_callback(qemu_console_write);
+    }
+
+    if ( IS_DEFINED(CONFIG_HVM) )
+    {
+        register_console_callback(com1_write);
+    }
 
     register_console_callback(xen_console_write);
 
common/console.c +2 -1
index 0724fc9..00dbbca 100644
@@ -13,8 +13,9 @@
  * - Xen hypervisor console
  * - PV console
  * - Qemu debug console
+ * - COM1 serial console
  */
-static cons_output_cb output_fns[3];
+static cons_output_cb output_fns[4];
 static unsigned int nr_cons_cb;
 
 /* Guest PV console details. */
Signature · 12 lines
2.16.6




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
#4 lore raw

PATCH v2 4/4 setup: Detect and display Xen version on test startup

In reply to Pawel Wieczorkiewicz

In arch_setup() detect Xen version by issuing xen_version hypercall and optionally pass the version to main_xtf().

---
Changed since v1:
* Do not limit setup_pv_console() to HVM only. It does not crash. It merely panics because the callbacks array wasn't increased.

 arch/x86/setup.c        | 8 +++++++-
 common/setup.c          | 6 +++++-
 include/xtf/framework.h | 2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)
arch/x86/setup.c +7 -1
index f6fa4df..15ca3bb 100644
@@ -250,8 +250,10 @@ static void xen_console_write(const char *buf, size_t len)
     hypercall_console_write(buf, len);
 }
 
-void arch_setup(void)
+void arch_setup(int *version)
 {
+    int xen_version;
+
     if ( IS_DEFINED(CONFIG_HVM) && !pvh_start_info )
     {
         register_console_callback(qemu_console_write);
@@ -272,6 +274,10 @@ void arch_setup(void)
 
     init_hypercalls();
 
+    xen_version = hypercall_xen_version(XENVER_version, NULL);
+    if ( version )
+        *version = xen_version;
+
     if ( !is_initdomain() )
     {
         setup_pv_console();
common/setup.c +5 -1
index 932fc09..1d3da15 100644
@@ -19,9 +19,13 @@
  */
 void __noreturn xtf_main(void)
 {
-    arch_setup();
+    int xen_version;
+
+    arch_setup(&xen_version);
 
     printk("--- Xen Test Framework ---\n");
+    printk("Found Xen: %d.%d\n", XEN_MAJOR(xen_version),
+           XEN_MINOR(xen_version));
     printk("Environment: %s\n", environment_description);
     printk("%s\n", test_title);
 
include/xtf/framework.h +1 -1
index a71bf39..6664733 100644
@@ -2,7 +2,7 @@
 #define XTF_FRAMEWORK_H
 
 /* To be implemented by each arch */
-void arch_setup(void);
+void arch_setup(int *);
 void test_setup(void);
 
 /* Single line summary of execution environment. */
Signature · 12 lines
2.16.6




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879