Date   

[PATCH v2] fix return-value violations for vpic/vioapic

Mingqiang Chi
 

From: Mingqiang Chi <mingqiang.chi@...>

v1-->v2:
add cleanup vpic
change some APIs to void type, add pre-conditions,
and move the parameter-check to upper-layer functions.

Mingqiang Chi (1):
hv:fix return value violations for vpic/vioapic

hypervisor/arch/x86/assign.c | 3 +-
hypervisor/common/hypercall.c | 61 ++++++++++--------
hypervisor/dm/vioapic.c | 40 +++++-------
hypervisor/dm/vpic.c | 99 +++++++----------------------
hypervisor/include/arch/x86/guest/vioapic.h | 6 +-
hypervisor/include/arch/x86/guest/vpic.h | 12 ++--
6 files changed, 83 insertions(+), 138 deletions(-)

--
2.7.4


Re: [PATCH v2] tools: acrntrace: Add ring buffer mode

Geoffroy Van Cutsem
 

-----Original Message-----
From: acrn-dev@... [mailto:acrn-dev@...]
On Behalf Of Kaige Fu
Sent: Tuesday, August 14, 2018 2:47 AM
To: acrn-dev@...
Subject: Re: [acrn-dev] [PATCH v2] tools: acrntrace: Add ring buffer mode

On 08-13 Mon 14:12, Geoffroy Van Cutsem wrote:


-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...]
On Behalf Of Zhipeng Gong
Sent: Monday, August 13, 2018 3:31 PM
To: acrn-dev@...
Subject: [acrn-dev] [PATCH v2] tools: acrntrace: Add ring buffer
mode

When running longevity test and capturing acrntrace, generated
acrntrace files sizes are too big.
Sometimes we don't care very old trace. This patch adds ring buffer
mode, fixes acrntrace file size and overwrites the oldest trace with
new trace when the buffer is full.

v2:
- update README.rst

Signed-off-by: Zhipeng Gong <zhipeng.gong@...>
---
tools/acrntrace/README.rst | 4 ++-- tools/acrntrace/acrntrace.c
| 44
+++++++++++++++++++++++++++++++++++++++++---
tools/acrntrace/acrntrace.h | 1 +
3 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/tools/acrntrace/README.rst b/tools/acrntrace/README.rst
index
433f161..f25c5b0 100644
--- a/tools/acrntrace/README.rst
+++ b/tools/acrntrace/README.rst
@@ -21,8 +21,8 @@ Options:
-i period specify polling interval in milliseconds [1-999]
-t max_time max time to capture trace data (in second)
-c clear the buffered old data
--r free_space amount of free space (in MB) remaining on the disk
- before acrntrace stops
+-r ring_buffer_size ring buffer size (in MB), which enables ring buffer
+ mode and overwrites old trace with new
+trace when full
Suggestion: s/when full/when reaching the end of the buffer

There is another paragraph later in the README.rst files that says:
512MB storage space will be reserved by default. This ensures that
acrntrace
will exit automatically when the free storage space on the disk is less than
reserved space. Reserved space on the disk is configurable through '-r'.
This should be updated too, shouldn't it?
This paragraph has been removed.
Yes, I forgot there was another patch in flight to remove this. Thanks.


In current implementation, we store the trace data in current directory with
no size limitation. Now, it's user's responsibility to avoid running out of
storage of the disk.

Thanks,
Geoffroy


The ``acrntrace_format.py`` is a offline tool for parsing trace
data (as output by acrntrace) to human-readable formats based on given
format.
diff --git a/tools/acrntrace/acrntrace.c
b/tools/acrntrace/acrntrace.c index
39fda35..e4b3899 100644
--- a/tools/acrntrace/acrntrace.c
+++ b/tools/acrntrace/acrntrace.c
@@ -37,16 +37,19 @@ static char trace_file_dir[TRACE_FILE_DIR_LEN];

static reader_struct *reader;
static int pcpu_num = 0;
+static int ring_buffer_size = 0;

static void display_usage(void)
{
printf("acrntrace - tool to collect ACRN trace data\n"
- "[Usage] acrntrace [-i] [period in msec] [-ch]\n\n"
+ "[Usage] acrntrace [-i] [period in msec] [-r] [ring buffer
+size] [-
ch]\n\n"
"[Options]\n"
"\t-h: print this message\n"
"\t-i: period_in_ms: specify polling interval [1-999]\n"
"\t-t: max time to capture trace data (in second)\n"
- "\t-c: clear the buffered old data\n");
+ "\t-c: clear the buffered old data\n"
+ "\t-r: ring_buffer_size (in MB), which enables ring buffer mode"
+ " and overwrites old trace with new trace when full\n");
}

static void timer_handler(union sigval sv) @@ -113,6 +116,15 @@
static int parse_opt(int argc, char *argv[])
timeout = ret;
pr_dbg("Capture trace data for at most %ds\n", ret);
break;
+ case 'r':
+ ret = atoi(optarg);
+ if (ret <= 0) {
+ pr_err("'-r' require integer greater than 0\n");
+ return -EINVAL;
+ }
+ ring_buffer_size = ret * 1024 * 1024;
+ pr_dbg("Ring buffer size is %dM\n", ret);
+ break;
case 'c':
flags |= FLAG_CLEAR_BUF;
break;
@@ -206,6 +218,15 @@ static void reader_fn(param_t * param)
trace_ev_t e;
struct statvfs stat;
uint64_t freespace;
+ int pos = 0;
+
+ if (ring_buffer_size != 0) {
+ param->buffer = malloc(ring_buffer_size);
+ if (!param->buffer) {
+ perror("Failed to allocate ring buffer\n");
+ return;
+ }
+ }

pr_dbg("reader thread[%lu] created for FILE*[0x%p]\n",
pthread_self(), fp);
@@ -219,7 +240,13 @@ static void reader_fn(param_t * param)

while (1) {
do {
- ret = sbuf_write(fd, sbuf);
+ if (ring_buffer_size != 0) {
+ ret = sbuf_get(sbuf, param->buffer + pos);
+ pos += sbuf->ele_size;
+ if (pos + sbuf->ele_size > ring_buffer_size)
+ pos = 0;
+ } else
+ ret = sbuf_write(fd, sbuf);
} while (ret > 0);

usleep(period);
@@ -284,6 +311,17 @@ static void destory_reader(reader_struct *
reader)
reader->thrd = 0;
}

+ if (ring_buffer_size != 0 && reader->param.buffer) {
+ int ret;
+
+ ret = write(reader->param.trace_fd, reader->param.buffer,
+ ring_buffer_size);
+ if (ret != ring_buffer_size) {
+ perror("Failed to write ring buffer\n");
+ }
+ free(reader->param.buffer);
+ }
+
if (reader->param.sbuf) {
munmap(reader->param.sbuf, MMAP_SIZE);
reader->param.sbuf = NULL;
diff --git a/tools/acrntrace/acrntrace.h
b/tools/acrntrace/acrntrace.h index
ea54f4d..6615157 100644
--- a/tools/acrntrace/acrntrace.h
+++ b/tools/acrntrace/acrntrace.h
@@ -76,6 +76,7 @@ typedef struct {
int trace_fd;
shared_buf_t *sbuf;
pthread_mutex_t *sbuf_lock;
+ uint8_t *buffer;
} param_t;

typedef struct {
--
2.7.4





Re: [PATCH] hv: vuart: fix 'Shifting value too far'

Shiqing Gao
 

On 8/15/2018 12:52 AM, Junjie Mao wrote:
Hi Shiqing,

Since you have touched the types of the registers, I doubt if it raises
integral-type-related violations in other places. Please check and fix
them accordingly. Thanks!
Hi Junjie,

Could we fix all the other violations in a separate patch?

Thanks,

Shiqing


Re: [PATCH] hv: vuart: fix 'Shifting value too far'

Shiqing Gao
 

On 8/14/2018 4:46 PM, bounce+13726+10486+767559+1700533@... wrote:


On Tuesday, August 14, 2018 03:29 PM, Shiqing Gao wrote:
MISRA-C requires that shift operation cannot exceed the word length.

What this patch does:
- Fix the bug in 'vuart_init'
   The register 'dll' and 'dlh' should be uint8_t rather than char.
   'dll' is the lower 8-bit of divisor.
   'dlh' is the higher 8-bit of divisor.
   So, the shift value should be 8U rather than 16U.
- Fix other data type issues regarding to the registers in 'struct
   vuart'
   The registers should be unsigned variables.

Tracked-On: #861
Signed-off-by: Shiqing Gao <shiqing.gao@...>
---
  hypervisor/debug/vuart.c         | 36 +++++++++++++++++-------------------
  hypervisor/include/debug/vuart.h | 20 ++++++++++----------
  2 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/hypervisor/debug/vuart.c b/hypervisor/debug/vuart.c
index 57e2611..549a8f4 100644
--- a/hypervisor/debug/vuart.c
+++ b/hypervisor/debug/vuart.c
@@ -133,9 +133,8 @@ static void vuart_toggle_intr(struct vuart *vu)
      }
  }
  -static void vuart_write(__unused struct vm_io_handler *hdlr,
-        struct vm *vm, uint16_t offset_arg,
-        __unused size_t width, uint32_t value)
+static void vuart_write(__unused struct vm_io_handler *hdlr, struct vm *vm,
+        uint16_t offset_arg, __unused size_t width, uint32_t value)
  {
      uint16_t offset = offset_arg;
      struct vuart *vu = vm_vuart(vm);
@@ -146,12 +145,12 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
       */
      if ((vu->lcr & LCR_DLAB) != 0) {
          if (offset == UART16550_DLL) {
-            vu->dll = value;
+            vu->dll = (uint8_t)value;
              goto done;
          }
            if (offset == UART16550_DLM) {
-            vu->dlh = value;
+            vu->dlh = (uint8_t)value;
              goto done;
          }
      }
@@ -166,7 +165,7 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
           * Apply mask so that bits 4-7 are 0
           * Also enables bits 0-3 only if they're 1
           */
-        vu->ier = value & 0x0FU;
+        vu->ier = (uint8_t)(value & 0x0FU);
Can we change "uint32_t value" as "uint8_t value"? Please check it.
No, vuart_write and vuart_read are used to register a io_emulation_handler.

        register_io_emulation_handler(vm, &range, vuart_read, vuart_write);

The last parameter of register_io_emulation_handler is a function pointer with predefined format.

register_io_emulation_handler are used multiple times in hypervisor. We are not able to change them all to uint8_t.

void register_io_emulation_handler(struct vm *vm, struct vm_io_range *range,
        io_read_fn_t io_read_fn_ptr,
        io_write_fn_t io_write_fn_ptr)

typedef
void (*io_write_fn_t)(struct vm_io_handler *handler, struct vm *vm,
                uint16_t port, size_t size, uint32_t val);



          break;
      case UART16550_FCR:
          /*
@@ -174,18 +173,18 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
           * of other FCR bits to be effective.
           */
          if ((value & FCR_FIFOE) == 0U) {
-            vu->fcr = 0;
+            vu->fcr = 0U;
          } else {
              if ((value & FCR_RFR) != 0U) {
                  fifo_reset(&vu->rxfifo);
              }
  -            vu->fcr = value &
-                (FCR_FIFOE | FCR_DMA | FCR_RX_MASK);
+            vu->fcr = (uint8_t)(value &
+                (FCR_FIFOE | FCR_DMA | FCR_RX_MASK));
          }
          break;
      case UART16550_LCR:
-        vu->lcr = value;
+        vu->lcr = (uint8_t)value;
          break;
      case UART16550_MCR:
          /* ignore modem */
@@ -202,7 +201,7 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
           */
          break;
      case UART16550_SCR:
-        vu->scr = value;
+        vu->scr = (uint8_t)value;
          break;
      default:
          /*
@@ -218,14 +217,13 @@ done:
      vuart_unlock(vu);
  }
  -static uint32_t vuart_read(__unused struct vm_io_handler *hdlr,
-        struct vm *vm, uint16_t offset_arg,
-        __unused size_t width)
+static uint32_t vuart_read(__unused struct vm_io_handler *hdlr, struct vm *vm,
+        uint16_t offset_arg, __unused size_t width)
  {
      uint16_t offset = offset_arg;
-    char iir, reg;
-    uint8_t intr_reason;
+    uint8_t iir, reg, intr_reason;
      struct vuart *vu = vm_vuart(vm);
+
      offset -= vu->base;
      vuart_lock(vu);
      /*
@@ -295,7 +293,7 @@ static uint32_t vuart_read(__unused struct vm_io_handler *hdlr,
  done:
      vuart_toggle_intr(vu);
      vuart_unlock(vu);
-    return reg;
+    return (uint32_t)reg;
  }
    static void vuart_register_io_handler(struct vm *vm)
@@ -370,8 +368,8 @@ void *vuart_init(struct vm *vm)
        /* Set baud rate*/
      divisor = UART_CLOCK_RATE / BAUD_9600 / 16U;
-    vu->dll = divisor;
-    vu->dlh = divisor >> 16U;
+    vu->dll = (uint8_t)(divisor & 0xFFU);
Can we change it as "vu->dll = (uint8_t)divisor" ? please check it.
Is it safer to use "vu->dll = (uint8_t)(divisor & 0xFFU)"?


BRs,
Xiangyang Wu.

+    vu->dlh = (uint8_t)(divisor >> 8U);
        vu->active = false;
      vu->base = COM1_BASE;
diff --git a/hypervisor/include/debug/vuart.h b/hypervisor/include/debug/vuart.h
index 38499a1..ea0754c 100644
--- a/hypervisor/include/debug/vuart.h
+++ b/hypervisor/include/debug/vuart.h
@@ -39,16 +39,16 @@ struct fifo {
  };
    struct vuart {
-    char data;        /* Data register (R/W) */
-    char ier;        /* Interrupt enable register (R/W) */
-    char lcr;        /* Line control register (R/W) */
-    char mcr;        /* Modem control register (R/W) */
-    char lsr;        /* Line status register (R/W) */
-    char msr;        /* Modem status register (R/W) */
-    char fcr;        /* FIFO control register (W) */
-    char scr;        /* Scratch register (R/W) */
-    char dll;        /* Baudrate divisor latch LSB */
-    char dlh;        /* Baudrate divisor latch MSB */
+    uint8_t data;        /* Data register (R/W) */
+    uint8_t ier;        /* Interrupt enable register (R/W) */
+    uint8_t lcr;        /* Line control register (R/W) */
+    uint8_t mcr;        /* Modem control register (R/W) */
+    uint8_t lsr;        /* Line status register (R/W) */
+    uint8_t msr;        /* Modem status register (R/W) */
+    uint8_t fcr;        /* FIFO control register (W) */
+    uint8_t scr;        /* Scratch register (R/W) */
+    uint8_t dll;        /* Baudrate divisor latch LSB */
+    uint8_t dlh;        /* Baudrate divisor latch MSB */
        struct fifo rxfifo;
      struct fifo txfifo;


[PATCH] ipu: virtio-ipu4 as default IPU DM

chang.ching.yew@...
 

Change-Id: I9dd504da79d31863be4c95bcec21fcc9640bd336
Signed-off-by: Yew, Chang Ching <chang.ching.yew@...>
---
devicemodel/samples/apl-mrb/launch_uos.sh | 74 +++++++++++++----------
1 file changed, 42 insertions(+), 32 deletions(-)

diff --git a/devicemodel/samples/apl-mrb/launch_uos.sh b/devicemodel/samples/apl-mrb/launch_uos.sh
index 8cadc40..b977780 100755
--- a/devicemodel/samples/apl-mrb/launch_uos.sh
+++ b/devicemodel/samples/apl-mrb/launch_uos.sh
@@ -1,5 +1,7 @@
#!/bin/bash

+ipu_passthrough=0
+
function launch_clearlinux()
{
if [ ! -f "/data/$5/$5.img" ]; then
@@ -54,22 +56,26 @@ echo "0000:00:0f.0" > /sys/bus/pci/devices/0000:00:0f.0/driver/unbind
echo "0000:00:0f.0" > /sys/bus/pci/drivers/pci-stub/bind

boot_ipu_option=""
-# for ipu passthrough - ipu device 0:3.0
-if [ -d "/sys/bus/pci/devices/0000:00:03.0" ]; then
- echo "8086 5a88" > /sys/bus/pci/drivers/pci-stub/new_id
- echo "0000:00:03.0" > /sys/bus/pci/devices/0000:00:03.0/driver/unbind
- echo "0000:00:03.0" > /sys/bus/pci/drivers/pci-stub/bind
- boot_ipu_option="$boot_ipu_option"" -s 12,passthru,0/3/0 "
-fi
-
-# for ipu passthrough - ipu related i2c 0:16.0
-# please use virtual slot 22 for i2c 0:16.0 to make sure that the i2c controller
-# could get the same virtaul BDF as physical BDF
-if [ -d "/sys/bus/pci/devices/0000:00:16.0" ]; then
- echo "8086 5aac" > /sys/bus/pci/drivers/pci-stub/new_id
- echo "0000:00:16.0" > /sys/bus/pci/devices/0000:00:16.0/driver/unbind
- echo "0000:00:16.0" > /sys/bus/pci/drivers/pci-stub/bind
- boot_ipu_option="$boot_ipu_option"" -s 22,passthru,0/16/0 "
+if [ $ipu_passthrough == 1 ];then
+ # for ipu passthrough - ipu device 0:3.0
+ if [ -d "/sys/bus/pci/devices/0000:00:03.0" ]; then
+ echo "8086 5a88" > /sys/bus/pci/drivers/pci-stub/new_id
+ echo "0000:00:03.0" > /sys/bus/pci/devices/0000:00:03.0/driver/unbind
+ echo "0000:00:03.0" > /sys/bus/pci/drivers/pci-stub/bind
+ boot_ipu_option="$boot_ipu_option"" -s 12,passthru,0/3/0 "
+ fi
+
+ # for ipu passthrough - ipu related i2c 0:16.0
+ # please use virtual slot 22 for i2c 0:16.0 to make sure that the i2c controller
+ # could get the same virtaul BDF as physical BDF
+ if [ -d "/sys/bus/pci/devices/0000:00:16.0" ]; then
+ echo "8086 5aac" > /sys/bus/pci/drivers/pci-stub/new_id
+ echo "0000:00:16.0" > /sys/bus/pci/devices/0000:00:16.0/driver/unbind
+ echo "0000:00:16.0" > /sys/bus/pci/drivers/pci-stub/bind
+ boot_ipu_option="$boot_ipu_option"" -s 22,passthru,0/16/0 "
+ fi
+else
+ boot_ipu_option="$boot_ipu_option"" -s 21,virtio-ipu4 "
fi

# for sd card passthrough - SDXC/MMC Host Controller 00:1b.0
@@ -210,22 +216,26 @@ echo "0000:00:18.0" > /sys/bus/pci/devices/0000:00:18.0/driver/unbind
echo "0000:00:18.0" > /sys/bus/pci/drivers/pci-stub/bind

boot_ipu_option=""
-# for ipu passthrough - ipu device 0:3.0
-if [ -d "/sys/bus/pci/devices/0000:00:03.0" ]; then
- echo "8086 5a88" > /sys/bus/pci/drivers/pci-stub/new_id
- echo "0000:00:03.0" > /sys/bus/pci/devices/0000:00:03.0/driver/unbind
- echo "0000:00:03.0" > /sys/bus/pci/drivers/pci-stub/bind
- boot_ipu_option="$boot_ipu_option"" -s 12,passthru,0/3/0 "
-fi
-
-# for ipu passthrough - ipu related i2c 0:16.0
-# please use virtual slot 22 for i2c 0:16.0 to make sure that the i2c controller
-# could get the same virtaul BDF as physical BDF
-if [ -d "/sys/bus/pci/devices/0000:00:16.0" ]; then
- echo "8086 5aac" > /sys/bus/pci/drivers/pci-stub/new_id
- echo "0000:00:16.0" > /sys/bus/pci/devices/0000:00:16.0/driver/unbind
- echo "0000:00:16.0" > /sys/bus/pci/drivers/pci-stub/bind
- boot_ipu_option="$boot_ipu_option"" -s 22,passthru,0/16/0 "
+if [ $ipu_passthrough == 1 ];then
+ # for ipu passthrough - ipu device 0:3.0
+ if [ -d "/sys/bus/pci/devices/0000:00:03.0" ]; then
+ echo "8086 5a88" > /sys/bus/pci/drivers/pci-stub/new_id
+ echo "0000:00:03.0" > /sys/bus/pci/devices/0000:00:03.0/driver/unbind
+ echo "0000:00:03.0" > /sys/bus/pci/drivers/pci-stub/bind
+ boot_ipu_option="$boot_ipu_option"" -s 12,passthru,0/3/0 "
+ fi
+
+ # for ipu passthrough - ipu related i2c 0:16.0
+ # please use virtual slot 22 for i2c 0:16.0 to make sure that the i2c controller
+ # could get the same virtaul BDF as physical BDF
+ if [ -d "/sys/bus/pci/devices/0000:00:16.0" ]; then
+ echo "8086 5aac" > /sys/bus/pci/drivers/pci-stub/new_id
+ echo "0000:00:16.0" > /sys/bus/pci/devices/0000:00:16.0/driver/unbind
+ echo "0000:00:16.0" > /sys/bus/pci/drivers/pci-stub/bind
+ boot_ipu_option="$boot_ipu_option"" -s 22,passthru,0/16/0 "
+ fi
+else
+ boot_ipu_option="$boot_ipu_option"" -s 21,virtio-ipu4 "
fi

#for memsize setting
--
2.18.0


Re: [PATCH] hv: vuart: fix 'Shifting value too far'

Junjie Mao
 

Hi Shiqing,

Since you have touched the types of the registers, I doubt if it raises
integral-type-related violations in other places. Please check and fix
them accordingly. Thanks!

--
Best Regards
Junjie Mao

Shiqing Gao <shiqing.gao@...> writes:

MISRA-C requires that shift operation cannot exceed the word length.

What this patch does:
- Fix the bug in 'vuart_init'
The register 'dll' and 'dlh' should be uint8_t rather than char.
'dll' is the lower 8-bit of divisor.
'dlh' is the higher 8-bit of divisor.
So, the shift value should be 8U rather than 16U.
- Fix other data type issues regarding to the registers in 'struct
vuart'
The registers should be unsigned variables.

Tracked-On: #861
Signed-off-by: Shiqing Gao <shiqing.gao@...>
---
hypervisor/debug/vuart.c | 36 +++++++++++++++++-------------------
hypervisor/include/debug/vuart.h | 20 ++++++++++----------
2 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/hypervisor/debug/vuart.c b/hypervisor/debug/vuart.c
index 57e2611..549a8f4 100644
--- a/hypervisor/debug/vuart.c
+++ b/hypervisor/debug/vuart.c
@@ -133,9 +133,8 @@ static void vuart_toggle_intr(struct vuart *vu)
}
}

-static void vuart_write(__unused struct vm_io_handler *hdlr,
- struct vm *vm, uint16_t offset_arg,
- __unused size_t width, uint32_t value)
+static void vuart_write(__unused struct vm_io_handler *hdlr, struct vm *vm,
+ uint16_t offset_arg, __unused size_t width, uint32_t value)
{
uint16_t offset = offset_arg;
struct vuart *vu = vm_vuart(vm);
@@ -146,12 +145,12 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
*/
if ((vu->lcr & LCR_DLAB) != 0) {
if (offset == UART16550_DLL) {
- vu->dll = value;
+ vu->dll = (uint8_t)value;
goto done;
}

if (offset == UART16550_DLM) {
- vu->dlh = value;
+ vu->dlh = (uint8_t)value;
goto done;
}
}
@@ -166,7 +165,7 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
* Apply mask so that bits 4-7 are 0
* Also enables bits 0-3 only if they're 1
*/
- vu->ier = value & 0x0FU;
+ vu->ier = (uint8_t)(value & 0x0FU);
break;
case UART16550_FCR:
/*
@@ -174,18 +173,18 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
* of other FCR bits to be effective.
*/
if ((value & FCR_FIFOE) == 0U) {
- vu->fcr = 0;
+ vu->fcr = 0U;
} else {
if ((value & FCR_RFR) != 0U) {
fifo_reset(&vu->rxfifo);
}

- vu->fcr = value &
- (FCR_FIFOE | FCR_DMA | FCR_RX_MASK);
+ vu->fcr = (uint8_t)(value &
+ (FCR_FIFOE | FCR_DMA | FCR_RX_MASK));
}
break;
case UART16550_LCR:
- vu->lcr = value;
+ vu->lcr = (uint8_t)value;
break;
case UART16550_MCR:
/* ignore modem */
@@ -202,7 +201,7 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
*/
break;
case UART16550_SCR:
- vu->scr = value;
+ vu->scr = (uint8_t)value;
break;
default:
/*
@@ -218,14 +217,13 @@ done:
vuart_unlock(vu);
}

-static uint32_t vuart_read(__unused struct vm_io_handler *hdlr,
- struct vm *vm, uint16_t offset_arg,
- __unused size_t width)
+static uint32_t vuart_read(__unused struct vm_io_handler *hdlr, struct vm *vm,
+ uint16_t offset_arg, __unused size_t width)
{
uint16_t offset = offset_arg;
- char iir, reg;
- uint8_t intr_reason;
+ uint8_t iir, reg, intr_reason;
struct vuart *vu = vm_vuart(vm);
+
offset -= vu->base;
vuart_lock(vu);
/*
@@ -295,7 +293,7 @@ static uint32_t vuart_read(__unused struct vm_io_handler *hdlr,
done:
vuart_toggle_intr(vu);
vuart_unlock(vu);
- return reg;
+ return (uint32_t)reg;
}

static void vuart_register_io_handler(struct vm *vm)
@@ -370,8 +368,8 @@ void *vuart_init(struct vm *vm)

/* Set baud rate*/
divisor = UART_CLOCK_RATE / BAUD_9600 / 16U;
- vu->dll = divisor;
- vu->dlh = divisor >> 16U;
+ vu->dll = (uint8_t)(divisor & 0xFFU);
+ vu->dlh = (uint8_t)(divisor >> 8U);

vu->active = false;
vu->base = COM1_BASE;
diff --git a/hypervisor/include/debug/vuart.h b/hypervisor/include/debug/vuart.h
index 38499a1..ea0754c 100644
--- a/hypervisor/include/debug/vuart.h
+++ b/hypervisor/include/debug/vuart.h
@@ -39,16 +39,16 @@ struct fifo {
};

struct vuart {
- char data; /* Data register (R/W) */
- char ier; /* Interrupt enable register (R/W) */
- char lcr; /* Line control register (R/W) */
- char mcr; /* Modem control register (R/W) */
- char lsr; /* Line status register (R/W) */
- char msr; /* Modem status register (R/W) */
- char fcr; /* FIFO control register (W) */
- char scr; /* Scratch register (R/W) */
- char dll; /* Baudrate divisor latch LSB */
- char dlh; /* Baudrate divisor latch MSB */
+ uint8_t data; /* Data register (R/W) */
+ uint8_t ier; /* Interrupt enable register (R/W) */
+ uint8_t lcr; /* Line control register (R/W) */
+ uint8_t mcr; /* Modem control register (R/W) */
+ uint8_t lsr; /* Line status register (R/W) */
+ uint8_t msr; /* Modem status register (R/W) */
+ uint8_t fcr; /* FIFO control register (W) */
+ uint8_t scr; /* Scratch register (R/W) */
+ uint8_t dll; /* Baudrate divisor latch LSB */
+ uint8_t dlh; /* Baudrate divisor latch MSB */

struct fifo rxfifo;
struct fifo txfifo;


Re: [PATCH] hv: vuart: fix 'Shifting value too far'

Wu, Xiangyang
 

On Tuesday, August 14, 2018 03:29 PM, Shiqing Gao wrote:
MISRA-C requires that shift operation cannot exceed the word length.

What this patch does:
- Fix the bug in 'vuart_init'
The register 'dll' and 'dlh' should be uint8_t rather than char.
'dll' is the lower 8-bit of divisor.
'dlh' is the higher 8-bit of divisor.
So, the shift value should be 8U rather than 16U.
- Fix other data type issues regarding to the registers in 'struct
vuart'
The registers should be unsigned variables.

Tracked-On: #861
Signed-off-by: Shiqing Gao <shiqing.gao@...>
---
hypervisor/debug/vuart.c | 36 +++++++++++++++++-------------------
hypervisor/include/debug/vuart.h | 20 ++++++++++----------
2 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/hypervisor/debug/vuart.c b/hypervisor/debug/vuart.c
index 57e2611..549a8f4 100644
--- a/hypervisor/debug/vuart.c
+++ b/hypervisor/debug/vuart.c
@@ -133,9 +133,8 @@ static void vuart_toggle_intr(struct vuart *vu)
}
}
-static void vuart_write(__unused struct vm_io_handler *hdlr,
- struct vm *vm, uint16_t offset_arg,
- __unused size_t width, uint32_t value)
+static void vuart_write(__unused struct vm_io_handler *hdlr, struct vm *vm,
+ uint16_t offset_arg, __unused size_t width, uint32_t value)
{
uint16_t offset = offset_arg;
struct vuart *vu = vm_vuart(vm);
@@ -146,12 +145,12 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
*/
if ((vu->lcr & LCR_DLAB) != 0) {
if (offset == UART16550_DLL) {
- vu->dll = value;
+ vu->dll = (uint8_t)value;
goto done;
}
if (offset == UART16550_DLM) {
- vu->dlh = value;
+ vu->dlh = (uint8_t)value;
goto done;
}
}
@@ -166,7 +165,7 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
* Apply mask so that bits 4-7 are 0
* Also enables bits 0-3 only if they're 1
*/
- vu->ier = value & 0x0FU;
+ vu->ier = (uint8_t)(value & 0x0FU);
Can we change "uint32_t value" as "uint8_t value"? Please check it.

break;
case UART16550_FCR:
/*
@@ -174,18 +173,18 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
* of other FCR bits to be effective.
*/
if ((value & FCR_FIFOE) == 0U) {
- vu->fcr = 0;
+ vu->fcr = 0U;
} else {
if ((value & FCR_RFR) != 0U) {
fifo_reset(&vu->rxfifo);
}
- vu->fcr = value &
- (FCR_FIFOE | FCR_DMA | FCR_RX_MASK);
+ vu->fcr = (uint8_t)(value &
+ (FCR_FIFOE | FCR_DMA | FCR_RX_MASK));
}
break;
case UART16550_LCR:
- vu->lcr = value;
+ vu->lcr = (uint8_t)value;
break;
case UART16550_MCR:
/* ignore modem */
@@ -202,7 +201,7 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
*/
break;
case UART16550_SCR:
- vu->scr = value;
+ vu->scr = (uint8_t)value;
break;
default:
/*
@@ -218,14 +217,13 @@ done:
vuart_unlock(vu);
}
-static uint32_t vuart_read(__unused struct vm_io_handler *hdlr,
- struct vm *vm, uint16_t offset_arg,
- __unused size_t width)
+static uint32_t vuart_read(__unused struct vm_io_handler *hdlr, struct vm *vm,
+ uint16_t offset_arg, __unused size_t width)
{
uint16_t offset = offset_arg;
- char iir, reg;
- uint8_t intr_reason;
+ uint8_t iir, reg, intr_reason;
struct vuart *vu = vm_vuart(vm);
+
offset -= vu->base;
vuart_lock(vu);
/*
@@ -295,7 +293,7 @@ static uint32_t vuart_read(__unused struct vm_io_handler *hdlr,
done:
vuart_toggle_intr(vu);
vuart_unlock(vu);
- return reg;
+ return (uint32_t)reg;
}
static void vuart_register_io_handler(struct vm *vm)
@@ -370,8 +368,8 @@ void *vuart_init(struct vm *vm)
/* Set baud rate*/
divisor = UART_CLOCK_RATE / BAUD_9600 / 16U;
- vu->dll = divisor;
- vu->dlh = divisor >> 16U;
+ vu->dll = (uint8_t)(divisor & 0xFFU);
Can we change it as "vu->dll = (uint8_t)divisor" ? please check it.


BRs,
Xiangyang Wu.

+ vu->dlh = (uint8_t)(divisor >> 8U);
vu->active = false;
vu->base = COM1_BASE;
diff --git a/hypervisor/include/debug/vuart.h b/hypervisor/include/debug/vuart.h
index 38499a1..ea0754c 100644
--- a/hypervisor/include/debug/vuart.h
+++ b/hypervisor/include/debug/vuart.h
@@ -39,16 +39,16 @@ struct fifo {
};
struct vuart {
- char data; /* Data register (R/W) */
- char ier; /* Interrupt enable register (R/W) */
- char lcr; /* Line control register (R/W) */
- char mcr; /* Modem control register (R/W) */
- char lsr; /* Line status register (R/W) */
- char msr; /* Modem status register (R/W) */
- char fcr; /* FIFO control register (W) */
- char scr; /* Scratch register (R/W) */
- char dll; /* Baudrate divisor latch LSB */
- char dlh; /* Baudrate divisor latch MSB */
+ uint8_t data; /* Data register (R/W) */
+ uint8_t ier; /* Interrupt enable register (R/W) */
+ uint8_t lcr; /* Line control register (R/W) */
+ uint8_t mcr; /* Modem control register (R/W) */
+ uint8_t lsr; /* Line status register (R/W) */
+ uint8_t msr; /* Modem status register (R/W) */
+ uint8_t fcr; /* FIFO control register (W) */
+ uint8_t scr; /* Scratch register (R/W) */
+ uint8_t dll; /* Baudrate divisor latch LSB */
+ uint8_t dlh; /* Baudrate divisor latch MSB */
struct fifo rxfifo;
struct fifo txfifo;


Re: [PATCH] HV: change wake vector info to accommodate ww32 sbl

Eddie Dong
 

Acked.

-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...] On Behalf Of Victor Sun
Sent: Tuesday, August 14, 2018 4:40 PM
To: acrn-dev@...
Subject: [acrn-dev] [PATCH] HV: change wake vector info to accommodate
ww32 sbl

The wake vector address in SBL ACPI table was changed since ww30, so
change platform acpi info accordingly to support system S3.

Signed-off-by: Victor Sun <victor.sun@...>
---
hypervisor/bsp/sbl/platform_acpi_info.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hypervisor/bsp/sbl/platform_acpi_info.c
b/hypervisor/bsp/sbl/platform_acpi_info.c
index 3b4294f..d8445a5 100644
--- a/hypervisor/bsp/sbl/platform_acpi_info.c
+++ b/hypervisor/bsp/sbl/platform_acpi_info.c
@@ -48,7 +48,7 @@ const struct acpi_info host_acpi_info = {
.val_pm1b = 0U,
.reserved = 0U
},
- .wake_vector_32 = (uint32_t *)0x7A86BC9CUL,
- .wake_vector_64 = (uint64_t *)0x7A86BCA8UL
+ .wake_vector_32 = (uint32_t *)0x7A86BBDCUL,
+ .wake_vector_64 = (uint64_t *)0x7A86BBE8UL
}
};
--
2.7.4



[PATCH] HV: change wake vector info to accommodate ww32 sbl

Victor Sun
 

The wake vector address in SBL ACPI table was changed since ww30,
so change platform acpi info accordingly to support system S3.

Signed-off-by: Victor Sun <victor.sun@...>
---
hypervisor/bsp/sbl/platform_acpi_info.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hypervisor/bsp/sbl/platform_acpi_info.c b/hypervisor/bsp/sbl/platform_acpi_info.c
index 3b4294f..d8445a5 100644
--- a/hypervisor/bsp/sbl/platform_acpi_info.c
+++ b/hypervisor/bsp/sbl/platform_acpi_info.c
@@ -48,7 +48,7 @@ const struct acpi_info host_acpi_info = {
.val_pm1b = 0U,
.reserved = 0U
},
- .wake_vector_32 = (uint32_t *)0x7A86BC9CUL,
- .wake_vector_64 = (uint64_t *)0x7A86BCA8UL
+ .wake_vector_32 = (uint32_t *)0x7A86BBDCUL,
+ .wake_vector_64 = (uint64_t *)0x7A86BBE8UL
}
};
--
2.7.4


Re: [PATCH] drm/i915: fix a kernel panic issue of plane restriction

Zhao, Yakui
 

-----Original Message-----
From: acrn-dev@... [mailto:acrn-dev@...]
On Behalf Of He, Min
Sent: Tuesday, August 14, 2018 10:33 AM
To: acrn-dev@...
Cc: He, Min <min.he@...>
Subject: [acrn-dev] [PATCH] drm/i915: fix a kernel panic issue of plane
restriction

When plane restriction feature enabled in sevice os, there could be the case
that there're some CRTC's without a primary plane. If we don't assign any
plane of pipe A to sos, like i915.avail_planes_per_pipe =0x000F00, it will cause
kernel panic when booting because it assumes primary plane existing in
intel_find_initial_plane_obj().

Added a check to the primary plane in CRTC to avoid such kind of issue.

Signed-off-by: Min He <min.he@...>
LGTM

Add: Reviewed-by: Zhao Yakui <yakui.zhao@...>

---
drivers/gpu/drm/i915/intel_display.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c
b/drivers/gpu/drm/i915/intel_display.c
index 01b432438bac..6aecd4c150d1 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -15058,7 +15058,7 @@ int intel_modeset_init(struct drm_device *dev)
for_each_intel_crtc(dev, crtc) {
struct intel_initial_plane_config plane_config = {};

- if (!crtc->active)
+ if (!crtc->active || !crtc->base.primary)
continue;

/*
--
2.17.0



Re: [PATCH] drm/i915: fix a kernel panic issue of plane restriction

Xinyun Liu
 

LGTM.
Reviewed-by: Xinyun Liu <xinyun.liu@...>

By the way, on my board, it doesn't hit that path, crtc->active is false.

On Tue, Aug 14, 2018 at 02:33:23AM +0000, He, Min wrote:
When plane restriction feature enabled in sevice os, there could be the
case that there're some CRTC's without a primary plane. If we don't
assign any plane of pipe A to sos, like i915.avail_planes_per_pipe
=0x000F00, it will cause kernel panic when booting because it assumes
primary plane existing in intel_find_initial_plane_obj().

Added a check to the primary plane in CRTC to avoid such kind of issue.

Signed-off-by: Min He <min.he@...>
---
drivers/gpu/drm/i915/intel_display.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 01b432438bac..6aecd4c150d1 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -15058,7 +15058,7 @@ int intel_modeset_init(struct drm_device *dev)
for_each_intel_crtc(dev, crtc) {
struct intel_initial_plane_config plane_config = {};

- if (!crtc->active)
+ if (!crtc->active || !crtc->base.primary)
continue;

/*
--
2.17.0




[PATCH v2] tools: acrnalyze: Make the result easier to read

Kaige Fu
 

Originally, we don't format the output of analyser well. It is hard to read the
result.

This patch make every entry of the result align with the corresponding title to
make it easier for users to read.

Without patch:
Event NR_Exit NR_Exit/Sec Time Consumed(cycles) Time Percentage
VMEXIT_INTERRUPT_WINDOW 78090 130.15 40 0.01
VMEXIT_CR_ACCESS 0 0.00 0 0.00
VMEXIT_APICV_ACCESS 0 0.00 0 0.00
VMEXIT_EXCEPTION_OR_NMI 0 0.00 0 0.00
VMEXIT_RDTSC 0 0.00 0 0.00

...

Vector Count NR_Exit/Sec
0x000000f0 82337 137.23
0x000000ef 247713 412.85

With patch:
Event NR_Exit NR_Exit/Sec Time Consumed(cycles) Time percentage
VMEXIT_APICV_WRITE 13352 22.25 14331304 0.00
VMEXIT_WRMSR 309085 515.14 241166212 0.02
VMEXIT_INTERRUPT_WINDOW 78090 130.15 76841734 0.01

...

Vector Count NR_Exit/Sec
0x000000f0 82337 137.23
0x000000ef 247713 412.85

Signed-off-by: Kaige Fu <kaige.fu@...>
Reviewed-by: Eddie Dong <eddie.dong@...>
---
tools/acrntrace/scripts/irq_analyze.py | 6 +++---
tools/acrntrace/scripts/vmexit_analyze.py | 9 +++++----
2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/tools/acrntrace/scripts/irq_analyze.py b/tools/acrntrace/scripts/irq_analyze.py
index f475da7..0d555aa 100755
--- a/tools/acrntrace/scripts/irq_analyze.py
+++ b/tools/acrntrace/scripts/irq_analyze.py
@@ -80,12 +80,12 @@ def generate_report(ofile, freq):

rt_sec = float(rt_cycle) / (float(freq) * 1000 * 1000)

- print ("\nVector \t\tCount \tNR_Exit/Sec")
+ print ("%-8s\t%-8s\t%-8s" % ("Vector", "Count", "NR_Exit/Sec"))
f_csv.writerow(['Vector', 'NR_Exit', 'NR_Exit/Sec'])
for e in IRQ_EXITS.keys():
pct = float(IRQ_EXITS[e]) / rt_sec
- print ("0x%08x \t %d \t%.2f" % (e, IRQ_EXITS[e], pct))
- f_csv.writerow([e, IRQ_EXITS[e], '%.2f' % pct])
+ print ("0x%08x\t%-8d\t%-8.2f" % (e, IRQ_EXITS[e], pct))
+ f_csv.writerow(['0x%08x' % e, IRQ_EXITS[e], '%.2f' % pct])

except IOError as err:
print ("Output File Error: " + str(err))
diff --git a/tools/acrntrace/scripts/vmexit_analyze.py b/tools/acrntrace/scripts/vmexit_analyze.py
index 21cfa23..2c0b434 100755
--- a/tools/acrntrace/scripts/vmexit_analyze.py
+++ b/tools/acrntrace/scripts/vmexit_analyze.py
@@ -171,7 +171,8 @@ def generate_report(ofile, freq):
'%.3f' % (rt_sec),
'%d' % (freq)])

- print ("Event \tNR_Exit \tNR_Exit/Sec \tTime Consumed \tTime Percentage")
+ print ("%-28s\t%-12s\t%-12s\t%-24s\t%-16s" % ("Event", "NR_Exit",
+ "NR_Exit/Sec", "Time Consumed(cycles)", "Time percentage"))
f_csv.writerow(['Exit_Reason',
'NR_Exit',
'NR_Exit/Sec',
@@ -182,7 +183,7 @@ def generate_report(ofile, freq):
ev_freq = float(NR_EXITS[event]) / rt_sec
pct = float(TIME_IN_EXIT[event]) * 100 / float(rt_cycle)

- print ("%s \t%d \t%.2f \t%d \t%2.2f" %
+ print ("%-28s\t%-12d\t%-12.2f\t%-24d\t%-16.2f" %
(event, NR_EXITS[event], ev_freq, TIME_IN_EXIT[event], pct))
row = [event, NR_EXITS[event], '%.2f' % ev_freq, TIME_IN_EXIT[event],
'%2.2f' % (pct)]
@@ -190,8 +191,8 @@ def generate_report(ofile, freq):

ev_freq = float(TOTAL_NR_EXITS) / rt_sec
pct = float(total_exit_time) * 100 / float(rt_cycle)
- print("Total \t%d \t%.2f \t%d \t%2.2f"
- % (TOTAL_NR_EXITS, ev_freq, total_exit_time, pct))
+ print("%-28s\t%-12d\t%-12.2f\t%-24d\t%-16.2f"
+ % ("Total", TOTAL_NR_EXITS, ev_freq, total_exit_time, pct))
row = ["Total", TOTAL_NR_EXITS, '%.2f' % ev_freq, total_exit_time,
'%2.2f' % (pct)]
f_csv.writerow(row)
--
2.7.4


[PATCH v2] Minor improvement of acrnalyze

Kaige Fu
 

v1 -> v2:
-Drop patch "tools: acrnalyze: Output event time cost with milliseconds"

Kaige Fu (1):
tools: acrnalyze: Make the result easier to read

tools/acrntrace/scripts/irq_analyze.py | 6 +++---
tools/acrntrace/scripts/vmexit_analyze.py | 9 +++++----
2 files changed, 8 insertions(+), 7 deletions(-)

--
2.7.4


Re: [PATCH v5 1/1] vbs: fix virtio_vq_index_get func handling of multi VQ concurrent request.

Shuo A Liu
 

Thanks for the patch. I am OK with the it except some minor code style.
Please run acrn-kernel/scripts/checkpatch.pl < 0001-xxx.patch and fix
all the warning and error.

On Mon 13.Aug'18 at 22:34:10 +0000, Ong Hock Yu wrote:
Under multiple VQ use case, it is possible to have concurrent requests.
Added support to return multiple vq index from all vcpu.

Signed-off-by: Ong Hock Yu <ong.hock.yu@...>
Reviewed-by: Shuo Liu <shuo.a.liu@...>

---
drivers/vbs/vbs.c | 22 +++++++++++++++++-----
drivers/vbs/vbs_rng.c | 2 +-
include/linux/vbs/vbs.h | 8 ++++++--
3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/drivers/vbs/vbs.c b/drivers/vbs/vbs.c
index 65b8a0bbe3d3..1cda5727a626 100644
--- a/drivers/vbs/vbs.c
+++ b/drivers/vbs/vbs.c
@@ -148,9 +148,11 @@ long virtio_dev_deregister(struct virtio_dev_info *dev)
return 0;
}

-int virtio_vq_index_get(struct virtio_dev_info *dev, unsigned long *ioreqs_map)
+int virtio_vqs_index_get(struct virtio_dev_info *dev,
+ unsigned long *ioreqs_map,
+ int *vqs_index, int max_vqs_index)
{
- int val = -1;
+ int idx = 0;
struct vhm_request *req;
int vcpu;

@@ -178,10 +180,20 @@ int virtio_vq_index_get(struct virtio_dev_info *dev, unsigned long *ioreqs_map)
} else {
pr_debug("%s: write request! type %d\n",
__func__, req->type);
+
+ if(idx == max_vqs_index)
if (idx == max_vqs_index)
^ space

+ {
+ pr_warn("%s: The allocated vqs size (%d) is smaller than \
+ the number of vcpu (%d)! This might caused the process \
+ of some requests be delayed.",__func__,max_vqs_index, \
+ dev->_ctx.max_vcpu);
The info might exceed 80 chars.

+ break;
+ }
+
if (dev->io_range_type == PIO_RANGE)
- val = req->reqs.pio_request.value;
+ vqs_index[idx++] = req->reqs.pio_request.value;
else
- val = req->reqs.mmio_request.value;
+ vqs_index[idx++] = req->reqs.mmio_request.value;
}
smp_mb();
atomic_set(&req->processed, REQ_STATE_COMPLETE);
@@ -189,7 +201,7 @@ int virtio_vq_index_get(struct virtio_dev_info *dev, unsigned long *ioreqs_map)
}
}

- return val;
+ return idx;
}

static long virtio_vqs_info_set(struct virtio_dev_info *dev,
diff --git a/drivers/vbs/vbs_rng.c b/drivers/vbs/vbs_rng.c
index fd2bb27af66e..c5e28cc12c55 100644
--- a/drivers/vbs/vbs_rng.c
+++ b/drivers/vbs/vbs_rng.c
@@ -268,7 +268,7 @@ static int handle_kick(int client_id, unsigned long *ioreqs_map)
return -EINVAL;
}

- val = virtio_vq_index_get(&rng->dev, ioreqs_map);
+ virtio_vqs_index_get(&rng->dev, ioreqs_map, &val, 1);

if (val >= 0)
handle_vq_kick(rng, val);
diff --git a/include/linux/vbs/vbs.h b/include/linux/vbs/vbs.h
index 30df8ebf68a0..964bacac865c 100644
--- a/include/linux/vbs/vbs.h
+++ b/include/linux/vbs/vbs.h
@@ -262,7 +262,7 @@ long virtio_dev_register(struct virtio_dev_info *dev);
long virtio_dev_deregister(struct virtio_dev_info *dev);

/**
- * virtio_vq_index_get - get virtqueue index that frontend kicks
+ * virtio_vqs_index_get - get virtqueue indexes that frontend kicks
*
* This API is normally called in the VBS-K device's callback
* function, to get value write to the "kick" register from
@@ -270,10 +270,14 @@ long virtio_dev_deregister(struct virtio_dev_info *dev);
*
* @dev: Pointer to VBS-K device data struct
* @ioreqs_map: requests bitmap need to handle, provided by VHM
+ * @vqs_index: array to store the vq indexes
+ * @max_vqs_index: size of vqs_index array
*
* Return: >=0 on virtqueue index, <0 on error
*/
-int virtio_vq_index_get(struct virtio_dev_info *dev, unsigned long *ioreqs_map);
+int virtio_vqs_index_get(struct virtio_dev_info *dev,
+ unsigned long *ioreqs_map,
+ int *vqs_index, int max_vqs_index);

/**
* virtio_dev_reset - reset a VBS-K device
--
2.17.0




Re: [PATCH 1/2] HV: acrntrace: Output event time cost with milliseconds

Kaige Fu
 

On 08-14 Tue 07:52, Eddie Dong wrote:
We should use TSC rather than ms.
OK. Will drop this patch.

-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...] On Behalf Of Kaige Fu
Sent: Tuesday, August 14, 2018 3:39 PM
To: acrn-dev@...
Subject: Re: [acrn-dev] [PATCH 1/2] HV: acrntrace: Output event time cost
with milliseconds

On 08-14 Tue 07:23, Eddie Dong wrote:
Why we use float? Long should be enough, not?
Yes, long is enough to hold the tsc value.

But, for the consumed time, it not enough. If we use long to hold the
consumed time with milliseconds, time less than 1ms will be lost.

So, we use float here to keep the precision.

-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...] On Behalf Of Kaige Fu
Sent: Tuesday, August 14, 2018 2:29 PM
To: acrn-dev@...
Cc: Yan, Like <like.yan@...>
Subject: [acrn-dev] [PATCH 1/2] HV: acrntrace: Output event time
cost with milliseconds

Originally, we output "Time Consumed" with RTC cycles. It's not easy
to read.
So, this patch convert it to milliseconds.

BTW, this patch also output "Total run time" with ms instead of
original second.

Signed-off-by: Kaige Fu <kaige.fu@...>
---
tools/acrntrace/scripts/vmexit_analyze.py | 30
+++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/tools/acrntrace/scripts/vmexit_analyze.py
b/tools/acrntrace/scripts/vmexit_analyze.py
index 21cfa23..0eee590 100755
--- a/tools/acrntrace/scripts/vmexit_analyze.py
+++ b/tools/acrntrace/scripts/vmexit_analyze.py
@@ -80,7 +80,13 @@ TIME_IN_EXIT = {
# 4 * 64bit per trace entry
TRCREC = "QQQQ"

-def parse_trace_data(ifile):
+def tsc_to_ms(tsc, freq):
+ """convert tsc to milliseconds according freq
+ """
+
+ return float(tsc) / (float(freq) * 1000)
+
+def parse_trace_data(ifile, freq):
"""parse the trace data file
Args:
ifile: input trace data file @@ -116,7 +122,8 @@ def
parse_trace_data(ifile):
tsc_last_exit_period = tsc_enter - tsc_exit

if tsc_last_exit_period != 0:
- TIME_IN_EXIT[last_ev_id] +=
tsc_last_exit_period
+ TIME_IN_EXIT[last_ev_id] += \
+ tsc_to_ms(tsc_last_exit_period, freq)

elif event == VM_EXIT:
tsc_exit = tsc
@@ -157,30 +164,31 @@ def generate_report(ofile, freq):
tsc_end %d, tsc_begin %d"\
% (TSC_END, TSC_BEGIN)

- rt_sec = float(rt_cycle) / (float(freq) * 1000 * 1000)
+ rt_ms = tsc_to_ms(rt_cycle, freq)
+ rt_sec = float(rt_ms) / 1000.0

for event in LIST_EVENTS:
total_exit_time += TIME_IN_EXIT[event]

print ("Total run time: %d cycles" % (rt_cycle))
print ("TSC Freq: %f MHz" % (freq))
- print ("Total run time: %d sec" % (rt_sec))
+ print ("Total run time: %d ms" % (rt_ms))

- f_csv.writerow(['Run time(cycles)', 'Run time(Sec)',
'Freq(MHz)'])
+ f_csv.writerow(['Run time(cycles)', 'Run time(ms)',
+ 'Freq(MHz)'])
f_csv.writerow(['%d' % (rt_cycle),
- '%.3f' % (rt_sec),
+ '%.3f' % (rt_ms),
'%d' % (freq)])

- print ("Event \tNR_Exit \tNR_Exit/Sec \tTime Consumed
\tTime Percentage")
+ print ("Event \tNR_Exit \tNR_Exit/Sec \tTime
+ Consumed(ms) \tTime Percentage")
f_csv.writerow(['Exit_Reason',
'NR_Exit',
'NR_Exit/Sec',
- 'Time Consumed(cycles)',
+ 'Time Consumed(ms)',
'Time Percentage'])

for event in LIST_EVENTS:
ev_freq = float(NR_EXITS[event]) / rt_sec
- pct = float(TIME_IN_EXIT[event]) * 100 /
float(rt_cycle)
+ pct = float(TIME_IN_EXIT[event]) * 100 /
+ float(rt_ms)

print ("%s \t%d \t%.2f \t%d \t%2.2f" %
(event, NR_EXITS[event], ev_freq,
TIME_IN_EXIT[event], pct)) @@ -189,7 +197,7 @@ def
generate_report(ofile, freq):
f_csv.writerow(row)

ev_freq = float(TOTAL_NR_EXITS) / rt_sec
- pct = float(total_exit_time) * 100 / float(rt_cycle)
+ pct = float(total_exit_time) * 100 / float(rt_ms)
print("Total \t%d \t%.2f \t%d \t%2.2f"
% (TOTAL_NR_EXITS, ev_freq, total_exit_time,
pct))
row = ["Total", TOTAL_NR_EXITS, '%.2f' % ev_freq,
total_exit_time, @@ -211,6 +219,6 @@ def analyze_vm_exit(ifile, ofile):
print("VM exits analysis started... \n\tinput file: %s\n"
"\toutput file: %s.csv" % (ifile, ofile))

- parse_trace_data(ifile)
+ parse_trace_data(ifile, TSC_FREQ)
# save report to the output file
generate_report(ofile, TSC_FREQ)
--
2.7.4







Re: [PATCH 1/2] HV: acrntrace: Output event time cost with milliseconds

Eddie Dong
 

We should use TSC rather than ms.

-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...] On Behalf Of Kaige Fu
Sent: Tuesday, August 14, 2018 3:39 PM
To: acrn-dev@...
Subject: Re: [acrn-dev] [PATCH 1/2] HV: acrntrace: Output event time cost
with milliseconds

On 08-14 Tue 07:23, Eddie Dong wrote:
Why we use float? Long should be enough, not?
Yes, long is enough to hold the tsc value.

But, for the consumed time, it not enough. If we use long to hold the
consumed time with milliseconds, time less than 1ms will be lost.

So, we use float here to keep the precision.

-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...] On Behalf Of Kaige Fu
Sent: Tuesday, August 14, 2018 2:29 PM
To: acrn-dev@...
Cc: Yan, Like <like.yan@...>
Subject: [acrn-dev] [PATCH 1/2] HV: acrntrace: Output event time
cost with milliseconds

Originally, we output "Time Consumed" with RTC cycles. It's not easy
to read.
So, this patch convert it to milliseconds.

BTW, this patch also output "Total run time" with ms instead of
original second.

Signed-off-by: Kaige Fu <kaige.fu@...>
---
tools/acrntrace/scripts/vmexit_analyze.py | 30
+++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/tools/acrntrace/scripts/vmexit_analyze.py
b/tools/acrntrace/scripts/vmexit_analyze.py
index 21cfa23..0eee590 100755
--- a/tools/acrntrace/scripts/vmexit_analyze.py
+++ b/tools/acrntrace/scripts/vmexit_analyze.py
@@ -80,7 +80,13 @@ TIME_IN_EXIT = {
# 4 * 64bit per trace entry
TRCREC = "QQQQ"

-def parse_trace_data(ifile):
+def tsc_to_ms(tsc, freq):
+ """convert tsc to milliseconds according freq
+ """
+
+ return float(tsc) / (float(freq) * 1000)
+
+def parse_trace_data(ifile, freq):
"""parse the trace data file
Args:
ifile: input trace data file @@ -116,7 +122,8 @@ def
parse_trace_data(ifile):
tsc_last_exit_period = tsc_enter - tsc_exit

if tsc_last_exit_period != 0:
- TIME_IN_EXIT[last_ev_id] +=
tsc_last_exit_period
+ TIME_IN_EXIT[last_ev_id] += \
+ tsc_to_ms(tsc_last_exit_period, freq)

elif event == VM_EXIT:
tsc_exit = tsc
@@ -157,30 +164,31 @@ def generate_report(ofile, freq):
tsc_end %d, tsc_begin %d"\
% (TSC_END, TSC_BEGIN)

- rt_sec = float(rt_cycle) / (float(freq) * 1000 * 1000)
+ rt_ms = tsc_to_ms(rt_cycle, freq)
+ rt_sec = float(rt_ms) / 1000.0

for event in LIST_EVENTS:
total_exit_time += TIME_IN_EXIT[event]

print ("Total run time: %d cycles" % (rt_cycle))
print ("TSC Freq: %f MHz" % (freq))
- print ("Total run time: %d sec" % (rt_sec))
+ print ("Total run time: %d ms" % (rt_ms))

- f_csv.writerow(['Run time(cycles)', 'Run time(Sec)',
'Freq(MHz)'])
+ f_csv.writerow(['Run time(cycles)', 'Run time(ms)',
+ 'Freq(MHz)'])
f_csv.writerow(['%d' % (rt_cycle),
- '%.3f' % (rt_sec),
+ '%.3f' % (rt_ms),
'%d' % (freq)])

- print ("Event \tNR_Exit \tNR_Exit/Sec \tTime Consumed
\tTime Percentage")
+ print ("Event \tNR_Exit \tNR_Exit/Sec \tTime
+ Consumed(ms) \tTime Percentage")
f_csv.writerow(['Exit_Reason',
'NR_Exit',
'NR_Exit/Sec',
- 'Time Consumed(cycles)',
+ 'Time Consumed(ms)',
'Time Percentage'])

for event in LIST_EVENTS:
ev_freq = float(NR_EXITS[event]) / rt_sec
- pct = float(TIME_IN_EXIT[event]) * 100 /
float(rt_cycle)
+ pct = float(TIME_IN_EXIT[event]) * 100 /
+ float(rt_ms)

print ("%s \t%d \t%.2f \t%d \t%2.2f" %
(event, NR_EXITS[event], ev_freq,
TIME_IN_EXIT[event], pct)) @@ -189,7 +197,7 @@ def
generate_report(ofile, freq):
f_csv.writerow(row)

ev_freq = float(TOTAL_NR_EXITS) / rt_sec
- pct = float(total_exit_time) * 100 / float(rt_cycle)
+ pct = float(total_exit_time) * 100 / float(rt_ms)
print("Total \t%d \t%.2f \t%d \t%2.2f"
% (TOTAL_NR_EXITS, ev_freq, total_exit_time,
pct))
row = ["Total", TOTAL_NR_EXITS, '%.2f' % ev_freq,
total_exit_time, @@ -211,6 +219,6 @@ def analyze_vm_exit(ifile, ofile):
print("VM exits analysis started... \n\tinput file: %s\n"
"\toutput file: %s.csv" % (ifile, ofile))

- parse_trace_data(ifile)
+ parse_trace_data(ifile, TSC_FREQ)
# save report to the output file
generate_report(ofile, TSC_FREQ)
--
2.7.4





Re: [PATCH 1/2] HV: acrntrace: Output event time cost with milliseconds

Kaige Fu
 

On 08-14 Tue 07:23, Eddie Dong wrote:
Why we use float? Long should be enough, not?
Yes, long is enough to hold the tsc value.

But, for the consumed time, it not enough. If we use long to hold the consumed
time with milliseconds, time less than 1ms will be lost.

So, we use float here to keep the precision.

-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...] On Behalf Of Kaige Fu
Sent: Tuesday, August 14, 2018 2:29 PM
To: acrn-dev@...
Cc: Yan, Like <like.yan@...>
Subject: [acrn-dev] [PATCH 1/2] HV: acrntrace: Output event time cost with
milliseconds

Originally, we output "Time Consumed" with RTC cycles. It's not easy to
read.
So, this patch convert it to milliseconds.

BTW, this patch also output "Total run time" with ms instead of original
second.

Signed-off-by: Kaige Fu <kaige.fu@...>
---
tools/acrntrace/scripts/vmexit_analyze.py | 30
+++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/tools/acrntrace/scripts/vmexit_analyze.py
b/tools/acrntrace/scripts/vmexit_analyze.py
index 21cfa23..0eee590 100755
--- a/tools/acrntrace/scripts/vmexit_analyze.py
+++ b/tools/acrntrace/scripts/vmexit_analyze.py
@@ -80,7 +80,13 @@ TIME_IN_EXIT = {
# 4 * 64bit per trace entry
TRCREC = "QQQQ"

-def parse_trace_data(ifile):
+def tsc_to_ms(tsc, freq):
+ """convert tsc to milliseconds according freq
+ """
+
+ return float(tsc) / (float(freq) * 1000)
+
+def parse_trace_data(ifile, freq):
"""parse the trace data file
Args:
ifile: input trace data file
@@ -116,7 +122,8 @@ def parse_trace_data(ifile):
tsc_last_exit_period = tsc_enter - tsc_exit

if tsc_last_exit_period != 0:
- TIME_IN_EXIT[last_ev_id] += tsc_last_exit_period
+ TIME_IN_EXIT[last_ev_id] += \
+ tsc_to_ms(tsc_last_exit_period, freq)

elif event == VM_EXIT:
tsc_exit = tsc
@@ -157,30 +164,31 @@ def generate_report(ofile, freq):
tsc_end %d, tsc_begin %d"\
% (TSC_END, TSC_BEGIN)

- rt_sec = float(rt_cycle) / (float(freq) * 1000 * 1000)
+ rt_ms = tsc_to_ms(rt_cycle, freq)
+ rt_sec = float(rt_ms) / 1000.0

for event in LIST_EVENTS:
total_exit_time += TIME_IN_EXIT[event]

print ("Total run time: %d cycles" % (rt_cycle))
print ("TSC Freq: %f MHz" % (freq))
- print ("Total run time: %d sec" % (rt_sec))
+ print ("Total run time: %d ms" % (rt_ms))

- f_csv.writerow(['Run time(cycles)', 'Run time(Sec)',
'Freq(MHz)'])
+ f_csv.writerow(['Run time(cycles)', 'Run time(ms)',
+ 'Freq(MHz)'])
f_csv.writerow(['%d' % (rt_cycle),
- '%.3f' % (rt_sec),
+ '%.3f' % (rt_ms),
'%d' % (freq)])

- print ("Event \tNR_Exit \tNR_Exit/Sec \tTime Consumed
\tTime Percentage")
+ print ("Event \tNR_Exit \tNR_Exit/Sec \tTime Consumed(ms)
+ \tTime Percentage")
f_csv.writerow(['Exit_Reason',
'NR_Exit',
'NR_Exit/Sec',
- 'Time Consumed(cycles)',
+ 'Time Consumed(ms)',
'Time Percentage'])

for event in LIST_EVENTS:
ev_freq = float(NR_EXITS[event]) / rt_sec
- pct = float(TIME_IN_EXIT[event]) * 100 / float(rt_cycle)
+ pct = float(TIME_IN_EXIT[event]) * 100 / float(rt_ms)

print ("%s \t%d \t%.2f \t%d \t%2.2f" %
(event, NR_EXITS[event], ev_freq,
TIME_IN_EXIT[event], pct)) @@ -189,7 +197,7 @@ def
generate_report(ofile, freq):
f_csv.writerow(row)

ev_freq = float(TOTAL_NR_EXITS) / rt_sec
- pct = float(total_exit_time) * 100 / float(rt_cycle)
+ pct = float(total_exit_time) * 100 / float(rt_ms)
print("Total \t%d \t%.2f \t%d \t%2.2f"
% (TOTAL_NR_EXITS, ev_freq, total_exit_time, pct))
row = ["Total", TOTAL_NR_EXITS, '%.2f' % ev_freq,
total_exit_time, @@ -211,6 +219,6 @@ def analyze_vm_exit(ifile, ofile):
print("VM exits analysis started... \n\tinput file: %s\n"
"\toutput file: %s.csv" % (ifile, ofile))

- parse_trace_data(ifile)
+ parse_trace_data(ifile, TSC_FREQ)
# save report to the output file
generate_report(ofile, TSC_FREQ)
--
2.7.4





Re: [PATCH] VHM: add ioctl/hypercall for UOS intr data monitor

Zhao, Yakui
 

-----Original Message-----
From: Cao, Minggui
Sent: Tuesday, August 14, 2018 3:14 PM
To: Zhao, Yakui <yakui.zhao@...>; acrn-dev@...
Subject: Re: [acrn-dev] [PATCH] VHM: add ioctl/hypercall for UOS intr data
monitor



On 8/14/2018 2:56 PM, Zhao, Yakui wrote:

-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...]
On Behalf Of Minggui Cao
Sent: Tuesday, August 14, 2018 2:17 PM
To: acrn-dev@...
Cc: Cao, Minggui <minggui.cao@...>
Subject: [acrn-dev] [PATCH] VHM: add ioctl/hypercall for UOS intr
data monitor

DM or VM monitor can use this ioctl/hypercall to get the UOS
interrupt count data, to check if it in normal status, and give a response.

Signed-off-by: Minggui Cao <minggui.cao@...>
---
drivers/char/vhm/vhm_dev.c | 17 +++++++++++++++++
drivers/vhm/vhm_hypercall.c | 5 +++++
include/linux/vhm/acrn_hv_defs.h | 1 +
include/linux/vhm/vhm_hypercall.h | 1 +
include/linux/vhm/vhm_ioctl_defs.h | 1 +
5 files changed, 25 insertions(+)

diff --git a/drivers/char/vhm/vhm_dev.c b/drivers/char/vhm/vhm_dev.c
index c681ace..fc1e852 100644
--- a/drivers/char/vhm/vhm_dev.c
+++ b/drivers/char/vhm/vhm_dev.c
@@ -604,6 +604,23 @@ static long vhm_dev_ioctl(struct file *filep,
break;
}

+ case IC_VM_INTR_MONITOR: {
+ struct page *page;
+
+ ret = get_user_pages_fast(ioctl_param, 1, 1, &page);
+ if (unlikely(ret != 1) || (page == NULL)) {
+ pr_err("vhm-dev: failed to pin intr hdr buffer!\n");
+ return -ENOMEM;
+ }
+
+ ret = hcall_vm_intr_monitor(vm->vmid, page_to_phys(page));
+ if (ret < 0) {
+ pr_err("vhm-dev: monitor intr data err=%d\n", ret);
+ return -EFAULT;
+ }
Does the page include intr data of monitored VM after this call is returned?
Yes, it includes the intr data.
OK. That means that it will take a snapshot of current intr data for the monitored VM and
the user-space APP is in charge of how to intercept them.

Another is that since we are adding more and more hcall, can we add one
HC to query whether one function is supported in HV?
In such case it can help to assure that the kernel is decoupled with HV.
if that we need add another one hypercall :); currently if not support, the HV
will return failure; it should be OK.
actually, I have a re-factor idea on current hypercall, talked with Jason/Eddie,
will give a proposal recently; mainly points:
is to classify them, if not need VHM handle, just pass it to HV....
(hypercall + sub-cmd) to design them; reduce some of them, just add in
DM/HV.
Looking forward to your proposal.

If the err is returned by HV for the unsupported hcall, it makes sense to use the new hcall.

+ break;
+ }
+
default:
pr_warn("Unknown IOCTL 0x%x\n", ioctl_num);
ret = 0;
diff --git a/drivers/vhm/vhm_hypercall.c
b/drivers/vhm/vhm_hypercall.c index 9a92d68..9a974e8 100644
--- a/drivers/vhm/vhm_hypercall.c
+++ b/drivers/vhm/vhm_hypercall.c
@@ -172,3 +172,8 @@ inline long hcall_vm_gpa2hpa(unsigned long vmid,
unsigned long addr) {
return acrn_hypercall2(HC_VM_GPA2HPA, vmid, addr); }
+
+inline long hcall_vm_intr_monitor(unsigned long vmid, unsigned long
+addr) {
+ return acrn_hypercall2(HC_VM_INTR_MONITOR, vmid, addr); }
diff --git a/include/linux/vhm/acrn_hv_defs.h
b/include/linux/vhm/acrn_hv_defs.h
index c12deaa..01494de 100644
--- a/include/linux/vhm/acrn_hv_defs.h
+++ b/include/linux/vhm/acrn_hv_defs.h
@@ -85,6 +85,7 @@
#define HC_DEASSERT_IRQLINE _HC_ID(HC_ID, HC_ID_IRQ_BASE +
0x01)
#define HC_PULSE_IRQLINE _HC_ID(HC_ID, HC_ID_IRQ_BASE + 0x02)
#define HC_INJECT_MSI _HC_ID(HC_ID, HC_ID_IRQ_BASE + 0x03)
+#define HC_VM_INTR_MONITOR _HC_ID(HC_ID, HC_ID_IRQ_BASE +
0x04UL)

/* DM ioreq management */
#define HC_ID_IOREQ_BASE 0x30UL
diff --git a/include/linux/vhm/vhm_hypercall.h
b/include/linux/vhm/vhm_hypercall.h
index bc9feec..868541e 100644
--- a/include/linux/vhm/vhm_hypercall.h
+++ b/include/linux/vhm/vhm_hypercall.h
@@ -166,5 +166,6 @@ inline long hcall_reset_ptdev_intr_info(unsigned
long vmid,
unsigned long pt_irq);
inline long hcall_remap_pci_msix(unsigned long vmid, unsigned long
msi); inline long hcall_vm_gpa2hpa(unsigned long vmid, unsigned long
addr);
+inline long hcall_vm_intr_monitor(unsigned long vmid, unsigned long
+addr);

#endif /* __VHM_HYPERCALL_H__ */
diff --git a/include/linux/vhm/vhm_ioctl_defs.h
b/include/linux/vhm/vhm_ioctl_defs.h
index 32e081a..042b8e9 100644
--- a/include/linux/vhm/vhm_ioctl_defs.h
+++ b/include/linux/vhm/vhm_ioctl_defs.h
@@ -80,6 +80,7 @@
#define IC_DEASSERT_IRQLINE _IC_ID(IC_ID, IC_ID_IRQ_BASE + 0x01)
#define IC_PULSE_IRQLINE _IC_ID(IC_ID, IC_ID_IRQ_BASE + 0x02)
#define IC_INJECT_MSI _IC_ID(IC_ID, IC_ID_IRQ_BASE + 0x03)
+#define IC_VM_INTR_MONITOR _IC_ID(IC_ID, IC_ID_IRQ_BASE +
0x04)

/* DM ioreq management */
#define IC_ID_IOREQ_BASE 0x30UL
--
2.7.4



[PATCH] hv: vuart: fix 'Shifting value too far'

Shiqing Gao
 

MISRA-C requires that shift operation cannot exceed the word length.

What this patch does:
- Fix the bug in 'vuart_init'
The register 'dll' and 'dlh' should be uint8_t rather than char.
'dll' is the lower 8-bit of divisor.
'dlh' is the higher 8-bit of divisor.
So, the shift value should be 8U rather than 16U.
- Fix other data type issues regarding to the registers in 'struct
vuart'
The registers should be unsigned variables.

Tracked-On: #861
Signed-off-by: Shiqing Gao <shiqing.gao@...>
---
hypervisor/debug/vuart.c | 36 +++++++++++++++++-------------------
hypervisor/include/debug/vuart.h | 20 ++++++++++----------
2 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/hypervisor/debug/vuart.c b/hypervisor/debug/vuart.c
index 57e2611..549a8f4 100644
--- a/hypervisor/debug/vuart.c
+++ b/hypervisor/debug/vuart.c
@@ -133,9 +133,8 @@ static void vuart_toggle_intr(struct vuart *vu)
}
}

-static void vuart_write(__unused struct vm_io_handler *hdlr,
- struct vm *vm, uint16_t offset_arg,
- __unused size_t width, uint32_t value)
+static void vuart_write(__unused struct vm_io_handler *hdlr, struct vm *vm,
+ uint16_t offset_arg, __unused size_t width, uint32_t value)
{
uint16_t offset = offset_arg;
struct vuart *vu = vm_vuart(vm);
@@ -146,12 +145,12 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
*/
if ((vu->lcr & LCR_DLAB) != 0) {
if (offset == UART16550_DLL) {
- vu->dll = value;
+ vu->dll = (uint8_t)value;
goto done;
}

if (offset == UART16550_DLM) {
- vu->dlh = value;
+ vu->dlh = (uint8_t)value;
goto done;
}
}
@@ -166,7 +165,7 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
* Apply mask so that bits 4-7 are 0
* Also enables bits 0-3 only if they're 1
*/
- vu->ier = value & 0x0FU;
+ vu->ier = (uint8_t)(value & 0x0FU);
break;
case UART16550_FCR:
/*
@@ -174,18 +173,18 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
* of other FCR bits to be effective.
*/
if ((value & FCR_FIFOE) == 0U) {
- vu->fcr = 0;
+ vu->fcr = 0U;
} else {
if ((value & FCR_RFR) != 0U) {
fifo_reset(&vu->rxfifo);
}

- vu->fcr = value &
- (FCR_FIFOE | FCR_DMA | FCR_RX_MASK);
+ vu->fcr = (uint8_t)(value &
+ (FCR_FIFOE | FCR_DMA | FCR_RX_MASK));
}
break;
case UART16550_LCR:
- vu->lcr = value;
+ vu->lcr = (uint8_t)value;
break;
case UART16550_MCR:
/* ignore modem */
@@ -202,7 +201,7 @@ static void vuart_write(__unused struct vm_io_handler *hdlr,
*/
break;
case UART16550_SCR:
- vu->scr = value;
+ vu->scr = (uint8_t)value;
break;
default:
/*
@@ -218,14 +217,13 @@ done:
vuart_unlock(vu);
}

-static uint32_t vuart_read(__unused struct vm_io_handler *hdlr,
- struct vm *vm, uint16_t offset_arg,
- __unused size_t width)
+static uint32_t vuart_read(__unused struct vm_io_handler *hdlr, struct vm *vm,
+ uint16_t offset_arg, __unused size_t width)
{
uint16_t offset = offset_arg;
- char iir, reg;
- uint8_t intr_reason;
+ uint8_t iir, reg, intr_reason;
struct vuart *vu = vm_vuart(vm);
+
offset -= vu->base;
vuart_lock(vu);
/*
@@ -295,7 +293,7 @@ static uint32_t vuart_read(__unused struct vm_io_handler *hdlr,
done:
vuart_toggle_intr(vu);
vuart_unlock(vu);
- return reg;
+ return (uint32_t)reg;
}

static void vuart_register_io_handler(struct vm *vm)
@@ -370,8 +368,8 @@ void *vuart_init(struct vm *vm)

/* Set baud rate*/
divisor = UART_CLOCK_RATE / BAUD_9600 / 16U;
- vu->dll = divisor;
- vu->dlh = divisor >> 16U;
+ vu->dll = (uint8_t)(divisor & 0xFFU);
+ vu->dlh = (uint8_t)(divisor >> 8U);

vu->active = false;
vu->base = COM1_BASE;
diff --git a/hypervisor/include/debug/vuart.h b/hypervisor/include/debug/vuart.h
index 38499a1..ea0754c 100644
--- a/hypervisor/include/debug/vuart.h
+++ b/hypervisor/include/debug/vuart.h
@@ -39,16 +39,16 @@ struct fifo {
};

struct vuart {
- char data; /* Data register (R/W) */
- char ier; /* Interrupt enable register (R/W) */
- char lcr; /* Line control register (R/W) */
- char mcr; /* Modem control register (R/W) */
- char lsr; /* Line status register (R/W) */
- char msr; /* Modem status register (R/W) */
- char fcr; /* FIFO control register (W) */
- char scr; /* Scratch register (R/W) */
- char dll; /* Baudrate divisor latch LSB */
- char dlh; /* Baudrate divisor latch MSB */
+ uint8_t data; /* Data register (R/W) */
+ uint8_t ier; /* Interrupt enable register (R/W) */
+ uint8_t lcr; /* Line control register (R/W) */
+ uint8_t mcr; /* Modem control register (R/W) */
+ uint8_t lsr; /* Line status register (R/W) */
+ uint8_t msr; /* Modem status register (R/W) */
+ uint8_t fcr; /* FIFO control register (W) */
+ uint8_t scr; /* Scratch register (R/W) */
+ uint8_t dll; /* Baudrate divisor latch LSB */
+ uint8_t dlh; /* Baudrate divisor latch MSB */

struct fifo rxfifo;
struct fifo txfifo;
--
1.9.1


Re: [RESEND 2/2] tools: acrnalyze: Make the result easier to read

Eddie Dong
 

LGTM

-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...] On Behalf Of Kaige Fu
Sent: Tuesday, August 14, 2018 2:45 PM
To: acrn-dev@...
Cc: Yan, Like <like.yan@...>
Subject: [acrn-dev] [RESEND 2/2] tools: acrnalyze: Make the result easier to
read

Originally, we don't format the output of analyser well. It is hard to read the
result.

This patch make every entry of the result align with the corresponding title to
make it easier for users to read.

Without patch:
Event NR_Exit NR_Exit/Sec Time
Consumed(ms) Time Percentage
VMEXIT_INTERRUPT_WINDOW 78090 130.15 40 0.01
VMEXIT_CR_ACCESS 0 0.00 0 0.00
VMEXIT_APICV_ACCESS 0 0.00 0 0.00
VMEXIT_EXCEPTION_OR_NMI 0 0.00 0 0.00
VMEXIT_RDTSC 0 0.00 0 0.00

...

Vector Count NR_Exit/Sec
0x000000f0 82337 137.23
0x000000ef 247713 412.85

With patch:
Event NR_Exit NR_Exit/Sec
Time Consumed(ms) Time percentage
VMEXIT_INTERRUPT_WINDOW 78090 130.15
40 0.01
VMEXIT_WRMSR 309085 515.14
128 0.02
VMEXIT_RDTSCP 0 0.00
0 0.00
VMEXIT_IO_INSTRUCTION 75250 125.42
12924 2.15
VMEXIT_EXTERNAL_INTERRUPT 330050 550.08
726 0.12

...

Vector Count NR_Exit/Sec
0x000000f0 82337 137.23
0x000000ef 247713 412.85

Signed-off-by: Kaige Fu <kaige.fu@...>
---
tools/acrntrace/scripts/irq_analyze.py | 6 +++---
tools/acrntrace/scripts/vmexit_analyze.py | 9 +++++----
2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/tools/acrntrace/scripts/irq_analyze.py
b/tools/acrntrace/scripts/irq_analyze.py
index f475da7..0d555aa 100755
--- a/tools/acrntrace/scripts/irq_analyze.py
+++ b/tools/acrntrace/scripts/irq_analyze.py
@@ -80,12 +80,12 @@ def generate_report(ofile, freq):

rt_sec = float(rt_cycle) / (float(freq) * 1000 * 1000)

- print ("\nVector \t\tCount \tNR_Exit/Sec")
+ print ("%-8s\t%-8s\t%-8s" % ("Vector", "Count",
+ "NR_Exit/Sec"))
f_csv.writerow(['Vector', 'NR_Exit', 'NR_Exit/Sec'])
for e in IRQ_EXITS.keys():
pct = float(IRQ_EXITS[e]) / rt_sec
- print ("0x%08x \t %d \t%.2f" % (e, IRQ_EXITS[e], pct))
- f_csv.writerow([e, IRQ_EXITS[e], '%.2f' % pct])
+ print ("0x%08x\t%-8d\t%-8.2f" % (e, IRQ_EXITS[e], pct))
+ f_csv.writerow(['0x%08x' % e, IRQ_EXITS[e], '%.2f' %
+ pct])

except IOError as err:
print ("Output File Error: " + str(err)) diff --git
a/tools/acrntrace/scripts/vmexit_analyze.py
b/tools/acrntrace/scripts/vmexit_analyze.py
index 0eee590..96dd40a 100755
--- a/tools/acrntrace/scripts/vmexit_analyze.py
+++ b/tools/acrntrace/scripts/vmexit_analyze.py
@@ -179,7 +179,8 @@ def generate_report(ofile, freq):
'%.3f' % (rt_ms),
'%d' % (freq)])

- print ("Event \tNR_Exit \tNR_Exit/Sec \tTime Consumed(ms)
\tTime Percentage")
+ print ("%-28s\t%-12s\t%-12s\t%-18s\t%-16s" % ("Event",
"NR_Exit",
+ "NR_Exit/Sec", "Time Consumed(ms)", "Time
+ percentage"))
f_csv.writerow(['Exit_Reason',
'NR_Exit',
'NR_Exit/Sec', @@ -190,7 +191,7 @@
def generate_report(ofile, freq):
ev_freq = float(NR_EXITS[event]) / rt_sec
pct = float(TIME_IN_EXIT[event]) * 100 / float(rt_ms)

- print ("%s \t%d \t%.2f \t%d \t%2.2f" %
+ print ("%-28s\t%-12d\t%-12.2f\t%-18d\t%-16.2f" %
(event, NR_EXITS[event], ev_freq,
TIME_IN_EXIT[event], pct))
row = [event, NR_EXITS[event], '%.2f' % ev_freq,
TIME_IN_EXIT[event],
'%2.2f' % (pct)] @@ -198,8 +199,8 @@ def
generate_report(ofile, freq):

ev_freq = float(TOTAL_NR_EXITS) / rt_sec
pct = float(total_exit_time) * 100 / float(rt_ms)
- print("Total \t%d \t%.2f \t%d \t%2.2f"
- % (TOTAL_NR_EXITS, ev_freq, total_exit_time, pct))
+ print("%-28s\t%-12d\t%-12.2f\t%-18d\t%-16.2f"
+ % ("Total", TOTAL_NR_EXITS, ev_freq,
total_exit_time,
+ pct))
row = ["Total", TOTAL_NR_EXITS, '%.2f' % ev_freq,
total_exit_time,
'%2.2f' % (pct)]
f_csv.writerow(row)
--
2.7.4