diff mbox

[v2,01/30] xen/x86: move setup of the VM86 TSS to the domain builder

Message ID 1474991845-27962-2-git-send-email-roger.pau@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roger Pau Monné Sept. 27, 2016, 3:56 p.m. UTC
This is also required for PVHv2 guests if they want to use real-mode, and
hvmloader is not executed for those kind of guests.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
---
 tools/firmware/hvmloader/hvmloader.c | 17 -----------------
 tools/libxc/include/xc_dom.h         |  2 +-
 tools/libxc/xc_dom_x86.c             | 16 ++++++++++++++++
 3 files changed, 17 insertions(+), 18 deletions(-)

Comments

Jan Beulich Sept. 28, 2016, 3:35 p.m. UTC | #1
>>> On 27.09.16 at 17:56, <roger.pau@citrix.com> wrote:
> This is also required for PVHv2 guests if they want to use real-mode, and
> hvmloader is not executed for those kind of guests.

While the intention is fine, I'm not convinced of consuming yet another
special page here: Other than the way hvmloader's allocation works,
here you permanently take away a page from the guest unconditionally
which (a) is used only on VMX, (b) only on old hardware, and (c) VMX
code appears to even be able to help itself without this TSS (at the
price of doing more emulation).

Jan
Roger Pau Monné Sept. 29, 2016, 12:57 p.m. UTC | #2
On Wed, Sep 28, 2016 at 09:35:21AM -0600, Jan Beulich wrote:
> >>> On 27.09.16 at 17:56, <roger.pau@citrix.com> wrote:
> > This is also required for PVHv2 guests if they want to use real-mode, and
> > hvmloader is not executed for those kind of guests.
> 
> While the intention is fine, I'm not convinced of consuming yet another
> special page here: Other than the way hvmloader's allocation works,
> here you permanently take away a page from the guest unconditionally
> which (a) is used only on VMX, (b) only on old hardware, and (c) VMX
> code appears to even be able to help itself without this TSS (at the
> price of doing more emulation).

Yes, real mode should also work without this. Given that I don't think we 
expect real-mode to be used for mostly anything but early AP initialization, 
I guess we could just leave PVHv2 guests without the TSS.

Roger.
diff mbox

Patch

diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c
index bbd4e34..9eabbd8 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -176,21 +176,6 @@  static void cmos_write_memory_size(void)
     cmos_outb(0x35, (uint8_t)( alt_mem >> 8));
 }
 
-/*
- * Set up an empty TSS area for virtual 8086 mode to use. 
- * The only important thing is that it musn't have any bits set 
- * in the interrupt redirection bitmap, so all zeros will do.
- */
-static void init_vm86_tss(void)
-{
-    void *tss;
-
-    tss = mem_alloc(128, 128);
-    memset(tss, 0, 128);
-    hvm_param_set(HVM_PARAM_VM86_TSS, virt_to_phys(tss));
-    printf("vm86 TSS at %08lx\n", virt_to_phys(tss));
-}
-
 static void apic_setup(void)
 {
     /*
@@ -398,8 +383,6 @@  int main(void)
         hvm_param_set(HVM_PARAM_ACPI_IOPORTS_LOCATION, 1);
     }
 
-    init_vm86_tss();
-
     cmos_write_memory_size();
 
     printf("BIOS map:\n");
diff --git a/tools/libxc/include/xc_dom.h b/tools/libxc/include/xc_dom.h
index de7dca9..e1cfaad 100644
--- a/tools/libxc/include/xc_dom.h
+++ b/tools/libxc/include/xc_dom.h
@@ -20,7 +20,7 @@ 
 #include <xenguest.h>
 
 #define INVALID_PFN ((xen_pfn_t)-1)
-#define X86_HVM_NR_SPECIAL_PAGES    8
+#define X86_HVM_NR_SPECIAL_PAGES    9
 #define X86_HVM_END_SPECIAL_REGION  0xff000u
 
 /* --- typedefs and structs ---------------------------------------- */
diff --git a/tools/libxc/xc_dom_x86.c b/tools/libxc/xc_dom_x86.c
index 0eab8a7..1676a3c 100644
--- a/tools/libxc/xc_dom_x86.c
+++ b/tools/libxc/xc_dom_x86.c
@@ -59,6 +59,7 @@ 
 #define SPECIALPAGE_IOREQ    5
 #define SPECIALPAGE_IDENT_PT 6
 #define SPECIALPAGE_CONSOLE  7
+#define SPECIALPAGE_VM86TSS  8
 #define special_pfn(x) \
     (X86_HVM_END_SPECIAL_REGION - X86_HVM_NR_SPECIAL_PAGES + (x))
 
@@ -590,6 +591,7 @@  static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
 {
     unsigned long i;
     uint32_t *ident_pt, domid = dom->guest_domid;
+    void *tss;
     int rc;
     xen_pfn_t special_array[X86_HVM_NR_SPECIAL_PAGES];
     xen_pfn_t ioreq_server_array[NR_IOREQ_SERVER_PAGES];
@@ -699,6 +701,20 @@  static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
     xc_hvm_param_set(xch, domid, HVM_PARAM_IDENT_PT,
                      special_pfn(SPECIALPAGE_IDENT_PT) << PAGE_SHIFT);
 
+    /*
+     * Set up an empty TSS area for virtual 8086 mode to use.
+     * The only important thing is that it musn't have any bits set
+     * in the interrupt redirection bitmap, so all zeros will do.
+     */
+    if ( (tss = xc_map_foreign_range(
+              xch, domid, PAGE_SIZE, PROT_READ | PROT_WRITE,
+              special_pfn(SPECIALPAGE_VM86TSS))) == NULL )
+        goto error_out;
+    memset(tss, 0, 128);
+    munmap(tss, PAGE_SIZE);
+    xc_hvm_param_set(xch, domid, HVM_PARAM_VM86_TSS,
+                     special_pfn(SPECIALPAGE_VM86TSS) << PAGE_SHIFT);
+
     dom->console_pfn = special_pfn(SPECIALPAGE_CONSOLE);
     dom->xenstore_pfn = special_pfn(SPECIALPAGE_XENSTORE);
     dom->parms.virt_hypercall = -1;