xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
	wei.liu2@citrix.com, George.Dunlap@eu.citrix.com,
	andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com,
	dfaggioli@suse.com, jbeulich@suse.com
Subject: [PATCH RFC v2 10/12] x86: allocate per-vcpu stacks for interrupt entries
Date: Mon, 22 Jan 2018 13:32:54 +0100	[thread overview]
Message-ID: <20180122123256.1431-11-jgross@suse.com> (raw)
In-Reply-To: <20180122123256.1431-1-jgross@suse.com>

In case of XPTI being active for a pv-domain allocate and initialize
per-vcpu stacks. The stacks are added to the per-domain mappings of
the pv-domain.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 xen/arch/x86/pv/domain.c      | 72 +++++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/config.h  | 13 +++++++-
 xen/include/asm-x86/current.h | 39 ++++++++++++++++++++---
 xen/include/asm-x86/domain.h  |  3 ++
 4 files changed, 121 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index 7d50f9bc19..834be96ed8 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -156,6 +156,75 @@ void pv_vcpu_destroy(struct vcpu *v)
     pv_destroy_gdt_ldt_l1tab(v);
     xfree(v->arch.pv_vcpu.trap_ctxt);
     v->arch.pv_vcpu.trap_ctxt = NULL;
+
+    if ( v->domain->arch.pv_domain.xpti )
+    {
+        free_xenheap_page(v->arch.pv_vcpu.stack_regs);
+        v->arch.pv_vcpu.stack_regs = NULL;
+        destroy_perdomain_mapping(v->domain, XPTI_START(v), STACK_PAGES);
+    }
+}
+
+static int pv_vcpu_init_xpti(struct vcpu *v)
+{
+    struct domain *d = v->domain;
+    struct page_info *pg;
+    void *ptr;
+    struct cpu_info *info;
+    unsigned long stack_bottom;
+    int rc;
+
+    /* Populate page tables. */
+    rc = create_perdomain_mapping(d, XPTI_START(v), STACK_PAGES,
+                                  NIL(l1_pgentry_t *), NULL);
+    if ( rc )
+        goto done;
+
+    /* Map stacks. */
+    rc = create_perdomain_mapping(d, XPTI_START(v), IST_MAX,
+                                  NULL, NIL(struct page_info *));
+    if ( rc )
+        goto done;
+
+    ptr = alloc_xenheap_page();
+    if ( !ptr )
+    {
+        rc = -ENOMEM;
+        goto done;
+    }
+    clear_page(ptr);
+    addmfn_to_perdomain_mapping(d, XPTI_START(v) + STACK_SIZE - PAGE_SIZE,
+                                _mfn(virt_to_mfn(ptr)));
+    info = (struct cpu_info *)((unsigned long)ptr + PAGE_SIZE) - 1;
+    info->flags = ON_VCPUSTACK;
+    v->arch.pv_vcpu.stack_regs = &info->guest_cpu_user_regs;
+
+    /* Map TSS. */
+    rc = create_perdomain_mapping(d, XPTI_TSS(v), 1, NULL, &pg);
+    if ( rc )
+        goto done;
+    info = (struct cpu_info *)(XPTI_START(v) + STACK_SIZE) - 1;
+    stack_bottom = (unsigned long)&info->guest_cpu_user_regs.es;
+    ptr = __map_domain_page(pg);
+    tss_init(ptr, stack_bottom);
+    unmap_domain_page(ptr);
+
+    /* Map stub trampolines. */
+    rc = create_perdomain_mapping(d, XPTI_TRAMPOLINE(v), 1, NULL, &pg);
+    if ( rc )
+        goto done;
+    ptr = __map_domain_page(pg);
+    write_stub_trampoline((unsigned char *)ptr, XPTI_TRAMPOLINE(v),
+                          stack_bottom, (unsigned long)lstar_enter);
+    write_stub_trampoline((unsigned char *)ptr + STUB_TRAMPOLINE_SIZE_PERVCPU,
+                          XPTI_TRAMPOLINE(v) + STUB_TRAMPOLINE_SIZE_PERVCPU,
+                          stack_bottom, (unsigned long)cstar_enter);
+    unmap_domain_page(ptr);
+    flipflags_perdomain_mapping(d, XPTI_TRAMPOLINE(v),
+                                _PAGE_NX | _PAGE_RW | _PAGE_DIRTY);
+
+ done:
+    return rc;
 }
 
 int pv_vcpu_initialise(struct vcpu *v)
@@ -195,6 +264,9 @@ int pv_vcpu_initialise(struct vcpu *v)
             goto done;
     }
 
+    if ( d->arch.pv_domain.xpti )
+        rc = pv_vcpu_init_xpti(v);
+
  done:
     if ( rc )
         pv_vcpu_destroy(v);
diff --git a/xen/include/asm-x86/config.h b/xen/include/asm-x86/config.h
index 9ef9d03ca7..cb107255af 100644
--- a/xen/include/asm-x86/config.h
+++ b/xen/include/asm-x86/config.h
@@ -66,6 +66,7 @@
 #endif
 
 #define STACK_ORDER 3
+#define STACK_PAGES (1 << STACK_ORDER)
 #define STACK_SIZE  (PAGE_SIZE << STACK_ORDER)
 
 #define TRAMPOLINE_STACK_SPACE  PAGE_SIZE
@@ -202,7 +203,7 @@ extern unsigned char boot_edid_info[128];
 /* Slot 260: per-domain mappings (including map cache). */
 #define PERDOMAIN_VIRT_START    (PML4_ADDR(260))
 #define PERDOMAIN_SLOT_MBYTES   (PML4_ENTRY_BYTES >> (20 + PAGETABLE_ORDER))
-#define PERDOMAIN_SLOTS         3
+#define PERDOMAIN_SLOTS         4
 #define PERDOMAIN_VIRT_SLOT(s)  (PERDOMAIN_VIRT_START + (s) * \
                                  (PERDOMAIN_SLOT_MBYTES << 20))
 /* Slot 261: machine-to-phys conversion table (256GB). */
@@ -310,6 +311,16 @@ extern unsigned long xen_phys_start;
 #define ARG_XLAT_START(v)        \
     (ARG_XLAT_VIRT_START + ((v)->vcpu_id << ARG_XLAT_VA_SHIFT))
 
+/* Per-vcpu XPTI pages. The fourth per-domain-mapping sub-area. */
+#define XPTI_VIRT_START          PERDOMAIN_VIRT_SLOT(3)
+#define XPTI_VA_SHIFT            (PAGE_SHIFT + STACK_ORDER)
+#define XPTI_TRAMPOLINE_OFF      (IST_MAX << PAGE_SHIFT)
+#define XPTI_TSS_OFF             ((IST_MAX + 2) << PAGE_SHIFT)
+#define XPTI_START(v)            (XPTI_VIRT_START + \
+                                  ((v)->vcpu_id << XPTI_VA_SHIFT))
+#define XPTI_TRAMPOLINE(v)       (XPTI_START(v) + XPTI_TRAMPOLINE_OFF)
+#define XPTI_TSS(v)              (XPTI_START(v) + XPTI_TSS_OFF)
+
 #define NATIVE_VM_ASSIST_VALID   ((1UL << VMASST_TYPE_4gb_segments)        | \
                                   (1UL << VMASST_TYPE_4gb_segments_notify) | \
                                   (1UL << VMASST_TYPE_writable_pagetables) | \
diff --git a/xen/include/asm-x86/current.h b/xen/include/asm-x86/current.h
index c7acbb97da..6ae0931a59 100644
--- a/xen/include/asm-x86/current.h
+++ b/xen/include/asm-x86/current.h
@@ -12,7 +12,7 @@
 #include <asm/page.h>
 
 /*
- * Xen's cpu stacks are 8 pages (8-page aligned), arranged as:
+ * Xen's physical cpu stacks are 8 pages (8-page aligned), arranged as:
  *
  * 7 - Primary stack (with a struct cpu_info at the top)
  * 6 - Primary stack
@@ -25,6 +25,21 @@
  */
 
 /*
+ * The vcpu stacks used for XPTI are arranged similar to the physical cpu
+ * stacks with some modifications. The main difference are the primary stack
+ * size (only 1 page) and usage of the unused mappings for TSS and IDT.
+ *
+ * 7 - Primary stack (with a struct cpu_info at the top)
+ * 6 - unused
+ * 5 - TSS
+ * 4 - unused
+ * 3 - Syscall trampolines
+ * 2 - MCE IST stack
+ * 1 - NMI IST stack
+ * 0 - Double Fault IST stack
+ */
+
+/*
  * Identify which stack page the stack pointer is on.  Returns an index
  * as per the comment above.
  */
@@ -37,10 +52,24 @@ struct vcpu;
 
 struct cpu_info {
     struct cpu_user_regs guest_cpu_user_regs;
-    unsigned int processor_id;
-    struct vcpu *current_vcpu;
-    unsigned long per_cpu_offset;
-    unsigned long cr4;
+    union {
+        /* per physical cpu mapping */
+        struct {
+            struct vcpu *current_vcpu;
+            unsigned long per_cpu_offset;
+            unsigned long cr4;
+        };
+        /* per vcpu mapping (xpti) */
+        struct {
+            unsigned long pad1;
+            unsigned long pad2;
+            unsigned long stack_bottom_cpu;
+        };
+    };
+    unsigned int processor_id;  /* per physical cpu mapping only */
+    unsigned int flags;
+#define ON_VCPUSTACK      0x00000001
+#define VCPUSTACK_ACTIVE  0x00000002
     /* get_stack_bottom() must be 16-byte aligned */
 };
 
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index f1230ac621..5eb67f4f4c 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -503,6 +503,9 @@ struct pv_vcpu
     /* Deferred VA-based update state. */
     bool_t need_update_runstate_area;
     struct vcpu_time_info pending_system_time;
+
+    /* If XPTI is active: pointer to user regs on stack. */
+    struct cpu_user_regs *stack_regs;
 };
 
 typedef enum __packed {
-- 
2.13.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-01-22 12:35 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-22 12:32 [PATCH RFC v2 00/12] xen/x86: use per-vcpu stacks for 64 bit pv domains Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 01/12] x86: cleanup processor.h Juergen Gross
2018-01-22 12:52   ` Jan Beulich
     [not found]   ` <5A65ECA502000078001A111C@suse.com>
2018-01-22 14:10     ` Juergen Gross
2018-01-22 14:25       ` Andrew Cooper
2018-01-22 14:32         ` Jan Beulich
2018-01-22 12:32 ` [PATCH RFC v2 02/12] x86: don't use hypervisor stack size for dumping guest stacks Juergen Gross
2018-01-23  9:26   ` Jan Beulich
     [not found]   ` <5A670DEF02000078001A16AF@suse.com>
2018-01-23  9:58     ` Juergen Gross
2018-01-23 10:11       ` Jan Beulich
     [not found]       ` <5A67187C02000078001A1742@suse.com>
2018-01-23 10:19         ` Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 03/12] x86: do a revert of e871e80c38547d9faefc6604532ba3e985e65873 Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 04/12] x86: revert 5784de3e2067ed73efc2fe42e62831e8ae7f46c4 Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 05/12] x86: don't access saved user regs via rsp in trap handlers Juergen Gross
2018-01-30 14:49   ` Jan Beulich
     [not found]   ` <5A70941B02000078001A3BF0@suse.com>
2018-01-30 16:33     ` Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 06/12] x86: add a xpti command line parameter Juergen Gross
2018-01-30 15:39   ` Jan Beulich
     [not found]   ` <5A709FDF02000078001A3C2C@suse.com>
2018-01-30 16:51     ` Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 07/12] x86: allow per-domain mappings without NX bit or with specific mfn Juergen Gross
2018-01-29 17:06   ` Jan Beulich
     [not found]   ` <5A6F62B602000078001A3810@suse.com>
2018-01-30  8:02     ` Juergen Gross
2018-01-30  8:41       ` Jan Beulich
2018-01-31 10:30   ` Jan Beulich
2018-01-22 12:32 ` [PATCH RFC v2 08/12] xen/x86: use dedicated function for tss initialization Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 09/12] x86: enhance syscall stub to work in per-domain mapping Juergen Gross
2018-01-30 15:11   ` Jan Beulich
     [not found]   ` <5A70991902000078001A3C16@suse.com>
2018-01-30 16:50     ` Juergen Gross
2018-01-22 12:32 ` Juergen Gross [this message]
2018-01-30 15:40   ` [PATCH RFC v2 10/12] x86: allocate per-vcpu stacks for interrupt entries Jan Beulich
2018-02-09 12:35     ` Juergen Gross
2018-02-13  9:10       ` Jan Beulich
     [not found]   ` <5A70A01402000078001A3C30@suse.com>
2018-01-30 17:12     ` Juergen Gross
2018-01-31 10:18       ` Jan Beulich
2018-01-22 12:32 ` [PATCH RFC v2 11/12] x86: modify interrupt handlers to support stack switching Juergen Gross
2018-01-30 16:07   ` Jan Beulich
     [not found]   ` <5A70A63D02000078001A3C7C@suse.com>
2018-01-30 17:19     ` Juergen Gross
2018-01-31 10:36       ` Jan Beulich
     [not found]       ` <5A71AA4202000078001A3F56@suse.com>
2018-02-02 15:42         ` Juergen Gross
2018-01-22 12:32 ` [PATCH RFC v2 12/12] x86: activate per-vcpu stacks in case of xpti Juergen Gross
2018-01-30 16:33   ` Jan Beulich
     [not found]   ` <5A70AC7F02000078001A3CA6@suse.com>
2018-01-30 17:33     ` Juergen Gross
2018-01-31 10:40       ` Jan Beulich
2018-01-22 12:50 ` [PATCH RFC v2 00/12] xen/x86: use per-vcpu stacks for 64 bit pv domains Jan Beulich
     [not found] ` <5A65EC0A02000078001A1118@suse.com>
2018-01-22 14:18   ` Juergen Gross
2018-01-22 14:22     ` Jan Beulich
     [not found]     ` <5A6601D302000078001A1230@suse.com>
2018-01-22 14:38       ` Juergen Gross
2018-01-22 14:48         ` Jan Beulich
     [not found]         ` <5A6607DB02000078001A127B@suse.com>
2018-01-22 15:00           ` Juergen Gross
2018-01-22 16:51             ` Jan Beulich
2018-01-22 18:39               ` Andrew Cooper
2018-01-22 18:48                 ` George Dunlap
2018-01-22 19:02                   ` Andrew Cooper
2018-01-23  8:36                     ` Jan Beulich
2018-01-23 11:23                       ` Andrew Cooper
2018-01-23 11:06                     ` George Dunlap
2018-01-23  6:34                 ` Juergen Gross
2018-01-23  7:21                   ` Juergen Gross
2018-01-23  8:53                   ` Jan Beulich
     [not found]                   ` <5A67061F02000078001A1669@suse.com>
2018-01-23  9:24                     ` Juergen Gross
2018-01-23  9:31                       ` Jan Beulich
     [not found]                       ` <5A670F0E02000078001A16C9@suse.com>
2018-01-23 10:10                         ` Juergen Gross
2018-01-23 11:45                           ` Andrew Cooper
2018-01-23 13:31                             ` Juergen Gross
2018-01-23 13:24                 ` Dario Faggioli
2018-01-23 16:45                 ` George Dunlap
2018-01-23 16:56                   ` Juergen Gross
2018-01-23 17:33                     ` George Dunlap
2018-01-24  7:37                       ` Jan Beulich
     [not found]             ` <5A6624A602000078001A1375@suse.com>
2018-01-23  5:50               ` Juergen Gross
2018-01-23  8:40                 ` Jan Beulich
     [not found]                 ` <5A67030F02000078001A164B@suse.com>
2018-01-23  9:45                   ` Juergen Gross
2018-01-22 21:45 ` Konrad Rzeszutek Wilk
2018-01-23  6:38   ` Juergen Gross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180122123256.1431-11-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dfaggioli@suse.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).