On 2017-01-16 17:07, Ralf Ramsauer wrote:
> Signed-off-by: Ralf Ramsauer <[email protected]>
> ---
>  Documentation/sysfs-entries.txt |   3 ++
>  TODO.md                         |   1 -
>  driver/main.c                   | 105 
> +++++++++++++++++++++++++++++++++++++++-
>  driver/main.h                   |   3 ++
>  driver/sysfs.c                  |  20 ++++++++
>  5 files changed, 130 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/sysfs-entries.txt b/Documentation/sysfs-entries.txt
> index 6b483bba..58d1f5a2 100644
> --- a/Documentation/sysfs-entries.txt
> +++ b/Documentation/sysfs-entries.txt
> @@ -5,6 +5,7 @@ The following sysfs entries are provided by the Jailhouse 
> Linux driver. These
>  can be used for monitoring the state of the hypervisor and its cells.
>  
>  /sys/devices/jailhouse
> +|- console                      - hypervisor console (see [1])
>  |- enabled                      - 1 if Jailhouse is enabled, 0 otherwise
>  |- mem_pool_size                - number of pages in hypervisor memory pool
>  |- mem_pool_used                - used pages of hypervisor memory pool
> @@ -30,3 +31,5 @@ may not reflect a fully consistent state. The existence and 
> semantics of VM
>  exit reason values are architecture-dependent and may change in future
>  versions. In general statistics shall only be considered as a first hint when
>  analyzing cell behavior.
> +
> +[1] Documentation/debug-output.md
> diff --git a/TODO.md b/TODO.md
> index e452d306..4e93b1d7 100644
> --- a/TODO.md
> +++ b/TODO.md
> @@ -89,7 +89,6 @@ Hardware error handling
>  
>  Monitoring
>    - report error-triggering devices behind IOMMUs via sysfs
> -  - hypervisor console via debugfs?
>    - cell software watchdog via comm region messages
>      -> time out pending comm region messages and kill failing cells
>         (includes timeouts of unanswered shutdown requests)
> diff --git a/driver/main.c b/driver/main.c
> index 676794be..8a4b929f 100644
> --- a/driver/main.c
> +++ b/driver/main.c
> @@ -19,6 +19,7 @@
>  #include <linux/miscdevice.h>
>  #include <linux/firmware.h>
>  #include <linux/mm.h>
> +#include <linux/slab.h>
>  #include <linux/smp.h>
>  #include <linux/uaccess.h>
>  #include <linux/reboot.h>
> @@ -37,7 +38,6 @@
>  #include "pci.h"
>  #include "sysfs.h"
>  
> -#include <jailhouse/header.h>
>  #include <jailhouse/hypercall.h>
>  #include <generated/version.h>
>  
> @@ -77,6 +77,8 @@ static void *hypervisor_mem;
>  static unsigned long hv_core_and_percpu_size;
>  static atomic_t call_done;
>  static int error_code;
> +static struct jailhouse_console *console_page;
> +static bool console_available;
>  
>  #ifdef CONFIG_X86
>  bool jailhouse_use_vmcall;
> @@ -91,6 +93,18 @@ static void init_hypercall(void)
>  }
>  #endif
>  
> +static void copy_console_page(struct jailhouse_console *dst)
> +{
> +retry:
> +     /* spin while hypervisor is writing to console */
> +     while (console_page->lock);

As commented elsewhere: spinning should issue cpu_relax.

> +     /* copy console page */
> +     memcpy(dst, console_page, sizeof(struct jailhouse_console));
> +     /* check consistency of console_page */
> +     if (dst->tail != console_page->tail)
> +             goto retry;

do { } while would work here.

But the logic isn't correct yet: you need to read lock and tail
atomically, only proceed if the lock is not set. Memory read barrier.
Then copy the page. Memory read barrier. Now fetch lock and tail from
memory again and check that they still match.

Jan

-- 
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to