Date   

[PATCH 0/2] Add ioeventfd and irqfd support for vhm

Shuo A Liu
 

To support vhost, we need implement call eventfd and notify eventfd in
kernel for it. For ACRN vhm, we implement ioeventfd and irqfd for that.

ioeventfd which is based on eventfd, intends to glue vhm module and
other modules who are interested in guest IOs.
Each ioeventfd registered by userspace can map a PIO/MMIO range of
the guest to eventfd, and response to signal the eventfd when get the
in-range IO write from guest. Then the other side of eventfd can be
notified to process the IO request.

irqfd is based on eventfd too, provides a pipe for injecting guest
interrupt through a file description writing operation.
Each irqfd registered by userspace can map a interrupt of the guest
to eventfd, and a writing operation on one side of the eventfd will
trigger the interrupt injection on vhm side.


Shuo Liu (2):
vhm: add ioeventfd support for ACRN hypervisor service module
vhm: add irqfd support for ACRN hypervisor service module

drivers/char/vhm/vhm_dev.c | 26 +++
drivers/vhm/Makefile | 2 +-
drivers/vhm/vhm_ioeventfd.c | 412 +++++++++++++++++++++++++++++++++++++
drivers/vhm/vhm_irqfd.c | 320 ++++++++++++++++++++++++++++
include/linux/vhm/vhm_eventfd.h | 16 ++
include/linux/vhm/vhm_ioctl_defs.h | 22 ++
6 files changed, 797 insertions(+), 1 deletion(-)
create mode 100644 drivers/vhm/vhm_ioeventfd.c
create mode 100644 drivers/vhm/vhm_irqfd.c
create mode 100644 include/linux/vhm/vhm_eventfd.h

--
2.8.3


[PATCH] drm/i915/gvt: fix display messy issue which is introduced by plane pvmmio

Fei Jiang
 

For plane pvmmio optimization, we need cache all plane related registers,
in previous commit 9c3e8b1a3f15 ("drm/i915/gvt: handling pvmmio update of
plane registers in GVT-g"), due to PLANE_AUX_DIST and PLANE_AUX_OFFSET are
trapped with _REG_701C0 and _REG_701C4, then they are missing by only
checking PLANE_AUX_DIST and PLANE_AUX_OFFSET.

Signed-off-by: Fei Jiang <fei.jiang@...>
---
drivers/gpu/drm/i915/gvt/handlers.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/i915/gvt/handlers.c b/drivers/gpu/drm/i915/gvt/handlers.c
index c33c771..6001127 100644
--- a/drivers/gpu/drm/i915/gvt/handlers.c
+++ b/drivers/gpu/drm/i915/gvt/handlers.c
@@ -777,6 +777,12 @@ static void pvmmio_update_plane_register(struct intel_vgpu *vgpu,
skl_plane_mmio_write(vgpu,
i915_mmio_reg_offset(PLANE_SIZE(pipe, plane)),
&pv_plane->plane_size, 4);
+ skl_plane_mmio_write(vgpu,
+ i915_mmio_reg_offset(PLANE_AUX_DIST(pipe, plane)),
+ &pv_plane.plane_aux_dist, 4);
+ skl_plane_mmio_write(vgpu,
+ i915_mmio_reg_offset(PLANE_AUX_OFFSET(pipe, plane)),
+ &pv_plane.plane_aux_offset, 4);

if (pv_plane->flags & PLANE_SCALER_BIT) {
skl_ps_mmio_write(vgpu,
--
2.7.4


[PATCH V3 3/3] dm: monotor: bugfix: update wakeup reason before call recume() callback

Tao, Yuhong
 

In handle_resume(), wakeup_reason is updated before call
ops->ops->resume(). Because ops->ops->resume() needs to know the
latest wakeup reason.

Signed-off-by: Tao Yuhong <yuhong.tao@...>
---
devicemodel/core/monitor.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/devicemodel/core/monitor.c b/devicemodel/core/monitor.c
index c5b41f1..4b97c5a 100644
--- a/devicemodel/core/monitor.c
+++ b/devicemodel/core/monitor.c
@@ -168,6 +168,8 @@ static void handle_resume(struct mngr_msg *msg, int client_fd, void *param)
ack.msgid = msg->msgid;
ack.timestamp = msg->timestamp;

+ wakeup_reason = msg->data.reason;
+
LIST_FOREACH(ops, &vm_ops_head, list) {
if (ops->ops->resume) {
ret += ops->ops->resume(ops->arg);
@@ -181,8 +183,6 @@ static void handle_resume(struct mngr_msg *msg, int client_fd, void *param)
} else
ack.data.err = ret;

- wakeup_reason = msg->data.reason;
-
mngr_send_msg(client_fd, &ack, NULL, ACK_TIMEOUT);
}

--
2.7.4


[PATCH V3 2/3] tools: acrnd: Fixed get_sos_wakeup_reason()

Tao, Yuhong
 

get_sos_wakeup_reason() runs into error branch without any error, so
no wakeup reason will be returend.

Signed-off-by: Tao Yuhong <yuhong.tao@...>
---
tools/acrn-manager/acrnd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/acrn-manager/acrnd.c b/tools/acrn-manager/acrnd.c
index 3b47bdd..f1eb338 100644
--- a/tools/acrn-manager/acrnd.c
+++ b/tools/acrn-manager/acrnd.c
@@ -284,7 +284,7 @@ unsigned get_sos_wakeup_reason(void)
req.msgid = WAKEUP_REASON;
req.timestamp = time(NULL);

- if (mngr_send_msg(client_fd, &req, &ack, DEFAULT_TIMEOUT))
+ if (mngr_send_msg(client_fd, &req, &ack, DEFAULT_TIMEOUT) <= 0)
fprintf(stderr, "Failed to get wakeup_reason from SOS, err(%d)\n", ret);
else
ret = ack.data.reason;
--
2.7.4


[PATCH V3 1/3] tools: vm_resume() requires wakeup reason

Tao, Yuhong
 

DM need to know wakeup reason when resume the VM, so
vm_resume(char *name) is updated to vm_resume(char *name, int reason),
in acrn_vm_ops.c

Signed-off-by: Tao Yuhong <yuhong.tao@...>
---
tools/acrn-manager/acrn_mngr.h | 2 +-
tools/acrn-manager/acrn_vm_ops.c | 4 +++-
tools/acrn-manager/acrnctl.c | 34 +++++++++++++++++++---------------
tools/acrn-manager/acrnctl.h | 2 +-
tools/acrn-manager/acrnd.c | 9 +++++++--
5 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/tools/acrn-manager/acrn_mngr.h b/tools/acrn-manager/acrn_mngr.h
index 6a93ea8..12c9f1c 100644
--- a/tools/acrn-manager/acrn_mngr.h
+++ b/tools/acrn-manager/acrn_mngr.h
@@ -27,7 +27,7 @@ struct mngr_msg {
int err;

/* ack of WAKEUP_REASON */
- int reason;
+ unsigned reason;

/* ack of DM_QUERY */
int state;
diff --git a/tools/acrn-manager/acrn_vm_ops.c b/tools/acrn-manager/acrn_vm_ops.c
index cd8ad29..a56e043 100644
--- a/tools/acrn-manager/acrn_vm_ops.c
+++ b/tools/acrn-manager/acrn_vm_ops.c
@@ -392,7 +392,7 @@ int suspend_vm(char *vmname)
return ack.data.err;
}

-int resume_vm(char *vmname)
+int resume_vm(char *vmname, unsigned reason)
{
struct mngr_msg req;
struct mngr_msg ack;
@@ -401,6 +401,8 @@ int resume_vm(char *vmname)
req.msgid = DM_RESUME;
req.timestamp = time(NULL);

+ req.data.reason = reason;
+
send_msg(vmname, &req, &ack);

if (ack.data.err) {
diff --git a/tools/acrn-manager/acrnctl.c b/tools/acrn-manager/acrnctl.c
index 84465a2..1fb3cea 100644
--- a/tools/acrn-manager/acrnctl.c
+++ b/tools/acrn-manager/acrnctl.c
@@ -466,23 +466,27 @@ static int acrnctl_do_suspend(int argc, char *argv[])
static int acrnctl_do_resume(int argc, char *argv[])
{
struct vmmngr_struct *s;
- int i;
+ unsigned reason = 0;

- for (i = 1; i < argc; i++) {
- s = vmmngr_find(argv[i]);
- if (!s) {
- printf("Can't find vm %s\n", argv[i]);
- continue;
- }
+ s = vmmngr_find(argv[1]);
+ if (!s) {
+ printf("Can't find vm %s\n", argv[1]);
+ return -1;
+ }

- switch (s->state) {
- case VM_PAUSED:
- resume_vm(argv[i]);
- break;
- default:
- printf("%s current state %s, can't resume\n",
- argv[i], state_str[s->state]);
- }
+ if (argc == 3) {
+ sscanf(argv[2], "%x", &reason);
+ reason = (reason & (0xff << 24)) ? 0 : reason;
+ }
+
+ switch (s->state) {
+ case VM_PAUSED:
+ resume_vm(argv[1], reason);
+ printf("resume %s reason(0x%x\n", argv[1], reason);
+ break;
+ default:
+ printf("%s current state %s, can't resume\n",
+ argv[1], state_str[s->state]);
}

return 0;
diff --git a/tools/acrn-manager/acrnctl.h b/tools/acrn-manager/acrnctl.h
index 721a637..1244748 100644
--- a/tools/acrn-manager/acrnctl.h
+++ b/tools/acrn-manager/acrnctl.h
@@ -56,6 +56,6 @@ int start_vm(char *vmname);
int pause_vm(char *vmname);
int continue_vm(char *vmname);
int suspend_vm(char *vmname);
-int resume_vm(char *vmname);
+int resume_vm(char *vmname, unsigned reason);

#endif /* _ACRNCTL_H_ */
diff --git a/tools/acrn-manager/acrnd.c b/tools/acrn-manager/acrnd.c
index 65783fd..3b47bdd 100644
--- a/tools/acrn-manager/acrnd.c
+++ b/tools/acrn-manager/acrnd.c
@@ -105,11 +105,13 @@ static void try_do_works(void)
}

static void acrnd_run_vm(char *name);
+unsigned get_sos_wakeup_reason(void);

/* Time to run/resume VM */
void acrnd_vm_timer_func(struct work_arg *arg)
{
struct vmmngr_struct *vm;
+ unsigned reason;

if (!arg) {
pdebug();
@@ -128,7 +130,8 @@ void acrnd_vm_timer_func(struct work_arg *arg)
acrnd_run_vm(arg->name);
break;
case VM_PAUSED:
- resume_vm(arg->name);
+ reason = get_sos_wakeup_reason();
+ resume_vm(arg->name, reason);
break;
default:
pdebug();
@@ -235,6 +238,7 @@ static int active_all_vms(void)
struct vmmngr_struct *vm;
int ret = 0;
pid_t pid;
+ unsigned reason;

vmmngr_update();

@@ -246,7 +250,8 @@ static int active_all_vms(void)
acrnd_run_vm(vm->name);
break;
case VM_PAUSED:
- ret += resume_vm(vm->name);
+ reason = get_sos_wakeup_reason();
+ ret += resume_vm(vm->name, reason);
break;
default:
pdebug();
--
2.7.4


[PATCH V3 0/3] Tools: fixed issues for S3 feature

Tao, Yuhong
 

With these changes, S3 feature works.

changes in V2:
1.fixed get_sos_wakeup_reason() in acrnd.c
2.fixed handle_resume() in monitor.c
changes in V3:
1.wakeup reason is unsigned int

yuhong.tao@... (3):
tools: vm_resume() requires wakeup reason
tools: acrnd: Fixed get_sos_wakeup_reason()
dm: monotor: bugfix: update wakeup reason before call recume()
callback

devicemodel/core/monitor.c | 4 ++--
tools/acrn-manager/acrn_mngr.h | 2 +-
tools/acrn-manager/acrn_vm_ops.c | 4 +++-
tools/acrn-manager/acrnctl.c | 34 +++++++++++++++++++---------------
tools/acrn-manager/acrnctl.h | 2 +-
tools/acrn-manager/acrnd.c | 11 ++++++++---
6 files changed, 34 insertions(+), 23 deletions(-)

--
2.7.4


[PATCH 4/4] HV: remove 'warm_reboot()' and other minor cleanup

Yonghua Huang
 

- 'reboot.c' defines 'warm_reboot()' only, which
is deprecated.
- remove the eXecution attribute for 'mttr.h'

Signed-off-by: Yonghua Huang <yonghua.huang@...>
---
hypervisor/Makefile | 1 -
hypervisor/arch/x86/debug/reboot.c | 12 ------------
hypervisor/include/arch/x86/mtrr.h | 0
hypervisor/include/arch/x86/reboot.h | 9 ---------
4 files changed, 22 deletions(-)
delete mode 100644 hypervisor/arch/x86/debug/reboot.c
mode change 100755 => 100644 hypervisor/include/arch/x86/mtrr.h
delete mode 100644 hypervisor/include/arch/x86/reboot.h

diff --git a/hypervisor/Makefile b/hypervisor/Makefile
index b0588b7..3978600 100644
--- a/hypervisor/Makefile
+++ b/hypervisor/Makefile
@@ -149,7 +149,6 @@ C_SRCS += arch/x86/guest/vmsr.c
C_SRCS += arch/x86/guest/instr_emul.c
C_SRCS += arch/x86/guest/ucode.c
C_SRCS += arch/x86/guest/pm.c
-C_SRCS += arch/x86/debug/reboot.c
C_SRCS += lib/spinlock.c
C_SRCS += lib/udelay.c
C_SRCS += lib/mdelay.c
diff --git a/hypervisor/arch/x86/debug/reboot.c b/hypervisor/arch/x86/debug/reboot.c
deleted file mode 100644
index 8fc5cb9..0000000
--- a/hypervisor/arch/x86/debug/reboot.c
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * Copyright (C) <2018> Intel Corporation
- * SPDX-License-Identifier: BSD-3-Clause
- */
-#include <hypervisor.h>
-#include <reboot.h>
-
-int warm_reboot(void)
-{
- pio_write8(0x6, 0xcf9);
- return 0;
-}
diff --git a/hypervisor/include/arch/x86/mtrr.h b/hypervisor/include/arch/x86/mtrr.h
old mode 100755
new mode 100644
diff --git a/hypervisor/include/arch/x86/reboot.h b/hypervisor/include/arch/x86/reboot.h
deleted file mode 100644
index db502b1..0000000
--- a/hypervisor/include/arch/x86/reboot.h
+++ /dev/null
@@ -1,9 +0,0 @@
-/*
- * Copyright (C) <2018> Intel Corporation
- * SPDX-License-Identifier: BSD-3-Clause
- */
-#ifndef REBOOT_H
-#define REBOOT_H
-
-int warm_reboot(void);
-#endif
--
2.7.4


[PATCH 3/4] HV: Merge hypervisor debug header files

Yonghua Huang
 

-- merge 'assert.h' & 'printf.h' into 'logmsg.h'
-- merge 'shell.h' into 'console.h'

Signed-off-by: Yonghua Huang <yonghua.huang@...>
---
hypervisor/include/debug/assert.h | 21 ----------------
hypervisor/include/debug/console.h | 9 +++++++
hypervisor/include/debug/logmsg.h | 45 ++++++++++++++++++++++++++++++++++
hypervisor/include/debug/printf.h | 49 --------------------------------------
hypervisor/include/debug/shell.h | 21 ----------------
hypervisor/include/hv_debug.h | 3 ---
6 files changed, 54 insertions(+), 94 deletions(-)
delete mode 100644 hypervisor/include/debug/assert.h
delete mode 100644 hypervisor/include/debug/printf.h
delete mode 100644 hypervisor/include/debug/shell.h

diff --git a/hypervisor/include/debug/assert.h b/hypervisor/include/debug/assert.h
deleted file mode 100644
index b5f170d..0000000
--- a/hypervisor/include/debug/assert.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2018 Intel Corporation. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef ASSERT_H
-#define ASSERT_H
-
-#ifdef HV_DEBUG
-void asm_assert(int32_t line, const char *file, const char *txt);
-
-#define ASSERT(x, ...) \
- if (!(x)) {\
- asm_assert(__LINE__, __FILE__, "fatal error");\
- }
-#else
-#define ASSERT(x, ...) do { } while(0)
-#endif
-
-#endif /* ASSERT_H */
diff --git a/hypervisor/include/debug/console.h b/hypervisor/include/debug/console.h
index 6c491bc..706f5b1 100644
--- a/hypervisor/include/debug/console.h
+++ b/hypervisor/include/debug/console.h
@@ -7,6 +7,9 @@
#ifndef CONSOLE_H
#define CONSOLE_H

+/* Switching key combinations for shell and uart console */
+#define GUEST_CONSOLE_TO_HV_SWITCH_KEY 0 /* CTRL + SPACE */
+
#ifdef HV_DEBUG
extern struct hv_timer console_timer;

@@ -52,6 +55,9 @@ static inline void resume_console(void)
}
void uart16550_set_property(bool enabled, bool port_mapped, uint64_t base_addr);

+void shell_init(void);
+void shell_kick(void);
+
#else
static inline void console_init(void)
{
@@ -70,6 +76,9 @@ static inline void suspend_console(void) {}
static inline void resume_console(void) {}
static inline void uart16550_set_property(__unused bool enabled,
__unused bool port_mapped, __unused uint64_t base_addr) {}
+
+static inline void shell_init(void) {}
+static inline void shell_kick(void) {}
#endif

#endif /* CONSOLE_H */
diff --git a/hypervisor/include/debug/logmsg.h b/hypervisor/include/debug/logmsg.h
index 7e1ed70..c8de4c5 100644
--- a/hypervisor/include/debug/logmsg.h
+++ b/hypervisor/include/debug/logmsg.h
@@ -33,6 +33,39 @@ void init_logmsg(__unused uint32_t mem_size, uint32_t flags);
void print_logmsg_buffer(uint16_t pcpu_id);
void do_logmsg(uint32_t severity, const char *fmt, ...);

+void asm_assert(int32_t line, const char *file, const char *txt);
+
+#define ASSERT(x, ...) \
+ do { \
+ if (!(x)) {\
+ asm_assert(__LINE__, __FILE__, "fatal error");\
+ } \
+ } while (0)
+
+/** The well known printf() function.
+ *
+ * Formats a string and writes it to the console output.
+ *
+ * @param fmt A pointer to the NUL terminated format string.
+ *
+ * @return The number of characters actually written or a negative
+ * number if an error occurred.
+ */
+
+int printf(const char *fmt, ...);
+
+/** The well known vprintf() function.
+ *
+ * Formats a string and writes it to the console output.
+ *
+ * @param fmt A pointer to the NUL terminated format string.
+ * @param args The variable long argument list as va_list.
+ * @return The number of characters actually written or a negative
+ * number if an error occurred.
+ */
+
+int vprintf(const char *fmt, va_list args);
+
#else /* HV_DEBUG */

static inline void init_logmsg(__unused uint32_t mem_size,
@@ -49,6 +82,18 @@ static inline void print_logmsg_buffer(__unused uint16_t pcpu_id)
{
}

+#define ASSERT(x, ...) do { } while (0)
+
+static inline int printf(__unused const char *fmt, ...)
+{
+ return 0;
+}
+
+static inline int vprintf(__unused const char *fmt, __unused va_list args)
+{
+ return 0;
+}
+
#endif /* HV_DEBUG */

#ifndef pr_prefix
diff --git a/hypervisor/include/debug/printf.h b/hypervisor/include/debug/printf.h
deleted file mode 100644
index 6e6c911..0000000
--- a/hypervisor/include/debug/printf.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2018 Intel Corporation. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef PRINTF_H
-#define PRINTF_H
-
-#ifdef HV_DEBUG
-/** The well known printf() function.
- *
- * Formats a string and writes it to the console output.
- *
- * @param fmt A pointer to the NUL terminated format string.
- *
- * @return The number of characters actually written or a negative
- * number if an error occurred.
- */
-
-int printf(const char *fmt, ...);
-
-/** The well known vprintf() function.
- *
- * Formats a string and writes it to the console output.
- *
- * @param fmt A pointer to the NUL terminated format string.
- * @param args The variable long argument list as va_list.
- * @return The number of characters actually written or a negative
- * number if an error occurred.
- */
-
-int vprintf(const char *fmt, va_list args);
-
-#else /* HV_DEBUG */
-
-static inline int printf(__unused const char *fmt, ...)
-{
- return 0;
-}
-
-static inline int vprintf(__unused const char *fmt, __unused va_list args)
-{
- return 0;
-}
-
-#endif /* HV_DEBUG */
-
-#endif /* PRINTF_H */
diff --git a/hypervisor/include/debug/shell.h b/hypervisor/include/debug/shell.h
deleted file mode 100644
index 829e0ac..0000000
--- a/hypervisor/include/debug/shell.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2018 Intel Corporation. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef SHELL_H
-#define SHELL_H
-
-/* Switching key combinations for shell and uart console */
-#define GUEST_CONSOLE_TO_HV_SWITCH_KEY 0 /* CTRL + SPACE */
-
-#ifdef HV_DEBUG
-void shell_init(void);
-void shell_kick(void);
-#else
-static inline void shell_init(void) {}
-static inline void shell_kick(void) {}
-#endif
-
-#endif /* SHELL_H */
diff --git a/hypervisor/include/hv_debug.h b/hypervisor/include/hv_debug.h
index ff41e32..7198132 100644
--- a/hypervisor/include/hv_debug.h
+++ b/hypervisor/include/hv_debug.h
@@ -12,9 +12,6 @@
#include <console.h>
#include <dump.h>
#include <trace.h>
-#include <shell.h>
#include <sbuf.h>
-#include <assert.h>
-#include <printf.h>

#endif /* HV_DEBUG_H */
--
2.7.4


[PATCH 2/4] HV: refine shell.c & shell_priv.h

Yonghua Huang
 

- move local functions declarations to shell.c
- remove 'name' field in 'struct shell' as i/o
session s/w layer is deprecated.

Signed-off-by: Yonghua Huang <yonghua.huang@...>
---
hypervisor/debug/shell.c | 180 +++++++++++++++++++++++-------------------
hypervisor/debug/shell_priv.h | 52 +++---------
2 files changed, 109 insertions(+), 123 deletions(-)

diff --git a/hypervisor/debug/shell.c b/hypervisor/debug/shell.c
index a3976e6..22ef919 100644
--- a/hypervisor/debug/shell.c
+++ b/hypervisor/debug/shell.c
@@ -16,6 +16,22 @@
*/
#define SHELL_INPUT_LINE_OTHER(v) (((v) + 1U) % 2U)

+static int shell_cmd_help(__unused int argc, __unused char **argv);
+static int shell_list_vm(__unused int argc, __unused char **argv);
+static int shell_list_vcpu(__unused int argc, __unused char **argv);
+static int shell_vcpu_dumpreg(int argc, char **argv);
+static int shell_dumpmem(int argc, char **argv);
+static int shell_to_sos_console(int argc, char **argv);
+static int shell_show_cpu_int(__unused int argc, __unused char **argv);
+static int shell_show_ptdev_info(__unused int argc, __unused char **argv);
+static int shell_show_vioapic_info(int argc, char **argv);
+static int shell_show_ioapic_info(__unused int argc, __unused char **argv);
+static int shell_show_vmexit_profile(__unused int argc, __unused char **argv);
+static int shell_dump_logbuf(int argc, char **argv);
+static int shell_loglevel(int argc, char **argv);
+static int shell_cpuid(int argc, char **argv);
+static int shell_trigger_crash(int argc, char **argv);
+
static struct shell_cmd shell_cmds[] = {
{
.str = SHELL_CMD_HELP,
@@ -179,11 +195,32 @@ static int string_to_argv(char *argv_str, void *p_argv_mem,
return 0;
}

+static struct shell_cmd *shell_find_cmd(const char *cmd_str)
+{
+ uint32_t i;
+ struct shell_cmd *p_cmd = NULL;
+
+ for (i = 0U; i < p_shell->cmd_count; i++) {
+ p_cmd = &p_shell->shell_cmd[i];
+ if (strcmp(p_cmd->str, cmd_str) == 0) {
+ return p_cmd;
+ }
+ }
+ return NULL;
+}
+
static char shell_getc(void)
{
return console_getc();
}

+static void shell_puts(const char *string_ptr)
+{
+ /* Output the string */
+ (void)console_write(string_ptr, strnlen_s(string_ptr,
+ SHELL_STRING_MAX_LEN));
+}
+
static void shell_handle_special_char(uint8_t ch)
{
switch (ch) {
@@ -289,6 +326,51 @@ static bool shell_input_line(void)
return done;
}

+static int shell_process_cmd(char *p_input_line)
+{
+ int status = -EINVAL;
+ struct shell_cmd *p_cmd;
+ char cmd_argv_str[SHELL_CMD_MAX_LEN + 1U];
+ int cmd_argv_mem[sizeof(char *) * ((SHELL_CMD_MAX_LEN + 1U) / 2U)];
+ int cmd_argc;
+ char **cmd_argv;
+
+ /* Copy the input line INTo an argument string to become part of the
+ * argument vector.
+ */
+ (void)strcpy_s(&cmd_argv_str[0], SHELL_CMD_MAX_LEN, p_input_line);
+ cmd_argv_str[SHELL_CMD_MAX_LEN] = 0;
+
+ /* Build the argv vector from the string. The first argument in the
+ * resulting vector will be the command string itself.
+ */
+
+ /* NOTE: This process is destructive to the argument string! */
+
+ (void) string_to_argv(&cmd_argv_str[0],
+ (void *) &cmd_argv_mem[0],
+ sizeof(cmd_argv_mem), (void *)&cmd_argc, &cmd_argv);
+
+ /* Determine if there is a command to process. */
+ if (cmd_argc != 0) {
+ /* See if command is in cmds supported */
+ p_cmd = shell_find_cmd(cmd_argv[0]);
+ if (p_cmd == NULL) {
+ shell_puts("\r\nError: Invalid command.\r\n");
+ return -EINVAL;
+ }
+
+ status = p_cmd->fcn(cmd_argc, &cmd_argv[0]);
+ if (status == -EINVAL) {
+ shell_puts("\r\nError: Invalid parameters.\r\n");
+ } else if (status != 0) {
+ shell_puts("\r\nCommand launch failed.\r\n");
+ }
+ }
+
+ return status;
+}
+
static int shell_process(void)
{
int status;
@@ -323,19 +405,6 @@ static int shell_process(void)
return status;
}

-struct shell_cmd *shell_find_cmd(const char *cmd_str)
-{
- uint32_t i;
- struct shell_cmd *p_cmd = NULL;
-
- for (i = 0U; i < p_shell->cmd_count; i++) {
- p_cmd = &p_shell->shell_cmd[i];
- if (strcmp(p_cmd->str, cmd_str) == 0) {
- return p_cmd;
- }
- }
- return NULL;
-}

void shell_kick(void)
{
@@ -363,58 +432,12 @@ void shell_kick(void)
}
}

-int shell_process_cmd(char *p_input_line)
-{
- int status = -EINVAL;
- struct shell_cmd *p_cmd;
- char cmd_argv_str[SHELL_CMD_MAX_LEN + 1U];
- int cmd_argv_mem[sizeof(char *) * ((SHELL_CMD_MAX_LEN + 1U) / 2U)];
- int cmd_argc;
- char **cmd_argv;
-
- /* Copy the input line INTo an argument string to become part of the
- * argument vector.
- */
- (void)strcpy_s(&cmd_argv_str[0], SHELL_CMD_MAX_LEN, p_input_line);
- cmd_argv_str[SHELL_CMD_MAX_LEN] = 0;
-
- /* Build the argv vector from the string. The first argument in the
- * resulting vector will be the command string itself.
- */
-
- /* NOTE: This process is destructive to the argument string! */
-
- (void) string_to_argv(&cmd_argv_str[0],
- (void *) &cmd_argv_mem[0],
- sizeof(cmd_argv_mem), (void *)&cmd_argc, &cmd_argv);
-
- /* Determine if there is a command to process. */
- if (cmd_argc != 0) {
- /* See if command is in cmds supported */
- p_cmd = shell_find_cmd(cmd_argv[0]);
- if (p_cmd == NULL) {
- shell_puts("\r\nError: Invalid command.\r\n");
- return -EINVAL;
- }
-
- status = p_cmd->fcn(cmd_argc, &cmd_argv[0]);
- if (status == -EINVAL) {
- shell_puts("\r\nError: Invalid parameters.\r\n");
- } else if (status != 0) {
- shell_puts("\r\nCommand launch failed.\r\n");
- }
- }
-
- return status;
-}

void shell_init(void)
{
p_shell->shell_cmd = shell_cmds;
p_shell->cmd_count = ARRAY_SIZE(shell_cmds);

- (void)strcpy_s((void *)p_shell->name, SHELL_NAME_MAX_LEN, "Serial");
-
/* Zero fill the input buffer */
(void)memset((void *)p_shell->input_line[p_shell->input_line_active], 0U,
SHELL_CMD_MAX_LEN + 1U);
@@ -422,7 +445,7 @@ void shell_init(void)

#define SHELL_ROWS 10
#define MAX_INDENT_LEN 16
-int shell_cmd_help(__unused int argc, __unused char **argv)
+static int shell_cmd_help(__unused int argc, __unused char **argv)
{
int spaces = 0;
struct shell_cmd *p_cmd = NULL;
@@ -496,7 +519,7 @@ int shell_cmd_help(__unused int argc, __unused char **argv)
return 0;
}

-int shell_list_vm(__unused int argc, __unused char **argv)
+static int shell_list_vm(__unused int argc, __unused char **argv)
{
char temp_str[MAX_STR_SIZE];
struct list_head *pos;
@@ -534,7 +557,7 @@ int shell_list_vm(__unused int argc, __unused char **argv)
return 0;
}

-int shell_list_vcpu(__unused int argc, __unused char **argv)
+static int shell_list_vcpu(__unused int argc, __unused char **argv)
{
char temp_str[MAX_STR_SIZE];
struct list_head *pos;
@@ -584,7 +607,7 @@ int shell_list_vcpu(__unused int argc, __unused char **argv)
}

#define DUMPREG_SP_SIZE 32
-int shell_vcpu_dumpreg(int argc, char **argv)
+static int shell_vcpu_dumpreg(int argc, char **argv)
{
int status = 0;
uint16_t vm_id;
@@ -702,7 +725,7 @@ int shell_vcpu_dumpreg(int argc, char **argv)
}

#define MAX_MEMDUMP_LEN (32U*8U)
-int shell_dumpmem(int argc, char **argv)
+static int shell_dumpmem(int argc, char **argv)
{
uint64_t addr;
uint64_t *ptr;
@@ -746,7 +769,7 @@ int shell_dumpmem(int argc, char **argv)
return 0;
}

-int shell_to_sos_console(__unused int argc, __unused char **argv)
+static int shell_to_sos_console(__unused int argc, __unused char **argv)
{
char temp_str[TEMP_STR_SIZE];
uint16_t guest_no = 0U;
@@ -782,7 +805,7 @@ int shell_to_sos_console(__unused int argc, __unused char **argv)
return 0;
}

-int shell_show_cpu_int(__unused int argc, __unused char **argv)
+static int shell_show_cpu_int(__unused int argc, __unused char **argv)
{
char *temp_str = alloc_page();

@@ -798,7 +821,7 @@ int shell_show_cpu_int(__unused int argc, __unused char **argv)
return 0;
}

-int shell_show_ptdev_info(__unused int argc, __unused char **argv)
+static int shell_show_ptdev_info(__unused int argc, __unused char **argv)
{
char *temp_str = alloc_page();

@@ -814,7 +837,7 @@ int shell_show_ptdev_info(__unused int argc, __unused char **argv)
return 0;
}

-int shell_show_vioapic_info(int argc, char **argv)
+static int shell_show_vioapic_info(int argc, char **argv)
{
char *temp_str = alloc_page();
uint16_t vmid;
@@ -842,7 +865,7 @@ int shell_show_vioapic_info(int argc, char **argv)
return -EINVAL;
}

-int shell_show_ioapic_info(__unused int argc, __unused char **argv)
+static int shell_show_ioapic_info(__unused int argc, __unused char **argv)
{
char *temp_str = alloc_pages(2U);

@@ -858,7 +881,7 @@ int shell_show_ioapic_info(__unused int argc, __unused char **argv)
return 0;
}

-int shell_show_vmexit_profile(__unused int argc, __unused char **argv)
+static int shell_show_vmexit_profile(__unused int argc, __unused char **argv)
{
char *temp_str = alloc_pages(2U);

@@ -874,7 +897,7 @@ int shell_show_vmexit_profile(__unused int argc, __unused char **argv)
return 0;
}

-int shell_dump_logbuf(int argc, char **argv)
+static int shell_dump_logbuf(int argc, char **argv)
{
uint16_t pcpu_id;
int val;
@@ -891,7 +914,7 @@ int shell_dump_logbuf(int argc, char **argv)
return -EINVAL;
}

-int shell_loglevel(int argc, char **argv)
+static int shell_loglevel(int argc, char **argv)
{
char str[MAX_STR_SIZE] = {0};

@@ -912,7 +935,7 @@ int shell_loglevel(int argc, char **argv)
return 0;
}

-int shell_cpuid(int argc, char **argv)
+static int shell_cpuid(int argc, char **argv)
{
char str[MAX_STR_SIZE] = {0};
uint32_t leaf, subleaf = 0;
@@ -939,7 +962,7 @@ int shell_cpuid(int argc, char **argv)
return 0;
}

-int shell_trigger_crash(int argc, char **argv)
+static int shell_trigger_crash(int argc, char **argv)
{
char str[MAX_STR_SIZE] = {0};

@@ -951,12 +974,3 @@ int shell_trigger_crash(int argc, char **argv)

return 0;
}
-
-void shell_puts(const char *string_ptr)
-{
- /* Output the string */
- (void)console_write(string_ptr, strnlen_s(string_ptr,
- SHELL_STRING_MAX_LEN));
-}
-
-
diff --git a/hypervisor/debug/shell_priv.h b/hypervisor/debug/shell_priv.h
index 404bac0..159254e 100644
--- a/hypervisor/debug/shell_priv.h
+++ b/hypervisor/debug/shell_priv.h
@@ -4,31 +4,17 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

-#ifndef SHELL_INTER_H
-#define SHELL_INTER_H
+#ifndef SHELL_PRIV_H
+#define SHELL_PRIV_H

#include <spinlock.h>

-struct shell;
-
-
#define SHELL_CMD_MAX_LEN 100U
#define SHELL_NAME_MAX_LEN 50
#define SHELL_PARA_MAX_LEN 64
#define SHELL_HELP_MAX_LEN 256
#define SHELL_STRING_MAX_LEN (CPU_PAGE_SIZE << 2)

-/* Shell Control Block */
-struct shell_cmd;
-struct shell {
- char input_line[2][SHELL_CMD_MAX_LEN + 1U]; /* current & last */
- char name[SHELL_NAME_MAX_LEN]; /* Session name */
- uint32_t input_line_len; /* Length of current input line */
- uint32_t input_line_active; /* Active input line index */
- struct shell_cmd *shell_cmd; /* cmds supported */
- uint32_t cmd_count; /* Count of cmds supported */
-};
-
/* Shell Command Function */
typedef int (*shell_cmd_fn_t)(int argc, char **argv);

@@ -41,6 +27,15 @@ struct shell_cmd {

};

+/* Shell Control Block */
+struct shell {
+ char input_line[2][SHELL_CMD_MAX_LEN + 1U]; /* current & last */
+ uint32_t input_line_len; /* Length of current input line */
+ uint32_t input_line_active; /* Active input line index */
+ struct shell_cmd *shell_cmd; /* cmds supported */
+ uint32_t cmd_count; /* Count of cmds supported */
+};
+
/* Shell Command list with parameters and help description */
#define SHELL_CMD_HELP "help"
#define SHELL_CMD_HELP_PARAM NULL
@@ -101,27 +96,4 @@ struct shell_cmd {
#define SHELL_CMD_CPUID "cpuid"
#define SHELL_CMD_CPUID_PARAM "<leaf> [subleaf]"
#define SHELL_CMD_CPUID_HELP "cpuid leaf [subleaf], in hexadecimal"
-
-/* Global function prototypes */
-int shell_show_req_info(__unused int argc, __unused char **argv);
-int shell_cmd_help(__unused int argc, __unused char **argv);
-int shell_list_vm(__unused int argc, __unused char **argv);
-int shell_list_vcpu(__unused int argc, __unused char **argv);
-int shell_vcpu_dumpreg(int argc, char **argv);
-int shell_dumpmem(int argc, char **argv);
-int shell_to_sos_console(int argc, char **argv);
-int shell_show_cpu_int(__unused int argc, __unused char **argv);
-int shell_show_ptdev_info(__unused int argc, __unused char **argv);
-int shell_reboot(__unused int argc, __unused char **argv);
-int shell_show_vioapic_info(int argc, char **argv);
-int shell_show_ioapic_info(__unused int argc, __unused char **argv);
-int shell_show_vmexit_profile(__unused int argc, __unused char **argv);
-int shell_dump_logbuf(int argc, char **argv);
-int shell_loglevel(int argc, char **argv);
-int shell_cpuid(int argc, char **argv);
-struct shell_cmd *shell_find_cmd(const char *cmd_str);
-int shell_process_cmd(char *p_input_line);
-void shell_puts(const char *string_ptr);
-int shell_trigger_crash(int argc, char **argv);
-
-#endif /* SHELL_INTER_H */
+#endif /* SHELL_PRIV_H */
--
2.7.4


[PATCH 1/4] HV: rename 'shell_internal.h' to 'shell_priv.h'

Yonghua Huang
 

- to align the coding style in hypervisor

Signed-off-by: Yonghua Huang <yonghua.huang@...>
---
hypervisor/debug/shell.c | 2 +-
hypervisor/debug/{shell_internal.h => shell_priv.h} | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename hypervisor/debug/{shell_internal.h => shell_priv.h} (100%)

diff --git a/hypervisor/debug/shell.c b/hypervisor/debug/shell.c
index 5e1dbe6..a3976e6 100644
--- a/hypervisor/debug/shell.c
+++ b/hypervisor/debug/shell.c
@@ -5,7 +5,7 @@
*/

#include <hypervisor.h>
-#include "shell_internal.h"
+#include "shell_priv.h"

#define TEMP_STR_SIZE 60U
#define MAX_STR_SIZE 256U
diff --git a/hypervisor/debug/shell_internal.h b/hypervisor/debug/shell_priv.h
similarity index 100%
rename from hypervisor/debug/shell_internal.h
rename to hypervisor/debug/shell_priv.h
--
2.7.4


Re: [PATCH v5 3/5] idle: enable IRQ in default idle

Yin, Fengwei <fengwei.yin@...>
 

On 8/13/2018 1:56 PM, Jason Chen CJ wrote:
On Mon, Aug 13, 2018 at 09:26:05AM +0800, Yin, Fengwei wrote:

On 08/12/2018 09:19 PM, Chen, Jason CJ wrote:
we should let cpu handle IRQ during idle
This may impact the performance of UOS. Can we get the performance data
with gvt test for this change?

Regards
Yin, Fengwei
hi, Fengwei,
I had a test based on Android GFX bench, there is no performance drop for
offscreen & T-Rex test.
That's good.

Regards
Yin, Fengwei




Signed-off-by: Jason Chen CJ <jason.cj.chen@...>
---
hypervisor/common/schedule.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c
index 1670d5f..a56d59c 100644
--- a/hypervisor/common/schedule.c
+++ b/hypervisor/common/schedule.c
@@ -172,8 +172,11 @@ void default_idle(void)
schedule();
} else if (need_offline(pcpu_id) != 0) {
cpu_dead(pcpu_id);
- } else
+ } else {
+ CPU_IRQ_ENABLE();
cpu_do_idle(pcpu_id);
+ CPU_IRQ_DISABLE();
+ }
}
}


Re: [PATCH v5 3/5] idle: enable IRQ in default idle

Chen, Jason CJ
 

On Mon, Aug 13, 2018 at 09:26:05AM +0800, Yin, Fengwei wrote:

On 08/12/2018 09:19 PM, Chen, Jason CJ wrote:
we should let cpu handle IRQ during idle
This may impact the performance of UOS. Can we get the performance data
with gvt test for this change?

Regards
Yin, Fengwei
hi, Fengwei,

I had a test based on Android GFX bench, there is no performance drop for
offscreen & T-Rex test.



Signed-off-by: Jason Chen CJ <jason.cj.chen@...>
---
hypervisor/common/schedule.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/hypervisor/common/schedule.c b/hypervisor/common/schedule.c
index 1670d5f..a56d59c 100644
--- a/hypervisor/common/schedule.c
+++ b/hypervisor/common/schedule.c
@@ -172,8 +172,11 @@ void default_idle(void)
schedule();
} else if (need_offline(pcpu_id) != 0) {
cpu_dead(pcpu_id);
- } else
+ } else {
+ CPU_IRQ_ENABLE();
cpu_do_idle(pcpu_id);
+ CPU_IRQ_DISABLE();
+ }
}
}
--

Thanks

Jason


[PATCH] HV: hv_main: Add #ifdef HV_DEBUG before debug specific code #ifdef

Kaige Fu
 

vmexit_time and vmexit_cnt is used for debuging only.
This patch encloses these debug specific code using #ifdef HV_DEBUG.

Signed-off-by: Kaige Fu <kaige.fu@...>
---
hypervisor/common/hv_main.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/hypervisor/common/hv_main.c b/hypervisor/common/hv_main.c
index 15f1d9d..e3657f9 100644
--- a/hypervisor/common/hv_main.c
+++ b/hypervisor/common/hv_main.c
@@ -59,11 +59,13 @@ void vcpu_thread(struct vcpu *vcpu)
continue;
}

+#ifdef HV_DEBUG
vmexit_end = rdtsc();
if (vmexit_begin != 0UL) {
per_cpu(vmexit_time, vcpu->pcpu_id)[basic_exit_reason]
+= (vmexit_end - vmexit_begin);
}
+#endif
TRACE_2L(TRACE_VM_ENTER, 0UL, 0UL);

/* Restore guest TSC_AUX */
@@ -79,7 +81,9 @@ void vcpu_thread(struct vcpu *vcpu)
continue;
}

+#ifdef HV_DEBUG
vmexit_begin = rdtsc();
+#endif

vcpu->arch_vcpu.nrexits++;
/* Save guest TSC_AUX */
@@ -90,16 +94,18 @@ void vcpu_thread(struct vcpu *vcpu)
CPU_IRQ_ENABLE();
/* Dispatch handler */
ret = vmexit_handler(vcpu);
+ basic_exit_reason = vcpu->arch_vcpu.exit_reason & 0xFFFFU;
if (ret < 0) {
pr_fatal("dispatch VM exit handler failed for reason"
- " %d, ret = %d!",
- vcpu->arch_vcpu.exit_reason & 0xFFFFU, ret);
+ " %d, ret = %d!", basic_exit_reason, ret);
vcpu_inject_gp(vcpu, 0U);
continue;
}

- basic_exit_reason = vcpu->arch_vcpu.exit_reason & 0xFFFFU;
+#ifdef HV_DEBUG
per_cpu(vmexit_cnt, vcpu->pcpu_id)[basic_exit_reason]++;
+#endif
+
TRACE_2L(TRACE_VM_EXIT, basic_exit_reason, vcpu_get_rip(vcpu));
} while (1);
}
--
2.7.4


Re: [PATCH V2 2/2] hv: add compile time assert for static checks

Eddie Dong
 

Acked...

-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...] On Behalf Of Wu, Binbin
Sent: Monday, August 13, 2018 11:55 AM
To: acrn-dev@...
Subject: [acrn-dev] [PATCH V2 2/2] hv: add compile time assert for static
checks

Add two files to do compile time assert.
One is arch specific, and put in hypervisor/arch/x86/.
The other one is common, and put in hypervisor/common/.

If the statement is not true, there will be error during compile time.
The file will not increase the size of HV binary.

Signed-off-by: Binbin Wu <binbin.wu@...>
Reviewed-by: Junjie Mao <junjie.mao@...>
---
hypervisor/Makefile | 2 ++
hypervisor/arch/x86/cpu.c | 72 -------------------------------------
hypervisor/arch/x86/static_checks.c | 61
+++++++++++++++++++++++++++++++
hypervisor/common/io_request.c | 4 ---
hypervisor/common/static_checks.c | 12 +++++++
5 files changed, 75 insertions(+), 76 deletions(-) create mode 100644
hypervisor/arch/x86/static_checks.c
create mode 100644 hypervisor/common/static_checks.c

diff --git a/hypervisor/Makefile b/hypervisor/Makefile index
b0588b7..a7e3283 100644
--- a/hypervisor/Makefile
+++ b/hypervisor/Makefile
@@ -140,6 +140,7 @@ C_SRCS += arch/x86/cpu_state_tbl.c C_SRCS +=
arch/x86/mtrr.c C_SRCS += arch/x86/pm.c S_SRCS += arch/x86/wakeup.S
+C_SRCS += arch/x86/static_checks.c
C_SRCS += arch/x86/guest/vcpu.c
C_SRCS += arch/x86/guest/vm.c
C_SRCS += arch/x86/guest/vlapic.c
@@ -166,6 +167,7 @@ C_SRCS += common/schedule.c C_SRCS +=
common/vm_load.c C_SRCS += common/io_request.c C_SRCS +=
common/ptdev.c
+C_SRCS += common/static_checks.c

ifdef STACK_PROTECTOR
C_SRCS += common/stack_protector.c
diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index
02cbaec..ad76a67 100644
--- a/hypervisor/arch/x86/cpu.c
+++ b/hypervisor/arch/x86/cpu.c
@@ -375,78 +375,6 @@ void bsp_boot_init(void)
(void)memset(&_ld_bss_start, 0U,
(size_t)(&_ld_bss_end - &_ld_bss_start));

- /* Build time sanity checks to make sure hard-coded offset
- * is matching the actual offset!
- */
- ASSERT((sizeof(struct trusty_startup_param)
- + sizeof(struct trusty_key_info)) < 0x1000U,
- "trusty_startup_param + key_info > 1Page size(4KB)!");
-
- ASSERT(NR_WORLD == 2, "Only 2 Worlds supported!");
- ASSERT(offsetof(struct cpu_gp_regs, rax) ==
- CPU_CONTEXT_OFFSET_RAX,
- "cpu_gp_regs rax offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, rbx) ==
- CPU_CONTEXT_OFFSET_RBX,
- "cpu_gp_regs rbx offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, rcx) ==
- CPU_CONTEXT_OFFSET_RCX,
- "cpu_gp_regs rcx offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, rdx) ==
- CPU_CONTEXT_OFFSET_RDX,
- "cpu_gp_regs rdx offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, rbp) ==
- CPU_CONTEXT_OFFSET_RBP,
- "cpu_gp_regs rbp offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, rsi) ==
- CPU_CONTEXT_OFFSET_RSI,
- "cpu_gp_regs rsi offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, rdi) ==
- CPU_CONTEXT_OFFSET_RDI,
- "cpu_gp_regs rdi offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r8) ==
- CPU_CONTEXT_OFFSET_R8,
- "cpu_gp_regs r8 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r9) ==
- CPU_CONTEXT_OFFSET_R9,
- "cpu_gp_regs r9 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r10) ==
- CPU_CONTEXT_OFFSET_R10,
- "cpu_gp_regs r10 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r11) ==
- CPU_CONTEXT_OFFSET_R11,
- "cpu_gp_regs r11 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r12) ==
- CPU_CONTEXT_OFFSET_R12,
- "cpu_gp_regs r12 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r13) ==
- CPU_CONTEXT_OFFSET_R13,
- "cpu_gp_regs r13 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r14) ==
- CPU_CONTEXT_OFFSET_R14,
- "cpu_gp_regs r14 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r15) ==
- CPU_CONTEXT_OFFSET_R15,
- "cpu_gp_regs r15 offset not match");
- ASSERT(offsetof(struct run_context, cr2) ==
- CPU_CONTEXT_OFFSET_CR2,
- "run_context cr2 offset not match");
- ASSERT(offsetof(struct run_context, ia32_spec_ctrl) ==
- CPU_CONTEXT_OFFSET_IA32_SPEC_CTRL,
- "run_context ia32_spec_ctrl offset not match");
- ASSERT(offsetof(struct run_context, rflags) ==
- CPU_CONTEXT_OFFSET_RFLAGS,
- "run_context rflags offset not match");
- ASSERT(offsetof(struct ext_context, cr3) ==
- CPU_CONTEXT_OFFSET_CR3 -
CPU_CONTEXT_OFFSET_EXTCTX_START,
- "ext_context cr3 offset not match");
- ASSERT(offsetof(struct ext_context, idtr) ==
- CPU_CONTEXT_OFFSET_IDTR -
CPU_CONTEXT_OFFSET_EXTCTX_START,
- "ext_context idtr offset not match");
- ASSERT(offsetof(struct ext_context, ldtr) ==
- CPU_CONTEXT_OFFSET_LDTR -
CPU_CONTEXT_OFFSET_EXTCTX_START,
- "ext_context ldtr offset not match");
-
bitmap_set_nolock(BOOT_CPU_ID, &pcpu_active_bitmap);

misc_en = msr_read(MSR_IA32_MISC_ENABLE); diff --git
a/hypervisor/arch/x86/static_checks.c
b/hypervisor/arch/x86/static_checks.c
new file mode 100644
index 0000000..95e79be
--- /dev/null
+++ b/hypervisor/arch/x86/static_checks.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2018 Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause */ #include <hv_lib.h>
+#include <hv_arch.h> #include <vm0_boot.h>
+
+#define CAT_(A,B) A ## B
+#define CTASSERT(expr) \
+typedef int CAT_(CTA_DummyType,__LINE__)[(expr) ? 1 : -1]
+
+/* Build time sanity checks to make sure hard-coded offset
+* is matching the actual offset!
+*/
+CTASSERT(BOOT_CTX_CR0_OFFSET == offsetof(struct boot_ctx,
cr0));
+CTASSERT(BOOT_CTX_CR3_OFFSET == offsetof(struct boot_ctx,
cr3));
+CTASSERT(BOOT_CTX_CR4_OFFSET == offsetof(struct boot_ctx,
cr4));
+CTASSERT(BOOT_CTX_IDT_OFFSET == offsetof(struct boot_ctx,
idt));
+CTASSERT(BOOT_CTX_GDT_OFFSET == offsetof(struct boot_ctx,
gdt));
+CTASSERT(BOOT_CTX_LDT_SEL_OFFSET == offsetof(struct boot_ctx,
ldt_sel));
+CTASSERT(BOOT_CTX_TR_SEL_OFFSET == offsetof(struct boot_ctx,
tr_sel));
+CTASSERT(BOOT_CTX_CS_SEL_OFFSET == offsetof(struct boot_ctx,
cs_sel));
+CTASSERT(BOOT_CTX_SS_SEL_OFFSET == offsetof(struct boot_ctx,
ss_sel));
+CTASSERT(BOOT_CTX_DS_SEL_OFFSET == offsetof(struct boot_ctx,
ds_sel));
+CTASSERT(BOOT_CTX_ES_SEL_OFFSET == offsetof(struct boot_ctx,
es_sel));
+CTASSERT(BOOT_CTX_FS_SEL_OFFSET == offsetof(struct boot_ctx,
fs_sel));
+CTASSERT(BOOT_CTX_GS_SEL_OFFSET == offsetof(struct boot_ctx,
gs_sel));
+CTASSERT(BOOT_CTX_CS_AR_OFFSET == offsetof(struct boot_ctx,
cs_ar));
+CTASSERT(BOOT_CTX_EFER_LOW_OFFSET == offsetof(struct boot_ctx,
+ia32_efer)); CTASSERT(BOOT_CTX_EFER_HIGH_OFFSET == offsetof(struct
+boot_ctx, ia32_efer) + 4);
+
+CTASSERT(CPU_CONTEXT_OFFSET_RAX == offsetof(struct cpu_gp_regs,
rax));
+CTASSERT(CPU_CONTEXT_OFFSET_RBX == offsetof(struct cpu_gp_regs,
rbx));
+CTASSERT(CPU_CONTEXT_OFFSET_RCX == offsetof(struct cpu_gp_regs,
rcx));
+CTASSERT(CPU_CONTEXT_OFFSET_RDX == offsetof(struct cpu_gp_regs,
rdx));
+CTASSERT(CPU_CONTEXT_OFFSET_RBP == offsetof(struct cpu_gp_regs,
rbp));
+CTASSERT(CPU_CONTEXT_OFFSET_RSI == offsetof(struct cpu_gp_regs,
rsi));
+CTASSERT(CPU_CONTEXT_OFFSET_RDI == offsetof(struct cpu_gp_regs,
rdi));
+CTASSERT(CPU_CONTEXT_OFFSET_R8 == offsetof(struct cpu_gp_regs,
r8));
+CTASSERT(CPU_CONTEXT_OFFSET_R9 == offsetof(struct cpu_gp_regs,
r9));
+CTASSERT(CPU_CONTEXT_OFFSET_R10 == offsetof(struct cpu_gp_regs,
r10));
+CTASSERT(CPU_CONTEXT_OFFSET_R11 == offsetof(struct cpu_gp_regs,
r11));
+CTASSERT(CPU_CONTEXT_OFFSET_R12 == offsetof(struct cpu_gp_regs,
r12));
+CTASSERT(CPU_CONTEXT_OFFSET_R13 == offsetof(struct cpu_gp_regs,
r13));
+CTASSERT(CPU_CONTEXT_OFFSET_R14 == offsetof(struct cpu_gp_regs,
r14));
+CTASSERT(CPU_CONTEXT_OFFSET_R15 == offsetof(struct cpu_gp_regs,
r15));
+CTASSERT(CPU_CONTEXT_OFFSET_CR2 == offsetof(struct run_context,
cr2));
+CTASSERT(CPU_CONTEXT_OFFSET_IA32_SPEC_CTRL
+ == offsetof(struct run_context, ia32_spec_ctrl));
+CTASSERT(CPU_CONTEXT_OFFSET_RFLAGS == offsetof(struct run_context,
+rflags));
+CTASSERT(CPU_CONTEXT_OFFSET_CR3 -
CPU_CONTEXT_OFFSET_EXTCTX_START
+ == offsetof(struct ext_context, cr3));
+CTASSERT(CPU_CONTEXT_OFFSET_IDTR -
CPU_CONTEXT_OFFSET_EXTCTX_START
+ == offsetof(struct ext_context, idtr));
+CTASSERT(CPU_CONTEXT_OFFSET_LDTR -
CPU_CONTEXT_OFFSET_EXTCTX_START
+ == offsetof(struct ext_context, ldtr));
CTASSERT((sizeof(struct
+trusty_startup_param)
+ + sizeof(struct trusty_key_info)) < 0x1000U); CTASSERT(NR_WORLD
==
+2);
diff --git a/hypervisor/common/io_request.c
b/hypervisor/common/io_request.c index 7897d6c..743c4ed 100644
--- a/hypervisor/common/io_request.c
+++ b/hypervisor/common/io_request.c
@@ -62,10 +62,6 @@ acrn_insert_request_wait(struct vcpu *vcpu, struct
io_request *io_req)
struct vhm_request *vhm_req;
uint16_t cur;

- ASSERT(sizeof(struct vhm_request) == (4096U/VHM_REQUEST_MAX),
- "vhm_request page broken!");
-
-
if (vcpu == NULL || io_req == NULL ||
vcpu->vm->sw.io_shared_page == NULL) {
return -EINVAL;
diff --git a/hypervisor/common/static_checks.c
b/hypervisor/common/static_checks.c
new file mode 100644
index 0000000..7c3692f
--- /dev/null
+++ b/hypervisor/common/static_checks.c
@@ -0,0 +1,12 @@
+/*
+ * Copyright (C) 2018 Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause */ #include <acrn_common.h>
+
+#define CAT_(A,B) A ## B
+#define CTASSERT(expr) \
+typedef int CAT_(CTA_DummyType,__LINE__)[(expr) ? 1 : -1]
+
+CTASSERT(sizeof(struct vhm_request) == (4096U/VHM_REQUEST_MAX));
--
2.7.4



Re: [PATCH] HV: add pcpu id check before send IPI

Minggui Cao
 

OK,will do it, and then submit a PR.

-----Original Message-----
From: Xu, Anthony
Sent: Saturday, August 11, 2018 5:55 AM
To: acrn-dev@...
Cc: Cao, Minggui <minggui.cao@...>
Subject: RE: [acrn-dev] [PATCH] HV: add pcpu id check before send IPI

Can you fix below code as well?

Anthony

void make_pcpu_offline(uint16_t pcpu_id) {
struct sched_context *ctx = &per_cpu(sched_ctx, pcpu_id);

bitmap_set_lock(NEED_OFFLINE, &ctx->flags);
send_single_ipi(pcpu_id, VECTOR_NOTIFY_VCPU); }



-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...]
On Behalf Of Minggui Cao
Sent: Thursday, August 9, 2018 11:36 PM
To: acrn-dev@...
Cc: Cao, Minggui <minggui.cao@...>
Subject: [acrn-dev] [PATCH] HV: add pcpu id check before send IPI

to avoid send IPI to self, also improve the related code:
1. get_cpu_id is uint16_t now
2. MISRA-C requirement. like add {}

Signed-off-by: Minggui Cao <minggui.cao@...>
---
hypervisor/arch/x86/virq.c | 3 ++-
hypervisor/arch/x86/vmexit.c | 2 +-
hypervisor/common/schedule.c | 4 +++-
3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/hypervisor/arch/x86/virq.c b/hypervisor/arch/x86/virq.c
index e9c46f7..4d3cf35 100644
--- a/hypervisor/arch/x86/virq.c
+++ b/hypervisor/arch/x86/virq.c
@@ -104,8 +104,9 @@ void vcpu_make_request(struct vcpu *vcpu, uint16_t
eventid)
* scheduling, we need change here to determine it target vcpu is
* VMX non-root or root mode
*/
- if ((int)get_cpu_id() != vcpu->pcpu_id)
+ if (get_cpu_id() != vcpu->pcpu_id) {
send_single_ipi(vcpu->pcpu_id, VECTOR_NOTIFY_VCPU);
+ }
}

static int vcpu_do_pending_event(struct vcpu *vcpu) diff --git
a/hypervisor/arch/x86/vmexit.c b/hypervisor/arch/x86/vmexit.c index
7f6eb40..ac908d1 100644
--- a/hypervisor/arch/x86/vmexit.c
+++ b/hypervisor/arch/x86/vmexit.c
@@ -157,7 +157,7 @@ int vmexit_handler(struct vcpu *vcpu)
uint16_t basic_exit_reason;
int ret;

- if ((int)get_cpu_id() != vcpu->pcpu_id) {
+ if (get_cpu_id() != vcpu->pcpu_id) {
pr_fatal("vcpu is not running on its pcpu!");
return -EINVAL;
}
diff --git a/hypervisor/common/schedule.c
b/hypervisor/common/schedule.c index 1670d5f..ead3435 100644
--- a/hypervisor/common/schedule.c
+++ b/hypervisor/common/schedule.c
@@ -101,7 +101,9 @@ void make_reschedule_request(struct vcpu *vcpu)
struct sched_context *ctx = &per_cpu(sched_ctx, vcpu->pcpu_id);

bitmap_set_lock(NEED_RESCHEDULE, &ctx->flags);
- send_single_ipi(vcpu->pcpu_id, VECTOR_NOTIFY_VCPU);
+ if (get_cpu_id() != vcpu->pcpu_id) {
+ send_single_ipi(vcpu->pcpu_id, VECTOR_NOTIFY_VCPU);
+ }
}

int need_reschedule(uint16_t pcpu_id)
--
2.7.4



[PATCH V2 2/2] hv: add compile time assert for static checks

Wu, Binbin
 

Add two files to do compile time assert.
One is arch specific, and put in hypervisor/arch/x86/.
The other one is common, and put in hypervisor/common/.

If the statement is not true, there will be error during compile time.
The file will not increase the size of HV binary.

Signed-off-by: Binbin Wu <binbin.wu@...>
Reviewed-by: Junjie Mao <junjie.mao@...>
---
hypervisor/Makefile | 2 ++
hypervisor/arch/x86/cpu.c | 72 -------------------------------------
hypervisor/arch/x86/static_checks.c | 61 +++++++++++++++++++++++++++++++
hypervisor/common/io_request.c | 4 ---
hypervisor/common/static_checks.c | 12 +++++++
5 files changed, 75 insertions(+), 76 deletions(-)
create mode 100644 hypervisor/arch/x86/static_checks.c
create mode 100644 hypervisor/common/static_checks.c

diff --git a/hypervisor/Makefile b/hypervisor/Makefile
index b0588b7..a7e3283 100644
--- a/hypervisor/Makefile
+++ b/hypervisor/Makefile
@@ -140,6 +140,7 @@ C_SRCS += arch/x86/cpu_state_tbl.c
C_SRCS += arch/x86/mtrr.c
C_SRCS += arch/x86/pm.c
S_SRCS += arch/x86/wakeup.S
+C_SRCS += arch/x86/static_checks.c
C_SRCS += arch/x86/guest/vcpu.c
C_SRCS += arch/x86/guest/vm.c
C_SRCS += arch/x86/guest/vlapic.c
@@ -166,6 +167,7 @@ C_SRCS += common/schedule.c
C_SRCS += common/vm_load.c
C_SRCS += common/io_request.c
C_SRCS += common/ptdev.c
+C_SRCS += common/static_checks.c

ifdef STACK_PROTECTOR
C_SRCS += common/stack_protector.c
diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c
index 02cbaec..ad76a67 100644
--- a/hypervisor/arch/x86/cpu.c
+++ b/hypervisor/arch/x86/cpu.c
@@ -375,78 +375,6 @@ void bsp_boot_init(void)
(void)memset(&_ld_bss_start, 0U,
(size_t)(&_ld_bss_end - &_ld_bss_start));

- /* Build time sanity checks to make sure hard-coded offset
- * is matching the actual offset!
- */
- ASSERT((sizeof(struct trusty_startup_param)
- + sizeof(struct trusty_key_info)) < 0x1000U,
- "trusty_startup_param + key_info > 1Page size(4KB)!");
-
- ASSERT(NR_WORLD == 2, "Only 2 Worlds supported!");
- ASSERT(offsetof(struct cpu_gp_regs, rax) ==
- CPU_CONTEXT_OFFSET_RAX,
- "cpu_gp_regs rax offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, rbx) ==
- CPU_CONTEXT_OFFSET_RBX,
- "cpu_gp_regs rbx offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, rcx) ==
- CPU_CONTEXT_OFFSET_RCX,
- "cpu_gp_regs rcx offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, rdx) ==
- CPU_CONTEXT_OFFSET_RDX,
- "cpu_gp_regs rdx offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, rbp) ==
- CPU_CONTEXT_OFFSET_RBP,
- "cpu_gp_regs rbp offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, rsi) ==
- CPU_CONTEXT_OFFSET_RSI,
- "cpu_gp_regs rsi offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, rdi) ==
- CPU_CONTEXT_OFFSET_RDI,
- "cpu_gp_regs rdi offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r8) ==
- CPU_CONTEXT_OFFSET_R8,
- "cpu_gp_regs r8 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r9) ==
- CPU_CONTEXT_OFFSET_R9,
- "cpu_gp_regs r9 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r10) ==
- CPU_CONTEXT_OFFSET_R10,
- "cpu_gp_regs r10 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r11) ==
- CPU_CONTEXT_OFFSET_R11,
- "cpu_gp_regs r11 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r12) ==
- CPU_CONTEXT_OFFSET_R12,
- "cpu_gp_regs r12 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r13) ==
- CPU_CONTEXT_OFFSET_R13,
- "cpu_gp_regs r13 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r14) ==
- CPU_CONTEXT_OFFSET_R14,
- "cpu_gp_regs r14 offset not match");
- ASSERT(offsetof(struct cpu_gp_regs, r15) ==
- CPU_CONTEXT_OFFSET_R15,
- "cpu_gp_regs r15 offset not match");
- ASSERT(offsetof(struct run_context, cr2) ==
- CPU_CONTEXT_OFFSET_CR2,
- "run_context cr2 offset not match");
- ASSERT(offsetof(struct run_context, ia32_spec_ctrl) ==
- CPU_CONTEXT_OFFSET_IA32_SPEC_CTRL,
- "run_context ia32_spec_ctrl offset not match");
- ASSERT(offsetof(struct run_context, rflags) ==
- CPU_CONTEXT_OFFSET_RFLAGS,
- "run_context rflags offset not match");
- ASSERT(offsetof(struct ext_context, cr3) ==
- CPU_CONTEXT_OFFSET_CR3 - CPU_CONTEXT_OFFSET_EXTCTX_START,
- "ext_context cr3 offset not match");
- ASSERT(offsetof(struct ext_context, idtr) ==
- CPU_CONTEXT_OFFSET_IDTR - CPU_CONTEXT_OFFSET_EXTCTX_START,
- "ext_context idtr offset not match");
- ASSERT(offsetof(struct ext_context, ldtr) ==
- CPU_CONTEXT_OFFSET_LDTR - CPU_CONTEXT_OFFSET_EXTCTX_START,
- "ext_context ldtr offset not match");
-
bitmap_set_nolock(BOOT_CPU_ID, &pcpu_active_bitmap);

misc_en = msr_read(MSR_IA32_MISC_ENABLE);
diff --git a/hypervisor/arch/x86/static_checks.c b/hypervisor/arch/x86/static_checks.c
new file mode 100644
index 0000000..95e79be
--- /dev/null
+++ b/hypervisor/arch/x86/static_checks.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2018 Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+#include <hv_lib.h>
+#include <hv_arch.h>
+#include <vm0_boot.h>
+
+#define CAT_(A,B) A ## B
+#define CTASSERT(expr) \
+typedef int CAT_(CTA_DummyType,__LINE__)[(expr) ? 1 : -1]
+
+/* Build time sanity checks to make sure hard-coded offset
+* is matching the actual offset!
+*/
+CTASSERT(BOOT_CTX_CR0_OFFSET == offsetof(struct boot_ctx, cr0));
+CTASSERT(BOOT_CTX_CR3_OFFSET == offsetof(struct boot_ctx, cr3));
+CTASSERT(BOOT_CTX_CR4_OFFSET == offsetof(struct boot_ctx, cr4));
+CTASSERT(BOOT_CTX_IDT_OFFSET == offsetof(struct boot_ctx, idt));
+CTASSERT(BOOT_CTX_GDT_OFFSET == offsetof(struct boot_ctx, gdt));
+CTASSERT(BOOT_CTX_LDT_SEL_OFFSET == offsetof(struct boot_ctx, ldt_sel));
+CTASSERT(BOOT_CTX_TR_SEL_OFFSET == offsetof(struct boot_ctx, tr_sel));
+CTASSERT(BOOT_CTX_CS_SEL_OFFSET == offsetof(struct boot_ctx, cs_sel));
+CTASSERT(BOOT_CTX_SS_SEL_OFFSET == offsetof(struct boot_ctx, ss_sel));
+CTASSERT(BOOT_CTX_DS_SEL_OFFSET == offsetof(struct boot_ctx, ds_sel));
+CTASSERT(BOOT_CTX_ES_SEL_OFFSET == offsetof(struct boot_ctx, es_sel));
+CTASSERT(BOOT_CTX_FS_SEL_OFFSET == offsetof(struct boot_ctx, fs_sel));
+CTASSERT(BOOT_CTX_GS_SEL_OFFSET == offsetof(struct boot_ctx, gs_sel));
+CTASSERT(BOOT_CTX_CS_AR_OFFSET == offsetof(struct boot_ctx, cs_ar));
+CTASSERT(BOOT_CTX_EFER_LOW_OFFSET == offsetof(struct boot_ctx, ia32_efer));
+CTASSERT(BOOT_CTX_EFER_HIGH_OFFSET == offsetof(struct boot_ctx, ia32_efer) + 4);
+
+CTASSERT(CPU_CONTEXT_OFFSET_RAX == offsetof(struct cpu_gp_regs, rax));
+CTASSERT(CPU_CONTEXT_OFFSET_RBX == offsetof(struct cpu_gp_regs, rbx));
+CTASSERT(CPU_CONTEXT_OFFSET_RCX == offsetof(struct cpu_gp_regs, rcx));
+CTASSERT(CPU_CONTEXT_OFFSET_RDX == offsetof(struct cpu_gp_regs, rdx));
+CTASSERT(CPU_CONTEXT_OFFSET_RBP == offsetof(struct cpu_gp_regs, rbp));
+CTASSERT(CPU_CONTEXT_OFFSET_RSI == offsetof(struct cpu_gp_regs, rsi));
+CTASSERT(CPU_CONTEXT_OFFSET_RDI == offsetof(struct cpu_gp_regs, rdi));
+CTASSERT(CPU_CONTEXT_OFFSET_R8 == offsetof(struct cpu_gp_regs, r8));
+CTASSERT(CPU_CONTEXT_OFFSET_R9 == offsetof(struct cpu_gp_regs, r9));
+CTASSERT(CPU_CONTEXT_OFFSET_R10 == offsetof(struct cpu_gp_regs, r10));
+CTASSERT(CPU_CONTEXT_OFFSET_R11 == offsetof(struct cpu_gp_regs, r11));
+CTASSERT(CPU_CONTEXT_OFFSET_R12 == offsetof(struct cpu_gp_regs, r12));
+CTASSERT(CPU_CONTEXT_OFFSET_R13 == offsetof(struct cpu_gp_regs, r13));
+CTASSERT(CPU_CONTEXT_OFFSET_R14 == offsetof(struct cpu_gp_regs, r14));
+CTASSERT(CPU_CONTEXT_OFFSET_R15 == offsetof(struct cpu_gp_regs, r15));
+CTASSERT(CPU_CONTEXT_OFFSET_CR2 == offsetof(struct run_context, cr2));
+CTASSERT(CPU_CONTEXT_OFFSET_IA32_SPEC_CTRL
+ == offsetof(struct run_context, ia32_spec_ctrl));
+CTASSERT(CPU_CONTEXT_OFFSET_RFLAGS == offsetof(struct run_context, rflags));
+CTASSERT(CPU_CONTEXT_OFFSET_CR3 - CPU_CONTEXT_OFFSET_EXTCTX_START
+ == offsetof(struct ext_context, cr3));
+CTASSERT(CPU_CONTEXT_OFFSET_IDTR - CPU_CONTEXT_OFFSET_EXTCTX_START
+ == offsetof(struct ext_context, idtr));
+CTASSERT(CPU_CONTEXT_OFFSET_LDTR - CPU_CONTEXT_OFFSET_EXTCTX_START
+ == offsetof(struct ext_context, ldtr));
+CTASSERT((sizeof(struct trusty_startup_param)
+ + sizeof(struct trusty_key_info)) < 0x1000U);
+CTASSERT(NR_WORLD == 2);
diff --git a/hypervisor/common/io_request.c b/hypervisor/common/io_request.c
index 7897d6c..743c4ed 100644
--- a/hypervisor/common/io_request.c
+++ b/hypervisor/common/io_request.c
@@ -62,10 +62,6 @@ acrn_insert_request_wait(struct vcpu *vcpu, struct io_request *io_req)
struct vhm_request *vhm_req;
uint16_t cur;

- ASSERT(sizeof(struct vhm_request) == (4096U/VHM_REQUEST_MAX),
- "vhm_request page broken!");
-
-
if (vcpu == NULL || io_req == NULL ||
vcpu->vm->sw.io_shared_page == NULL) {
return -EINVAL;
diff --git a/hypervisor/common/static_checks.c b/hypervisor/common/static_checks.c
new file mode 100644
index 0000000..7c3692f
--- /dev/null
+++ b/hypervisor/common/static_checks.c
@@ -0,0 +1,12 @@
+/*
+ * Copyright (C) 2018 Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+#include <acrn_common.h>
+
+#define CAT_(A,B) A ## B
+#define CTASSERT(expr) \
+typedef int CAT_(CTA_DummyType,__LINE__)[(expr) ? 1 : -1]
+
+CTASSERT(sizeof(struct vhm_request) == (4096U/VHM_REQUEST_MAX));
--
2.7.4


[PATCH V2 1/2] hv: move boot_ctx offset definitions

Wu, Binbin
 

Move the definitions of offset of fields in boot_ctx to the same header
file that the struct boot_ctx is in, to reduce the possibility that some
modification would make the offset inconsistant with the fields within
the structure.

Signed-off-by: Binbin Wu <binbin.wu@...>
---
hypervisor/arch/x86/cpu_save_boot_ctx.S | 17 +----------
hypervisor/include/arch/x86/guest/vm0_boot.h | 44 ++++++++++++++++++++++++----
2 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/hypervisor/arch/x86/cpu_save_boot_ctx.S b/hypervisor/arch/x86/cpu_save_boot_ctx.S
index c7b7be2..8e36c00 100644
--- a/hypervisor/arch/x86/cpu_save_boot_ctx.S
+++ b/hypervisor/arch/x86/cpu_save_boot_ctx.S
@@ -4,22 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

-#define BOOT_CTX_CR0_OFFSET 0
-#define BOOT_CTX_CR3_OFFSET 8
-#define BOOT_CTX_CR4_OFFSET 16
-#define BOOT_CTX_IDT_OFFSET 24
-#define BOOT_CTX_GDT_OFFSET 34
-#define BOOT_CTX_LDT_SEL_OFFSET 44
-#define BOOT_CTX_TR_SEL_OFFSET 46
-#define BOOT_CTX_CS_SEL_OFFSET 48
-#define BOOT_CTX_SS_SEL_OFFSET 50
-#define BOOT_CTX_DS_SEL_OFFSET 52
-#define BOOT_CTX_ES_SEL_OFFSET 54
-#define BOOT_CTX_FS_SEL_OFFSET 56
-#define BOOT_CTX_GS_SEL_OFFSET 58
-#define BOOT_CTX_CS_AR_OFFSET 60
-#define BOOT_CTX_EFER_LOW_OFFSET 64
-#define BOOT_CTX_EFER_HIGH_OFFSET 68
+#include <vm0_boot.h>

.section entry, "ax"
.align 8
diff --git a/hypervisor/include/arch/x86/guest/vm0_boot.h b/hypervisor/include/arch/x86/guest/vm0_boot.h
index aeace43..b7e149b 100644
--- a/hypervisor/include/arch/x86/guest/vm0_boot.h
+++ b/hypervisor/include/arch/x86/guest/vm0_boot.h
@@ -7,20 +7,54 @@
#ifndef VM0_BOOT_H
#define VM0_BOOT_H

+#ifdef ASSEMBLER
+#define BOOT_CTX_CR0_OFFSET 0
+#define BOOT_CTX_CR3_OFFSET 8
+#define BOOT_CTX_CR4_OFFSET 16
+#define BOOT_CTX_IDT_OFFSET 24
+#define BOOT_CTX_GDT_OFFSET 34
+#define BOOT_CTX_LDT_SEL_OFFSET 44
+#define BOOT_CTX_TR_SEL_OFFSET 46
+#define BOOT_CTX_CS_SEL_OFFSET 48
+#define BOOT_CTX_SS_SEL_OFFSET 50
+#define BOOT_CTX_DS_SEL_OFFSET 52
+#define BOOT_CTX_ES_SEL_OFFSET 54
+#define BOOT_CTX_FS_SEL_OFFSET 56
+#define BOOT_CTX_GS_SEL_OFFSET 58
+#define BOOT_CTX_CS_AR_OFFSET 60
+#define BOOT_CTX_EFER_LOW_OFFSET 64
+#define BOOT_CTX_EFER_HIGH_OFFSET 68
+#else
#include <gpr.h>
+#define BOOT_CTX_CR0_OFFSET 0U
+#define BOOT_CTX_CR3_OFFSET 8U
+#define BOOT_CTX_CR4_OFFSET 16U
+#define BOOT_CTX_IDT_OFFSET 24U
+#define BOOT_CTX_GDT_OFFSET 34U
+#define BOOT_CTX_LDT_SEL_OFFSET 44U
+#define BOOT_CTX_TR_SEL_OFFSET 46U
+#define BOOT_CTX_CS_SEL_OFFSET 48U
+#define BOOT_CTX_SS_SEL_OFFSET 50U
+#define BOOT_CTX_DS_SEL_OFFSET 52U
+#define BOOT_CTX_ES_SEL_OFFSET 54U
+#define BOOT_CTX_FS_SEL_OFFSET 56U
+#define BOOT_CTX_GS_SEL_OFFSET 58U
+#define BOOT_CTX_CS_AR_OFFSET 60U
+#define BOOT_CTX_EFER_LOW_OFFSET 64U
+#define BOOT_CTX_EFER_HIGH_OFFSET 68U

-typedef struct {
+struct dt_addr {
uint16_t limit;
uint64_t base;
-} __attribute__((packed)) dt_addr_t;
+} __attribute__((packed));

struct boot_ctx {
uint64_t cr0;
uint64_t cr3;
uint64_t cr4;

- dt_addr_t idt;
- dt_addr_t gdt;
+ struct dt_addr idt;
+ struct dt_addr gdt;
uint16_t ldt_sel;
uint16_t tr_sel;

@@ -47,5 +81,5 @@ struct boot_ctx {
void *get_rsdp_from_uefi(void);
void *get_ap_trampoline_buf(void);
#endif
-
+#endif /* ASSEMBLER */
#endif /* VM0_BOOT_H */
--
2.7.4


[PATCH V2 0/2] hv: add compile time assert

Wu, Binbin
 

The patch series moves the definitions of offset of fields in boot_ctx to the
same header file that the struct boot_ctx is in, to reduce the possibility that
some modification would make the offset inconsistant with the fields within
the structure.

Also, the patch series adds two files to do compile time assert.
One is arch specific, and put in hypervisor/arch/x86/.
The other one is common, and put in hypervisor/common/.
If the statement is not true, there will be error during compile time.
The source files will not increase the size of HV binary.

V1->V2:
Move other ASSERT statements, which should be checked in compile time.
Rename dummy.c to static_checks.c
Two static_checks.c, one for x86 arch specific code, the other for common code.

Binbin Wu (2):
hv: move boot_ctx offset definitions
hv: add compile time assert for static checks

hypervisor/Makefile | 2 +
hypervisor/arch/x86/cpu.c | 72 ----------------------------
hypervisor/arch/x86/cpu_save_boot_ctx.S | 17 +------
hypervisor/arch/x86/static_checks.c | 61 +++++++++++++++++++++++
hypervisor/common/io_request.c | 4 --
hypervisor/common/static_checks.c | 12 +++++
hypervisor/include/arch/x86/guest/vm0_boot.h | 44 +++++++++++++++--
7 files changed, 115 insertions(+), 97 deletions(-)
create mode 100644 hypervisor/arch/x86/static_checks.c
create mode 100644 hypervisor/common/static_checks.c

--
2.7.4


[PATCH V2 3/3] dm: monotor: bugfix: update wakeup reason before call recume() callback

Tao, Yuhong
 

In handle_resume(), wakeup_reason is updated before call
ops->ops->resume(). Because ops->ops->resume() needs to know the
latest wakeup reason.

Signed-off-by: Tao Yuhong <yuhong.tao@...>
---
devicemodel/core/monitor.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/devicemodel/core/monitor.c b/devicemodel/core/monitor.c
index c5b41f1..4b97c5a 100644
--- a/devicemodel/core/monitor.c
+++ b/devicemodel/core/monitor.c
@@ -168,6 +168,8 @@ static void handle_resume(struct mngr_msg *msg, int client_fd, void *param)
ack.msgid = msg->msgid;
ack.timestamp = msg->timestamp;

+ wakeup_reason = msg->data.reason;
+
LIST_FOREACH(ops, &vm_ops_head, list) {
if (ops->ops->resume) {
ret += ops->ops->resume(ops->arg);
@@ -181,8 +183,6 @@ static void handle_resume(struct mngr_msg *msg, int client_fd, void *param)
} else
ack.data.err = ret;

- wakeup_reason = msg->data.reason;
-
mngr_send_msg(client_fd, &ack, NULL, ACK_TIMEOUT);
}

--
2.7.4


[PATCH V2 2/3] tools: acrnd: Fixed get_sos_wakeup_reason()

Tao, Yuhong
 

get_sos_wakeup_reason() runs into error branch without any error, so
no wakeup reason will be returend.

Signed-off-by: Tao Yuhong <yuhong.tao@...>
---
tools/acrn-manager/acrnd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/acrn-manager/acrnd.c b/tools/acrn-manager/acrnd.c
index 94ed4ef..162daae 100644
--- a/tools/acrn-manager/acrnd.c
+++ b/tools/acrn-manager/acrnd.c
@@ -284,7 +284,7 @@ unsigned get_sos_wakeup_reason(void)
req.msgid = WAKEUP_REASON;
req.timestamp = time(NULL);

- if (mngr_send_msg(client_fd, &req, &ack, DEFAULT_TIMEOUT))
+ if (mngr_send_msg(client_fd, &req, &ack, DEFAULT_TIMEOUT) <= 0)
fprintf(stderr, "Failed to get wakeup_reason from SOS, err(%d)\n", ret);
else
ret = ack.data.reason;
--
2.7.4