Skip to contentSkip to conversation

x86: refactor trap handling code

PATCH Superseded Wei Liu 3 participants 72 messages Jun 8, 2017 – Jun 23, 2017

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

v4 cover x86: refactor trap handling code

V4 of this series, rebased on top of staging.

git://xenbits.xen.org/people/liuw/xen.git wip.move-traps-v4

Wei Liu (27):
x86: factor out common PV emulation code
x86: move PV privileged instruction emulation code
x86: move PV gate op emulation code
x86: move PV invalid op emulation code
x86/traps: remove now unused inclusion of emulate.h
x86: clean up PV emulation code
x86: move do_set_trap_table to pv/traps.c
x86: move some misc PV hypercalls to misc-hypercalls.c x86/traps: move pv_inject_event to pv/traps.c
x86/traps: move set_guest_{machine,nmi}_trapbounce x86:/traps: move {un,}register_guest_nmi_callback x86/traps: move guest_has_trap_callback to pv/traps.c
x86: move toggle_guest_mode to pv/domain.c
x86: move do_iret to pv/iret.c
x86: move callback_op code to pv/callback.c
x86/traps: factor out pv_trap_init
x86/traps: move some PV specific functions and struct to pv/traps.c x86/traps: move init_int80_direct_trap to pv/traps.c
x86: move hypercall_page_initialise_ring3_kernel to pv/hypercall.c
x86: move hypercall_page_initialise_ring1_kernel
x86: move compat_set_trap_table along side the non-compat variant
x86: move compat_iret along side its non-compat variant
x86: move the compat callback ops next to the non-compat variant
x86: move compat_show_guest_statck near its non-compat variant
x86: remove the now empty x86_64/compat/traps.c
x86: fix coding a style issue in asm-x86/traps.h
x86: clean up traps.c

 xen/arch/x86/pv/Makefile                 |    8 +
 xen/arch/x86/pv/callback.c               |  299 ++++
 xen/arch/x86/pv/domain.c                 |   30 +
 xen/arch/x86/pv/emul-gate-op.c           |  439 ++++++
 xen/arch/x86/pv/emul-inv-op.c            |  123 ++
 xen/arch/x86/pv/emul-priv-op.c           | 1418 +++++++++++++++++
 xen/arch/x86/pv/emulate.c                |   98 ++
 xen/arch/x86/pv/emulate.h                |   10 +
 xen/arch/x86/{x86_64 => pv}/gpr_switch.S |    0
 xen/arch/x86/pv/hypercall.c              |   67 +
 xen/arch/x86/pv/iret.c                   |  192 +++
 xen/arch/x86/pv/misc-hypercalls.c        |   78 +
 xen/arch/x86/pv/traps.c                  |  370 +++++
 xen/arch/x86/traps.c                     | 2497 +++---------------------------
 xen/arch/x86/x86_64/Makefile             |    1 -
 xen/arch/x86/x86_64/compat/traps.c       |  416 -----
 xen/arch/x86/x86_64/traps.c              |  286 ----
 xen/include/asm-x86/hypercall.h          |    2 +
 xen/include/asm-x86/processor.h          |    3 -
 xen/include/asm-x86/pv/traps.h           |   56 +
 xen/include/asm-x86/traps.h              |   24 +-
 21 files changed, 3382 insertions(+), 3035 deletions(-)
 create mode 100644 xen/arch/x86/pv/callback.c
 create mode 100644 xen/arch/x86/pv/emul-gate-op.c
 create mode 100644 xen/arch/x86/pv/emul-inv-op.c
 create mode 100644 xen/arch/x86/pv/emul-priv-op.c
 create mode 100644 xen/arch/x86/pv/emulate.c
 create mode 100644 xen/arch/x86/pv/emulate.h
 rename xen/arch/x86/{x86_64 => pv}/gpr_switch.S (100%)
 create mode 100644 xen/arch/x86/pv/iret.c
 create mode 100644 xen/arch/x86/pv/misc-hypercalls.c
 delete mode 100644 xen/arch/x86/x86_64/compat/traps.c
 create mode 100644 xen/include/asm-x86/pv/traps.h
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#16 lore raw

PATCH v4 5/27 x86/traps: remove now unused inclusion of emulate.h

---
Can be squashed into previous patch. Kept separated in case further code churn is required.

---
 xen/arch/x86/traps.c | 2 --
 1 file changed, 2 deletions(-)
xen/arch/x86/traps.c +0 -2
index ff25f679f5..b5642b0f9a 100644
@@ -79,8 +79,6 @@
 #include <xsm/xsm.h>
 #include <asm/pv/traps.h>
 
-#include "pv/emulate.h"
-
 /*
  * opt_nmi: one of 'ignore', 'dom0', or 'fatal'.
  *  fatal:  Xen prints diagnostic message and then hangs.
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#20 lore raw

PATCH v4 7/27 x86: move do_set_trap_table to pv/traps.c

In reply to Wei Liu
---
 xen/arch/x86/pv/traps.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/traps.c    | 49 ----------------------------------------------
 2 files changed, 52 insertions(+), 49 deletions(-)
xen/arch/x86/pv/traps.c +52 -0
index 51125a8d86..6e69f2ad58 100644
@@ -19,7 +19,10 @@
  * Copyright (c) 2017 Citrix Systems Ltd.
  */
 
+#include <xen/event.h>
+#include <xen/guest_access.h>
 #include <xen/hypercall.h>
+#include <xen/sched.h>
 
 #include <asm/apic.h>
 
@@ -31,6 +34,55 @@ void do_entry_int82(struct cpu_user_regs *regs)
     pv_hypercall(regs);
 }
 
+long do_set_trap_table(XEN_GUEST_HANDLE_PARAM(const_trap_info_t) traps)
+{
+    struct trap_info cur;
+    struct vcpu *curr = current;
+    struct trap_info *dst = curr->arch.pv_vcpu.trap_ctxt;
+    long rc = 0;
+
+    /* If no table is presented then clear the entire virtual IDT. */
+    if ( guest_handle_is_null(traps) )
+    {
+        memset(dst, 0, NR_VECTORS * sizeof(*dst));
+        init_int80_direct_trap(curr);
+        return 0;
+    }
+
+    for ( ; ; )
+    {
+        if ( copy_from_guest(&cur, traps, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
+        if ( cur.address == 0 )
+            break;
+
+        if ( !is_canonical_address(cur.address) )
+            return -EINVAL;
+
+        fixup_guest_code_selector(curr->domain, cur.cs);
+
+        memcpy(&dst[cur.vector], &cur, sizeof(cur));
+
+        if ( cur.vector == 0x80 )
+            init_int80_direct_trap(curr);
+
+        guest_handle_add_offset(traps, 1);
+
+        if ( hypercall_preempt_check() )
+        {
+            rc = hypercall_create_continuation(
+                __HYPERVISOR_set_trap_table, "h", traps);
+            break;
+        }
+    }
+
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/traps.c +0 -49

55 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#1 lore raw

PATCH v4 1/27 x86: factor out common PV emulation code

In reply to Wei Liu

We're going to split PV emulation code into several files. This patch extracts the functions needed by them into a dedicated file.

The functions are now prefixed with "pv_emul_" and exported via a local header file.

While at it, change bool_t to bool.

---
 xen/arch/x86/pv/Makefile  |  1 +
 xen/arch/x86/pv/emulate.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/pv/emulate.h | 10 +++++
 xen/arch/x86/traps.c      | 95 ++++++++-------------------------------------
 4 files changed, 126 insertions(+), 78 deletions(-)
 create mode 100644 xen/arch/x86/pv/emulate.c
 create mode 100644 xen/arch/x86/pv/emulate.h
xen/arch/x86/pv/Makefile +1 -0
index 489a9f59cb..564202cbb7 100644
@@ -3,3 +3,4 @@ obj-y += traps.o
 
 obj-bin-y += dom0_build.init.o
 obj-y += domain.o
+obj-y += emulate.o
xen/arch/x86/pv/emulate.c new file +98 -0

98 lines not on this page · raw message

xen/arch/x86/pv/emulate.h new file +10 -0
new file mode 100644
index 0000000000..b2b1192d48
@@ -0,0 +1,10 @@
+#ifndef __PV_EMULATE_H__
+#define __PV_EMULATE_H__
+
+int pv_emul_read_descriptor(unsigned int sel, const struct vcpu *v,
+                            unsigned long *base, unsigned long *limit,
+                            unsigned int *ar, bool insn_fetch);
+
+void pv_emul_instruction_done(struct cpu_user_regs *regs, unsigned long rip);
+
+#endif /* __PV_EMULATE_H__ */
xen/arch/x86/traps.c +17 -78

179 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#24 lore raw

PATCH v4 8/27 x86: move some misc PV hypercalls to misc-hypercalls.c

In reply to Wei Liu
---
 xen/arch/x86/pv/Makefile          |  1 +
 xen/arch/x86/pv/misc-hypercalls.c | 78 +++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/traps.c              | 44 ----------------------
 3 files changed, 79 insertions(+), 44 deletions(-)
 create mode 100644 xen/arch/x86/pv/misc-hypercalls.c
xen/arch/x86/pv/Makefile +1 -0
index 42ca64dc9e..939ea60bea 100644
@@ -8,3 +8,4 @@ obj-y += emul-gate-op.o
 obj-y += emul-inv-op.o
 obj-y += emul-priv-op.o
 obj-bin-y += gpr_switch.o
+obj-y += misc-hypercalls.o
xen/arch/x86/pv/misc-hypercalls.c new file +78 -0

78 lines not on this page · raw message

xen/arch/x86/traps.c +0 -44

56 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#7 lore raw

PATCH v4 4/27 x86: move PV invalid op emulation code

In reply to Wei Liu

Move the code to pv/emul-inv-op.c. Prefix emulate_* functions with pv_ and export them via pv/traps.h.

Pure code motion except for the rename.

---
 xen/arch/x86/pv/Makefile       |   1 +
 xen/arch/x86/pv/emul-inv-op.c  | 123 +++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/traps.c           |  75 +------------------------
 xen/include/asm-x86/pv/traps.h |   4 ++
 4 files changed, 130 insertions(+), 73 deletions(-)
 create mode 100644 xen/arch/x86/pv/emul-inv-op.c
xen/arch/x86/pv/Makefile +1 -0
index 1f6fbd3f5c..42ca64dc9e 100644
@@ -5,5 +5,6 @@ obj-bin-y += dom0_build.init.o
 obj-y += domain.o
 obj-y += emulate.o
 obj-y += emul-gate-op.o
+obj-y += emul-inv-op.o
 obj-y += emul-priv-op.o
 obj-bin-y += gpr_switch.o
xen/arch/x86/pv/emul-inv-op.c new file +123 -0

123 lines not on this page · raw message

xen/arch/x86/traps.c +2 -73

87 lines not on this page · raw message

xen/include/asm-x86/pv/traps.h +4 -0
index 3f3bab4d8c..a4af69e486 100644
@@ -27,11 +27,15 @@
 
 int pv_emulate_privileged_op(struct cpu_user_regs *regs);
 void pv_emulate_gate_op(struct cpu_user_regs *regs);
+int pv_emulate_invalid_rdtscp(struct cpu_user_regs *regs);
+int pv_emulate_forced_invalid_op(struct cpu_user_regs *regs);
 
 #else  /* !CONFIG_PV */
 
 int pv_emulate_privileged_op(struct cpu_user_regs *regs) { return 0; }
 void pv_emulate_gate_op(struct cpu_user_regs *regs) {}
+int pv_emulate_invalid_rdtscp(struct cpu_user_regs *regs) { return 0; }
+int pv_emulate_forced_invalid_op(struct cpu_user_regs *regs) { return 0; }
 
 #endif /* CONFIG_PV */
 
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#18 lore raw

PATCH v4 6/27 x86: clean up PV emulation code

In reply to Wei Liu

Replace bool_t with bool. Fix coding style issues. Add spaces around binary ops. Use 1U for shifting. Eliminate TOGGLE_MODE.

---
 xen/arch/x86/pv/emul-gate-op.c |  5 ++-
 xen/arch/x86/pv/emul-priv-op.c | 82 ++++++++++++++++++++++--------------------
 2 files changed, 45 insertions(+), 42 deletions(-)
xen/arch/x86/pv/emul-gate-op.c +2 -3
index 97a4b31a56..cdf3b308f2 100644
@@ -50,7 +50,6 @@ static int read_gate_descriptor(unsigned int gate_sel,
     struct desc_struct desc;
     const struct desc_struct *pdesc;
 
-
     pdesc = (const struct desc_struct *)
         (!(gate_sel & 4) ? GDT_VIRT_START(v) : LDT_VIRT_START(v))
         + (gate_sel >> 3);
@@ -97,8 +96,8 @@ static int read_gate_descriptor(unsigned int gate_sel,
     return 1;
 }
 
-static inline int check_stack_limit(unsigned int ar, unsigned int limit,
-                                    unsigned int esp, unsigned int decr)
+static inline bool check_stack_limit(unsigned int ar, unsigned int limit,
+                                     unsigned int esp, unsigned int decr)
 {
     return (((esp - decr) < (esp - 1)) &&
             (!(ar & _SEGMENT_EC) ? (esp - 1) <= limit : (esp - decr) > limit));
xen/arch/x86/pv/emul-priv-op.c +43 -39

196 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#26 lore raw

PATCH v4 9/27 x86/traps: move pv_inject_event to pv/traps.c

In reply to Wei Liu

Take the opportunity to rename "v" to "curr".

No functional change.

---
 xen/arch/x86/pv/traps.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/traps.c    | 69 ----------------------------------------------
 2 files changed, 73 insertions(+), 69 deletions(-)
xen/arch/x86/pv/traps.c +73 -0
index 6e69f2ad58..ec7ff1040b 100644
@@ -22,9 +22,13 @@
 #include <xen/event.h>
 #include <xen/guest_access.h>
 #include <xen/hypercall.h>
+#include <xen/lib.h>
 #include <xen/sched.h>
+#include <xen/trace.h>
 
 #include <asm/apic.h>
+#include <asm/shared.h>
+#include <asm/traps.h>
 
 void do_entry_int82(struct cpu_user_regs *regs)
 {
@@ -83,6 +87,75 @@ long do_set_trap_table(XEN_GUEST_HANDLE_PARAM(const_trap_info_t) traps)
     return rc;
 }
 
+void pv_inject_event(const struct x86_event *event)
+{
+    struct vcpu *curr = current;
+    struct cpu_user_regs *regs = guest_cpu_user_regs();
+    struct trap_bounce *tb;
+    const struct trap_info *ti;
+    const uint8_t vector = event->vector;
+    unsigned int error_code = event->error_code;
+    bool use_error_code;
+
+    ASSERT(vector == event->vector); /* Confirm no truncation. */
+    if ( event->type == X86_EVENTTYPE_HW_EXCEPTION )
+    {
+        ASSERT(vector < 32);
+        use_error_code = TRAP_HAVE_EC & (1u << vector);
+    }
+    else
+    {
+        ASSERT(event->type == X86_EVENTTYPE_SW_INTERRUPT);
+        use_error_code = false;
+    }
+    if ( use_error_code )
+        ASSERT(error_code != X86_EVENT_NO_EC);
+    else
+        ASSERT(error_code == X86_EVENT_NO_EC);
+
+    tb = &curr->arch.pv_vcpu.trap_bounce;
+    ti = &curr->arch.pv_vcpu.trap_ctxt[vector];
+
+    tb->flags = TBF_EXCEPTION;
+    tb->cs    = ti->cs;
+    tb->eip   = ti->address;
+
+    if ( event->type == X86_EVENTTYPE_HW_EXCEPTION &&
+         vector == TRAP_page_fault )
+    {
+        curr->arch.pv_vcpu.ctrlreg[2] = event->cr2;
+        arch_set_cr2(curr, event->cr2);
+
+        /* Re-set error_code.user flag appropriately for the guest. */
+        error_code &= ~PFEC_user_mode;
+        if ( !guest_kernel_mode(curr, regs) )
+            error_code |= PFEC_user_mode;
+
+        trace_pv_page_fault(event->cr2, error_code);
+    }
+    else
+        trace_pv_trap(vector, regs->rip, use_error_code, error_code);
+
+    if ( use_error_code )
+    {
+        tb->flags |= TBF_EXCEPTION_ERRCODE;
+        tb->error_code = error_code;
+    }
+
+    if ( TI_GET_IF(ti) )
+        tb->flags |= TBF_INTERRUPT;
+
+    if ( unlikely(null_trap_bounce(curr, tb)) )
+    {
+        gprintk(XENLOG_WARNING,
+                "Unhandled %s fault/trap [#%d, ec=%04x]\n",
+                trapstr(vector), vector, error_code);
+
+        if ( vector == TRAP_page_fault )
+            show_page_walk(event->cr2);
+    }
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/traps.c +0 -69

75 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#3 lore raw

PATCH v4 2/27 x86: move PV privileged instruction emulation code

In reply to Wei Liu

Move the code to pv/emul-priv-op.c. Prefix emulate_privileged_op with pv_ and export it via pv/traps.h.

Also move gpr_switch.S since it is used by the privileged instruction emulation code only.

Code motion only except for the rename. Cleanup etc will come later.

---
 xen/arch/x86/pv/Makefile                 |    2 +
 xen/arch/x86/pv/emul-priv-op.c           | 1414 ++++++++++++++++++++++++++++++
 xen/arch/x86/{x86_64 => pv}/gpr_switch.S |    0
 xen/arch/x86/traps.c                     | 1360 +---------------------------
 xen/arch/x86/x86_64/Makefile             |    1 -
 xen/include/asm-x86/pv/traps.h           |   46 +
 6 files changed, 1464 insertions(+), 1359 deletions(-)
 create mode 100644 xen/arch/x86/pv/emul-priv-op.c
 rename xen/arch/x86/{x86_64 => pv}/gpr_switch.S (100%)
 create mode 100644 xen/include/asm-x86/pv/traps.h
xen/arch/x86/pv/Makefile +2 -0
index 564202cbb7..e48c460680 100644
@@ -4,3 +4,5 @@ obj-y += traps.o
 obj-bin-y += dom0_build.init.o
 obj-y += domain.o
 obj-y += emulate.o
+obj-y += emul-priv-op.o
+obj-bin-y += gpr_switch.o
xen/arch/x86/pv/emul-priv-op.c new file +1414 -0

1,414 lines not on this page · raw message

xen/arch/x86/pv/gpr_switch.S renamed from xen/arch/x86/x86_64/gpr_switch.S +0 -0
similarity index 100%
rename from xen/arch/x86/x86_64/gpr_switch.S
rename to xen/arch/x86/pv/gpr_switch.S
xen/arch/x86/traps.c +2 -1358

1,384 lines not on this page · raw message

xen/arch/x86/x86_64/Makefile +0 -1
index d8815e78b0..f336a6ae65 100644
@@ -1,7 +1,6 @@
 subdir-y += compat
 
 obj-bin-y += entry.o
-obj-bin-y += gpr_switch.o
 obj-y += traps.o
 obj-$(CONFIG_KEXEC) += machine_kexec.o
 obj-y += pci.o
xen/include/asm-x86/pv/traps.h new file +46 -0

46 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#5 lore raw

PATCH v4 3/27 x86: move PV gate op emulation code

In reply to Wei Liu

Move the code to pv/emul-gate-op.c. Prefix emulate_gate_op with pv_ and export it via pv/traps.h.

Pure code motion except for the rename.

---
 xen/arch/x86/pv/Makefile       |   1 +
 xen/arch/x86/pv/emul-gate-op.c | 440 +++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/traps.c           | 390 +-----------------------------------
 xen/include/asm-x86/pv/traps.h |   2 +
 4 files changed, 444 insertions(+), 389 deletions(-)
 create mode 100644 xen/arch/x86/pv/emul-gate-op.c
xen/arch/x86/pv/Makefile +1 -0
index e48c460680..1f6fbd3f5c 100644
@@ -4,5 +4,6 @@ obj-y += traps.o
 obj-bin-y += dom0_build.init.o
 obj-y += domain.o
 obj-y += emulate.o
+obj-y += emul-gate-op.o
 obj-y += emul-priv-op.o
 obj-bin-y += gpr_switch.o
xen/arch/x86/pv/emul-gate-op.c new file +440 -0

440 lines not on this page · raw message

xen/arch/x86/traps.c +1 -389

402 lines not on this page · raw message

xen/include/asm-x86/pv/traps.h +2 -0
index 5aeb061551..3f3bab4d8c 100644
@@ -26,10 +26,12 @@
 #include <public/xen.h>
 
 int pv_emulate_privileged_op(struct cpu_user_regs *regs);
+void pv_emulate_gate_op(struct cpu_user_regs *regs);
 
 #else  /* !CONFIG_PV */
 
 int pv_emulate_privileged_op(struct cpu_user_regs *regs) { return 0; }
+void pv_emulate_gate_op(struct cpu_user_regs *regs) {}
 
 #endif /* CONFIG_PV */
 
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#35 lore raw

PATCH v4 13/27 x86: move toggle_guest_mode to pv/domain.c

In reply to Wei Liu
---
 xen/arch/x86/pv/domain.c    | 30 ++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/traps.c | 30 ------------------------------
 2 files changed, 30 insertions(+), 30 deletions(-)
xen/arch/x86/pv/domain.c +30 -0
index 1c0c040ca0..0f3f0e85d6 100644
@@ -213,6 +213,36 @@ int pv_domain_initialise(struct domain *d, unsigned int domcr_flags,
     return rc;
 }
 
+void toggle_guest_mode(struct vcpu *v)
+{
+    if ( is_pv_32bit_vcpu(v) )
+        return;
+    if ( cpu_has_fsgsbase )
+    {
+        if ( v->arch.flags & TF_kernel_mode )
+            v->arch.pv_vcpu.gs_base_kernel = __rdgsbase();
+        else
+            v->arch.pv_vcpu.gs_base_user = __rdgsbase();
+    }
+    v->arch.flags ^= TF_kernel_mode;
+    asm volatile ( "swapgs" );
+    update_cr3(v);
+    /* Don't flush user global mappings from the TLB. Don't tick TLB clock. */
+    asm volatile ( "mov %0, %%cr3" : : "r" (v->arch.cr3) : "memory" );
+
+    if ( !(v->arch.flags & TF_kernel_mode) )
+        return;
+
+    if ( v->arch.pv_vcpu.need_update_runstate_area &&
+         update_runstate_area(v) )
+        v->arch.pv_vcpu.need_update_runstate_area = 0;
+
+    if ( v->arch.pv_vcpu.pending_system_time.version &&
+         update_secondary_system_time(v,
+                                      &v->arch.pv_vcpu.pending_system_time) )
+        v->arch.pv_vcpu.pending_system_time.version = 0;
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/x86_64/traps.c +0 -30
index 78f410517c..36b694c605 100644
@@ -254,36 +254,6 @@ void do_double_fault(struct cpu_user_regs *regs)
     panic("DOUBLE FAULT -- system shutdown");
 }
 
-void toggle_guest_mode(struct vcpu *v)
-{
-    if ( is_pv_32bit_vcpu(v) )
-        return;
-    if ( cpu_has_fsgsbase )
-    {
-        if ( v->arch.flags & TF_kernel_mode )
-            v->arch.pv_vcpu.gs_base_kernel = __rdgsbase();
-        else
-            v->arch.pv_vcpu.gs_base_user = __rdgsbase();
-    }
-    v->arch.flags ^= TF_kernel_mode;
-    asm volatile ( "swapgs" );
-    update_cr3(v);
-    /* Don't flush user global mappings from the TLB. Don't tick TLB clock. */
-    asm volatile ( "mov %0, %%cr3" : : "r" (v->arch.cr3) : "memory" );
-
-    if ( !(v->arch.flags & TF_kernel_mode) )
-        return;
-
-    if ( v->arch.pv_vcpu.need_update_runstate_area &&
-         update_runstate_area(v) )
-        v->arch.pv_vcpu.need_update_runstate_area = 0;
-
-    if ( v->arch.pv_vcpu.pending_system_time.version &&
-         update_secondary_system_time(v,
-                                      &v->arch.pv_vcpu.pending_system_time) )
-        v->arch.pv_vcpu.pending_system_time.version = 0;
-}
-
 unsigned long do_iret(void)
 {
     struct cpu_user_regs *regs = guest_cpu_user_regs();
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#57 lore raw

PATCH v4 21/27 x86: move compat_set_trap_table along side the non-compat variant

In reply to Wei Liu
---
 xen/arch/x86/pv/traps.c            | 45 ++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/compat/traps.c | 45 --------------------------------------
 2 files changed, 45 insertions(+), 45 deletions(-)
xen/arch/x86/pv/traps.c +45 -0
index f2556c7e4a..3dcb3f1877 100644
@@ -87,6 +87,51 @@ long do_set_trap_table(XEN_GUEST_HANDLE_PARAM(const_trap_info_t) traps)
     return rc;
 }
 
+int compat_set_trap_table(XEN_GUEST_HANDLE(trap_info_compat_t) traps)
+{
+    struct compat_trap_info cur;
+    struct trap_info *dst = current->arch.pv_vcpu.trap_ctxt;
+    long rc = 0;
+
+    /* If no table is presented then clear the entire virtual IDT. */
+    if ( guest_handle_is_null(traps) )
+    {
+        memset(dst, 0, NR_VECTORS * sizeof(*dst));
+        init_int80_direct_trap(current);
+        return 0;
+    }
+
+    for ( ; ; )
+    {
+        if ( copy_from_guest(&cur, traps, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
+        if ( cur.address == 0 )
+            break;
+
+        fixup_guest_code_selector(current->domain, cur.cs);
+
+        XLAT_trap_info(dst + cur.vector, &cur);
+
+        if ( cur.vector == 0x80 )
+            init_int80_direct_trap(current);
+
+        guest_handle_add_offset(traps, 1);
+
+        if ( hypercall_preempt_check() )
+        {
+            rc = hypercall_create_continuation(
+                __HYPERVISOR_set_trap_table, "h", traps);
+            break;
+        }
+    }
+
+    return rc;
+}
+
 void pv_inject_event(const struct x86_event *event)
 {
     struct vcpu *curr = current;
xen/arch/x86/x86_64/compat/traps.c +0 -45

51 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#33 lore raw

PATCH v4 12/27 x86/traps: move guest_has_trap_callback to pv/traps.c

In reply to Wei Liu

Take the chance to constify pointers, replace uint16_t with unsigned int etc.

---
 xen/arch/x86/pv/traps.c     | 18 ++++++++++++++++++
 xen/arch/x86/traps.c        | 18 ------------------
 xen/include/asm-x86/traps.h |  6 +++---
 3 files changed, 21 insertions(+), 21 deletions(-)
xen/arch/x86/pv/traps.c +18 -0
index d0e651616d..be215df57a 100644
@@ -219,6 +219,24 @@ long unregister_guest_nmi_callback(void)
     return 0;
 }
 
+bool guest_has_trap_callback(const struct domain *d, unsigned int vcpuid,
+                             unsigned int trap_nr)
+{
+    const struct vcpu *v;
+    const struct trap_info *t;
+
+    BUG_ON(d == NULL);
+    BUG_ON(vcpuid >= d->max_vcpus);
+
+    /* Sanity check - XXX should be more fine grained. */
+    BUG_ON(trap_nr >= NR_VECTORS);
+
+    v = d->vcpu[vcpuid];
+    t = &v->arch.pv_vcpu.trap_ctxt[trap_nr];
+
+    return t->address;
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/traps.c +0 -18
index babb476097..8861dfd332 100644
@@ -1909,24 +1909,6 @@ void __init trap_init(void)
     open_softirq(PCI_SERR_SOFTIRQ, pci_serr_softirq);
 }
 
-int guest_has_trap_callback(struct domain *d, uint16_t vcpuid, unsigned int trap_nr)
-{
-    struct vcpu *v;
-    struct trap_info *t;
-
-    BUG_ON(d == NULL);
-    BUG_ON(vcpuid >= d->max_vcpus);
-
-    /* Sanity check - XXX should be more fine grained. */
-    BUG_ON(trap_nr >= NR_VECTORS);
-
-    v = d->vcpu[vcpuid];
-    t = &v->arch.pv_vcpu.trap_ctxt[trap_nr];
-
-    return (t->address != 0);
-}
-
-
 int send_guest_trap(struct domain *d, uint16_t vcpuid, unsigned int trap_nr)
 {
     struct vcpu *v;
xen/include/asm-x86/traps.h +3 -3
index f1d2513e6b..26625ce5a6 100644
@@ -32,10 +32,10 @@ void async_exception_cleanup(struct vcpu *);
 /**
  * guest_has_trap_callback
  *
- * returns true (non-zero) if guest registered a trap handler
+ * returns true if guest registered a trap handler
  */
-extern int guest_has_trap_callback(struct domain *d, uint16_t vcpuid,
-				unsigned int trap_nr);
+bool guest_has_trap_callback(const struct domain *d, unsigned int vcpuid,
+                             unsigned int trap_nr);
 
 /**
  * send_guest_trap
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#41 lore raw

PATCH v4 15/27 x86: move callback_op code to pv/callback.c

In reply to Wei Liu
---
 xen/arch/x86/pv/Makefile    |   1 +
 xen/arch/x86/pv/callback.c  | 157 ++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/traps.c | 148 -----------------------------------------
 3 files changed, 158 insertions(+), 148 deletions(-)
 create mode 100644 xen/arch/x86/pv/callback.c
xen/arch/x86/pv/Makefile +1 -0
index 7e3da332d8..bd1a7081fc 100644
@@ -1,6 +1,7 @@
 obj-y += hypercall.o
 obj-y += traps.o
 
+obj-y += callback.o
 obj-bin-y += dom0_build.init.o
 obj-y += domain.o
 obj-y += emulate.o
xen/arch/x86/pv/callback.c new file +157 -0

157 lines not on this page · raw message

xen/arch/x86/x86_64/traps.c +0 -148

160 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#53 lore raw

PATCH v4 20/27 x86: move hypercall_page_initialise_ring1_kernel

In reply to Wei Liu
---
 xen/arch/x86/pv/hypercall.c        | 31 +++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/compat/traps.c | 31 -------------------------------
 xen/include/asm-x86/hypercall.h    |  1 +
 3 files changed, 32 insertions(+), 31 deletions(-)
xen/arch/x86/pv/hypercall.c +31 -0
index 287340e774..58dc0f5c32 100644
@@ -291,6 +291,37 @@ void hypercall_page_initialise_ring3_kernel(void *hypercall_page)
     *(u16 *)(p+ 9) = 0x050f;  /* syscall */
 }
 
+void hypercall_page_initialise_ring1_kernel(void *hypercall_page)
+{
+    char *p;
+    int i;
+
+    /* Fill in all the transfer points with template machine code. */
+
+    for ( i = 0; i < (PAGE_SIZE / 32); i++ )
+    {
+        if ( i == __HYPERVISOR_iret )
+            continue;
+
+        p = (char *)(hypercall_page + (i * 32));
+        *(u8  *)(p+ 0) = 0xb8;    /* mov  $<i>,%eax */
+        *(u32 *)(p+ 1) = i;
+        *(u16 *)(p+ 5) = (HYPERCALL_VECTOR << 8) | 0xcd; /* int  $xx */
+        *(u8  *)(p+ 7) = 0xc3;    /* ret */
+    }
+
+    /*
+     * HYPERVISOR_iret is special because it doesn't return and expects a
+     * special stack frame. Guests jump at this transfer point instead of
+     * calling it.
+     */
+    p = (char *)(hypercall_page + (__HYPERVISOR_iret * 32));
+    *(u8  *)(p+ 0) = 0x50;    /* push %eax */
+    *(u8  *)(p+ 1) = 0xb8;    /* mov  $__HYPERVISOR_iret,%eax */
+    *(u32 *)(p+ 2) = __HYPERVISOR_iret;
+    *(u16 *)(p+ 6) = (HYPERCALL_VECTOR << 8) | 0xcd; /* int  $xx */
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/x86_64/compat/traps.c +0 -31
index 1751ec67e8..f485299c88 100644
@@ -374,37 +374,6 @@ int compat_set_trap_table(XEN_GUEST_HANDLE(trap_info_compat_t) traps)
     return rc;
 }
 
-static void hypercall_page_initialise_ring1_kernel(void *hypercall_page)
-{
-    char *p;
-    int i;
-
-    /* Fill in all the transfer points with template machine code. */
-
-    for ( i = 0; i < (PAGE_SIZE / 32); i++ )
-    {
-        if ( i == __HYPERVISOR_iret )
-            continue;
-
-        p = (char *)(hypercall_page + (i * 32));
-        *(u8  *)(p+ 0) = 0xb8;    /* mov  $<i>,%eax */
-        *(u32 *)(p+ 1) = i;
-        *(u16 *)(p+ 5) = (HYPERCALL_VECTOR << 8) | 0xcd; /* int  $xx */
-        *(u8  *)(p+ 7) = 0xc3;    /* ret */
-    }
-
-    /*
-     * HYPERVISOR_iret is special because it doesn't return and expects a
-     * special stack frame. Guests jump at this transfer point instead of
-     * calling it.
-     */
-    p = (char *)(hypercall_page + (__HYPERVISOR_iret * 32));
-    *(u8  *)(p+ 0) = 0x50;    /* push %eax */
-    *(u8  *)(p+ 1) = 0xb8;    /* mov  $__HYPERVISOR_iret,%eax */
-    *(u32 *)(p+ 2) = __HYPERVISOR_iret;
-    *(u16 *)(p+ 6) = (HYPERCALL_VECTOR << 8) | 0xcd; /* int  $xx */
-}
-
 /*
  * Local variables:
  * mode: C
xen/include/asm-x86/hypercall.h +1 -0
index 5631cf2694..3eb4a8db89 100644
@@ -27,6 +27,7 @@ extern const hypercall_args_t hypercall_args_table[NR_hypercalls];
 
 void pv_hypercall(struct cpu_user_regs *regs);
 void hypercall_page_initialise_ring3_kernel(void *hypercall_page);
+void hypercall_page_initialise_ring1_kernel(void *hypercall_page);
 
 /*
  * Both do_mmuext_op() and do_mmu_update():
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#42 lore raw

PATCH v4 16/27 x86/traps: factor out pv_trap_init

In reply to Wei Liu
---
 xen/arch/x86/traps.c           | 22 ++++++++++++++--------
 xen/include/asm-x86/pv/traps.h |  4 ++++
 2 files changed, 18 insertions(+), 8 deletions(-)
xen/arch/x86/traps.c +14 -8
index 8861dfd332..29a83994bd 100644
@@ -1871,14 +1871,8 @@ void __init init_idt_traps(void)
     this_cpu(compat_gdt_table) = boot_cpu_compat_gdt_table;
 }
 
-extern void (*const autogen_entrypoints[NR_VECTORS])(void);
-void __init trap_init(void)
+void __init pv_trap_init(void)
 {
-    unsigned int vector;
-
-    /* Replace early pagefault with real pagefault handler. */
-    set_intr_gate(TRAP_page_fault, &page_fault);
-
     /* The 32-on-64 hypercall vector is only accessible from ring 1. */
     _set_gate(idt_table + HYPERCALL_VECTOR,
               SYS_DESC_trap_gate, 1, entry_int82);
@@ -1886,6 +1880,19 @@ void __init trap_init(void)
     /* Fast trap for int80 (faster than taking the #GP-fixup path). */
     _set_gate(idt_table + 0x80, SYS_DESC_trap_gate, 3, &int80_direct_trap);
 
+    open_softirq(NMI_MCE_SOFTIRQ, nmi_mce_softirq);
+}
+
+extern void (*const autogen_entrypoints[NR_VECTORS])(void);
+void __init trap_init(void)
+{
+    unsigned int vector;
+
+    pv_trap_init();
+
+    /* Replace early pagefault with real pagefault handler. */
+    set_intr_gate(TRAP_page_fault, &page_fault);
+
     for ( vector = 0; vector < NR_VECTORS; ++vector )
     {
         if ( autogen_entrypoints[vector] )
@@ -1905,7 +1912,6 @@ void __init trap_init(void)
 
     cpu_init();
 
-    open_softirq(NMI_MCE_SOFTIRQ, nmi_mce_softirq);
     open_softirq(PCI_SERR_SOFTIRQ, pci_serr_softirq);
 }
 
xen/include/asm-x86/pv/traps.h +4 -0
index a4af69e486..426c8f6216 100644
@@ -25,6 +25,8 @@
 
 #include <public/xen.h>
 
+void pv_trap_init(void);
+
 int pv_emulate_privileged_op(struct cpu_user_regs *regs);
 void pv_emulate_gate_op(struct cpu_user_regs *regs);
 int pv_emulate_invalid_rdtscp(struct cpu_user_regs *regs);
@@ -32,6 +34,8 @@ int pv_emulate_forced_invalid_op(struct cpu_user_regs *regs);
 
 #else  /* !CONFIG_PV */
 
+void pv_trap_init(void) {}
+
 int pv_emulate_privileged_op(struct cpu_user_regs *regs) { return 0; }
 void pv_emulate_gate_op(struct cpu_user_regs *regs) {}
 int pv_emulate_invalid_rdtscp(struct cpu_user_regs *regs) { return 0; }
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#28 lore raw

PATCH v4 10/27 x86/traps: move set_guest_{machine, nmi}_trapbounce

In reply to Wei Liu

Take the opportunity to change their return type to bool. And rename "v" to "curr".

---
 xen/arch/x86/pv/traps.c | 27 +++++++++++++++++++++++++++
 xen/arch/x86/traps.c    | 27 ---------------------------
 2 files changed, 27 insertions(+), 27 deletions(-)
xen/arch/x86/pv/traps.c +27 -0
index ec7ff1040b..e374cd73b4 100644
@@ -156,6 +156,33 @@ void pv_inject_event(const struct x86_event *event)
     }
 }
 
+/*
+ * Called from asm to set up the MCE trapbounce info.
+ * Returns false no callback is set up, else true.
+ */
+bool set_guest_machinecheck_trapbounce(void)
+{
+    struct vcpu *curr = current;
+    struct trap_bounce *tb = &curr->arch.pv_vcpu.trap_bounce;
+
+    pv_inject_hw_exception(TRAP_machine_check, X86_EVENT_NO_EC);
+    tb->flags &= ~TBF_EXCEPTION; /* not needed for MCE delivery path */
+    return !null_trap_bounce(curr, tb);
+}
+
+/*
+ * Called from asm to set up the NMI trapbounce info.
+ * Returns false if no callback is set up, else true.
+ */
+bool set_guest_nmi_trapbounce(void)
+{
+    struct vcpu *curr = current;
+    struct trap_bounce *tb = &curr->arch.pv_vcpu.trap_bounce;
+    pv_inject_hw_exception(TRAP_nmi, X86_EVENT_NO_EC);
+    tb->flags &= ~TBF_EXCEPTION; /* not needed for NMI delivery path */
+    return !null_trap_bounce(curr, tb);
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/traps.c +0 -27
index 6abfb62c0c..013de702ad 100644
@@ -626,33 +626,6 @@ void fatal_trap(const struct cpu_user_regs *regs, bool_t show_remote)
           (regs->eflags & X86_EFLAGS_IF) ? "" : ", IN INTERRUPT CONTEXT");
 }
 
-/*
- * Called from asm to set up the MCE trapbounce info.
- * Returns 0 if no callback is set up, else 1.
- */
-int set_guest_machinecheck_trapbounce(void)
-{
-    struct vcpu *v = current;
-    struct trap_bounce *tb = &v->arch.pv_vcpu.trap_bounce;
- 
-    pv_inject_hw_exception(TRAP_machine_check, X86_EVENT_NO_EC);
-    tb->flags &= ~TBF_EXCEPTION; /* not needed for MCE delivery path */
-    return !null_trap_bounce(v, tb);
-}
-
-/*
- * Called from asm to set up the NMI trapbounce info.
- * Returns 0 if no callback is set up, else 1.
- */
-int set_guest_nmi_trapbounce(void)
-{
-    struct vcpu *v = current;
-    struct trap_bounce *tb = &v->arch.pv_vcpu.trap_bounce;
-    pv_inject_hw_exception(TRAP_nmi, X86_EVENT_NO_EC);
-    tb->flags &= ~TBF_EXCEPTION; /* not needed for NMI delivery path */
-    return !null_trap_bounce(v, tb);
-}
-
 void do_reserved_trap(struct cpu_user_regs *regs)
 {
     unsigned int trapnr = regs->entry_vector;
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#59 lore raw

PATCH v4 22/27 x86: move compat_iret along side its non-compat variant

In reply to Wei Liu
---
 xen/arch/x86/pv/iret.c             | 120 +++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/compat/traps.c | 120 -------------------------------------
 2 files changed, 120 insertions(+), 120 deletions(-)
xen/arch/x86/pv/iret.c +120 -0
index 358ae7cf08..013e619b3f 100644
@@ -61,6 +61,126 @@ unsigned long do_iret(void)
     return 0;
 }
 
+unsigned int compat_iret(void)
+{
+    struct cpu_user_regs *regs = guest_cpu_user_regs();
+    struct vcpu *v = current;
+    u32 eflags;
+
+    /* Trim stack pointer to 32 bits. */
+    regs->rsp = (u32)regs->rsp;
+
+    /* Restore EAX (clobbered by hypercall). */
+    if ( unlikely(__get_user(regs->eax, (u32 *)regs->rsp)) )
+    {
+        domain_crash(v->domain);
+        return 0;
+    }
+
+    /* Restore CS and EIP. */
+    if ( unlikely(__get_user(regs->eip, (u32 *)regs->rsp + 1)) ||
+        unlikely(__get_user(regs->cs, (u32 *)regs->rsp + 2)) )
+    {
+        domain_crash(v->domain);
+        return 0;
+    }
+
+    /*
+     * Fix up and restore EFLAGS. We fix up in a local staging area
+     * to avoid firing the BUG_ON(IOPL) check in arch_get_info_guest.
+     */
+    if ( unlikely(__get_user(eflags, (u32 *)regs->rsp + 3)) )
+    {
+        domain_crash(v->domain);
+        return 0;
+    }
+
+    if ( VM_ASSIST(v->domain, architectural_iopl) )
+        v->arch.pv_vcpu.iopl = eflags & X86_EFLAGS_IOPL;
+
+    regs->eflags = (eflags & ~X86_EFLAGS_IOPL) | X86_EFLAGS_IF;
+
+    if ( unlikely(eflags & X86_EFLAGS_VM) )
+    {
+        /*
+         * Cannot return to VM86 mode: inject a GP fault instead. Note that
+         * the GP fault is reported on the first VM86 mode instruction, not on
+         * the IRET (which is why we can simply leave the stack frame as-is
+         * (except for perhaps having to copy it), which in turn seems better
+         * than teaching create_bounce_frame() to needlessly deal with vm86
+         * mode frames).
+         */
+        const struct trap_info *ti;
+        u32 x, ksp = v->arch.pv_vcpu.kernel_sp - 40;
+        unsigned int i;
+        int rc = 0;
+
+        gdprintk(XENLOG_ERR, "VM86 mode unavailable (ksp:%08X->%08X)\n",
+                 regs->esp, ksp);
+        if ( ksp < regs->esp )
+        {
+            for (i = 1; i < 10; ++i)
+            {
+                rc |= __get_user(x, (u32 *)regs->rsp + i);
+                rc |= __put_user(x, (u32 *)(unsigned long)ksp + i);
+            }
+        }
+        else if ( ksp > regs->esp )
+        {
+            for ( i = 9; i > 0; --i )
+            {
+                rc |= __get_user(x, (u32 *)regs->rsp + i);
+                rc |= __put_user(x, (u32 *)(unsigned long)ksp + i);
+            }
+        }
+        if ( rc )
+        {
+            domain_crash(v->domain);
+            return 0;
+        }
+        regs->esp = ksp;
+        regs->ss = v->arch.pv_vcpu.kernel_ss;
+
+        ti = &v->arch.pv_vcpu.trap_ctxt[TRAP_gp_fault];
+        if ( TI_GET_IF(ti) )
+            eflags &= ~X86_EFLAGS_IF;
+        regs->eflags &= ~(X86_EFLAGS_VM|X86_EFLAGS_RF|
+                          X86_EFLAGS_NT|X86_EFLAGS_TF);
+        if ( unlikely(__put_user(0, (u32 *)regs->rsp)) )
+        {
+            domain_crash(v->domain);
+            return 0;
+        }
+        regs->eip = ti->address;
+        regs->cs = ti->cs;
+    }
+    else if ( unlikely(ring_0(regs)) )
+    {
+        domain_crash(v->domain);
+        return 0;
+    }
+    else if ( ring_1(regs) )
+        regs->esp += 16;
+    /* Return to ring 2/3: restore ESP and SS. */
+    else if ( __get_user(regs->ss, (u32 *)regs->rsp + 5) ||
+              __get_user(regs->esp, (u32 *)regs->rsp + 4) )
+    {
+        domain_crash(v->domain);
+        return 0;
+    }
+
+    /* Restore upcall mask from supplied EFLAGS.IF. */
+    vcpu_info(v, evtchn_upcall_mask) = !(eflags & X86_EFLAGS_IF);
+
+    async_exception_cleanup(v);
+
+    /*
+     * The hypercall exit path will overwrite EAX with this return
+     * value.
+     */
+    return regs->eax;
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/x86_64/compat/traps.c +0 -120

126 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#69 lore raw

PATCH v4 27/27 x86: clean up traps.c

In reply to Wei Liu

Replace bool_t with bool. Delete trailing white spaces. Fix some coding style issues.

---
 xen/arch/x86/traps.c | 77 +++++++++++++++++++++++++++-------------------------
 1 file changed, 40 insertions(+), 37 deletions(-)
xen/arch/x86/traps.c +40 -37
index 0cedd5159b..e568586573 100644
@@ -1,18 +1,18 @@
 /******************************************************************************
  * arch/x86/traps.c
- * 
+ *
  * Modifications to Linux original are copyright (c) 2002-2004, K A Fraser
- * 
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; If not, see <http://www.gnu.org/licenses/>.
  */
@@ -112,7 +112,7 @@ void (*ioemul_handle_quirk)(
 static int debug_stack_lines = 20;
 integer_param("debug_stack_lines", debug_stack_lines);
 
-static bool_t opt_ler;
+static bool opt_ler;
 boolean_param("ler", opt_ler);
 
 #define stack_words_per_line 4
@@ -591,7 +591,7 @@ void vcpu_show_execution_state(struct vcpu *v)
 }
 
 static cpumask_t show_state_mask;
-static bool_t opt_show_all;
+static bool opt_show_all;
 boolean_param("async-show-all", opt_show_all);
 
 static int nmi_show_execution_state(const struct cpu_user_regs *regs, int cpu)
@@ -602,8 +602,8 @@ static int nmi_show_execution_state(const struct cpu_user_regs *regs, int cpu)
     if ( opt_show_all )
         show_execution_state(regs);
     else
-        printk(XENLOG_ERR "CPU%d @ %04x:%08lx (%pS)\n", cpu, regs->cs, regs->rip,
-               guest_mode(regs) ? _p(regs->rip) : NULL);
+        printk(XENLOG_ERR "CPU%d @ %04x:%08lx (%pS)\n", cpu, regs->cs,
+               regs->rip, guest_mode(regs) ? _p(regs->rip) : NULL);
     cpumask_clear_cpu(cpu, &show_state_mask);
 
     return 1;
@@ -628,7 +628,7 @@ const char *trapstr(unsigned int trapnr)
  * are disabled). In such situations we can't do much that is safe. We try to
  * print out some tracing and then we just spin.
  */
-void fatal_trap(const struct cpu_user_regs *regs, bool_t show_remote)
+void fatal_trap(const struct cpu_user_regs *regs, bool show_remote)
 {
     static DEFINE_PER_CPU(char, depth);
     unsigned int trapnr = regs->entry_vector;
@@ -1081,8 +1081,8 @@ void do_int3(struct cpu_user_regs *regs)
     pv_inject_hw_exception(TRAP_int3, X86_EVENT_NO_EC);
 }
 
-static void reserved_bit_page_fault(
-    unsigned long addr, struct cpu_user_regs *regs)
+static void reserved_bit_page_fault(unsigned long addr,
+                                    struct cpu_user_regs *regs)
 {
     printk("%pv: reserved bit in page table (ec=%04X)\n",
            current, regs->error_code);
@@ -1090,8 +1090,8 @@ static void reserved_bit_page_fault(
     show_execution_state(regs);
 }
 
-static int handle_gdt_ldt_mapping_fault(
-    unsigned long offset, struct cpu_user_regs *regs)
+static int handle_gdt_ldt_mapping_fault(unsigned long offset,
+                                        struct cpu_user_regs *regs)
 {
     struct vcpu *curr = current;
     /* Which vcpu's area did we fault in, and is it in the ldt sub-area? */
@@ -1159,8 +1159,8 @@ enum pf_type {
     spurious_fault
 };
 
-static enum pf_type __page_fault_type(
-    unsigned long addr, const struct cpu_user_regs *regs)
+static enum pf_type __page_fault_type(unsigned long addr,
+                                      const struct cpu_user_regs *regs)
 {
     unsigned long mfn, cr3 = read_cr3();
     l4_pgentry_t l4e, *l4t;
@@ -1266,8 +1266,8 @@ leaf:
     return spurious_fault;
 }
 
-static enum pf_type spurious_page_fault(
-    unsigned long addr, const struct cpu_user_regs *regs)
+static enum pf_type spurious_page_fault(unsigned long addr,
+                                        const struct cpu_user_regs *regs)
 {
     unsigned long flags;
     enum pf_type pf_type;
@@ -1376,7 +1376,8 @@ void do_page_fault(struct cpu_user_regs *regs)
         if ( (pf_type == smep_fault) || (pf_type == smap_fault) )
         {
             console_start_sync();
-            printk("Xen SM%cP violation\n", (pf_type == smep_fault) ? 'E' : 'A');
+            printk("Xen SM%cP violation\n",
+                   (pf_type == smep_fault) ? 'E' : 'A');
             fatal_trap(regs, 0);
         }
 
@@ -1426,9 +1427,9 @@ void do_page_fault(struct cpu_user_regs *regs)
 
 /*
  * Early #PF handler to print CR2, error code, and stack.
- * 
+ *
  * We also deal with spurious faults here, even though they should never happen
- * during early boot (an issue was seen once, but was most likely a hardware 
+ * during early boot (an issue was seen once, but was most likely a hardware
  * problem).
  */
 void __init do_early_page_fault(struct cpu_user_regs *regs)
@@ -1472,7 +1473,7 @@ void do_general_protection(struct cpu_user_regs *regs)
 
     /*
      * Cunning trick to allow arbitrary "INT n" handling.
-     * 
+     *
      * We set DPL == 0 on all vectors in the IDT. This prevents any INT <n>
      * instruction from trapping to the appropriate vector, when that might not
      * be expected by Xen or the guest OS. For example, that entry might be for
@@ -1480,12 +1481,12 @@ void do_general_protection(struct cpu_user_regs *regs)
      * expect an error code on the stack (which a software trap never
      * provides), or might be a hardware interrupt handler that doesn't like
      * being called spuriously.
-     * 
+     *
      * Instead, a GPF occurs with the faulting IDT vector in the error code.
-     * Bit 1 is set to indicate that an IDT entry caused the fault. Bit 0 is 
+     * Bit 1 is set to indicate that an IDT entry caused the fault. Bit 0 is
      * clear (which got already checked above) to indicate that it's a software
      * fault, not a hardware one.
-     * 
+     *
      * NOTE: Vectors 3 and 4 are dealt with from their own handler. This is
      * okay because they can only be triggered by an explicit DPL-checked
      * instruction. The DPL specified by the guest OS for these vectors is NOT
@@ -1631,7 +1632,8 @@ static void io_check_error(const struct cpu_user_regs *regs)
     outb((inb(0x61) & 0x07) | 0x00, 0x61); /* enable IOCK */
 }
 
-static void unknown_nmi_error(const struct cpu_user_regs *regs, unsigned char reason)
+static void unknown_nmi_error(const struct cpu_user_regs *regs,
+                              unsigned char reason)
 {
     switch ( opt_nmi[0] )
     {
@@ -1651,14 +1653,14 @@ static int dummy_nmi_callback(const struct cpu_user_regs *regs, int cpu)
 {
     return 0;
 }
- 
+
 static nmi_callback_t *nmi_callback = dummy_nmi_callback;
 
 void do_nmi(const struct cpu_user_regs *regs)
 {
     unsigned int cpu = smp_processor_id();
     unsigned char reason;
-    bool_t handle_unknown = 0;
+    bool handle_unknown = false;
 
     ++nmi_count(cpu);
 
@@ -1667,7 +1669,7 @@ void do_nmi(const struct cpu_user_regs *regs)
 
     if ( (nmi_watchdog == NMI_NONE) ||
          (!nmi_watchdog_tick(regs) && watchdog_force) )
-        handle_unknown = 1;
+        handle_unknown = true;
 
     /* Only the BSP gets external NMIs from the system. */
     if ( cpu == 0 )
@@ -1787,7 +1789,8 @@ void do_debug(struct cpu_user_regs *regs)
     return;
 }
 
-static void __init noinline __set_intr_gate(unsigned int n, uint32_t dpl, void *addr)
+static void __init noinline __set_intr_gate(unsigned int n,
+                                            uint32_t dpl, void *addr)
 {
     _set_gate(&idt_table[n], SYS_DESC_irq_gate, dpl, addr);
 }
@@ -1968,28 +1971,28 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)
 
     switch ( reg )
     {
-    case 0: 
+    case 0:
         if ( !access_ok(value, sizeof(long)) )
             return -EPERM;
-        if ( v == curr ) 
+        if ( v == curr )
             write_debugreg(0, value);
         break;
-    case 1: 
+    case 1:
         if ( !access_ok(value, sizeof(long)) )
             return -EPERM;
-        if ( v == curr ) 
+        if ( v == curr )
             write_debugreg(1, value);
         break;
-    case 2: 
+    case 2:
         if ( !access_ok(value, sizeof(long)) )
             return -EPERM;
-        if ( v == curr ) 
+        if ( v == curr )
             write_debugreg(2, value);
         break;
     case 3:
         if ( !access_ok(value, sizeof(long)) )
             return -EPERM;
-        if ( v == curr ) 
+        if ( v == curr )
             write_debugreg(3, value);
         break;
     case 6:
@@ -1999,7 +2002,7 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)
          */
         value &= ~DR_STATUS_RESERVED_ZERO; /* reserved bits => 0 */
         value |=  DR_STATUS_RESERVED_ONE;  /* reserved bits => 1 */
-        if ( v == curr ) 
+        if ( v == curr )
             write_debugreg(6, value);
         break;
     case 7:
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#37 lore raw

PATCH v4 14/27 x86: move do_iret to pv/iret.c

In reply to Wei Liu

---
There is no copyright header in the original file. Use the default one?

---
 xen/arch/x86/pv/Makefile    |  1 +
 xen/arch/x86/pv/iret.c      | 72 +++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/traps.c | 56 -----------------------------------
 3 files changed, 73 insertions(+), 56 deletions(-)
 create mode 100644 xen/arch/x86/pv/iret.c
xen/arch/x86/pv/Makefile +1 -0
index 939ea60bea..7e3da332d8 100644
@@ -8,4 +8,5 @@ obj-y += emul-gate-op.o
 obj-y += emul-inv-op.o
 obj-y += emul-priv-op.o
 obj-bin-y += gpr_switch.o
+obj-y += iret.o
 obj-y += misc-hypercalls.o
xen/arch/x86/pv/iret.c new file +72 -0

72 lines not on this page · raw message

xen/arch/x86/x86_64/traps.c +0 -56

62 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#63 lore raw

PATCH v4 24/27 x86: move compat_show_guest_statck near its non-compat variant

In reply to Wei Liu

And make it static, remove the declaration in header.

---
 xen/arch/x86/traps.c               | 64 ++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/compat/traps.c | 63 -------------------------------------
 xen/include/asm-x86/processor.h    |  3 --
 3 files changed, 64 insertions(+), 66 deletions(-)
xen/arch/x86/traps.c +64 -0
index 287503cd56..0cedd5159b 100644
@@ -186,6 +186,70 @@ static void show_code(const struct cpu_user_regs *regs)
     printk("\n");
 }
 
+static void compat_show_guest_stack(struct vcpu *v,
+                                    const struct cpu_user_regs *regs,
+                                    int debug_stack_lines)
+{
+    unsigned int i, *stack, addr, mask = STACK_SIZE;
+
+    stack = (unsigned int *)(unsigned long)regs->esp;
+    printk("Guest stack trace from esp=%08lx:\n ", (unsigned long)stack);
+
+    if ( !__compat_access_ok(v->domain, stack, sizeof(*stack)) )
+    {
+        printk("Guest-inaccessible memory.\n");
+        return;
+    }
+
+    if ( v != current )
+    {
+        struct vcpu *vcpu;
+        unsigned long mfn;
+
+        ASSERT(guest_kernel_mode(v, regs));
+        mfn = read_cr3() >> PAGE_SHIFT;
+        for_each_vcpu( v->domain, vcpu )
+            if ( pagetable_get_pfn(vcpu->arch.guest_table) == mfn )
+                break;
+        if ( !vcpu )
+        {
+            stack = do_page_walk(v, (unsigned long)stack);
+            if ( (unsigned long)stack < PAGE_SIZE )
+            {
+                printk("Inaccessible guest memory.\n");
+                return;
+            }
+            mask = PAGE_SIZE;
+        }
+    }
+
+    for ( i = 0; i < debug_stack_lines * 8; i++ )
+    {
+        if ( (((long)stack - 1) ^ ((long)(stack + 1) - 1)) & mask )
+            break;
+        if ( __get_user(addr, stack) )
+        {
+            if ( i != 0 )
+                printk("\n    ");
+            printk("Fault while accessing guest memory.");
+            i = 1;
+            break;
+        }
+        if ( (i != 0) && ((i % 8) == 0) )
+            printk("\n ");
+        printk(" %08x", addr);
+        stack++;
+    }
+    if ( mask == PAGE_SIZE )
+    {
+        BUILD_BUG_ON(PAGE_SIZE == STACK_SIZE);
+        unmap_domain_page(stack);
+    }
+    if ( i == 0 )
+        printk("Stack empty.");
+    printk("\n");
+}
+
 static void show_guest_stack(struct vcpu *v, const struct cpu_user_regs *regs)
 {
     int i;
xen/arch/x86/x86_64/compat/traps.c +0 -63

69 lines not on this page · raw message

xen/include/asm-x86/processor.h +0 -3
index 6a335d3a61..5bf56b45e1 100644
@@ -480,9 +480,6 @@ void show_execution_state(const struct cpu_user_regs *regs);
 void show_page_walk(unsigned long addr);
 void noreturn fatal_trap(const struct cpu_user_regs *regs, bool_t show_remote);
 
-void compat_show_guest_stack(struct vcpu *v,
-                             const struct cpu_user_regs *regs, int lines);
-
 extern void mtrr_ap_init(void);
 extern void mtrr_bp_init(void);
 
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#49 lore raw

PATCH v4 19/27 x86: move hypercall_page_initialise_ring3_kernel to pv/hypercall.c

In reply to Wei Liu
---
 xen/arch/x86/pv/hypercall.c     | 36 ++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/traps.c     | 36 ------------------------------------
 xen/include/asm-x86/hypercall.h |  1 +
 3 files changed, 37 insertions(+), 36 deletions(-)
xen/arch/x86/pv/hypercall.c +36 -0
index 7c5e5a629d..287340e774 100644
@@ -255,6 +255,42 @@ enum mc_disposition arch_do_multicall_call(struct mc_state *state)
              ? mc_continue : mc_preempt;
 }
 
+void hypercall_page_initialise_ring3_kernel(void *hypercall_page)
+{
+    char *p;
+    int i;
+
+    /* Fill in all the transfer points with template machine code. */
+    for ( i = 0; i < (PAGE_SIZE / 32); i++ )
+    {
+        if ( i == __HYPERVISOR_iret )
+            continue;
+
+        p = (char *)(hypercall_page + (i * 32));
+        *(u8  *)(p+ 0) = 0x51;    /* push %rcx */
+        *(u16 *)(p+ 1) = 0x5341;  /* push %r11 */
+        *(u8  *)(p+ 3) = 0xb8;    /* mov  $<i>,%eax */
+        *(u32 *)(p+ 4) = i;
+        *(u16 *)(p+ 8) = 0x050f;  /* syscall */
+        *(u16 *)(p+10) = 0x5b41;  /* pop  %r11 */
+        *(u8  *)(p+12) = 0x59;    /* pop  %rcx */
+        *(u8  *)(p+13) = 0xc3;    /* ret */
+    }
+
+    /*
+     * HYPERVISOR_iret is special because it doesn't return and expects a
+     * special stack frame. Guests jump at this transfer point instead of
+     * calling it.
+     */
+    p = (char *)(hypercall_page + (__HYPERVISOR_iret * 32));
+    *(u8  *)(p+ 0) = 0x51;    /* push %rcx */
+    *(u16 *)(p+ 1) = 0x5341;  /* push %r11 */
+    *(u8  *)(p+ 3) = 0x50;    /* push %rax */
+    *(u8  *)(p+ 4) = 0xb8;    /* mov  $__HYPERVISOR_iret,%eax */
+    *(u32 *)(p+ 5) = __HYPERVISOR_iret;
+    *(u16 *)(p+ 9) = 0x050f;  /* syscall */
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/x86_64/traps.c +0 -36
index d15c9023e8..79bfc4d3f0 100644
@@ -335,42 +335,6 @@ void subarch_percpu_traps_init(void)
     wrmsrl(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK);
 }
 
-static void hypercall_page_initialise_ring3_kernel(void *hypercall_page)
-{
-    char *p;
-    int i;
-
-    /* Fill in all the transfer points with template machine code. */
-    for ( i = 0; i < (PAGE_SIZE / 32); i++ )
-    {
-        if ( i == __HYPERVISOR_iret )
-            continue;
-
-        p = (char *)(hypercall_page + (i * 32));
-        *(u8  *)(p+ 0) = 0x51;    /* push %rcx */
-        *(u16 *)(p+ 1) = 0x5341;  /* push %r11 */
-        *(u8  *)(p+ 3) = 0xb8;    /* mov  $<i>,%eax */
-        *(u32 *)(p+ 4) = i;
-        *(u16 *)(p+ 8) = 0x050f;  /* syscall */
-        *(u16 *)(p+10) = 0x5b41;  /* pop  %r11 */
-        *(u8  *)(p+12) = 0x59;    /* pop  %rcx */
-        *(u8  *)(p+13) = 0xc3;    /* ret */
-    }
-
-    /*
-     * HYPERVISOR_iret is special because it doesn't return and expects a
-     * special stack frame. Guests jump at this transfer point instead of
-     * calling it.
-     */
-    p = (char *)(hypercall_page + (__HYPERVISOR_iret * 32));
-    *(u8  *)(p+ 0) = 0x51;    /* push %rcx */
-    *(u16 *)(p+ 1) = 0x5341;  /* push %r11 */
-    *(u8  *)(p+ 3) = 0x50;    /* push %rax */
-    *(u8  *)(p+ 4) = 0xb8;    /* mov  $__HYPERVISOR_iret,%eax */
-    *(u32 *)(p+ 5) = __HYPERVISOR_iret;
-    *(u16 *)(p+ 9) = 0x050f;  /* syscall */
-}
-
 #include "compat/traps.c"
 
 void hypercall_page_initialise(struct domain *d, void *hypercall_page)
xen/include/asm-x86/hypercall.h +1 -0
index cfbcefe52f..5631cf2694 100644
@@ -26,6 +26,7 @@ typedef struct {
 extern const hypercall_args_t hypercall_args_table[NR_hypercalls];
 
 void pv_hypercall(struct cpu_user_regs *regs);
+void hypercall_page_initialise_ring3_kernel(void *hypercall_page);
 
 /*
  * Both do_mmuext_op() and do_mmu_update():
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#30 lore raw

PATCH v4 11/27 x86:/traps: move {un, }register_guest_nmi_callback

In reply to Wei Liu

Take the opportunity to rename "v" to "curr".

---
 xen/arch/x86/pv/traps.c | 36 ++++++++++++++++++++++++++++++++++++
 xen/arch/x86/traps.c    | 36 ------------------------------------
 2 files changed, 36 insertions(+), 36 deletions(-)
xen/arch/x86/pv/traps.c +36 -0
index e374cd73b4..d0e651616d 100644
@@ -183,6 +183,42 @@ bool set_guest_nmi_trapbounce(void)
     return !null_trap_bounce(curr, tb);
 }
 
+long register_guest_nmi_callback(unsigned long address)
+{
+    struct vcpu *curr = current;
+    struct domain *d = curr->domain;
+    struct trap_info *t = &curr->arch.pv_vcpu.trap_ctxt[TRAP_nmi];
+
+    if ( !is_canonical_address(address) )
+        return -EINVAL;
+
+    t->vector  = TRAP_nmi;
+    t->flags   = 0;
+    t->cs      = (is_pv_32bit_domain(d) ?
+                  FLAT_COMPAT_KERNEL_CS : FLAT_KERNEL_CS);
+    t->address = address;
+    TI_SET_IF(t, 1);
+
+    /*
+     * If no handler was registered we can 'lose the NMI edge'. Re-assert it
+     * now.
+     */
+    if ( (curr->vcpu_id == 0) && (arch_get_nmi_reason(d) != 0) )
+        curr->nmi_pending = 1;
+
+    return 0;
+}
+
+long unregister_guest_nmi_callback(void)
+{
+    struct vcpu *curr = current;
+    struct trap_info *t = &curr->arch.pv_vcpu.trap_ctxt[TRAP_nmi];
+
+    memset(t, 0, sizeof(*t));
+
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/traps.c +0 -36
index 013de702ad..babb476097 100644
@@ -1909,42 +1909,6 @@ void __init trap_init(void)
     open_softirq(PCI_SERR_SOFTIRQ, pci_serr_softirq);
 }
 
-long register_guest_nmi_callback(unsigned long address)
-{
-    struct vcpu *v = current;
-    struct domain *d = v->domain;
-    struct trap_info *t = &v->arch.pv_vcpu.trap_ctxt[TRAP_nmi];
-
-    if ( !is_canonical_address(address) )
-        return -EINVAL;
-
-    t->vector  = TRAP_nmi;
-    t->flags   = 0;
-    t->cs      = (is_pv_32bit_domain(d) ?
-                  FLAT_COMPAT_KERNEL_CS : FLAT_KERNEL_CS);
-    t->address = address;
-    TI_SET_IF(t, 1);
-
-    /*
-     * If no handler was registered we can 'lose the NMI edge'. Re-assert it
-     * now.
-     */
-    if ( (v->vcpu_id == 0) && (arch_get_nmi_reason(d) != 0) )
-        v->nmi_pending = 1;
-
-    return 0;
-}
-
-long unregister_guest_nmi_callback(void)
-{
-    struct vcpu *v = current;
-    struct trap_info *t = &v->arch.pv_vcpu.trap_ctxt[TRAP_nmi];
-
-    memset(t, 0, sizeof(*t));
-
-    return 0;
-}
-
 int guest_has_trap_callback(struct domain *d, uint16_t vcpuid, unsigned int trap_nr)
 {
     struct vcpu *v;
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#61 lore raw

PATCH v4 23/27 x86: move the compat callback ops next to the non-compat variant

In reply to Wei Liu
---
 xen/arch/x86/pv/callback.c         | 142 ++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/compat/traps.c | 143 -------------------------------------
 2 files changed, 142 insertions(+), 143 deletions(-)
xen/arch/x86/pv/callback.c +142 -0
index dbd602c89d..00981d0f47 100644
@@ -1,6 +1,7 @@
 #include <xen/guest_access.h>
 #include <xen/lib.h>
 #include <xen/sched.h>
+#include <compat/callback.h>
 
 #include <asm/current.h>
 #include <asm/nmi.h>
@@ -155,3 +156,144 @@ long do_set_callbacks(unsigned long event_address,
     return 0;
 }
 
+static long compat_register_guest_callback(struct compat_callback_register *reg)
+{
+    long ret = 0;
+    struct vcpu *v = current;
+
+    fixup_guest_code_selector(v->domain, reg->address.cs);
+
+    switch ( reg->type )
+    {
+    case CALLBACKTYPE_event:
+        v->arch.pv_vcpu.event_callback_cs     = reg->address.cs;
+        v->arch.pv_vcpu.event_callback_eip    = reg->address.eip;
+        break;
+
+    case CALLBACKTYPE_failsafe:
+        v->arch.pv_vcpu.failsafe_callback_cs  = reg->address.cs;
+        v->arch.pv_vcpu.failsafe_callback_eip = reg->address.eip;
+        if ( reg->flags & CALLBACKF_mask_events )
+            set_bit(_VGCF_failsafe_disables_events,
+                    &v->arch.vgc_flags);
+        else
+            clear_bit(_VGCF_failsafe_disables_events,
+                      &v->arch.vgc_flags);
+        break;
+
+    case CALLBACKTYPE_syscall32:
+        v->arch.pv_vcpu.syscall32_callback_cs     = reg->address.cs;
+        v->arch.pv_vcpu.syscall32_callback_eip    = reg->address.eip;
+        v->arch.pv_vcpu.syscall32_disables_events =
+            (reg->flags & CALLBACKF_mask_events) != 0;
+        break;
+
+    case CALLBACKTYPE_sysenter:
+        v->arch.pv_vcpu.sysenter_callback_cs     = reg->address.cs;
+        v->arch.pv_vcpu.sysenter_callback_eip    = reg->address.eip;
+        v->arch.pv_vcpu.sysenter_disables_events =
+            (reg->flags & CALLBACKF_mask_events) != 0;
+        break;
+
+    case CALLBACKTYPE_nmi:
+        ret = register_guest_nmi_callback(reg->address.eip);
+        break;
+
+    default:
+        ret = -ENOSYS;
+        break;
+    }
+
+    return ret;
+}
+
+static long compat_unregister_guest_callback(
+    struct compat_callback_unregister *unreg)
+{
+    long ret;
+
+    switch ( unreg->type )
+    {
+    case CALLBACKTYPE_event:
+    case CALLBACKTYPE_failsafe:
+    case CALLBACKTYPE_syscall32:
+    case CALLBACKTYPE_sysenter:
+        ret = -EINVAL;
+        break;
+
+    case CALLBACKTYPE_nmi:
+        ret = unregister_guest_nmi_callback();
+        break;
+
+    default:
+        ret = -ENOSYS;
+        break;
+    }
+
+    return ret;
+}
+
+
+long compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg)
+{
+    long ret;
+
+    switch ( cmd )
+    {
+    case CALLBACKOP_register:
+    {
+        struct compat_callback_register reg;
+
+        ret = -EFAULT;
+        if ( copy_from_guest(&reg, arg, 1) )
+            break;
+
+        ret = compat_register_guest_callback(&reg);
+    }
+    break;
+
+    case CALLBACKOP_unregister:
+    {
+        struct compat_callback_unregister unreg;
+
+        ret = -EFAULT;
+        if ( copy_from_guest(&unreg, arg, 1) )
+            break;
+
+        ret = compat_unregister_guest_callback(&unreg);
+    }
+    break;
+
+    default:
+        ret = -EINVAL;
+        break;
+    }
+
+    return ret;
+}
+
+long compat_set_callbacks(unsigned long event_selector,
+                          unsigned long event_address,
+                          unsigned long failsafe_selector,
+                          unsigned long failsafe_address)
+{
+    struct compat_callback_register event = {
+        .type = CALLBACKTYPE_event,
+        .address = {
+            .cs = event_selector,
+            .eip = event_address
+        }
+    };
+    struct compat_callback_register failsafe = {
+        .type = CALLBACKTYPE_failsafe,
+        .address = {
+            .cs = failsafe_selector,
+            .eip = failsafe_address
+        }
+    };
+
+    compat_register_guest_callback(&event);
+    compat_register_guest_callback(&failsafe);
+
+    return 0;
+}
xen/arch/x86/x86_64/compat/traps.c +0 -143

149 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#67 lore raw

PATCH v4 26/27 x86: fix coding a style issue in asm-x86/traps.h

In reply to Wei Liu

And add an emacs block.

---
 xen/include/asm-x86/traps.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
xen/include/asm-x86/traps.h +11 -1
index 8cf6105d8d..1ac6718257 100644
@@ -38,7 +38,7 @@ bool guest_has_trap_callback(const struct domain *d, unsigned int vcpuid,
  * return 0 on successful delivery
  */
 extern int send_guest_trap(struct domain *d, uint16_t vcpuid,
-				unsigned int trap_nr);
+                           unsigned int trap_nr);
 
 uint32_t guest_io_read(unsigned int port, unsigned int bytes,
                        struct domain *);
@@ -48,3 +48,13 @@ void guest_io_write(unsigned int port, unsigned int bytes, uint32_t data,
 const char *trapstr(unsigned int trapnr);
 
 #endif /* ASM_TRAP_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#45 lore raw

PATCH v4 17/27 x86/traps: move some PV specific functions and struct to pv/traps.c

In reply to Wei Liu

Those functions need to be moved at the same time. Also move softirq_trap because it is only used in that one place.

Fix some coding style issues while moving.

---
 xen/arch/x86/pv/traps.c     | 105 ++++++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/traps.c        |  93 ---------------------------------------
 xen/include/asm-x86/traps.h |   6 ---
 3 files changed, 105 insertions(+), 99 deletions(-)
xen/arch/x86/pv/traps.c +105 -0
index be215df57a..0c1600d886 100644
@@ -237,6 +237,111 @@ bool guest_has_trap_callback(const struct domain *d, unsigned int vcpuid,
     return t->address;
 }
 
+struct softirq_trap {
+    struct domain *domain;  /* domain to inject trap */
+    struct vcpu *vcpu;      /* vcpu to inject trap */
+    int processor;          /* physical cpu to inject trap */
+};
+static DEFINE_PER_CPU(struct softirq_trap, softirq_trap);
+
+static void nmi_mce_softirq(void)
+{
+    int cpu = smp_processor_id();
+    struct softirq_trap *st = &per_cpu(softirq_trap, cpu);
+
+    BUG_ON(st->vcpu == NULL);
+
+    /*
+     * Set the tmp value unconditionally, so that
+     * the check in the iret hypercall works.
+     */
+    cpumask_copy(st->vcpu->cpu_hard_affinity_tmp,
+                 st->vcpu->cpu_hard_affinity);
+
+    if ( (cpu != st->processor) ||
+         (st->processor != st->vcpu->processor) )
+    {
+        /*
+         * We are on a different physical cpu.
+         * Make sure to wakeup the vcpu on the
+         * specified processor.
+         */
+        vcpu_set_hard_affinity(st->vcpu, cpumask_of(st->processor));
+
+        /* Affinity is restored in the iret hypercall. */
+    }
+
+    /*
+     * Only used to defer wakeup of domain/vcpu to
+     * a safe (non-NMI/MCE) context.
+     */
+    vcpu_kick(st->vcpu);
+    st->vcpu = NULL;
+}
+
+void __init pv_trap_init(void)
+{
+    /* The 32-on-64 hypercall vector is only accessible from ring 1. */
+    _set_gate(idt_table + HYPERCALL_VECTOR,
+              SYS_DESC_trap_gate, 1, entry_int82);
+
+    /* Fast trap for int80 (faster than taking the #GP-fixup path). */
+    _set_gate(idt_table + 0x80, SYS_DESC_trap_gate, 3, &int80_direct_trap);
+
+    open_softirq(NMI_MCE_SOFTIRQ, nmi_mce_softirq);
+}
+
+int send_guest_trap(struct domain *d, uint16_t vcpuid, unsigned int trap_nr)
+{
+    struct vcpu *v;
+    struct softirq_trap *st = &per_cpu(softirq_trap, smp_processor_id());
+
+    BUG_ON(d == NULL);
+    BUG_ON(vcpuid >= d->max_vcpus);
+    v = d->vcpu[vcpuid];
+
+    switch ( trap_nr )
+    {
+    case TRAP_nmi:
+        if ( cmpxchgptr(&st->vcpu, NULL, v) )
+            return -EBUSY;
+        if ( !test_and_set_bool(v->nmi_pending) )
+        {
+            st->domain = d;
+            st->processor = v->processor;
+
+            /* not safe to wake up a vcpu here */
+            raise_softirq(NMI_MCE_SOFTIRQ);
+            return 0;
+        }
+        st->vcpu = NULL;
+        break;
+
+    case TRAP_machine_check:
+        if ( cmpxchgptr(&st->vcpu, NULL, v) )
+            return -EBUSY;
+
+        /*
+	 * We are called by the machine check (exception or polling) handlers
+	 * on the physical CPU that reported a machine check error.
+         */
+        if ( !test_and_set_bool(v->mce_pending) )
+        {
+            st->domain = d;
+            st->processor = v->processor;
+
+            /* not safe to wake up a vcpu here */
+            raise_softirq(NMI_MCE_SOFTIRQ);
+            return 0;
+        }
+        st->vcpu = NULL;
+        break;
+    }
+
+    /* delivery failed */
+    return -EIO;
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/traps.c +0 -93

111 lines not on this page · raw message

xen/include/asm-x86/traps.h +0 -6
index 26625ce5a6..8cf6105d8d 100644
@@ -19,12 +19,6 @@
 #ifndef ASM_TRAP_H
 #define ASM_TRAP_H
 
-struct softirq_trap {
-	struct domain *domain;  /* domain to inject trap */
-	struct vcpu *vcpu;	/* vcpu to inject trap */
-	int processor;		/* physical cpu to inject trap */
-};
-
 struct cpu_user_regs;
 
 void async_exception_cleanup(struct vcpu *);
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#47 lore raw

PATCH v4 18/27 x86/traps: move init_int80_direct_trap to pv/traps.c

In reply to Wei Liu
---
 xen/arch/x86/pv/traps.c     | 14 ++++++++++++++
 xen/arch/x86/x86_64/traps.c | 14 --------------
 2 files changed, 14 insertions(+), 14 deletions(-)
xen/arch/x86/pv/traps.c +14 -0
index 0c1600d886..f2556c7e4a 100644
@@ -342,6 +342,20 @@ int send_guest_trap(struct domain *d, uint16_t vcpuid, unsigned int trap_nr)
     return -EIO;
 }
 
+void init_int80_direct_trap(struct vcpu *v)
+{
+    struct trap_info *ti = &v->arch.pv_vcpu.trap_ctxt[0x80];
+    struct trap_bounce *tb = &v->arch.pv_vcpu.int80_bounce;
+
+    tb->cs    = ti->cs;
+    tb->eip   = ti->address;
+
+    if ( null_trap_bounce(v, tb) )
+        tb->flags = 0;
+    else
+        tb->flags = TBF_EXCEPTION | (TI_GET_IF(ti) ? TBF_INTERRUPT : 0);
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/x86_64/traps.c +0 -14
index 1a8beb8068..d15c9023e8 100644
@@ -335,20 +335,6 @@ void subarch_percpu_traps_init(void)
     wrmsrl(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK);
 }
 
-void init_int80_direct_trap(struct vcpu *v)
-{
-    struct trap_info *ti = &v->arch.pv_vcpu.trap_ctxt[0x80];
-    struct trap_bounce *tb = &v->arch.pv_vcpu.int80_bounce;
-
-    tb->cs    = ti->cs;
-    tb->eip   = ti->address;
-
-    if ( null_trap_bounce(v, tb) )
-        tb->flags = 0;
-    else
-        tb->flags = TBF_EXCEPTION | (TI_GET_IF(ti) ? TBF_INTERRUPT : 0);
-}
-
 static void hypercall_page_initialise_ring3_kernel(void *hypercall_page)
 {
     char *p;
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#65 lore raw

PATCH v4 25/27 x86: remove the now empty x86_64/compat/traps.c

In reply to Wei Liu
---
 xen/arch/x86/x86_64/compat/traps.c | 14 --------------
 xen/arch/x86/x86_64/traps.c        |  2 --
 2 files changed, 16 deletions(-)
 delete mode 100644 xen/arch/x86/x86_64/compat/traps.c
xen/arch/x86/x86_64/compat/traps.c deleted +0 -14
deleted file mode 100644
index 18cd2c017c..0000000000
@@ -1,14 +0,0 @@
-#include <xen/event.h>
-#include <asm/regs.h>
-#include <compat/callback.h>
-#include <compat/arch-x86_32.h>
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
xen/arch/x86/x86_64/traps.c +0 -2
index 79bfc4d3f0..a15231ca0c 100644
@@ -335,8 +335,6 @@ void subarch_percpu_traps_init(void)
     wrmsrl(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK);
 }
 
-#include "compat/traps.c"
-
 void hypercall_page_initialise(struct domain *d, void *hypercall_page)
 {
     memset(hypercall_page, 0xCC, PAGE_SIZE);
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v4 1/27
#2 lore raw

Re: [PATCH v4 01/27] x86: factor out common PV emulation code

In reply to Wei Liu
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 08.06.17 at 19:11, <[email protected]> wrote:

We're going to split PV emulation code into several files. This patch extracts the functions needed by them into a dedicated file.

The functions are now prefixed with "pv_emul_" and exported via a local header file.

While at it, change bool_t to bool.

On the basis that beyond this the two functions are simply being moved, ...

Quoted 1 line

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by on v4 2/27
#4 lore raw

Re: [PATCH v4 02/27] x86: move PV privileged instruction emulation code

In reply to Wei Liu
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 08.06.17 at 19:11, <[email protected]> wrote:

Move the code to pv/emul-priv-op.c. Prefix emulate_privileged_op with pv_ and export it via pv/traps.h.

Also move gpr_switch.S since it is used by the privileged instruction emulation code only.

Code motion only except for the rename. Cleanup etc will come later.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by on v4 3/27
#6 lore raw

Re: [PATCH v4 03/27] x86: move PV gate op emulation code

In reply to Wei Liu

xen/include/asm-x86/pv/traps.h line 34

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 08.06.17 at 19:11, <[email protected]> wrote:
xen/include/asm-x86/pv/traps.h +2 -0
@@ -26,10 +26,12 @@
 #include <public/xen.h>
 
 int pv_emulate_privileged_op(struct cpu_user_regs *regs);
+void pv_emulate_gate_op(struct cpu_user_regs *regs);
 
 #else  /* !CONFIG_PV */
 
 int pv_emulate_privileged_op(struct cpu_user_regs *regs) { return 0; }
+void pv_emulate_gate_op(struct cpu_user_regs *regs) {}

Missing "inline" (also applies to patch 2 as I've just noticed)? With that corrected,

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH v4 04/27] x86: move PV invalid op emulation code

In reply to Wei Liu

xen/arch/x86/traps.c void do_invalid_op(struct cpu_user_regs *regs) · line 986

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.06.17 at 19:11, <[email protected]> wrote:
xen/arch/x86/traps.c +2 -2
@@ -1053,8 +982,8 @@ void do_invalid_op(struct cpu_user_regs *regs)
 
     if ( likely(guest_mode(regs)) )
     {
-        if ( !emulate_invalid_rdtscp(regs) &&
-             !emulate_forced_invalid_op(regs) )
+        if ( !pv_emulate_invalid_rdtscp(regs) &&
+             !pv_emulate_forced_invalid_op(regs) )

I wonder if the first couldn't be called by the second, making it unnecessary to export both. Or maybe have a wrapper pv_emulate_invalid_op() around both.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#9 lore raw

Re: [PATCH v4 04/27] x86: move PV invalid op emulation code

In reply to Jan Beulich
Quoted 14 lines · Jan Beulich

xen/arch/x86/traps.c void do_invalid_op(struct cpu_user_regs *regs) · line 986

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.06.17 at 19:11, <[email protected]> wrote:
xen/arch/x86/traps.c +2 -2
@@ -1053,8 +982,8 @@ void do_invalid_op(struct cpu_user_regs *regs)
 
     if ( likely(guest_mode(regs)) )
     {
-        if ( !emulate_invalid_rdtscp(regs) &&
-             !emulate_forced_invalid_op(regs) )
+        if ( !pv_emulate_invalid_rdtscp(regs) &&
+             !pv_emulate_forced_invalid_op(regs) )

I wonder if the first couldn't be called by the second, making it unnecessary to export both. Or maybe have a wrapper pv_emulate_invalid_op() around both.

Do you want me to refactor and move code in the same patch? Wouldn't that make it hard for you to review?

I can submit a follow-up patch to do what you ask for.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#10 lore raw

Re: [PATCH v4 04/27] x86: move PV invalid op emulation code

Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 20.06.17 at 18:25, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich

xen/arch/x86/traps.c void do_invalid_op(struct cpu_user_regs *regs) · line 986

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.06.17 at 19:11, <[email protected]> wrote:
xen/arch/x86/traps.c +2 -2
@@ -1053,8 +982,8 @@ void do_invalid_op(struct cpu_user_regs *regs)
 
     if ( likely(guest_mode(regs)) )
     {
-        if ( !emulate_invalid_rdtscp(regs) &&
-             !emulate_forced_invalid_op(regs) )
+        if ( !pv_emulate_invalid_rdtscp(regs) &&
+             !pv_emulate_forced_invalid_op(regs) )

I wonder if the first couldn't be called by the second, making it unnecessary to export both. Or maybe have a wrapper pv_emulate_invalid_op() around both.

Quoted 2 lines

Do you want me to refactor and move code in the same patch? Wouldn't that make it hard for you to review?

Why - especially in the wrapper variant you'd move both functions unchanged (perhaps even with the names left as they are), and merely add the wrapper (and of course use it in the code fragment above). That'll make review rather simple, as you'll still be able to state that you left both existing functions unchanged.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#11 lore raw

Re: [PATCH v4 04/27] x86: move PV invalid op emulation code

Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 20.06.17 at 18:25, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich

Review void do_invalid_op(struct cpu_user_regs *regs) · line 986

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.06.17 at 19:11, <[email protected]> wrote:
(quoted diff) +2 -2
@@ -1053,8 +982,8 @@ void do_invalid_op(struct cpu_user_regs *regs)
 
     if ( likely(guest_mode(regs)) )
     {
-        if ( !emulate_invalid_rdtscp(regs) &&
-             !emulate_forced_invalid_op(regs) )
+        if ( !pv_emulate_invalid_rdtscp(regs) &&
+             !pv_emulate_forced_invalid_op(regs) )

I wonder if the first couldn't be called by the second, making it unnecessary to export both. Or maybe have a wrapper pv_emulate_invalid_op() around both.

Quoted 8 lines
Quoted 2 lines

Do you want me to refactor and move code in the same patch? Wouldn't that make it hard for you to review?

Why - especially in the wrapper variant you'd move both functions unchanged (perhaps even with the names left as they are), and merely add the wrapper (and of course use it in the code fragment above). That'll make review rather simple, as you'll still be able to state that you left both existing functions unchanged.

OK

---8<---
From 50dfe1fe116c28a3953f0b72acc7b1dee4136e2b Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Mon, 5 Jun 2017 13:07:16 +0100
Subject: [PATCH] x86: move PV invalid op emulation code

Move the code to pv/emul-inv-op.c. Both functions are unchanged. Provide pv_emulate_invalid_op and use it in traps.c.

---
 xen/arch/x86/pv/Makefile       |   1 +
 xen/arch/x86/pv/emul-inv-op.c  | 128 +++++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/traps.c           |  74 +-----------------------
 xen/include/asm-x86/pv/traps.h |   2 +
 4 files changed, 132 insertions(+), 73 deletions(-)
 create mode 100644 xen/arch/x86/pv/emul-inv-op.c
xen/arch/x86/pv/Makefile +1 -0
index 1f6fbd3f5c..42ca64dc9e 100644
@@ -5,5 +5,6 @@ obj-bin-y += dom0_build.init.o
 obj-y += domain.o
 obj-y += emulate.o
 obj-y += emul-gate-op.o
+obj-y += emul-inv-op.o
 obj-y += emul-priv-op.o
 obj-bin-y += gpr_switch.o
xen/arch/x86/pv/emul-inv-op.c new file +128 -0

128 lines not on this page · raw message

xen/arch/x86/traps.c +1 -73

86 lines not on this page · raw message

xen/include/asm-x86/pv/traps.h +2 -0
index b1b6b1d0ad..458028a94b 100644
@@ -27,11 +27,13 @@
 
 int pv_emulate_privileged_op(struct cpu_user_regs *regs);
 void pv_emulate_gate_op(struct cpu_user_regs *regs);
+int pv_emulate_invalid_op(struct cpu_user_regs *regs);
 
 #else  /* !CONFIG_PV */
 
 static inline int pv_emulate_privileged_op(struct cpu_user_regs *regs) { return 0; }
 static inline void pv_emulate_gate_op(struct cpu_user_regs *regs) {}
+static int pv_emulate_invalid_op(struct cpu_user_regs *regs) { return 0; }
 
 #endif /* CONFIG_PV */
 
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#12 lore raw

Re: [PATCH v4 04/27] x86: move PV invalid op emulation code

xen/arch/x86/pv/emul-inv-op.c line 118

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 21.06.17 at 10:57, <[email protected]> wrote:
xen/arch/x86/pv/emul-inv-op.c new file +4 -0
+int pv_emulate_invalid_op(struct cpu_user_regs *regs)
+{
+    return !emulate_invalid_rdtscp(regs) && !emulate_forced_invalid_op(regs);
+}

This way you want to make the function return bool. Alternatively you would want to preserve the EXCRET_* return value here, and handle it accordingly in the caller.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#13 lore raw

Re: [PATCH v4 04/27] x86: move PV invalid op emulation code

Quoted 10 lines · Jan Beulich

xen/arch/x86/pv/emul-inv-op.c line 118

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 21.06.17 at 10:57, <[email protected]> wrote:
xen/arch/x86/pv/emul-inv-op.c new file +4 -0
+int pv_emulate_invalid_op(struct cpu_user_regs *regs)
+{
+    return !emulate_invalid_rdtscp(regs) && !emulate_forced_invalid_op(regs);
+}

This way you want to make the function return bool. Alternatively you would want to preserve the EXCRET_* return value here, and handle it accordingly in the caller.

I will just make it return bool. Do you want me to send another version?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#14 lore raw

Re: [PATCH v4 04/27] x86: move PV invalid op emulation code

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 21.06.17 at 11:14, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich

xen/arch/x86/pv/emul-inv-op.c line 118

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 21.06.17 at 10:57, <[email protected]> wrote:
xen/arch/x86/pv/emul-inv-op.c new file +4 -0
+int pv_emulate_invalid_op(struct cpu_user_regs *regs)
+{
+    return !emulate_invalid_rdtscp(regs) && !emulate_forced_invalid_op(regs);
+}

This way you want to make the function return bool. Alternatively you would want to preserve the EXCRET_* return value here, and handle it accordingly in the caller.

Quoted 1 line

I will just make it return bool. Do you want me to send another version?

No need to I think - feel free to add my ack.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#15 lore raw

Re: [PATCH v4 04/27] x86: move PV invalid op emulation code

Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 21.06.17 at 11:14, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich

xen/arch/x86/pv/emul-inv-op.c line 118

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 21.06.17 at 10:57, <[email protected]> wrote:
xen/arch/x86/pv/emul-inv-op.c new file +4 -0
+int pv_emulate_invalid_op(struct cpu_user_regs *regs)
+{
+    return !emulate_invalid_rdtscp(regs) && !emulate_forced_invalid_op(regs);
+}

This way you want to make the function return bool. Alternatively you would want to preserve the EXCRET_* return value here, and handle it accordingly in the caller.

Quoted 4 lines
Quoted 1 line

I will just make it return bool. Do you want me to send another version?

No need to I think - feel free to add my ack.

Cool. Thank you.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v4 6/27
#19 lore raw

Re: [PATCH v4 06/27] x86: clean up PV emulation code

In reply to Wei Liu
Quoted 5 lines · Wei Liu

Replace bool_t with bool. Fix coding style issues. Add spaces around binary ops. Use 1U for shifting. Eliminate TOGGLE_MODE.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#29 lore raw

Re: [PATCH v4 10/27] x86/traps: move set_guest_{machine, nmi}_trapbounce

In reply to Wei Liu
Quoted 18 lines · Wei Liu

Take the opportunity to change their return type to bool. And rename "v" to "curr".

---
 xen/arch/x86/pv/traps.c | 27 +++++++++++++++++++++++++++
 xen/arch/x86/traps.c    | 27 ---------------------------
 2 files changed, 27 insertions(+), 27 deletions(-)
xen/arch/x86/pv/traps.c +1 -0
index ec7ff1040b..e374cd73b4 100644
@@ -156,6 +156,33 @@ void pv_inject_event(const struct x86_event *event)
     }
 }
 
+/*

xen/arch/x86/pv/traps.c void pv_inject_event(const struct x86_event *event) · line 169

Quoted 10 lines
xen/arch/x86/pv/traps.c +10 -0
+ * Called from asm to set up the MCE trapbounce info.
+ * Returns false no callback is set up, else true.
+ */
+bool set_guest_machinecheck_trapbounce(void)
+{
+    struct vcpu *curr = current;
+    struct trap_bounce *tb = &curr->arch.pv_vcpu.trap_bounce;
+
+    pv_inject_hw_exception(TRAP_machine_check, X86_EVENT_NO_EC);
+    tb->flags &= ~TBF_EXCEPTION; /* not needed for MCE delivery path */

As we are fixing style, newline.

xen/arch/x86/pv/traps.c void pv_inject_event(const struct x86_event *event) · line 180

Quoted 11 lines
xen/arch/x86/pv/traps.c +11 -0
+    return !null_trap_bounce(curr, tb);
+}
+
+/*
+ * Called from asm to set up the NMI trapbounce info.
+ * Returns false if no callback is set up, else true.
+ */
+bool set_guest_nmi_trapbounce(void)
+{
+    struct vcpu *curr = current;
+    struct trap_bounce *tb = &curr->arch.pv_vcpu.trap_bounce;

newline.

xen/arch/x86/pv/traps.c void pv_inject_event(const struct x86_event *event) · line 182

Quoted 2 lines
xen/arch/x86/pv/traps.c +2 -0
+    pv_inject_hw_exception(TRAP_nmi, X86_EVENT_NO_EC);
+    tb->flags &= ~TBF_EXCEPTION; /* not needed for NMI delivery path */

and newline.

Otherwise, Reviewed-by: Andrew Cooper <[email protected]>

Quoted 34 lines
xen/arch/x86/pv/traps.c +3 -0
+    return !null_trap_bounce(curr, tb);
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/traps.c +0 -20
index 6abfb62c0c..013de702ad 100644
@@ -626,33 +626,6 @@ void fatal_trap(const struct cpu_user_regs *regs, bool_t show_remote)
           (regs->eflags & X86_EFLAGS_IF) ? "" : ", IN INTERRUPT CONTEXT");
 }
 
-/*
- * Called from asm to set up the MCE trapbounce info.
- * Returns 0 if no callback is set up, else 1.
- */
-int set_guest_machinecheck_trapbounce(void)
-{
-    struct vcpu *v = current;
-    struct trap_bounce *tb = &v->arch.pv_vcpu.trap_bounce;
- 
-    pv_inject_hw_exception(TRAP_machine_check, X86_EVENT_NO_EC);
-    tb->flags &= ~TBF_EXCEPTION; /* not needed for MCE delivery path */
-    return !null_trap_bounce(v, tb);
-}
-
-/*
- * Called from asm to set up the NMI trapbounce info.
- * Returns 0 if no callback is set up, else 1.
- */
-int set_guest_nmi_trapbounce(void)
-{

xen/arch/x86/traps.c void fatal_trap(const struct cpu_user_regs *regs, bool_t show_remote) · line 631

Quoted 10 lines
xen/arch/x86/traps.c +0 -7
-    struct vcpu *v = current;
-    struct trap_bounce *tb = &v->arch.pv_vcpu.trap_bounce;
-    pv_inject_hw_exception(TRAP_nmi, X86_EVENT_NO_EC);
-    tb->flags &= ~TBF_EXCEPTION; /* not needed for NMI delivery path */
-    return !null_trap_bounce(v, tb);
-}
-
 void do_reserved_trap(struct cpu_user_regs *regs)
 {
     unsigned int trapnr = regs->entry_vector;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#34 lore raw

Re: [PATCH v4 12/27] x86/traps: move guest_has_trap_callback to pv/traps.c

In reply to Wei Liu
Quoted 5 lines · Wei Liu
xen/include/asm-x86/traps.h +0 -0
index f1d2513e6b..26625ce5a6 100644

xen/include/asm-x86/traps.h void async_exception_cleanup(struct vcpu *); · line 38

Quoted 10 lines
xen/include/asm-x86/traps.h +3 -3
@@ -32,10 +32,10 @@ void async_exception_cleanup(struct vcpu *);
 /**
  * guest_has_trap_callback
  *
- * returns true (non-zero) if guest registered a trap handler
+ * returns true if guest registered a trap handler
  */
-extern int guest_has_trap_callback(struct domain *d, uint16_t vcpuid,
-				unsigned int trap_nr);
+bool guest_has_trap_callback(const struct domain *d, unsigned int vcpuid,
+                             unsigned int trap_nr);

IMO, It would be better to reduce this to:

static inline bool pv_callback_registered(const struct vcpu *v, uint8_t vector)

{
    return v->arch.pv_vcpu.trap_ctxt[vector].address;
}

and adjust its single caller to match. inject_vmce() already has a struct vcpu in its hand at the call point, so we can loose all the range checking.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#36 lore raw

Re: [PATCH v4 13/27] x86: move toggle_guest_mode to pv/domain.c

In reply to Wei Liu
Quoted 11 lines · Wei Liu
---
 xen/arch/x86/pv/domain.c    | 30 ++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/traps.c | 30 ------------------------------
 2 files changed, 30 insertions(+), 30 deletions(-)
xen/arch/x86/pv/domain.c +0 -0
index 1c0c040ca0..0f3f0e85d6 100644

xen/arch/x86/pv/domain.c int pv_domain_initialise(struct domain *d, unsigned int domcr_flags, · line 219

Quoted 7 lines
xen/arch/x86/pv/domain.c +4 -0
@@ -213,6 +213,36 @@ int pv_domain_initialise(struct domain *d, unsigned int domcr_flags,
     return rc;
 }
 
+void toggle_guest_mode(struct vcpu *v)
+{
+    if ( is_pv_32bit_vcpu(v) )
+        return;

newline.

Otherwise, Reviewed-by: Andrew Cooper <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#32 lore raw

Re: [PATCH v4 11/27] x86:/traps: move {un, }register_guest_nmi_callback

In reply to Andrew Cooper
Quoted 5 lines · Andrew Cooper
Quoted 3 lines · Wei Liu

Take the opportunity to rename "v" to "curr".

misc-hypercalls.c. Again, this is just a hypercall handler stashing state.

Actually, on reviewing a later patch, we can do better here.

do_nmi_op() is one of the callsites of these helpers. It is in common/kernel.c, but only wired up into the hypercall table for x86 PV guests.

It would be better to move do_nmi_op() to being x86-specific, at which point you can drop the ARM stubs, and make all the helpers local to misc-hypercalls.c

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#43 lore raw

Re: [PATCH v4 16/27] x86/traps: factor out pv_trap_init

In reply to Wei Liu
Quoted 29 lines · Wei Liu
---
 xen/arch/x86/traps.c           | 22 ++++++++++++++--------
 xen/include/asm-x86/pv/traps.h |  4 ++++
 2 files changed, 18 insertions(+), 8 deletions(-)
xen/arch/x86/traps.c +1 -7
index 8861dfd332..29a83994bd 100644
@@ -1871,14 +1871,8 @@ void __init init_idt_traps(void)
     this_cpu(compat_gdt_table) = boot_cpu_compat_gdt_table;
 }
 
-extern void (*const autogen_entrypoints[NR_VECTORS])(void);
-void __init trap_init(void)
+void __init pv_trap_init(void)
 {
-    unsigned int vector;
-
-    /* Replace early pagefault with real pagefault handler. */
-    set_intr_gate(TRAP_page_fault, &page_fault);
-
     /* The 32-on-64 hypercall vector is only accessible from ring 1. */
     _set_gate(idt_table + HYPERCALL_VECTOR,
               SYS_DESC_trap_gate, 1, entry_int82);
@@ -1886,6 +1880,19 @@ void __init trap_init(void)
     /* Fast trap for int80 (faster than taking the #GP-fixup path). */
     _set_gate(idt_table + 0x80, SYS_DESC_trap_gate, 3, &int80_direct_trap);

xen/arch/x86/traps.c void __init trap_init(void) · line 1891

Quoted 10 lines
xen/arch/x86/traps.c +9 -0
 
+    open_softirq(NMI_MCE_SOFTIRQ, nmi_mce_softirq);
+}
+
+extern void (*const autogen_entrypoints[NR_VECTORS])(void);
+void __init trap_init(void)
+{
+    unsigned int vector;
+
+    pv_trap_init();

This call should be at the end of trap_init(), but I guess you hit the assertion?

The !CONFIG_PV case will similarly hit the assertion.

For !CONFIG_PV, 0x80 and 0x82 would best become general interrupt handlers, which means you need to tweak entry.S autogen_stubs, and also tweak init_irq_data()

~Andrew

Quoted 29 lines
xen/arch/x86/traps.c +4 -1
+
+    /* Replace early pagefault with real pagefault handler. */
+    set_intr_gate(TRAP_page_fault, &page_fault);
+
     for ( vector = 0; vector < NR_VECTORS; ++vector )
     {
         if ( autogen_entrypoints[vector] )
@@ -1905,7 +1912,6 @@ void __init trap_init(void)
 
     cpu_init();
 
-    open_softirq(NMI_MCE_SOFTIRQ, nmi_mce_softirq);
     open_softirq(PCI_SERR_SOFTIRQ, pci_serr_softirq);
 }
 
xen/include/asm-x86/pv/traps.h +2 -0
index a4af69e486..426c8f6216 100644
@@ -25,6 +25,8 @@
 
 #include <public/xen.h>
 
+void pv_trap_init(void);
+
 int pv_emulate_privileged_op(struct cpu_user_regs *regs);
 void pv_emulate_gate_op(struct cpu_user_regs *regs);
 int pv_emulate_invalid_rdtscp(struct cpu_user_regs *regs);

xen/include/asm-x86/pv/traps.h int pv_emulate_forced_invalid_op(struct cpu_user_regs *regs); · line 41

Quoted 8 lines
xen/include/asm-x86/pv/traps.h +2 -0
@@ -32,6 +34,8 @@ int pv_emulate_forced_invalid_op(struct cpu_user_regs *regs);
 
 #else  /* !CONFIG_PV */
 
+void pv_trap_init(void) {}
+
 int pv_emulate_privileged_op(struct cpu_user_regs *regs) { return 0; }
 void pv_emulate_gate_op(struct cpu_user_regs *regs) {}
 int pv_emulate_invalid_rdtscp(struct cpu_user_regs *regs) { return 0; }

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#46 lore raw

Re: [PATCH v4 17/27] x86/traps: move some PV specific functions and struct to pv/traps.c

In reply to Wei Liu

xen/arch/x86/pv/traps.c bool guest_has_trap_callback(const struct domain *d, unsigned int vcpuid, · line 294

Quoted 13 lines · Wei Liu
xen/arch/x86/pv/traps.c +13 -0
+void __init pv_trap_init(void)
+{
+    /* The 32-on-64 hypercall vector is only accessible from ring 1. */
+    _set_gate(idt_table + HYPERCALL_VECTOR,
+              SYS_DESC_trap_gate, 1, entry_int82);
+
+    /* Fast trap for int80 (faster than taking the #GP-fixup path). */
+    _set_gate(idt_table + 0x80, SYS_DESC_trap_gate, 3, &int80_direct_trap);
+
+    open_softirq(NMI_MCE_SOFTIRQ, nmi_mce_softirq);
+}
+
+int send_guest_trap(struct domain *d, uint16_t vcpuid, unsigned int trap_nr)

Just like guest_has_trap_callback(), there is only a single caller and it has a struct vcpu in its hand.

I'd recommend breaking out a cleanup patch which switches this to:

int pv_raise_interrupt(struct vcpu *v, uint8_t vector);

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#48 lore raw

Re: [PATCH v4 18/27] x86/traps: move init_int80_direct_trap to pv/traps.c

In reply to Wei Liu
Quoted 12 lines · Wei Liu
---
 xen/arch/x86/pv/traps.c     | 14 ++++++++++++++
 xen/arch/x86/x86_64/traps.c | 14 --------------
 2 files changed, 14 insertions(+), 14 deletions(-)
xen/arch/x86/pv/traps.c +0 -0
index 0c1600d886..f2556c7e4a 100644

xen/arch/x86/pv/traps.c int send_guest_trap(struct domain *d, uint16_t vcpuid, unsigned int trap_nr) · line 351

Quoted 10 lines
xen/arch/x86/pv/traps.c +7 -0
@@ -342,6 +342,20 @@ int send_guest_trap(struct domain *d, uint16_t vcpuid, unsigned int trap_nr)
     return -EIO;
 }
 
+void init_int80_direct_trap(struct vcpu *v)
+{
+    struct trap_info *ti = &v->arch.pv_vcpu.trap_ctxt[0x80];
+    struct trap_bounce *tb = &v->arch.pv_vcpu.int80_bounce;
+
+    tb->cs    = ti->cs;
+    tb->eip   = ti->address;

Mind reducing the spaces here? Otherwise, Reviewed-by: Andrew Cooper <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#50 lore raw

Re: [PATCH v4 19/27] x86: move hypercall_page_initialise_ring3_kernel to pv/hypercall.c

In reply to Wei Liu
Quoted 12 lines · Wei Liu
---
 xen/arch/x86/pv/hypercall.c     | 36 ++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/traps.c     | 36 ------------------------------------
 xen/include/asm-x86/hypercall.h |  1 +
 3 files changed, 37 insertions(+), 36 deletions(-)
xen/arch/x86/pv/hypercall.c +0 -0
index 7c5e5a629d..287340e774 100644

xen/arch/x86/pv/hypercall.c enum mc_disposition arch_do_multicall_call(struct mc_state *state) · line 261

Quoted 7 lines
xen/arch/x86/pv/hypercall.c +4 -0
@@ -255,6 +255,42 @@ enum mc_disposition arch_do_multicall_call(struct mc_state *state)
              ? mc_continue : mc_preempt;
 }
 
+void hypercall_page_initialise_ring3_kernel(void *hypercall_page)
+{
+    char *p;
+    int i;

void *p = hypercall_page;
unsigned int i;

xen/arch/x86/pv/hypercall.c enum mc_disposition arch_do_multicall_call(struct mc_state *state) · line 265

Quoted 4 lines
xen/arch/x86/pv/hypercall.c +4 -0
+
+    /* Fill in all the transfer points with template machine code. */
+    for ( i = 0; i < (PAGE_SIZE / 32); i++ )
+    {

i++, p += 32

Otherwise, Reviewed-by: Andrew Cooper <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#58 lore raw

Re: [PATCH v4 21/27] x86: move compat_set_trap_table along side the non-compat variant

In reply to Wei Liu
Quoted 11 lines · Wei Liu
---
 xen/arch/x86/pv/traps.c            | 45 ++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/compat/traps.c | 45 --------------------------------------
 2 files changed, 45 insertions(+), 45 deletions(-)
xen/arch/x86/pv/traps.c +0 -0
index f2556c7e4a..3dcb3f1877 100644

xen/arch/x86/pv/traps.c long do_set_trap_table(XEN_GUEST_HANDLE_PARAM(const_trap_info_t) traps) · line 91

Quoted 5 lines
xen/arch/x86/pv/traps.c +2 -0
@@ -87,6 +87,51 @@ long do_set_trap_table(XEN_GUEST_HANDLE_PARAM(const_trap_info_t) traps)
     return rc;
 }
 
+int compat_set_trap_table(XEN_GUEST_HANDLE(trap_info_compat_t) traps)
+{

struct vcpu *curr = current;

Otherwise, Reviewed-by: Andrew Cooper <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#70 lore raw

Re: [PATCH v4 27/27] x86: clean up traps.c

In reply to Wei Liu

xen/arch/x86/traps.c void do_int3(struct cpu_user_regs *regs) · line 1085

Quoted 8 lines · Wei Liu
xen/arch/x86/traps.c +2 -2
@@ -1081,8 +1081,8 @@ void do_int3(struct cpu_user_regs *regs)
     pv_inject_hw_exception(TRAP_int3, X86_EVENT_NO_EC);
 }
 
-static void reserved_bit_page_fault(
-    unsigned long addr, struct cpu_user_regs *regs)
+static void reserved_bit_page_fault(unsigned long addr,
+                                    struct cpu_user_regs *regs)

Why are these prototypes changing? For this case, it doesn't matter, but the former is necessary if any of them gain more parameters.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by on v4 23/27
#62 lore raw

Re: [PATCH v4 23/27] x86: move the compat callback ops next to the non-compat variant

In reply to Wei Liu

xen/arch/x86/pv/callback.c long do_set_callbacks(unsigned long event_address, · line 237

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 08.06.17 at 19:11, <[email protected]> wrote:
xen/arch/x86/pv/callback.c +4 -0
+}
+
+
+long compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg)

Please avoid double blank lines like above. And preferably, please, just like you did in earlier patches, use "curr" instead of "v". Then

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#71 lore raw

Re: [PATCH v4 27/27] x86: clean up traps.c

In reply to Andrew Cooper
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 23.06.17 at 14:50, <[email protected]> wrote:
Quoted 4 lines · Wei Liu
xen/arch/x86/traps.c +0 -0
@@ -1081,8 +1081,8 @@ void do_int3(struct cpu_user_regs *regs)
     pv_inject_hw_exception(TRAP_int3, X86_EVENT_NO_EC);
 }
 
Quoted 7 lines

xen/arch/x86/traps.c void do_int3(struct cpu_user_regs *regs) · line 1085

Quoted 4 lines
xen/arch/x86/traps.c +2 -2
-static void reserved_bit_page_fault(
-    unsigned long addr, struct cpu_user_regs *regs)
+static void reserved_bit_page_fault(unsigned long addr,
+                                    struct cpu_user_regs *regs)

Why are these prototypes changing? For this case, it doesn't matter, but the former is necessary if any of them gain more parameters.

I think we should use consistent format, and while originally there may have been quite a few cases of what is being removed here, over time we've been switching towards what is being put in place here. I don't see why adding more parameters would be in conflict with this. If not even a single parameter declaration fits on a line, then imo this is a good suggestion that the function name is too long.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#44 lore raw

Re: [PATCH v4 16/27] x86/traps: factor out pv_trap_init

In reply to Andrew Cooper
Quoted 31 lines · Andrew Cooper
Quoted 30 lines · Wei Liu
---
 xen/arch/x86/traps.c           | 22 ++++++++++++++--------
 xen/include/asm-x86/pv/traps.h |  4 ++++
 2 files changed, 18 insertions(+), 8 deletions(-)
xen/arch/x86/traps.c +1 -7
index 8861dfd332..29a83994bd 100644
@@ -1871,14 +1871,8 @@ void __init init_idt_traps(void)
     this_cpu(compat_gdt_table) = boot_cpu_compat_gdt_table;
 }
 
-extern void (*const autogen_entrypoints[NR_VECTORS])(void);
-void __init trap_init(void)
+void __init pv_trap_init(void)
 {
-    unsigned int vector;
-
-    /* Replace early pagefault with real pagefault handler. */
-    set_intr_gate(TRAP_page_fault, &page_fault);
-
     /* The 32-on-64 hypercall vector is only accessible from ring 1. */
     _set_gate(idt_table + HYPERCALL_VECTOR,
               SYS_DESC_trap_gate, 1, entry_int82);
@@ -1886,6 +1880,19 @@ void __init trap_init(void)
     /* Fast trap for int80 (faster than taking the #GP-fixup path). */
     _set_gate(idt_table + 0x80, SYS_DESC_trap_gate, 3, &int80_direct_trap);
 
Quoted 13 lines

xen/arch/x86/traps.c void __init trap_init(void) · line 1891

Quoted 9 lines
xen/arch/x86/traps.c +9 -0
+    open_softirq(NMI_MCE_SOFTIRQ, nmi_mce_softirq);
+}
+
+extern void (*const autogen_entrypoints[NR_VECTORS])(void);
+void __init trap_init(void)
+{
+    unsigned int vector;
+
+    pv_trap_init();

This call should be at the end of trap_init(), but I guess you hit the assertion?

Yes, that would hit the assertion.

Quoted 6 lines

The !CONFIG_PV case will similarly hit the assertion.

For !CONFIG_PV, 0x80 and 0x82 would best become general interrupt handlers, which means you need to tweak entry.S autogen_stubs, and also tweak init_irq_data()

Good point. I will tweak both locations.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#22 lore raw

Re: [PATCH v4 07/27] x86: move do_set_trap_table to pv/traps.c

In reply to Andrew Cooper
Quoted 8 lines · Andrew Cooper
Quoted 1 line · Wei Liu

I'd suggest folding this into the next patch, and putting the hypercall in misc-hypercalls.c

Despite its name, this hypercall is just setting up state in the vcpu.

This is trivial to do. But if I do it, does your Rb in the next patch apply to the new version?

Quoted 1 line

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#23 lore raw

Re: [PATCH v4 07/27] x86: move do_set_trap_table to pv/traps.c

Quoted 10 lines · Wei Liu
Quoted 7 lines · Andrew Cooper
Quoted 1 line · Wei Liu

I'd suggest folding this into the next patch, and putting the hypercall in misc-hypercalls.c

Despite its name, this hypercall is just setting up state in the vcpu.

This is trivial to do. But if I do it, does your Rb in the next patch apply to the new version?

Yes.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#39 lore raw

Re: [PATCH v4 14/27] x86: move do_iret to pv/iret.c

In reply to Andrew Cooper
Quoted 10 lines · Andrew Cooper
Quoted 4 lines · Wei Liu

---
There is no copyright header in the original file. Use the default one?

It should at least gain a basic GPLv2 header.

Otherwise, LGTM.

I'm going to insert the following license from CONTRIBUTING:\

/*
* pv/iret.c
*
* iret hypercall handling code
*
* This program is free software; you can redistribute it and/or
* modify it under the terms and conditions of the GNU General Public
* License, version 2, as published by the Free Software Foundation. *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; If not, see
* <http://www.gnu.org/licenses/>.
*/

Can I have your ack or rb?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by
#40 lore raw

Re: [PATCH v4 14/27] x86: move do_iret to pv/iret.c

Quoted 32 lines · Wei Liu
Quoted 9 lines · Andrew Cooper
Quoted 4 lines · Wei Liu

---
There is no copyright header in the original file. Use the default one?

It should at least gain a basic GPLv2 header.

Otherwise, LGTM.

I'm going to insert the following license from CONTRIBUTING:\

/*
* pv/iret.c
*
* iret hypercall handling code
*
* This program is free software; you can redistribute it and/or
* modify it under the terms and conditions of the GNU General Public
* License, version 2, as published by the Free Software Foundation. *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; If not, see
* <http://www.gnu.org/licenses/>.
*/

Quoted 1 line

Can I have your ack or rb?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#51 lore raw

Re: [PATCH v4 19/27] x86: move hypercall_page_initialise_ring3_kernel to pv/hypercall.c

In reply to Andrew Cooper
Quoted 24 lines · Andrew Cooper
Quoted 12 lines · Wei Liu
---
 xen/arch/x86/pv/hypercall.c     | 36 ++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/traps.c     | 36 ------------------------------------
 xen/include/asm-x86/hypercall.h |  1 +
 3 files changed, 37 insertions(+), 36 deletions(-)
xen/arch/x86/pv/hypercall.c +0 -0
index 7c5e5a629d..287340e774 100644

xen/arch/x86/pv/hypercall.c enum mc_disposition arch_do_multicall_call(struct mc_state *state) · line 261

Quoted 7 lines
xen/arch/x86/pv/hypercall.c +4 -0
@@ -255,6 +255,42 @@ enum mc_disposition arch_do_multicall_call(struct mc_state *state)
              ? mc_continue : mc_preempt;
 }
 
+void hypercall_page_initialise_ring3_kernel(void *hypercall_page)
+{
+    char *p;
+    int i;

void *p = hypercall_page;
unsigned int i;

Quoted 6 lines

xen/arch/x86/pv/hypercall.c enum mc_disposition arch_do_multicall_call(struct mc_state *state) · line 265

Quoted 4 lines
xen/arch/x86/pv/hypercall.c +4 -0
+
+    /* Fill in all the transfer points with template machine code. */
+    for ( i = 0; i < (PAGE_SIZE / 32); i++ )
+    {

i++, p += 32

Wait, I think pointer arithmetic is not allowed on void* ?

Quoted 2 lines

Otherwise, Reviewed-by: Andrew Cooper <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#52 lore raw

Re: [PATCH v4 19/27] x86: move hypercall_page_initialise_ring3_kernel to pv/hypercall.c

Quoted 24 lines · Wei Liu
Quoted 23 lines · Andrew Cooper
Quoted 12 lines · Wei Liu
---
 xen/arch/x86/pv/hypercall.c     | 36 ++++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/traps.c     | 36 ------------------------------------
 xen/include/asm-x86/hypercall.h |  1 +
 3 files changed, 37 insertions(+), 36 deletions(-)
xen/arch/x86/pv/hypercall.c +0 -0
index 7c5e5a629d..287340e774 100644

xen/arch/x86/pv/hypercall.c enum mc_disposition arch_do_multicall_call(struct mc_state *state) · line 261

Quoted 7 lines
xen/arch/x86/pv/hypercall.c +4 -0
@@ -255,6 +255,42 @@ enum mc_disposition arch_do_multicall_call(struct mc_state *state)
              ? mc_continue : mc_preempt;
 }
 
+void hypercall_page_initialise_ring3_kernel(void *hypercall_page)
+{
+    char *p;
+    int i;

void *p = hypercall_page;
unsigned int i;

Quoted 6 lines
Quoted 5 lines

xen/arch/x86/pv/hypercall.c enum mc_disposition arch_do_multicall_call(struct mc_state *state) · line 265

Quoted 4 lines
xen/arch/x86/pv/hypercall.c +4 -0
+
+    /* Fill in all the transfer points with template machine code. */
+    for ( i = 0; i < (PAGE_SIZE / 32); i++ )
+    {

i++, p += 32

Wait, I think pointer arithmetic is not allowed on void* ?

void pointer arithmetic is a GCCism, which we use in plenty of other locations.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel