Skip to contentSkip to conversation

Introduce HVM without dm and new boot ABI

PATCH Superseded Roger Pau Monne 9 participants 121 messages Jul 3, 2015 – Aug 11, 2015 Arm/actions semi architecture

v3 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#1 lore raw

PATCH v3 1/32 libxc: split x86 HVM setup_guest into smaller logical functions

In reply to Roger Pau Monne

This is just a preparatory change to clean up the code in setup_guest. Should not introduce any functional changes.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxc/xc_hvm_build_x86.c | 198 ++++++++++++++++++++++++-----------------
 1 file changed, 117 insertions(+), 81 deletions(-)
tools/libxc/xc_hvm_build_x86.c +117 -81
index 003ea06..f7616a8 100644
@@ -232,28 +232,20 @@ static int check_mmio_hole(uint64_t start, uint64_t memsize,
         return 1;
 }
 
-static int setup_guest(xc_interface *xch,
-                       uint32_t dom, struct xc_hvm_build_args *args,
-                       char *image, unsigned long image_size)
+static int xc_hvm_populate_memory(xc_interface *xch, uint32_t dom,
+                                  struct xc_hvm_build_args *args,
+                                  xen_pfn_t *page_array)
 {
-    xen_pfn_t *page_array = NULL;
     unsigned long i, vmemid, nr_pages = args->mem_size >> PAGE_SHIFT;
     unsigned long p2m_size;
     unsigned long target_pages = args->mem_target >> PAGE_SHIFT;
-    unsigned long entry_eip, cur_pages, cur_pfn;
-    void *hvm_info_page;
-    uint32_t *ident_pt;
-    struct elf_binary elf;
-    uint64_t v_start, v_end;
-    uint64_t m_start = 0, m_end = 0;
+    unsigned long cur_pages, cur_pfn;
     int rc;
     xen_capabilities_info_t caps;
     unsigned long stat_normal_pages = 0, stat_2mb_pages = 0, 
         stat_1gb_pages = 0;
     unsigned int memflags = 0;
     int claim_enabled = args->claim_enabled;
-    xen_pfn_t special_array[NR_SPECIAL_PAGES];
-    xen_pfn_t ioreq_server_array[NR_IOREQ_SERVER_PAGES];
     uint64_t total_pages;
     xen_vmemrange_t dummy_vmemrange[2];
     unsigned int dummy_vnode_to_pnode[1];
@@ -261,19 +253,6 @@ static int setup_guest(xc_interface *xch,
     unsigned int *vnode_to_pnode;
     unsigned int nr_vmemranges, nr_vnodes;
 
-    memset(&elf, 0, sizeof(elf));
-    if ( elf_init(&elf, image, image_size) != 0 )
-    {
-        PERROR("Could not initialise ELF image");
-        goto error_out;
-    }
-
-    xc_elf_set_logfile(xch, &elf, 1);
-
-    elf_parse_binary(&elf);
-    v_start = 0;
-    v_end = args->mem_size;
-
     if ( nr_pages > target_pages )
         memflags |= XENMEMF_populate_on_demand;
 
@@ -346,24 +325,6 @@ static int setup_guest(xc_interface *xch,
         goto error_out;
     }
 
-    if ( modules_init(args, v_end, &elf, &m_start, &m_end) != 0 )
-    {
-        ERROR("Insufficient space to load modules.");
-        goto error_out;
-    }
-
-    DPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n");
-    DPRINTF("  Loader:   %016"PRIx64"->%016"PRIx64"\n", elf.pstart, elf.pend);
-    DPRINTF("  Modules:  %016"PRIx64"->%016"PRIx64"\n", m_start, m_end);
-    DPRINTF("  TOTAL:    %016"PRIx64"->%016"PRIx64"\n", v_start, v_end);
-    DPRINTF("  ENTRY:    %016"PRIx64"\n", elf_uval(&elf, elf.ehdr, e_entry));
-
-    if ( (page_array = malloc(p2m_size * sizeof(xen_pfn_t))) == NULL )
-    {
-        PERROR("Could not allocate memory.");
-        goto error_out;
-    }
-
     for ( i = 0; i < p2m_size; i++ )
         page_array[i] = ((xen_pfn_t)-1);
     for ( vmemid = 0; vmemid < nr_vmemranges; vmemid++ )
@@ -563,7 +524,54 @@ static int setup_guest(xc_interface *xch,
     DPRINTF("  4KB PAGES: 0x%016lx\n", stat_normal_pages);
     DPRINTF("  2MB PAGES: 0x%016lx\n", stat_2mb_pages);
     DPRINTF("  1GB PAGES: 0x%016lx\n", stat_1gb_pages);
-    
+
+    rc = 0;
+    goto out;
+ error_out:
+    rc = -1;
+ out:
+
+    /* ensure no unclaimed pages are left unused */
+    xc_domain_claim_pages(xch, dom, 0 /* cancels the claim */);
+
+    return rc;
+}
+
+static int xc_hvm_load_image(xc_interface *xch,
+                       uint32_t dom, struct xc_hvm_build_args *args,
+                       xen_pfn_t *page_array)
+{
+    unsigned long entry_eip, image_size;
+    struct elf_binary elf;
+    uint64_t v_start, v_end;
+    uint64_t m_start = 0, m_end = 0;
+    char *image;
+    int rc;
+
+    image = xc_read_image(xch, args->image_file_name, &image_size);
+    if ( image == NULL )
+        return -1;
+
+    memset(&elf, 0, sizeof(elf));
+    if ( elf_init(&elf, image, image_size) != 0 )
+        goto error_out;
+
+    xc_elf_set_logfile(xch, &elf, 1);
+
+    elf_parse_binary(&elf);
+    v_start = 0;
+    v_end = args->mem_size;
+
+    if ( modules_init(args, v_end, &elf, &m_start, &m_end) != 0 )
+    {
+        ERROR("Insufficient space to load modules.");
+        goto error_out;
+    }
+
+    DPRINTF("VIRTUAL MEMORY ARRANGEMENT:\n");
+    DPRINTF("  Loader:   %016"PRIx64"->%016"PRIx64"\n", elf.pstart, elf.pend);
+    DPRINTF("  Modules:  %016"PRIx64"->%016"PRIx64"\n", m_start, m_end);
+
     if ( loadelfimage(xch, &elf, dom, page_array) != 0 )
     {
         PERROR("Could not load ELF image");
@@ -576,6 +584,44 @@ static int setup_guest(xc_interface *xch,
         goto error_out;
     }
 
+    /* Insert JMP <rel32> instruction at address 0x0 to reach entry point. */
+    entry_eip = elf_uval(&elf, elf.ehdr, e_entry);
+    if ( entry_eip != 0 )
+    {
+        char *page0 = xc_map_foreign_range(
+            xch, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, 0);
+        if ( page0 == NULL )
+            goto error_out;
+        page0[0] = 0xe9;
+        *(uint32_t *)&page0[1] = entry_eip - 5;
+        munmap(page0, PAGE_SIZE);
+    }
+
+    rc = 0;
+    goto out;
+ error_out:
+    rc = -1;
+ out:
+    if ( elf_check_broken(&elf) )
+        ERROR("HVM ELF broken: %s", elf_check_broken(&elf));
+    free(image);
+
+    return rc;
+}
+
+static int xc_hvm_populate_params(xc_interface *xch, uint32_t dom,
+                                  struct xc_hvm_build_args *args)
+{
+    unsigned long i;
+    void *hvm_info_page;
+    uint32_t *ident_pt;
+    uint64_t v_end;
+    int rc;
+    xen_pfn_t special_array[NR_SPECIAL_PAGES];
+    xen_pfn_t ioreq_server_array[NR_IOREQ_SERVER_PAGES];
+
+    v_end = args->mem_size;
+
     if ( (hvm_info_page = xc_map_foreign_range(
               xch, dom, PAGE_SIZE, PROT_READ | PROT_WRITE,
               HVM_INFO_PFN)) == NULL )
@@ -664,34 +710,12 @@ static int setup_guest(xc_interface *xch,
     xc_hvm_param_set(xch, dom, HVM_PARAM_IDENT_PT,
                      special_pfn(SPECIALPAGE_IDENT_PT) << PAGE_SHIFT);
 
-    /* Insert JMP <rel32> instruction at address 0x0 to reach entry point. */
-    entry_eip = elf_uval(&elf, elf.ehdr, e_entry);
-    if ( entry_eip != 0 )
-    {
-        char *page0 = xc_map_foreign_range(
-            xch, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, 0);
-        if ( page0 == NULL )
-        {
-            PERROR("Could not map page0");
-            goto error_out;
-        }
-        page0[0] = 0xe9;
-        *(uint32_t *)&page0[1] = entry_eip - 5;
-        munmap(page0, PAGE_SIZE);
-    }
-
     rc = 0;
     goto out;
  error_out:
     rc = -1;
  out:
-    if ( elf_check_broken(&elf) )
-        ERROR("HVM ELF broken: %s", elf_check_broken(&elf));
-
-    /* ensure no unclaimed pages are left unused */
-    xc_domain_claim_pages(xch, dom, 0 /* cancels the claim */);
 
-    free(page_array);
     return rc;
 }
 
@@ -702,9 +726,8 @@ int xc_hvm_build(xc_interface *xch, uint32_t domid,
                  struct xc_hvm_build_args *hvm_args)
 {
     struct xc_hvm_build_args args = *hvm_args;
-    void *image;
-    unsigned long image_size;
-    int sts;
+    xen_pfn_t *parray = NULL;
+    int rc;
 
     if ( domid == 0 )
         return -1;
@@ -715,24 +738,37 @@ int xc_hvm_build(xc_interface *xch, uint32_t domid,
     if ( args.mem_size < (2ull << 20) || args.mem_target < (2ull << 20) )
         return -1;
 
-    image = xc_read_image(xch, args.image_file_name, &image_size);
-    if ( image == NULL )
+    parray = malloc((args.mem_size >> PAGE_SHIFT) * sizeof(xen_pfn_t));
+    if ( parray == NULL )
         return -1;
 
-    sts = setup_guest(xch, domid, &args, image, image_size);
-
-    if (!sts)
+    rc = xc_hvm_populate_memory(xch, domid, &args, parray);
+    if ( rc != 0 )
     {
-        /* Return module load addresses to caller */
-        hvm_args->acpi_module.guest_addr_out = 
-            args.acpi_module.guest_addr_out;
-        hvm_args->smbios_module.guest_addr_out = 
-            args.smbios_module.guest_addr_out;
+        PERROR("xc_hvm_populate_memory failed");
+        goto out;
+    }
+    rc = xc_hvm_load_image(xch, domid, &args, parray);
+    if ( rc != 0 )
+    {
+        PERROR("xc_hvm_load_image failed");
+        goto out;
+    }
+    rc = xc_hvm_populate_params(xch, domid, &args);
+    if ( rc != 0 )
+    {
+        PERROR("xc_hvm_populate_params failed");
+        goto out;
     }
 
-    free(image);
+    /* Return module load addresses to caller */
+    hvm_args->acpi_module.guest_addr_out = args.acpi_module.guest_addr_out;
+    hvm_args->smbios_module.guest_addr_out = args.smbios_module.guest_addr_out;
 
-    return sts;
+out:
+    free(parray);
+
+    return rc;
 }
 
 /* xc_hvm_build_target_mem: 
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 4/32 libxc: introduce a domain loader for HVM guest firmware

In reply to Roger Pau Monne

Introduce a very simple (and dummy) domain loader to be used to load the firmware (hvmloader) into HVM guests. Since hmvloader is just a 32bit elf executable the loader is fairly simple.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxc/Makefile           |   1 +
 tools/libxc/include/xc_dom.h   |   8 ++
 tools/libxc/xc_dom_hvmloader.c | 316 +++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/libelf.h       |   1 +
 4 files changed, 326 insertions(+)
 create mode 100644 tools/libxc/xc_dom_hvmloader.c
tools/libxc/Makefile +1 -0
index 153b79e..48fc473 100644
@@ -87,6 +87,7 @@ GUEST_SRCS-y                 += xc_dom_core.c xc_dom_boot.c
 GUEST_SRCS-y                 += xc_dom_elfloader.c
 GUEST_SRCS-$(CONFIG_X86)     += xc_dom_bzimageloader.c
 GUEST_SRCS-$(CONFIG_X86)     += xc_dom_decompress_lz4.c
+GUEST_SRCS-$(CONFIG_X86)     += xc_dom_hvmloader.c
 GUEST_SRCS-$(CONFIG_ARM)     += xc_dom_armzimageloader.c
 GUEST_SRCS-y                 += xc_dom_binloader.c
 GUEST_SRCS-y                 += xc_dom_compat_linux.c
tools/libxc/include/xc_dom.h +8 -0
index f7b5f0f..d61482c 100644
@@ -15,6 +15,7 @@
  */
 
 #include <xen/libelf/libelf.h>
+#include <xenguest.h>
 
 #define INVALID_P2M_ENTRY   ((xen_pfn_t)-1)
 
@@ -186,6 +187,13 @@ struct xc_dom_image {
         XC_DOM_PV_CONTAINER,
         XC_DOM_HVM_CONTAINER,
     } container_type;
+
+    /* HVM specific fields. */
+    /* Extra ACPI tables passed to HVMLOADER */
+    struct xc_hvm_firmware_module acpi_module;
+
+    /* Extra SMBIOS structures passed to HVMLOADER */
+    struct xc_hvm_firmware_module smbios_module;
 };
 
 /* --- pluggable kernel loader ------------------------------------- */
tools/libxc/xc_dom_hvmloader.c new file +316 -0

316 lines not on this page · raw message

xen/include/xen/libelf.h +1 -0
index 6393040..03d449e 100644
@@ -424,6 +424,7 @@ struct elf_dom_parms {
     uint64_t elf_paddr_offset;
     uint32_t f_supported[XENFEAT_NR_SUBMAPS];
     uint32_t f_required[XENFEAT_NR_SUBMAPS];
+    uint32_t phys_entry;
 
     /* calculated */
     uint64_t virt_offset;
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 2/32 libxc: unify xc_dom_p2m_{host/guest}

In reply to Roger Pau Monne

Unify both functions into xc_dom_p2m. Should not introduce any functional change.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Samuel Thibault <[email protected]>
---
 stubdom/grub/kexec.c              |  4 ++--
 tools/libxc/include/xc_dom.h      | 14 ++------------
 tools/libxc/xc_dom_boot.c         | 10 +++++-----
 tools/libxc/xc_dom_compat_linux.c |  4 ++--
 tools/libxc/xc_dom_x86.c          | 32 ++++++++++++++++----------------
 tools/libxl/libxl_dom.c           |  4 ++--
 6 files changed, 29 insertions(+), 39 deletions(-)
stubdom/grub/kexec.c +2 -2
index 4c33b25..0b2f4f3 100644
@@ -358,9 +358,9 @@ void kexec(void *kernel, long kernel_size, void *module, long module_size, char
 #ifdef __x86_64__
                 MMUEXT_PIN_L4_TABLE,
 #endif
-                xc_dom_p2m_host(dom, dom->pgtables_seg.pfn),
+                xc_dom_p2m(dom, dom->pgtables_seg.pfn),
                 dom->guest_domid)) != 0 ) {
-        grub_printf("pin_table(%lx) returned %d\n", xc_dom_p2m_host(dom,
+        grub_printf("pin_table(%lx) returned %d\n", xc_dom_p2m(dom,
                     dom->pgtables_seg.pfn), rc);
         errnum = ERR_BOOT_FAILURE;
         goto out_remap;
tools/libxc/include/xc_dom.h +2 -12
index a7d059a..ec9e293 100644
@@ -376,19 +376,9 @@ static inline void *xc_dom_vaddr_to_ptr(struct xc_dom_image *dom,
     return ptr + offset;
 }
 
-static inline xen_pfn_t xc_dom_p2m_host(struct xc_dom_image *dom, xen_pfn_t pfn)
+static inline xen_pfn_t xc_dom_p2m(struct xc_dom_image *dom, xen_pfn_t pfn)
 {
-    if (dom->shadow_enabled)
-        return pfn;
-    if (pfn < dom->rambase_pfn || pfn >= dom->rambase_pfn + dom->total_pages)
-        return INVALID_MFN;
-    return dom->p2m_host[pfn - dom->rambase_pfn];
-}
-
-static inline xen_pfn_t xc_dom_p2m_guest(struct xc_dom_image *dom,
-                                         xen_pfn_t pfn)
-{
-    if (xc_dom_feature_translated(dom))
+    if ( dom->shadow_enabled || xc_dom_feature_translated(dom) )
         return pfn;
     if (pfn < dom->rambase_pfn || pfn >= dom->rambase_pfn + dom->total_pages)
         return INVALID_MFN;
tools/libxc/xc_dom_boot.c +5 -5
index f82db2d..fda9e52 100644
@@ -54,7 +54,7 @@ static int setup_hypercall_page(struct xc_dom_image *dom)
                   dom->parms.virt_hypercall, pfn);
     domctl.cmd = XEN_DOMCTL_hypercall_init;
     domctl.domain = dom->guest_domid;
-    domctl.u.hypercall_init.gmfn = xc_dom_p2m_guest(dom, pfn);
+    domctl.u.hypercall_init.gmfn = xc_dom_p2m(dom, pfn);
     rc = do_domctl(dom->xch, &domctl);
     if ( rc != 0 )
         xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
@@ -84,7 +84,7 @@ static int clear_page(struct xc_dom_image *dom, xen_pfn_t pfn)
     if ( pfn == 0 )
         return 0;
 
-    dst = xc_dom_p2m_host(dom, pfn);
+    dst = xc_dom_p2m(dom, pfn);
     DOMPRINTF("%s: pfn 0x%" PRIpfn ", mfn 0x%" PRIpfn "",
               __FUNCTION__, pfn, dst);
     rc = xc_clear_domain_page(dom->xch, dom->guest_domid, dst);
@@ -178,7 +178,7 @@ void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,
     }
 
     for ( i = 0; i < count; i++ )
-        entries[i].mfn = xc_dom_p2m_host(dom, pfn + i);
+        entries[i].mfn = xc_dom_p2m(dom, pfn + i);
 
     ptr = xc_map_foreign_ranges(dom->xch, dom->guest_domid,
                 count << page_shift, PROT_READ | PROT_WRITE, 1 << page_shift,
@@ -435,8 +435,8 @@ int xc_dom_gnttab_init(struct xc_dom_image *dom)
                                       dom->console_domid, dom->xenstore_domid);
     } else {
         return xc_dom_gnttab_seed(dom->xch, dom->guest_domid,
-                                  xc_dom_p2m_host(dom, dom->console_pfn),
-                                  xc_dom_p2m_host(dom, dom->xenstore_pfn),
+                                  xc_dom_p2m(dom, dom->console_pfn),
+                                  xc_dom_p2m(dom, dom->xenstore_pfn),
                                   dom->console_domid, dom->xenstore_domid);
     }
 }
tools/libxc/xc_dom_compat_linux.c +2 -2
index 2c14a0f..acccde9 100644
@@ -65,8 +65,8 @@ static int xc_linux_build_internal(struct xc_dom_image *dom,
     if ( (rc = xc_dom_gnttab_init(dom)) != 0)
         goto out;
 
-    *console_mfn = xc_dom_p2m_host(dom, dom->console_pfn);
-    *store_mfn = xc_dom_p2m_host(dom, dom->xenstore_pfn);
+    *console_mfn = xc_dom_p2m(dom, dom->console_pfn);
+    *store_mfn = xc_dom_p2m(dom, dom->xenstore_pfn);
 
  out:
     return rc;
tools/libxc/xc_dom_x86.c +16 -16
index 920fe42..0d80c18 100644
@@ -248,7 +248,7 @@ static int setup_pgtables_x86_32_pae(struct xc_dom_image *dom)
     unsigned long l3off, l2off = 0, l1off;
     xen_vaddr_t addr;
     xen_pfn_t pgpfn;
-    xen_pfn_t l3mfn = xc_dom_p2m_guest(dom, l3pfn);
+    xen_pfn_t l3mfn = xc_dom_p2m(dom, l3pfn);
 
     if ( dom->parms.pae == 1 )
     {
@@ -280,7 +280,7 @@ static int setup_pgtables_x86_32_pae(struct xc_dom_image *dom)
                 goto pfn_error;
             l3off = l3_table_offset_pae(addr);
             l3tab[l3off] =
-                pfn_to_paddr(xc_dom_p2m_guest(dom, l2pfn)) | L3_PROT;
+                pfn_to_paddr(xc_dom_p2m(dom, l2pfn)) | L3_PROT;
             l2pfn++;
         }
 
@@ -292,7 +292,7 @@ static int setup_pgtables_x86_32_pae(struct xc_dom_image *dom)
                 goto pfn_error;
             l2off = l2_table_offset_pae(addr);
             l2tab[l2off] =
-                pfn_to_paddr(xc_dom_p2m_guest(dom, l1pfn)) | L2_PROT;
+                pfn_to_paddr(xc_dom_p2m(dom, l1pfn)) | L2_PROT;
             l1pfn++;
         }
 
@@ -300,7 +300,7 @@ static int setup_pgtables_x86_32_pae(struct xc_dom_image *dom)
         l1off = l1_table_offset_pae(addr);
         pgpfn = (addr - dom->parms.virt_base) >> PAGE_SHIFT_X86;
         l1tab[l1off] =
-            pfn_to_paddr(xc_dom_p2m_guest(dom, pgpfn)) | L1_PROT;
+            pfn_to_paddr(xc_dom_p2m(dom, pgpfn)) | L1_PROT;
         if ( (addr >= dom->pgtables_seg.vstart) &&
              (addr < dom->pgtables_seg.vend) )
             l1tab[l1off] &= ~_PAGE_RW; /* page tables are r/o */
@@ -316,7 +316,7 @@ static int setup_pgtables_x86_32_pae(struct xc_dom_image *dom)
     if ( dom->virt_pgtab_end <= 0xc0000000 )
     {
         DOMPRINTF("%s: PAE: extra l2 page table for l3#3", __FUNCTION__);
-        l3tab[3] = pfn_to_paddr(xc_dom_p2m_guest(dom, l2pfn)) | L3_PROT;
+        l3tab[3] = pfn_to_paddr(xc_dom_p2m(dom, l2pfn)) | L3_PROT;
     }
     return 0;
 
@@ -375,7 +375,7 @@ static int setup_pgtables_x86_64(struct xc_dom_image *dom)
                 goto pfn_error;
             l4off = l4_table_offset_x86_64(addr);
             l4tab[l4off] =
-                pfn_to_paddr(xc_dom_p2m_guest(dom, l3pfn)) | L4_PROT;
+                pfn_to_paddr(xc_dom_p2m(dom, l3pfn)) | L4_PROT;
             l3pfn++;
         }
 
@@ -387,7 +387,7 @@ static int setup_pgtables_x86_64(struct xc_dom_image *dom)
                 goto pfn_error;
             l3off = l3_table_offset_x86_64(addr);
             l3tab[l3off] =
-                pfn_to_paddr(xc_dom_p2m_guest(dom, l2pfn)) | L3_PROT;
+                pfn_to_paddr(xc_dom_p2m(dom, l2pfn)) | L3_PROT;
             l2pfn++;
         }
 
@@ -399,7 +399,7 @@ static int setup_pgtables_x86_64(struct xc_dom_image *dom)
                 goto pfn_error;
             l2off = l2_table_offset_x86_64(addr);
             l2tab[l2off] =
-                pfn_to_paddr(xc_dom_p2m_guest(dom, l1pfn)) | L2_PROT;
+                pfn_to_paddr(xc_dom_p2m(dom, l1pfn)) | L2_PROT;
             l1pfn++;
         }
 
@@ -407,7 +407,7 @@ static int setup_pgtables_x86_64(struct xc_dom_image *dom)
         l1off = l1_table_offset_x86_64(addr);
         pgpfn = (addr - dom->parms.virt_base) >> PAGE_SHIFT_X86;
         l1tab[l1off] =
-            pfn_to_paddr(xc_dom_p2m_guest(dom, pgpfn)) | L1_PROT;
+            pfn_to_paddr(xc_dom_p2m(dom, pgpfn)) | L1_PROT;
         if ( (!dom->pvh_enabled)                &&
              (addr >= dom->pgtables_seg.vstart) &&
              (addr < dom->pgtables_seg.vend) )
@@ -490,9 +490,9 @@ static int start_info_x86_32(struct xc_dom_image *dom)
     start_info->mfn_list = dom->p2m_seg.vstart;
 
     start_info->flags = dom->flags;
-    start_info->store_mfn = xc_dom_p2m_guest(dom, dom->xenstore_pfn);
+    start_info->store_mfn = xc_dom_p2m(dom, dom->xenstore_pfn);
     start_info->store_evtchn = dom->xenstore_evtchn;
-    start_info->console.domU.mfn = xc_dom_p2m_guest(dom, dom->console_pfn);
+    start_info->console.domU.mfn = xc_dom_p2m(dom, dom->console_pfn);
     start_info->console.domU.evtchn = dom->console_evtchn;
 
     if ( dom->ramdisk_blob )
@@ -536,9 +536,9 @@ static int start_info_x86_64(struct xc_dom_image *dom)
     start_info->mfn_list = dom->p2m_seg.vstart;
 
     start_info->flags = dom->flags;
-    start_info->store_mfn = xc_dom_p2m_guest(dom, dom->xenstore_pfn);
+    start_info->store_mfn = xc_dom_p2m(dom, dom->xenstore_pfn);
     start_info->store_evtchn = dom->xenstore_evtchn;
-    start_info->console.domU.mfn = xc_dom_p2m_guest(dom, dom->console_pfn);
+    start_info->console.domU.mfn = xc_dom_p2m(dom, dom->console_pfn);
     start_info->console.domU.evtchn = dom->console_evtchn;
 
     if ( dom->ramdisk_blob )
@@ -622,7 +622,7 @@ static int vcpu_x86_32(struct xc_dom_image *dom, void *ptr)
          dom->parms.pae == 3 /* bimodal */ )
         ctxt->vm_assist |= (1UL << VMASST_TYPE_pae_extended_cr3);
 
-    cr3_pfn = xc_dom_p2m_guest(dom, dom->pgtables_seg.pfn);
+    cr3_pfn = xc_dom_p2m(dom, dom->pgtables_seg.pfn);
     ctxt->ctrlreg[3] = xen_pfn_to_cr3_x86_32(cr3_pfn);
     DOMPRINTF("%s: cr3: pfn 0x%" PRIpfn " mfn 0x%" PRIpfn "",
               __FUNCTION__, dom->pgtables_seg.pfn, cr3_pfn);
@@ -648,7 +648,7 @@ static int vcpu_x86_64(struct xc_dom_image *dom, void *ptr)
     ctxt->user_regs.rflags = 1 << 9; /* Interrupt Enable */
 
     ctxt->flags = VGCF_in_kernel_X86_64 | VGCF_online_X86_64;
-    cr3_pfn = xc_dom_p2m_guest(dom, dom->pgtables_seg.pfn);
+    cr3_pfn = xc_dom_p2m(dom, dom->pgtables_seg.pfn);
     ctxt->ctrlreg[3] = xen_pfn_to_cr3_x86_64(cr3_pfn);
     DOMPRINTF("%s: cr3: pfn 0x%" PRIpfn " mfn 0x%" PRIpfn "",
               __FUNCTION__, dom->pgtables_seg.pfn, cr3_pfn);
@@ -1020,7 +1020,7 @@ int arch_setup_bootlate(struct xc_dom_image *dom)
         /* paravirtualized guest */
         xc_dom_unmap_one(dom, dom->pgtables_seg.pfn);
         rc = pin_table(dom->xch, pgd_type,
-                       xc_dom_p2m_host(dom, dom->pgtables_seg.pfn),
+                       xc_dom_p2m(dom, dom->pgtables_seg.pfn),
                        dom->guest_domid);
         if ( rc != 0 )
         {
tools/libxl/libxl_dom.c +2 -2
index 1c9418a..fb2f916 100644
@@ -745,8 +745,8 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
         state->console_mfn = dom->console_pfn;
         state->store_mfn = dom->xenstore_pfn;
     } else {
-        state->console_mfn = xc_dom_p2m_host(dom, dom->console_pfn);
-        state->store_mfn = xc_dom_p2m_host(dom, dom->xenstore_pfn);
+        state->console_mfn = xc_dom_p2m(dom, dom->console_pfn);
+        state->store_mfn = xc_dom_p2m(dom, dom->xenstore_pfn);
     }
 
     libxl__file_reference_unmap(&state->pv_kernel);
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 5/32 libxc: make arch_setup_meminit a xc_dom_arch hook

In reply to Roger Pau Monne

This allows having different arch_setup_meminit implementations based on the guest type. It should not introduce any functional changes.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxc/include/xc_dom.h |  4 ++-
 tools/libxc/xc_dom_arm.c     | 70 +++++++++++++++++++++++--------------------
 tools/libxc/xc_dom_boot.c    |  2 +-
 tools/libxc/xc_dom_x86.c     | 71 +++++++++++++++++++++++---------------------
 4 files changed, 78 insertions(+), 69 deletions(-)
tools/libxc/include/xc_dom.h +3 -1
index d61482c..b461f19 100644
@@ -224,6 +224,9 @@ struct xc_dom_arch {
     int (*shared_info) (struct xc_dom_image * dom, void *shared_info);
     int (*vcpu) (struct xc_dom_image * dom, void *vcpu_ctxt);
 
+    /* arch-specific memory initialization. */
+    int (*meminit) (struct xc_dom_image * dom);
+
     char *guest_type;
     char *native_protocol;
     int page_shift;
@@ -401,7 +404,6 @@ static inline xen_pfn_t xc_dom_p2m(struct xc_dom_image *dom, xen_pfn_t pfn)
 
 /* --- arch bits --------------------------------------------------- */
 
-int arch_setup_meminit(struct xc_dom_image *dom);
 int arch_setup_bootearly(struct xc_dom_image *dom);
 int arch_setup_bootlate(struct xc_dom_image *dom);
 
tools/libxc/xc_dom_arm.c +37 -33

88 lines not on this page · raw message

tools/libxc/xc_dom_boot.c +1 -1
index fda9e52..3ef7e6c 100644
@@ -147,7 +147,7 @@ int xc_dom_boot_mem_init(struct xc_dom_image *dom)
 
     DOMPRINTF_CALLED(dom->xch);
 
-    rc = arch_setup_meminit(dom);
+    rc = dom->arch_hooks->meminit(dom);
     if ( rc != 0 )
     {
         xc_dom_panic(dom->xch, XC_OUT_OF_MEMORY,
tools/libxc/xc_dom_x86.c +37 -34

95 lines not on this page · raw message

Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 6/32 libxc: make arch_setup_boot{init/late} xc_dom_arch hooks

In reply to Roger Pau Monne

This should not introduce any functional change.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxc/include/xc_dom.h |  7 ++--
 tools/libxc/xc_dom_arm.c     | 38 ++++++++++++---------
 tools/libxc/xc_dom_boot.c    |  4 +--
 tools/libxc/xc_dom_x86.c     | 78 ++++++++++++++++++++++++--------------------
 4 files changed, 68 insertions(+), 59 deletions(-)
tools/libxc/include/xc_dom.h +2 -5
index b461f19..42533a5 100644
@@ -223,6 +223,8 @@ struct xc_dom_arch {
     int (*start_info) (struct xc_dom_image * dom);
     int (*shared_info) (struct xc_dom_image * dom, void *shared_info);
     int (*vcpu) (struct xc_dom_image * dom, void *vcpu_ctxt);
+    int (*bootearly) (struct xc_dom_image * dom);
+    int (*bootlate) (struct xc_dom_image * dom);
 
     /* arch-specific memory initialization. */
     int (*meminit) (struct xc_dom_image * dom);
@@ -402,11 +404,6 @@ static inline xen_pfn_t xc_dom_p2m(struct xc_dom_image *dom, xen_pfn_t pfn)
     return dom->p2m_host[pfn - dom->rambase_pfn];
 }
 
-/* --- arch bits --------------------------------------------------- */
-
-int arch_setup_bootearly(struct xc_dom_image *dom);
-int arch_setup_bootlate(struct xc_dom_image *dom);
-
 /*
  * Local variables:
  * mode: C
tools/libxc/xc_dom_arm.c +22 -16
index 1f00d05..b0d964c 100644
@@ -492,6 +492,24 @@ static int meminit(struct xc_dom_image *dom)
 
 /* ------------------------------------------------------------------------ */
 
+static int bootearly(struct xc_dom_image *dom)
+{
+    DOMPRINTF("%s: doing nothing", __FUNCTION__);
+    return 0;
+}
+
+static int bootlate(struct xc_dom_image *dom)
+{
+    /* XXX
+     *   map shared info
+     *   map grant tables
+     *   setup shared info
+     */
+    return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+
 static struct xc_dom_arch xc_dom_32 = {
     .guest_type = "xen-3.0-armv7l",
     .native_protocol = XEN_IO_PROTO_ABI_ARM,
@@ -504,6 +522,8 @@ static struct xc_dom_arch xc_dom_32 = {
     .shared_info = shared_info_arm,
     .vcpu = vcpu_arm32,
     .meminit = meminit,
+    .bootearly = bootearly,
+    .bootlate = bootlate,
 };
 
 static struct xc_dom_arch xc_dom_64 = {
@@ -518,6 +538,8 @@ static struct xc_dom_arch xc_dom_64 = {
     .shared_info = shared_info_arm,
     .vcpu = vcpu_arm64,
     .meminit = meminit,
+    .bootearly = bootearly,
+    .bootlate = bootlate,
 };
 
 static void __init register_arch_hooks(void)
@@ -526,22 +548,6 @@ static void __init register_arch_hooks(void)
     xc_dom_register_arch_hooks(&xc_dom_64);
 }
 
-int arch_setup_bootearly(struct xc_dom_image *dom)
-{
-    DOMPRINTF("%s: doing nothing", __FUNCTION__);
-    return 0;
-}
-
-int arch_setup_bootlate(struct xc_dom_image *dom)
-{
-    /* XXX
-     *   map shared info
-     *   map grant tables
-     *   setup shared info
-     */
-    return 0;
-}
-
 int xc_dom_feature_translated(struct xc_dom_image *dom)
 {
     return 1;
tools/libxc/xc_dom_boot.c +2 -2
index 3ef7e6c..2f7488d 100644
@@ -209,7 +209,7 @@ int xc_dom_boot_image(struct xc_dom_image *dom)
     DOMPRINTF_CALLED(dom->xch);
 
     /* misc stuff*/
-    if ( (rc = arch_setup_bootearly(dom)) != 0 )
+    if ( (rc = dom->arch_hooks->bootearly(dom)) != 0 )
         return rc;
 
     /* collect some info */
@@ -256,7 +256,7 @@ int xc_dom_boot_image(struct xc_dom_image *dom)
     xc_dom_log_memory_footprint(dom);
 
     /* misc x86 stuff */
-    if ( (rc = arch_setup_bootlate(dom)) != 0 )
+    if ( (rc = dom->arch_hooks->bootlate(dom)) != 0 )
         return rc;
 
     /* let the vm run */
tools/libxc/xc_dom_x86.c +42 -36

96 lines not on this page · raw message

Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 7/32 xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monne

Add checks for ignored vcpu fields in HVM mode. HVM vCPUs (BSP and APs) are always started in 32bit protected mode with paging disabled.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/domain.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
xen/arch/x86/domain.c +11 -3
index a8fe046..a112953 100644
@@ -795,6 +795,15 @@ int arch_set_info_guest(
               c.nat->fs_base || c.nat->gs_base_user)) )
             return -EINVAL;
     }
+    else if ( is_hvm_domain(d) )
+    {
+        if ( c(ctrlreg[0]) || c(ctrlreg[1]) || c(ctrlreg[2]) ||
+             c(ctrlreg[3]) || c(ctrlreg[4]) || c(ctrlreg[5]) ||
+             c(ctrlreg[6]) || c(ctrlreg[7]) || c(ldt_base) ||
+             c(ldt_ents) || c(kernel_ss) || c(kernel_sp) ||
+             c(gdt_ents) )
+            return -EINVAL;
+    }
 
     v->fpu_initialised = !!(flags & VGCF_I387_VALID);
 
@@ -1064,15 +1073,14 @@ int arch_set_info_guest(
     if ( v->vcpu_id == 0 )
         update_domain_wallclock_time(d);
 
-    /* Don't redo final setup */
-    v->is_initialised = 1;
-
     if ( paging_mode_enabled(d) )
         paging_update_paging_modes(v);
 
     update_cr3(v);
 
  out:
+    /* Don't redo final setup */
+    v->is_initialised = 1;
     if ( flags & VGCF_online )
         clear_bit(_VPF_down, &v->pause_flags);
     else
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 8/32 libxc: introduce a xc_dom_arch for hvm-3.0-x86_32 guests

In reply to Roger Pau Monne

This xc_dom_arch will be used in order to build HVM domains. The code is based on the existing xc_hvm_populate_memory and xc_hvm_populate_params functions.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxc/include/xc_dom.h |   6 +
 tools/libxc/xc_dom_x86.c     | 541 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 536 insertions(+), 11 deletions(-)
tools/libxc/include/xc_dom.h +6 -0
index 42533a5..68b052c 100644
@@ -189,6 +189,12 @@ struct xc_dom_image {
     } container_type;
 
     /* HVM specific fields. */
+    xen_pfn_t target_pages;
+    xen_pfn_t mmio_start;
+    xen_pfn_t mmio_size;
+    xen_pfn_t lowmem_end;
+    xen_pfn_t highmem_end;
+
     /* Extra ACPI tables passed to HVMLOADER */
     struct xc_hvm_firmware_module acpi_module;
 
tools/libxc/xc_dom_x86.c +530 -11

622 lines not on this page · raw message

Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 9/32 libxl: switch HVM domain building to use xc_dom_* helpers

In reply to Roger Pau Monne

Now that we have all the code in place HVM domain building in libxl can be switched to use the xc_dom_* family of functions, just like they are used in order to build PV guests.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxl/libxl_dom.c      | 224 +++++++++++++++++++++++++------------------
 tools/libxl/libxl_internal.h |   2 +-
 tools/libxl/libxl_vnuma.c    |  12 ++-
 3 files changed, 139 insertions(+), 99 deletions(-)
tools/libxl/libxl_dom.c +131 -93
index 2bae277..480b7e7 100644
@@ -609,6 +609,64 @@ static int set_vnuma_info(libxl__gc *gc, uint32_t domid,
     return rc;
 }
 
+static int libxl__build_dom(libxl__gc *gc, uint32_t domid,
+             libxl_domain_build_info *info, libxl__domain_build_state *state,
+             struct xc_dom_image *dom)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    uint64_t mem_kb;
+    int ret;
+
+    if ( (ret = xc_dom_boot_xen_init(dom, ctx->xch, domid)) != 0 ) {
+        LOGE(ERROR, "xc_dom_boot_xen_init failed");
+        goto out;
+    }
+#ifdef GUEST_RAM_BASE
+    if ( (ret = xc_dom_rambase_init(dom, GUEST_RAM_BASE)) != 0 ) {
+        LOGE(ERROR, "xc_dom_rambase failed");
+        goto out;
+    }
+#endif
+    if ( (ret = xc_dom_parse_image(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_parse_image failed");
+        goto out;
+    }
+    if ( (ret = libxl__arch_domain_init_hw_description(gc, info, state, dom)) != 0 ) {
+        LOGE(ERROR, "libxl__arch_domain_init_hw_description failed");
+        goto out;
+    }
+
+    mem_kb = dom->container_type == XC_DOM_HVM_CONTAINER ?
+             (info->max_memkb - info->video_memkb) : info->target_memkb;
+    if ( (ret = xc_dom_mem_init(dom, mem_kb / 1024)) != 0 ) {
+        LOGE(ERROR, "xc_dom_mem_init failed");
+        goto out;
+    }
+    if ( (ret = xc_dom_boot_mem_init(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_boot_mem_init failed");
+        goto out;
+    }
+    if ( (ret = libxl__arch_domain_finalise_hw_description(gc, info, dom)) != 0 ) {
+        LOGE(ERROR, "libxl__arch_domain_finalise_hw_description failed");
+        goto out;
+    }
+    if ( (ret = xc_dom_build_image(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_build_image failed");
+        goto out;
+    }
+    if ( (ret = xc_dom_boot_image(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_boot_image failed");
+        goto out;
+    }
+    if ( (ret = xc_dom_gnttab_init(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_gnttab_init failed");
+        goto out;
+    }
+
+out:
+    return ret;
+}
+
 int libxl__build_pv(libxl__gc *gc, uint32_t domid,
              libxl_domain_build_info *info, libxl__domain_build_state *state)
 {
@@ -699,48 +757,9 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
             dom->vnode_to_pnode[i] = info->vnuma_nodes[i].pnode;
     }
 
-    if ( (ret = xc_dom_boot_xen_init(dom, ctx->xch, domid)) != 0 ) {
-        LOGE(ERROR, "xc_dom_boot_xen_init failed");
-        goto out;
-    }
-#ifdef GUEST_RAM_BASE
-    if ( (ret = xc_dom_rambase_init(dom, GUEST_RAM_BASE)) != 0 ) {
-        LOGE(ERROR, "xc_dom_rambase failed");
-        goto out;
-    }
-#endif
-    if ( (ret = xc_dom_parse_image(dom)) != 0 ) {
-        LOGE(ERROR, "xc_dom_parse_image failed");
-        goto out;
-    }
-    if ( (ret = libxl__arch_domain_init_hw_description(gc, info, state, dom)) != 0 ) {
-        LOGE(ERROR, "libxl__arch_domain_init_hw_description failed");
-        goto out;
-    }
-    if ( (ret = xc_dom_mem_init(dom, info->target_memkb / 1024)) != 0 ) {
-        LOGE(ERROR, "xc_dom_mem_init failed");
-        goto out;
-    }
-    if ( (ret = xc_dom_boot_mem_init(dom)) != 0 ) {
-        LOGE(ERROR, "xc_dom_boot_mem_init failed");
+    ret = libxl__build_dom(gc, domid, info, state, dom);
+    if (ret != 0)
         goto out;
-    }
-    if ( (ret = libxl__arch_domain_finalise_hw_description(gc, info, dom)) != 0 ) {
-        LOGE(ERROR, "libxl__arch_domain_finalise_hw_description failed");
-        goto out;
-    }
-    if ( (ret = xc_dom_build_image(dom)) != 0 ) {
-        LOGE(ERROR, "xc_dom_build_image failed");
-        goto out;
-    }
-    if ( (ret = xc_dom_boot_image(dom)) != 0 ) {
-        LOGE(ERROR, "xc_dom_boot_image failed");
-        goto out;
-    }
-    if ( (ret = xc_dom_gnttab_init(dom)) != 0 ) {
-        LOGE(ERROR, "xc_dom_gnttab_init failed");
-        goto out;
-    }
 
     if (xc_dom_feature_translated(dom)) {
         state->console_mfn = dom->console_pfn;
@@ -800,39 +819,39 @@ static int hvm_build_set_params(xc_interface *handle, uint32_t domid,
 
 static int hvm_build_set_xs_values(libxl__gc *gc,
                                    uint32_t domid,
-                                   struct xc_hvm_build_args *args)
+                                   struct xc_dom_image *dom)
 {
     char *path = NULL;
     int ret = 0;
 
-    if (args->smbios_module.guest_addr_out) {
+    if (dom->smbios_module.guest_addr_out) {
         path = GCSPRINTF("/local/domain/%d/"HVM_XS_SMBIOS_PT_ADDRESS, domid);
 
         ret = libxl__xs_write(gc, XBT_NULL, path, "0x%"PRIx64,
-                              args->smbios_module.guest_addr_out);
+                              dom->smbios_module.guest_addr_out);
         if (ret)
             goto err;
 
         path = GCSPRINTF("/local/domain/%d/"HVM_XS_SMBIOS_PT_LENGTH, domid);
 
         ret = libxl__xs_write(gc, XBT_NULL, path, "0x%x",
-                              args->smbios_module.length);
+                              dom->smbios_module.length);
         if (ret)
             goto err;
     }
 
-    if (args->acpi_module.guest_addr_out) {
+    if (dom->acpi_module.guest_addr_out) {
         path = GCSPRINTF("/local/domain/%d/"HVM_XS_ACPI_PT_ADDRESS, domid);
 
         ret = libxl__xs_write(gc, XBT_NULL, path, "0x%"PRIx64,
-                              args->acpi_module.guest_addr_out);
+                              dom->acpi_module.guest_addr_out);
         if (ret)
             goto err;
 
         path = GCSPRINTF("/local/domain/%d/"HVM_XS_ACPI_PT_LENGTH, domid);
 
         ret = libxl__xs_write(gc, XBT_NULL, path, "0x%x",
-                              args->acpi_module.length);
+                              dom->acpi_module.length);
         if (ret)
             goto err;
     }
@@ -846,7 +865,7 @@ err:
 
 static int libxl__domain_firmware(libxl__gc *gc,
                                   libxl_domain_build_info *info,
-                                  struct xc_hvm_build_args *args)
+                                  struct xc_dom_image *dom)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     const char *firmware;
@@ -872,8 +891,13 @@ static int libxl__domain_firmware(libxl__gc *gc,
             break;
         }
     }
-    args->image_file_name = libxl__abs_path(gc, firmware,
-                                            libxl__xenfirmwaredir_path());
+
+    rc = xc_dom_kernel_file(dom, libxl__abs_path(gc, firmware,
+                                                 libxl__xenfirmwaredir_path()));
+    if (rc != 0) {
+        LOGE(ERROR, "xc_dom_kernel_file failed");
+        goto out;
+    }
 
     if (info->u.hvm.smbios_firmware) {
         data = NULL;
@@ -887,8 +911,8 @@ static int libxl__domain_firmware(libxl__gc *gc,
         libxl__ptr_add(gc, data);
         if (datalen) {
             /* Only accept non-empty files */
-            args->smbios_module.data = data;
-            args->smbios_module.length = (uint32_t)datalen;
+            dom->smbios_module.data = data;
+            dom->smbios_module.length = (uint32_t)datalen;
         }
     }
 
@@ -904,8 +928,8 @@ static int libxl__domain_firmware(libxl__gc *gc,
         libxl__ptr_add(gc, data);
         if (datalen) {
             /* Only accept non-empty files */
-            args->acpi_module.data = data;
-            args->acpi_module.length = (uint32_t)datalen;
+            dom->acpi_module.data = data;
+            dom->acpi_module.length = (uint32_t)datalen;
         }
     }
 
@@ -919,50 +943,60 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
               libxl__domain_build_state *state)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
-    struct xc_hvm_build_args args = {};
-    int ret, rc = ERROR_FAIL;
-    uint64_t mmio_start, lowmem_end, highmem_end;
+    int ret;
+    uint64_t mmio_start, lowmem_end, highmem_end, mem_size;
+    struct xc_dom_image *dom = NULL;
+
+    xc_dom_loginit(ctx->xch);
+
+    dom = xc_dom_allocate(ctx->xch, NULL, NULL);
+    if (!dom) {
+        LOGE(ERROR, "xc_dom_allocate failed");
+        goto out;
+    }
+
+    dom->container_type = XC_DOM_HVM_CONTAINER;
 
-    memset(&args, 0, sizeof(struct xc_hvm_build_args));
     /* The params from the configuration file are in Mb, which are then
      * multiplied by 1 Kb. This was then divided off when calling
      * the old xc_hvm_build_target_mem() which then turned them to bytes.
      * Do all this in one step here...
      */
-    args.mem_size = (uint64_t)(info->max_memkb - info->video_memkb) << 10;
-    args.mem_target = (uint64_t)(info->target_memkb - info->video_memkb) << 10;
-    args.claim_enabled = libxl_defbool_val(info->claim_mode);
+    mem_size = (uint64_t)(info->max_memkb - info->video_memkb) << 10;
+    dom->target_pages = (uint64_t)(info->target_memkb - info->video_memkb) >> 2;
+    dom->claim_enabled = libxl_defbool_val(info->claim_mode);
     if (info->u.hvm.mmio_hole_memkb) {
         uint64_t max_ram_below_4g = (1ULL << 32) -
             (info->u.hvm.mmio_hole_memkb << 10);
 
         if (max_ram_below_4g < HVM_BELOW_4G_MMIO_START)
-            args.mmio_size = info->u.hvm.mmio_hole_memkb << 10;
+            dom->mmio_size = info->u.hvm.mmio_hole_memkb << 10;
     }
-    if (libxl__domain_firmware(gc, info, &args)) {
+    if (libxl__domain_firmware(gc, info, dom)) {
         LOG(ERROR, "initializing domain firmware failed");
         goto out;
     }
-    if (args.mem_target == 0)
-        args.mem_target = args.mem_size;
-    if (args.mmio_size == 0)
-        args.mmio_size = HVM_BELOW_4G_MMIO_LENGTH;
-    lowmem_end = args.mem_size;
+
+    if (dom->target_pages == 0)
+        dom->target_pages = mem_size >> XC_PAGE_SHIFT;
+    if (dom->mmio_size == 0)
+        dom->mmio_size = HVM_BELOW_4G_MMIO_LENGTH;
+    lowmem_end = mem_size;
     highmem_end = 0;
-    mmio_start = (1ull << 32) - args.mmio_size;
+    mmio_start = (1ull << 32) - dom->mmio_size;
     if (lowmem_end > mmio_start)
     {
         highmem_end = (1ull << 32) + (lowmem_end - mmio_start);
         lowmem_end = mmio_start;
     }
-    args.lowmem_end = lowmem_end;
-    args.highmem_end = highmem_end;
-    args.mmio_start = mmio_start;
+    dom->lowmem_end = lowmem_end;
+    dom->highmem_end = highmem_end;
+    dom->mmio_start = mmio_start;
 
     if (info->num_vnuma_nodes != 0) {
         int i;
 
-        ret = libxl__vnuma_build_vmemrange_hvm(gc, domid, info, state, &args);
+        ret = libxl__vnuma_build_vmemrange_hvm(gc, domid, info, state, dom);
         if (ret) {
             LOGEV(ERROR, ret, "hvm build vmemranges failed");
             goto out;
@@ -972,30 +1006,34 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
         ret = set_vnuma_info(gc, domid, info, state);
         if (ret) goto out;
 
-        args.nr_vmemranges = state->num_vmemranges;
-        args.vmemranges = libxl__malloc(gc, sizeof(*args.vmemranges) *
-                                        args.nr_vmemranges);
+        dom->nr_vmemranges = state->num_vmemranges;
+        dom->vmemranges = libxl__malloc(gc, sizeof(*dom->vmemranges) *
+                                        dom->nr_vmemranges);
 
-        for (i = 0; i < args.nr_vmemranges; i++) {
-            args.vmemranges[i].start = state->vmemranges[i].start;
-            args.vmemranges[i].end   = state->vmemranges[i].end;
-            args.vmemranges[i].flags = state->vmemranges[i].flags;
-            args.vmemranges[i].nid   = state->vmemranges[i].nid;
+        for (i = 0; i < dom->nr_vmemranges; i++) {
+            dom->vmemranges[i].start = state->vmemranges[i].start;
+            dom->vmemranges[i].end   = state->vmemranges[i].end;
+            dom->vmemranges[i].flags = state->vmemranges[i].flags;
+            dom->vmemranges[i].nid   = state->vmemranges[i].nid;
         }
 
-        args.nr_vnodes = info->num_vnuma_nodes;
-        args.vnode_to_pnode = libxl__malloc(gc, sizeof(*args.vnode_to_pnode) *
-                                            args.nr_vnodes);
-        for (i = 0; i < args.nr_vnodes; i++)
-            args.vnode_to_pnode[i] = info->vnuma_nodes[i].pnode;
+        dom->nr_vnodes = info->num_vnuma_nodes;
+        dom->vnode_to_pnode = libxl__malloc(gc, sizeof(*dom->vnode_to_pnode) *
+                                            dom->nr_vnodes);
+        for (i = 0; i < dom->nr_vnodes; i++)
+            dom->vnode_to_pnode[i] = info->vnuma_nodes[i].pnode;
     }
 
-    ret = xc_hvm_build(ctx->xch, domid, &args);
-    if (ret) {
-        LOGEV(ERROR, ret, "hvm building failed");
+    ret = xc_dom_boot_xen_init(dom, ctx->xch, domid);
+    if (ret != 0) {
+        LOGE(ERROR, "xc_dom_boot_xen_init failed");
         goto out;
     }
 
+    ret = libxl__build_dom(gc, domid, info, state, dom);
+    if (ret != 0)
+        goto out;
+
     ret = hvm_build_set_params(ctx->xch, domid, info, state->store_port,
                                &state->store_mfn, state->console_port,
                                &state->console_mfn, state->store_domid,
@@ -1005,15 +1043,15 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
         goto out;
     }
 
-    ret = hvm_build_set_xs_values(gc, domid, &args);
+    ret = hvm_build_set_xs_values(gc, domid, dom);
     if (ret) {
         LOG(ERROR, "hvm build set xenstore values failed (ret=%d)", ret);
         goto out;
     }
 
-    return 0;
 out:
-    return rc;
+    if (dom != NULL) xc_dom_release(dom);
+    return ret == 0 ? 0 : ERROR_FAIL;
 }
 
 int libxl__qemu_traditional_cmd(libxl__gc *gc, uint32_t domid,
tools/libxl/libxl_internal.h +1 -1
index d52589e..f4314e6 100644
@@ -3540,7 +3540,7 @@ int libxl__vnuma_build_vmemrange_hvm(libxl__gc *gc,
                                      uint32_t domid,
                                      libxl_domain_build_info *b_info,
                                      libxl__domain_build_state *state,
-                                     struct xc_hvm_build_args *args);
+                                     struct xc_dom_image *dom);
 bool libxl__vnuma_configured(const libxl_domain_build_info *b_info);
 
 _hidden int libxl__ms_vm_genid_set(libxl__gc *gc, uint32_t domid,
tools/libxl/libxl_vnuma.c +7 -5
index 56856d2..db22799 100644
@@ -17,6 +17,8 @@
 #include "libxl_arch.h"
 #include <stdlib.h>
 
+#include <xc_dom.h>
+
 bool libxl__vnuma_configured(const libxl_domain_build_info *b_info)
 {
     return b_info->num_vnuma_nodes != 0;
@@ -252,7 +254,7 @@ int libxl__vnuma_build_vmemrange_hvm(libxl__gc *gc,
                                      uint32_t domid,
                                      libxl_domain_build_info *b_info,
                                      libxl__domain_build_state *state,
-                                     struct xc_hvm_build_args *args)
+                                     struct xc_dom_image *dom)
 {
     uint64_t hole_start, hole_end, next;
     int nid, nr_vmemrange;
@@ -264,10 +266,10 @@ int libxl__vnuma_build_vmemrange_hvm(libxl__gc *gc,
      * Guest physical address space layout:
      * [0, hole_start) [hole_start, hole_end) [hole_end, highmem_end)
      */
-    hole_start = args->lowmem_end < args->mmio_start ?
-        args->lowmem_end : args->mmio_start;
-    hole_end = (args->mmio_start + args->mmio_size) > (1ULL << 32) ?
-        (args->mmio_start + args->mmio_size) : (1ULL << 32);
+    hole_start = dom->lowmem_end < dom->mmio_start ?
+        dom->lowmem_end : dom->mmio_start;
+    hole_end = (dom->mmio_start + dom->mmio_size) > (1ULL << 32) ?
+        (dom->mmio_start + dom->mmio_size) : (1ULL << 32);
 
     assert(state->vmemranges == NULL);
 
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 3/32 libxc: introduce the notion of a container type

In reply to Roger Pau Monne

Introduce the notion of a container type into xc_dom_image. This will be needed by later changes that will also use xc_dom_image in order to build HVM guests.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxc/include/xc_dom.h | 6 ++++++
 tools/libxc/xc_dom_x86.c     | 4 ++++
 tools/libxl/libxl_dom.c      | 1 +
 3 files changed, 11 insertions(+)
tools/libxc/include/xc_dom.h +6 -0
index ec9e293..f7b5f0f 100644
@@ -180,6 +180,12 @@ struct xc_dom_image {
     struct xc_dom_arch *arch_hooks;
     /* allocate up to virt_alloc_end */
     int (*allocate) (struct xc_dom_image * dom, xen_vaddr_t up_to);
+
+    /* Container type (HVM or PV). */
+    enum {
+        XC_DOM_PV_CONTAINER,
+        XC_DOM_HVM_CONTAINER,
+    } container_type;
 };
 
 /* --- pluggable kernel loader ------------------------------------- */
tools/libxc/xc_dom_x86.c +4 -0
index 0d80c18..b89f5c2 100644
@@ -1071,6 +1071,10 @@ int arch_setup_bootlate(struct xc_dom_image *dom)
 
 int xc_dom_feature_translated(struct xc_dom_image *dom)
 {
+    /* Guests running inside HVM containers are always auto-translated. */
+    if ( dom->container_type == XC_DOM_HVM_CONTAINER )
+        return 1;
+
     return elf_xen_feature_get(XENFEAT_auto_translated_physmap, dom->f_active);
 }
 
tools/libxl/libxl_dom.c +1 -0
index fb2f916..2bae277 100644
@@ -626,6 +626,7 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
     }
 
     dom->pvh_enabled = state->pvh_enabled;
+    dom->container_type = XC_DOM_PV_CONTAINER;
 
     LOG(DEBUG, "pv kernel mapped %d path %s", state->pv_kernel.mapped, state->pv_kernel.path);
 
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

v3 cover Introduce HVM without dm and new boot ABI

This series are now rebased on top of Paul Durrant "x86/hvm: I/O emulation cleanup and fix" v5.

This series is split in the following order:

- Patches from 1 to 10 switch HVM domain contruction to use the xc_dom_* family of functions, like they are used to build PV domains.
- Patches from 11 to 21 allow disabling the devices emulated inside of Xen.
- Patches from 22 to 32 introduce the creation of HVM guests without a device model and without the devices emulated inside of Xen.

THe main difference with v2 is that instead of using a
single XEN_DOMCTL_CDF_noemu flag in order to disable all devices emulated in Xen a bitmap is used, which should allow enabling or disabling specific emulated devices in the future.

This series has been successfully tested on the following hardware:

- Intel Xeon W3550.
- AMD Opteron 4184.

With both hap=0 and hap=1 in the configuration file. I've been able to boot a SMP guest in this mode with a virtual hard drive and a virtual network card, all working fine AFAICT.

For this round only maintainers of the specific code being modified have been Cced on the patches.

The series can also be found in the following git repo:

git://xenbits.xen.org/people/royger/xen.git branch hvm_without_dm_v3

And for the FreeBSD part:

git://xenbits.xen.org/people/royger/freebsd.git branch new_entry_point_v2

In case someone wants to give it a try, I've uploaded a FreeBSD kernel that should work when booted into this mode:

https://people.freebsd.org/~royger/kernel_no_dm

The config file that I've used is:

<config>
kernel="/path/to/kernel_no_dm"

builder="hvm"
device_model_version="none"

memory=128
vcpus=2
name = "freebsd"
</config>

Of course if you have a FreeBSD disk already setup it can also be added to the configuration file, and the following line can be used to point FreeBSD to the disk:

extra="vfs.root.mountfrom=ufs:/dev/ufsid/<disk_id>"

Thanks, Roger.

#100 lore raw

PATCH v3 27/32 libxc: change the position of the special pages

Change the physical memory address of the special pages when there are no emulated devices. On HVM guests the special pages have always been reserved so that they end at the 0xff000 pfn, but there are some problems with this approach when used without emulated devices:

- If we want to allow HVMlite to be used for Dom0 those special pages cannot be placed inside of the MMIO hole or else they may clash with MMIO regions of physical devices passed-through to Dom0.
- If there's no emulated devices the guests needs to access the console page and the command line very early during boot. This is a problem for FreeBSD at least, since the early page tables only map memory up to 1GiB.

So instead append the special pages after the kernel and ramdisk. The guest must make sure it figures out the position of those pages very early during boot, since the region is not marked as reserved in the memory map.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxc/xc_dom_x86.c | 50 ++++++++++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 19 deletions(-)
tools/libxc/xc_dom_x86.c +31 -19
index 45b1f03..1195400 100644
@@ -58,15 +58,27 @@
 #define SPECIALPAGE_IDENT_PT 6
 #define SPECIALPAGE_CONSOLE  7
 #define NR_SPECIAL_PAGES     8
-#define special_pfn(x) (0xff000u - NR_SPECIAL_PAGES + (x))
+#define LAST_SPECIAL_PFN     0xff000u
 
 #define NR_IOREQ_SERVER_PAGES 8
-#define ioreq_server_pfn(x) (special_pfn(0) - NR_IOREQ_SERVER_PAGES + (x))
+#define ioreq_server_pfn(x, dom) (special_pfn(0, dom) - NR_IOREQ_SERVER_PAGES + (x))
 
 #define bits_to_mask(bits)       (((xen_vaddr_t)1 << (bits))-1)
 #define round_down(addr, mask)   ((addr) & ~(mask))
 #define round_up(addr, mask)     ((addr) | (mask))
 
+static unsigned long special_pfn(int index, struct xc_dom_image *dom)
+{
+    unsigned long start_pfn;
+
+    if ( dom->emulation )
+        return (LAST_SPECIAL_PFN - NR_SPECIAL_PAGES + index);
+
+    start_pfn = (dom->virt_alloc_end - dom->parms.virt_base) >>
+                XC_DOM_PAGE_SHIFT(dom);
+    return (start_pfn + index);
+}
+
 /* get guest IO ABI protocol */
 const char *xc_domain_get_native_protocol(xc_interface *xch,
                                           uint32_t domid)
@@ -502,7 +514,7 @@ static void build_hvm_info(void *hvm_info_page, struct xc_dom_image *dom)
     /* Memory parameters. */
     hvm_info->low_mem_pgend = dom->lowmem_end >> PAGE_SHIFT;
     hvm_info->high_mem_pgend = dom->highmem_end >> PAGE_SHIFT;
-    hvm_info->reserved_mem_pgstart = ioreq_server_pfn(0);
+    hvm_info->reserved_mem_pgstart = ioreq_server_pfn(0, dom);
 
     /* Finish with the checksum. */
     for ( i = 0, sum = 0; i < hvm_info->length; i++ )
@@ -532,7 +544,7 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
 
     /* Allocate and clear special pages. */
     for ( i = 0; i < NR_SPECIAL_PAGES; i++ )
-        special_array[i] = special_pfn(i);
+        special_array[i] = special_pfn(i, dom);
 
     rc = xc_domain_populate_physmap_exact(xch, domid, NR_SPECIAL_PAGES, 0, 0,
                                           special_array);
@@ -542,23 +554,23 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
         goto error_out;
     }
 
-    if ( xc_clear_domain_pages(xch, domid, special_pfn(0), NR_SPECIAL_PAGES) )
+    if ( xc_clear_domain_pages(xch, domid, special_pfn(0, dom), NR_SPECIAL_PAGES) )
             goto error_out;
 
     xc_hvm_param_set(xch, domid, HVM_PARAM_STORE_PFN,
-                     special_pfn(SPECIALPAGE_XENSTORE));
+                     special_pfn(SPECIALPAGE_XENSTORE, dom));
     xc_hvm_param_set(xch, domid, HVM_PARAM_BUFIOREQ_PFN,
-                     special_pfn(SPECIALPAGE_BUFIOREQ));
+                     special_pfn(SPECIALPAGE_BUFIOREQ, dom));
     xc_hvm_param_set(xch, domid, HVM_PARAM_IOREQ_PFN,
-                     special_pfn(SPECIALPAGE_IOREQ));
+                     special_pfn(SPECIALPAGE_IOREQ, dom));
     xc_hvm_param_set(xch, domid, HVM_PARAM_CONSOLE_PFN,
-                     special_pfn(SPECIALPAGE_CONSOLE));
+                     special_pfn(SPECIALPAGE_CONSOLE, dom));
     xc_hvm_param_set(xch, domid, HVM_PARAM_PAGING_RING_PFN,
-                     special_pfn(SPECIALPAGE_PAGING));
+                     special_pfn(SPECIALPAGE_PAGING, dom));
     xc_hvm_param_set(xch, domid, HVM_PARAM_MONITOR_RING_PFN,
-                     special_pfn(SPECIALPAGE_ACCESS));
+                     special_pfn(SPECIALPAGE_ACCESS, dom));
     xc_hvm_param_set(xch, domid, HVM_PARAM_SHARING_RING_PFN,
-                     special_pfn(SPECIALPAGE_SHARING));
+                     special_pfn(SPECIALPAGE_SHARING, dom));
 
     if ( dom->emulation )
     {
@@ -567,7 +579,7 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
          * server will use the IOREQ and BUFIOREQ special pages above.
          */
         for ( i = 0; i < NR_IOREQ_SERVER_PAGES; i++ )
-            ioreq_server_array[i] = ioreq_server_pfn(i);
+            ioreq_server_array[i] = ioreq_server_pfn(i, dom);
 
         rc = xc_domain_populate_physmap_exact(xch, domid, NR_IOREQ_SERVER_PAGES, 0,
                                               0, ioreq_server_array);
@@ -577,13 +589,13 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
             goto error_out;
         }
 
-        if ( xc_clear_domain_pages(xch, domid, ioreq_server_pfn(0),
+        if ( xc_clear_domain_pages(xch, domid, ioreq_server_pfn(0, dom),
                                    NR_IOREQ_SERVER_PAGES) )
                 goto error_out;
 
         /* Tell the domain where the pages are and how many there are */
         xc_hvm_param_set(xch, domid, HVM_PARAM_IOREQ_SERVER_PFN,
-                         ioreq_server_pfn(0));
+                         ioreq_server_pfn(0, dom));
         xc_hvm_param_set(xch, domid, HVM_PARAM_NR_IOREQ_SERVER_PAGES,
                          NR_IOREQ_SERVER_PAGES);
     }
@@ -594,17 +606,17 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
      */
     if ( (ident_pt = xc_map_foreign_range(
               xch, domid, PAGE_SIZE, PROT_READ | PROT_WRITE,
-              special_pfn(SPECIALPAGE_IDENT_PT))) == NULL )
+              special_pfn(SPECIALPAGE_IDENT_PT, dom))) == NULL )
         goto error_out;
     for ( i = 0; i < PAGE_SIZE / sizeof(*ident_pt); i++ )
         ident_pt[i] = ((i << 22) | _PAGE_PRESENT | _PAGE_RW | _PAGE_USER |
                        _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_PSE);
     munmap(ident_pt, PAGE_SIZE);
     xc_hvm_param_set(xch, domid, HVM_PARAM_IDENT_PT,
-                     special_pfn(SPECIALPAGE_IDENT_PT) << PAGE_SHIFT);
+                     special_pfn(SPECIALPAGE_IDENT_PT, dom) << PAGE_SHIFT);
 
-    dom->console_pfn = special_pfn(SPECIALPAGE_CONSOLE);
-    dom->xenstore_pfn = special_pfn(SPECIALPAGE_XENSTORE);
+    dom->console_pfn = special_pfn(SPECIALPAGE_CONSOLE, dom);
+    dom->xenstore_pfn = special_pfn(SPECIALPAGE_XENSTORE, dom);
     dom->parms.virt_hypercall = -1;
 
     rc = 0;
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 15/32 xen/x86: allow disabling the emulated RTC

In reply to Roger Pau Monne
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/rtc.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
xen/arch/x86/hvm/rtc.c +16 -0
index fde120b..d6d24c8 100644
@@ -726,6 +726,9 @@ void rtc_migrate_timers(struct vcpu *v)
 {
     RTCState *s = vcpu_vrtc(v);
 
+    if ( !has_vrtc(v->domain) )
+        return;
+
     if ( v->vcpu_id == 0 )
     {
         migrate_timer(&s->update_timer, v->processor);;
@@ -739,6 +742,10 @@ static int rtc_save(struct domain *d, hvm_domain_context_t *h)
 {
     RTCState *s = domain_vrtc(d);
     int rc;
+
+    if ( !has_vrtc(d) )
+        return 0;
+
     spin_lock(&s->lock);
     rc = hvm_save_entry(RTC, 0, h, &s->hw);
     spin_unlock(&s->lock);
@@ -750,6 +757,9 @@ static int rtc_load(struct domain *d, hvm_domain_context_t *h)
 {
     RTCState *s = domain_vrtc(d);
 
+    if ( !has_vrtc(d) )
+        return 0;
+
     spin_lock(&s->lock);
 
     /* Restore the registers */
@@ -790,6 +800,9 @@ void rtc_init(struct domain *d)
 {
     RTCState *s = domain_vrtc(d);
 
+    if ( !has_vrtc(d) )
+        return;
+
     spin_lock_init(&s->lock);
 
     init_timer(&s->update_timer, rtc_update_timer, s, smp_processor_id());
@@ -820,6 +833,9 @@ void rtc_deinit(struct domain *d)
 {
     RTCState *s = domain_vrtc(d);
 
+    if ( !has_vrtc(d) )
+        return;
+
     spin_barrier(&s->lock);
 
     TRACE_0D(TRC_HVM_EMUL_RTC_STOP_TIMER);
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 30/32 libxc/xen: introduce HVM_PARAM_MODLIST_PFN

In reply to Roger Pau Monne

This HVM parameter is used to pass a list of loaded modules to the guest. Right now the number of loaded modules is limited to 1 by the current implementation, but this interface allows passing more than one module.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 tools/libxc/xc_dom_x86.c        | 24 +++++++++++++++++++++++-
 xen/arch/x86/hvm/hvm.c          |  1 +
 xen/include/public/hvm/params.h | 23 ++++++++++++++++++++++-
 3 files changed, 46 insertions(+), 2 deletions(-)
tools/libxc/xc_dom_x86.c +23 -1
index 74c3819..71b353e 100644
@@ -58,7 +58,8 @@
 #define SPECIALPAGE_IDENT_PT 6
 #define SPECIALPAGE_CONSOLE  7
 #define SPECIALPAGE_CMDLINE  8
-#define NR_SPECIAL_PAGES     9
+#define SPECIALPAGE_MODLIST  9
+#define NR_SPECIAL_PAGES     10
 #define LAST_SPECIAL_PFN     0xff000u
 
 #define NR_IOREQ_SERVER_PAGES 8
@@ -533,6 +534,7 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
     xen_pfn_t ioreq_server_array[NR_IOREQ_SERVER_PAGES];
     xc_interface *xch = dom->xch;
     char *cmdline;
+    uint64_t *modlist;
 
     if ( dom->emulation )
     {
@@ -621,6 +623,26 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
                          NR_IOREQ_SERVER_PAGES);
     }
 
+    if ( dom->ramdisk_blob )
+    {
+        modlist = xc_map_foreign_range(
+                  xch, domid, PAGE_SIZE, PROT_READ | PROT_WRITE,
+                  special_pfn(SPECIALPAGE_MODLIST, dom));
+        if ( modlist == NULL ) {
+            DOMPRINTF("Unable to map module list page");
+            goto error_out;
+        }
+
+        /* This is currently limited to only one module. */
+        modlist[0] = dom->ramdisk_seg.vstart - dom->parms.virt_base;
+        modlist[1] = dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart;
+        modlist[2] = 0;
+        modlist[3] = 0;
+        munmap(modlist, PAGE_SIZE);
+        xc_hvm_param_set(xch, domid, HVM_PARAM_MODLIST_PFN,
+                     special_pfn(SPECIALPAGE_MODLIST, dom));
+    }
+
     /*
      * Identity-map page table is required for running with CR0.PG=0 when
      * using Intel EPT. Create a 32-bit non-PAE page directory of superpages.
xen/arch/x86/hvm/hvm.c +1 -0
index 2b190e9..95f12c0 100644
@@ -5919,6 +5919,7 @@ static int hvm_allow_get_param(struct domain *d,
     case HVM_PARAM_CONSOLE_EVTCHN:
     case HVM_PARAM_CMDLINE_PFN:
     case HVM_PARAM_FIRST_FREE_PFN:
+    case HVM_PARAM_MODLIST_PFN:
         break;
     /*
      * The following parameters must not be read by the guest
xen/include/public/hvm/params.h +22 -1
index 47e38a8..86cc15b 100644
@@ -193,6 +193,27 @@
 /* First free PFN after the special pages. */
 #define HVM_PARAM_FIRST_FREE_PFN 36
 
-#define HVM_NR_PARAMS          37
+/*
+ * List of modules passed to the kernel.
+ *
+ * The PFN returned by this HVM_PARAM points to a page that contains an
+ * array of unsigned 64bit integers encoded in little endian.
+ *
+ * The first integer contains the address where the module has been loaded,
+ * while the second contains the size of the module in bytes. The last element
+ * in the array is a module with address 0 and length 0:
+ *
+ * module[0] = <address of 1st module>
+ * module[1] = <size of 1st module>
+ * [...]
+ * module[N/2] = <address of module N>
+ * module[N/2+1] = <size of module N>
+ * [...]
+ * module[M] = 0
+ * module[M+1] = 0
+ */
+#define HVM_PARAM_MODLIST_PFN 37
+
+#define HVM_NR_PARAMS          38
 
 #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 20/32 xen/x86: allow disabling the emulated IOMMU

In reply to Roger Pau Monne
Cc Suravee Suthikulpanit <[email protected]>
Cc Aravind Gopalakrishnan <[email protected]>
---
 xen/drivers/passthrough/amd/iommu_guest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/drivers/passthrough/amd/iommu_guest.c +2 -1
index 5908bf3..0831908 100644
@@ -888,7 +888,8 @@ int guest_iommu_init(struct domain* d)
     struct guest_iommu *iommu;
     struct hvm_iommu *hd  = domain_hvm_iommu(d);
 
-    if ( !is_hvm_domain(d) || !iommu_enabled || !iommuv2_enabled )
+    if ( !is_hvm_domain(d) || !iommu_enabled || !iommuv2_enabled ||
+         !has_viommu(d) )
         return 0;
 
     iommu = xzalloc(struct guest_iommu);
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 10/32 libxc: remove dead HVM building code

In reply to Roger Pau Monne

Remove xc_hvm_build_x86.c and xc_hvm_build_arm.c since xc_hvm_build is not longer used in order to create HVM guests.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxc/Makefile              |   2 -
 tools/libxc/include/xenguest.h    |  44 ---
 tools/libxc/xc_hvm_build_arm.c    |  49 ---
 tools/libxc/xc_hvm_build_x86.c    | 805 --------------------------------------
 tools/libxc/xg_private.c          |   9 -
 tools/python/xen/lowlevel/xc/xc.c |  81 ----
 6 files changed, 990 deletions(-)
 delete mode 100644 tools/libxc/xc_hvm_build_arm.c
 delete mode 100644 tools/libxc/xc_hvm_build_x86.c
tools/libxc/Makefile +0 -2
index 48fc473..a143c0f 100644
@@ -94,9 +94,7 @@ GUEST_SRCS-y                 += xc_dom_compat_linux.c
 
 GUEST_SRCS-$(CONFIG_X86)     += xc_dom_x86.c
 GUEST_SRCS-$(CONFIG_X86)     += xc_cpuid_x86.c
-GUEST_SRCS-$(CONFIG_X86)     += xc_hvm_build_x86.c
 GUEST_SRCS-$(CONFIG_ARM)     += xc_dom_arm.c
-GUEST_SRCS-$(CONFIG_ARM)     += xc_hvm_build_arm.c
 
 ifeq ($(CONFIG_LIBXC_MINIOS),y)
 GUEST_SRCS-y                 += xc_dom_decompress_unsafe.c
tools/libxc/include/xenguest.h +0 -44

50 lines not on this page · raw message

tools/libxc/xc_hvm_build_arm.c deleted +0 -49

49 lines not on this page · raw message

tools/libxc/xc_hvm_build_x86.c deleted +0 -805

805 lines not on this page · raw message

tools/libxc/xg_private.c +0 -9
index c52cb44..98f33b2 100644
@@ -188,15 +188,6 @@ unsigned long csum_page(void *page)
     return sum ^ (sum>>32);
 }
 
-__attribute__((weak)) 
-    int xc_hvm_build(xc_interface *xch,
-                     uint32_t domid,
-                     struct xc_hvm_build_args *hvm_args)
-{
-    errno = ENOSYS;
-    return -1;
-}
-
 /*
  * Local variables:
  * mode: C
tools/python/xen/lowlevel/xc/xc.c +0 -81

93 lines not on this page · raw message

Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 22/32 elfnotes: intorduce a new PHYS_ENTRY elfnote

In reply to Roger Pau Monne

This new elfnote contains the 32bit entry point into the kernel. Xen will use this entry point in order to launch the guest kernel in 32bit protected mode with paging disabled.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/xcutils/readnotes.c          |  3 +++
 xen/common/libelf/libelf-dominfo.c |  4 ++++
 xen/include/public/elfnote.h       | 11 ++++++++++-
 3 files changed, 17 insertions(+), 1 deletion(-)
tools/xcutils/readnotes.c +3 -0
index 5fa445e..e682dd1 100644
@@ -159,6 +159,9 @@ static unsigned print_notes(struct elf_binary *elf, ELF_HANDLE_DECL(elf_note) st
 		case XEN_ELFNOTE_L1_MFN_VALID:
 			print_l1_mfn_valid_note("L1_MFN_VALID", elf , note);
 			break;
+		case XEN_ELFNOTE_PHYS32_ENTRY:
+			print_numeric_note("PHYS32_ENTRY", elf , note);
+			break;
 		default:
 			printf("unknown note type %#x\n",
 			       (unsigned)elf_uval(elf, note, type));
xen/common/libelf/libelf-dominfo.c +4 -0
index 0771323..78d75ad 100644
@@ -120,6 +120,7 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf,
         [XEN_ELFNOTE_BSD_SYMTAB] = { "BSD_SYMTAB", 1},
         [XEN_ELFNOTE_SUSPEND_CANCEL] = { "SUSPEND_CANCEL", 0 },
         [XEN_ELFNOTE_MOD_START_PFN] = { "MOD_START_PFN", 0 },
+        [XEN_ELFNOTE_PHYS32_ENTRY] = { "PHYS32_ENTRY", 0 },
     };
 /* *INDENT-ON* */
 
@@ -213,6 +214,9 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf,
                 elf, note, sizeof(*parms->f_supported), i);
         break;
 
+    case XEN_ELFNOTE_PHYS32_ENTRY:
+        parms->phys_entry = val;
+        break;
     }
     return 0;
 }
xen/include/public/elfnote.h +10 -1
index 3824a94..e6fc596 100644
@@ -200,9 +200,18 @@
 #define XEN_ELFNOTE_SUPPORTED_FEATURES 17
 
 /*
+ * Physical entry point into the kernel.
+ *
+ * 32bit entry point into the kernel. Xen will use this entry point
+ * in order to launch the guest kernel in 32bit protected mode
+ * with paging disabled.
+ */
+#define XEN_ELFNOTE_PHYS32_ENTRY 18
+
+/*
  * The number of the highest elfnote defined.
  */
-#define XEN_ELFNOTE_MAX XEN_ELFNOTE_SUPPORTED_FEATURES
+#define XEN_ELFNOTE_MAX XEN_ELFNOTE_PHYS32_ENTRY
 
 /*
  * System information exported through crash notes.
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 17/32 xen/x86: allow disabling the emulated PIC

In reply to Roger Pau Monne
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/vpic.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vpic.c +10 -1
index 909b9d0..2eb162a 100644
@@ -377,6 +377,9 @@ static int vpic_save(struct domain *d, hvm_domain_context_t *h)
     struct hvm_hw_vpic *s;
     int i;
 
+    if ( !has_vpic(d) )
+        return 0;
+
     /* Save the state of both PICs */
     for ( i = 0; i < 2 ; i++ )
     {
@@ -392,7 +395,10 @@ static int vpic_load(struct domain *d, hvm_domain_context_t *h)
 {
     struct hvm_hw_vpic *s;
     uint16_t inst;
-    
+
+    if ( !has_vpic(d) )
+        return 0;
+
     /* Which PIC is this? */
     inst = hvm_load_instance(h);
     if ( inst > 1 )
@@ -425,6 +431,9 @@ void vpic_reset(struct domain *d)
 
 void vpic_init(struct domain *d)
 {
+    if ( !has_vpic(d) )
+        return;
+
     vpic_reset(d);
 
     register_portio_handler(d, 0x20, 2, vpic_intercept_pic_io);
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 32/32 libxl: allow the creation of HVM domains without a device model.

In reply to Roger Pau Monne

Replace the firmware loaded into HVM guests with an OS kernel. Since the HVM builder now uses the PV xc_dom_* set of functions this kernel will be parsed and loaded inside the guest like on PV, but the container is a pure HVM guest.

Also, if device_model_version is set to none unconditinally set the nic type to LIBXL_NIC_TYPE_VIF.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 docs/man/xl.cfg.pod.5       |  5 ++++
 tools/libxl/libxl.c         |  7 +++---
 tools/libxl/libxl_create.c  | 18 ++++++++++++++
 tools/libxl/libxl_dom.c     | 60 ++++++++++++++++++++++++++++++---------------
 tools/libxl/libxl_types.idl |  1 +
 tools/libxl/libxl_x86.c     |  4 ++-
 tools/libxl/xl_cmdimpl.c    |  2 ++
 7 files changed, 72 insertions(+), 25 deletions(-)
docs/man/xl.cfg.pod.5 +5 -0
index a3e0e2e..1270605 100644
@@ -1631,6 +1631,11 @@ This device-model is the default for Linux dom0.
 Use the device-model based upon the historical Xen fork of Qemu.
 This device-model is still the default for NetBSD dom0.
 
+=item B<none>
+
+Don't use any device model. This requires a kernel capable of booting
+in this mode.
+
 =back
 
 It is recommended to accept the default value for new guests.  If
tools/libxl/libxl.c +3 -4
index e9a2d26..a6690cf 100644
@@ -1590,11 +1590,10 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis)
 
     switch (libxl__domain_type(gc, domid)) {
     case LIBXL_DOMAIN_TYPE_HVM:
-        if (!libxl_get_stubdom_id(CTX, domid))
-            dm_present = 1;
-        else
+        if (libxl_get_stubdom_id(CTX, domid)) {
             dm_present = 0;
-        break;
+            break;
+        }
     case LIBXL_DOMAIN_TYPE_PV:
         pid = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "/local/domain/%d/image/device-model-pid", domid));
         dm_present = (pid != NULL);
tools/libxl/libxl_create.c +18 -0
index f366a09..1444e40 100644
@@ -164,6 +164,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
                 b_info->u.hvm.bios = LIBXL_BIOS_TYPE_ROMBIOS; break;
             case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
                 b_info->u.hvm.bios = LIBXL_BIOS_TYPE_SEABIOS; break;
+            case LIBXL_DEVICE_MODEL_VERSION_NONE:
+                break;
             default:return ERROR_INVAL;
             }
 
@@ -177,6 +179,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
             if (b_info->u.hvm.bios == LIBXL_BIOS_TYPE_ROMBIOS)
                 return ERROR_INVAL;
             break;
+        case LIBXL_DEVICE_MODEL_VERSION_NONE:
+            break;
         default:abort();
         }
 
@@ -278,6 +282,9 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
                 break;
             }
             break;
+        case LIBXL_DEVICE_MODEL_VERSION_NONE:
+            b_info->video_memkb = 0;
+            break;
         case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
         default:
             switch (b_info->u.hvm.vga.kind) {
@@ -945,6 +952,11 @@ static void initiate_domain_create(libxl__egc *egc,
         ret = libxl__device_nic_setdefault(gc, &d_config->nics[i], domid);
         if (ret) goto error_out;
 
+        /* HVM guests without a device model only have PV nics. */
+        if (d_config->b_info.device_model_version ==
+            LIBXL_DEVICE_MODEL_VERSION_NONE)
+            d_config->nics[i].nictype = LIBXL_NIC_TYPE_VIF;
+
         if (d_config->nics[i].devid > last_devid)
             last_devid = d_config->nics[i].devid;
     }
@@ -1293,6 +1305,12 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
         libxl__device_console_add(gc, domid, &console, state, &device);
         libxl__device_console_dispose(&console);
 
+        if (d_config->b_info.device_model_version ==
+            LIBXL_DEVICE_MODEL_VERSION_NONE) {
+            domcreate_devmodel_started(egc, &dcs->dmss.dm, 0);
+            return;
+        }
+
         libxl_device_vkb_init(&vkb);
         libxl__device_vkb_add(gc, domid, &vkb);
         libxl_device_vkb_dispose(&vkb);
tools/libxl/libxl_dom.c +40 -20

101 lines not on this page · raw message

tools/libxl/libxl_types.idl +1 -0
index e1632fa..0283197 100644
@@ -86,6 +86,7 @@ libxl_device_model_version = Enumeration("device_model_version", [
     (0, "UNKNOWN"),
     (1, "QEMU_XEN_TRADITIONAL"), # Historical qemu-xen device model (qemu-dm)
     (2, "QEMU_XEN"),             # Upstream based qemu-xen device model
+    (3, "NONE"),                 # No device model
     ])
 
 libxl_console_type = Enumeration("console_type", [
tools/libxl/libxl_x86.c +3 -1
index f04433a..435290b 100644
@@ -5,7 +5,9 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
                                       libxl_domain_config *d_config,
                                       xc_domain_configuration_t *xc_config)
 {
-    if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM)
+    if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM &&
+        d_config->b_info.device_model_version !=
+        LIBXL_DEVICE_MODEL_VERSION_NONE)
         xc_config->emulation_flags = (EMU_LAPIC | EMU_HPET | EMU_PMTIMER |
                                       EMU_RTC | EMU_IOAPIC | EMU_PIC |
                                       EMU_PMU | EMU_VGA | EMU_IOMMU);
tools/libxl/xl_cmdimpl.c +2 -0
index c858068..3d9b3d4 100644
@@ -2067,6 +2067,8 @@ skip_vfb:
         } else if (!strcmp(buf, "qemu-xen")) {
             b_info->device_model_version
                 = LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
+        } else if (!strcmp(buf, "none")) {
+            b_info->device_model_version = LIBXL_DEVICE_MODEL_VERSION_NONE;
         } else {
             fprintf(stderr,
                     "Unknown device_model_version \"%s\" specified\n", buf);
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 21/32 xen/x86: allow disabling all emulated devices inside of Xen

In reply to Roger Pau Monne

Only allow enabling or disabling all the emulated devices inside of Xen, right now Xen doesn't support enabling specific emulated devices only.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/domain.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/domain.c +2 -1
index d684f49..bdaf646 100644
@@ -555,7 +555,8 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     {
         emulation_mask = (EMU_LAPIC | EMU_HPET | EMU_PMTIMER | EMU_RTC |
                           EMU_IOAPIC | EMU_PIC | EMU_PMU | EMU_VGA | EMU_IOMMU);
-        if ( (config->emulation_flags & emulation_mask) != emulation_mask )
+        if ( (config->emulation_flags & emulation_mask) != emulation_mask &&
+             (config->emulation_flags & emulation_mask) != 0 )
         {
             printk(XENLOG_G_ERR "Xen does not allow HVM creation with the "
                    "current selection of emulators: 0x%x.\n",
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 23/32 libxc: allow creating domains without emulated devices.

In reply to Roger Pau Monne

Introduce a new flag in xc_dom_image that turns on and off the emulated devices. This prevents creating the VGA hole, the hvm_info page and the ioreq server pages. libxl unconditionally sets it to true for all HVM domains at the moment.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxc/include/xc_dom.h |  1 +
 tools/libxc/xc_dom_x86.c     | 71 +++++++++++++++++++++++++-------------------
 tools/libxl/libxl_dom.c      |  1 +
 3 files changed, 42 insertions(+), 31 deletions(-)
tools/libxc/include/xc_dom.h +1 -0
index 68b052c..7086f6e 100644
@@ -194,6 +194,7 @@ struct xc_dom_image {
     xen_pfn_t mmio_size;
     xen_pfn_t lowmem_end;
     xen_pfn_t highmem_end;
+    bool emulation;
 
     /* Extra ACPI tables passed to HVMLOADER */
     struct xc_hvm_firmware_module acpi_module;
tools/libxc/xc_dom_x86.c +40 -31

111 lines not on this page · raw message

tools/libxl/libxl_dom.c +1 -0
index 480b7e7..6ce4115 100644
@@ -992,6 +992,7 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
     dom->lowmem_end = lowmem_end;
     dom->highmem_end = highmem_end;
     dom->mmio_start = mmio_start;
+    dom->emulation = true;
 
     if (info->num_vnuma_nodes != 0) {
         int i;
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 14/32 xen/x86: allow disabling the pmtimer

In reply to Roger Pau Monne
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/pmtimer.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
xen/arch/x86/hvm/pmtimer.c +13 -0
index 8b531d9..335a296 100644
@@ -248,6 +248,9 @@ static int pmtimer_save(struct domain *d, hvm_domain_context_t *h)
     uint32_t x, msb = s->pm.tmr_val & TMR_VAL_MSB;
     int rc;
 
+    if ( !has_vpmtimer(d) )
+        return 0;
+
     spin_lock(&s->lock);
 
     /* Update the counter to the guest's current time.  We always save
@@ -272,6 +275,9 @@ static int pmtimer_load(struct domain *d, hvm_domain_context_t *h)
 {
     PMTState *s = &d->arch.hvm_domain.pl_time.vpmt;
 
+    if ( !has_vpmtimer(d) )
+        return 0;
+
     spin_lock(&s->lock);
 
     /* Reload the registers */
@@ -329,6 +335,9 @@ void pmtimer_init(struct vcpu *v)
 {
     PMTState *s = &v->domain->arch.hvm_domain.pl_time.vpmt;
 
+    if ( !has_vpmtimer(v->domain) )
+        return;
+
     spin_lock_init(&s->lock);
 
     s->scale = ((uint64_t)FREQUENCE_PMTIMER << 32) / SYSTEM_TIME_HZ;
@@ -349,6 +358,10 @@ void pmtimer_init(struct vcpu *v)
 void pmtimer_deinit(struct domain *d)
 {
     PMTState *s = &d->arch.hvm_domain.pl_time.vpmt;
+
+    if ( !has_vpmtimer(d) )
+        return;
+
     kill_timer(&s->timer);
 }
 
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 28/32 libxc/xen: introduce HVM_PARAM_CMDLINE_PFN

In reply to Roger Pau Monne

This HVM parameter returns a PFN that contains the address of the memory page where the guest command line has been placed.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 tools/libxc/xc_dom_x86.c        | 21 ++++++++++++++++++++-
 xen/arch/x86/hvm/hvm.c          |  1 +
 xen/include/public/hvm/params.h |  5 ++++-
 3 files changed, 25 insertions(+), 2 deletions(-)
tools/libxc/xc_dom_x86.c +20 -1
index 1195400..41ff7a4 100644
@@ -57,7 +57,8 @@
 #define SPECIALPAGE_IOREQ    5
 #define SPECIALPAGE_IDENT_PT 6
 #define SPECIALPAGE_CONSOLE  7
-#define NR_SPECIAL_PAGES     8
+#define SPECIALPAGE_CMDLINE  8
+#define NR_SPECIAL_PAGES     9
 #define LAST_SPECIAL_PFN     0xff000u
 
 #define NR_IOREQ_SERVER_PAGES 8
@@ -531,6 +532,7 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
     xen_pfn_t special_array[NR_SPECIAL_PAGES];
     xen_pfn_t ioreq_server_array[NR_IOREQ_SERVER_PAGES];
     xc_interface *xch = dom->xch;
+    char *cmdline;
 
     if ( dom->emulation )
     {
@@ -572,6 +574,23 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
     xc_hvm_param_set(xch, domid, HVM_PARAM_SHARING_RING_PFN,
                      special_pfn(SPECIALPAGE_SHARING, dom));
 
+    if ( dom->cmdline )
+    {
+        cmdline = xc_map_foreign_range(
+                  xch, domid, PAGE_SIZE, PROT_READ | PROT_WRITE,
+                  special_pfn(SPECIALPAGE_CMDLINE, dom));
+        if ( cmdline == NULL ) {
+            DOMPRINTF("Unable to map command line page");
+            goto error_out;
+        }
+
+        strncpy(cmdline, dom->cmdline, MAX_GUEST_CMDLINE);
+        cmdline[MAX_GUEST_CMDLINE - 1] = '\0';
+        munmap(cmdline, PAGE_SIZE);
+        xc_hvm_param_set(xch, domid, HVM_PARAM_CMDLINE_PFN,
+                     special_pfn(SPECIALPAGE_CMDLINE, dom));
+    }
+
     if ( dom->emulation )
     {
         /*
xen/arch/x86/hvm/hvm.c +1 -0
index 350e409..efe7232 100644
@@ -5917,6 +5917,7 @@ static int hvm_allow_get_param(struct domain *d,
     case HVM_PARAM_STORE_EVTCHN:
     case HVM_PARAM_CONSOLE_PFN:
     case HVM_PARAM_CONSOLE_EVTCHN:
+    case HVM_PARAM_CMDLINE_PFN:
         break;
     /*
      * The following parameters must not be read by the guest
xen/include/public/hvm/params.h +4 -1
index 7c73089..b7f8839 100644
@@ -187,6 +187,9 @@
 /* Location of the VM Generation ID in guest physical address space. */
 #define HVM_PARAM_VM_GENERATION_ID_ADDR 34
 
-#define HVM_NR_PARAMS          35
+/* PFN of the command line. */
+#define HVM_PARAM_CMDLINE_PFN 35
+
+#define HVM_NR_PARAMS          36
 
 #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 16/32 xen/x86: allow disabling the emulated IO APIC

In reply to Roger Pau Monne
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/vioapic.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
xen/arch/x86/hvm/vioapic.c +14 -0
index 9de2ff3..4cfc704 100644
@@ -425,12 +425,20 @@ void vioapic_update_EOI(struct domain *d, u8 vector)
 static int ioapic_save(struct domain *d, hvm_domain_context_t *h)
 {
     struct hvm_hw_vioapic *s = domain_vioapic(d);
+
+    if ( !has_vioapic(d) )
+        return 0;
+
     return hvm_save_entry(IOAPIC, 0, h, s);
 }
 
 static int ioapic_load(struct domain *d, hvm_domain_context_t *h)
 {
     struct hvm_hw_vioapic *s = domain_vioapic(d);
+
+    if ( !has_vioapic(d) )
+        return 0;
+
     return hvm_load_entry(IOAPIC, h, s);
 }
 
@@ -449,6 +457,9 @@ void vioapic_reset(struct domain *d)
 
 int vioapic_init(struct domain *d)
 {
+    if ( !has_vioapic(d) )
+        return 0;
+
     if ( (d->arch.hvm_domain.vioapic == NULL) &&
          ((d->arch.hvm_domain.vioapic = xmalloc(struct hvm_vioapic)) == NULL) )
         return -ENOMEM;
@@ -463,6 +474,9 @@ int vioapic_init(struct domain *d)
 
 void vioapic_deinit(struct domain *d)
 {
+    if ( !has_vioapic(d) )
+        return;
+
     xfree(d->arch.hvm_domain.vioapic);
     d->arch.hvm_domain.vioapic = NULL;
 }
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 13/32 xen/x86: allow disabling the emulated HPET

In reply to Roger Pau Monne
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/hpet.c | 13 +++++++++++++
 xen/arch/x86/hvm/hvm.c  |  1 -
 2 files changed, 13 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/hpet.c +13 -0
index 732504a..9773034 100644
@@ -517,6 +517,9 @@ static int hpet_save(struct domain *d, hvm_domain_context_t *h)
     int rc;
     uint64_t guest_time;
 
+    if ( !has_vhpet(d) )
+        return 0;
+
     write_lock(&hp->lock);
     guest_time = guest_time_hpet(hp);
 
@@ -576,6 +579,9 @@ static int hpet_load(struct domain *d, hvm_domain_context_t *h)
     uint64_t guest_time;
     int i;
 
+    if ( !has_vhpet(d) )
+        return 0;
+
     write_lock(&hp->lock);
 
     /* Reload the HPET registers */
@@ -634,6 +640,9 @@ void hpet_init(struct domain *d)
     HPETState *h = domain_vhpet(d);
     int i;
 
+    if ( !has_vhpet(d) )
+        return;
+
     memset(h, 0, sizeof(HPETState));
 
     rwlock_init(&h->lock);
@@ -661,6 +670,7 @@ void hpet_init(struct domain *d)
     }
 
     register_mmio_handler(d, &hpet_mmio_ops);
+    d->arch.hvm_domain.params[HVM_PARAM_HPET_ENABLED] = 1;
 }
 
 void hpet_deinit(struct domain *d)
@@ -668,6 +678,9 @@ void hpet_deinit(struct domain *d)
     int i;
     HPETState *h = domain_vhpet(d);
 
+    if ( !has_vhpet(d) )
+        return;
+
     write_lock(&h->lock);
 
     if ( hpet_enabled(h) )
xen/arch/x86/hvm/hvm.c +0 -1
index 901f9a8..9c6e7fd 100644
@@ -1547,7 +1547,6 @@ int hvm_domain_initialise(struct domain *d)
 
     hvm_init_guest_time(d);
 
-    d->arch.hvm_domain.params[HVM_PARAM_HPET_ENABLED] = 1;
     d->arch.hvm_domain.params[HVM_PARAM_TRIPLE_FAULT_REASON] = SHUTDOWN_reboot;
 
     vpic_init(d);
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 11/32 xen/x86: add bitmap of enabled emulated devices

In reply to Roger Pau Monne

Introduce a bitmap in x86 xen_arch_domainconfig that allows enabling or disabling specific devices emulated inside of Xen for HVM guests.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 tools/libxl/libxl_x86.c           |  6 ++++--
 xen/arch/x86/domain.c             | 15 +++++++++++++++
 xen/include/asm-x86/domain.h      | 13 +++++++++++++
 xen/include/public/arch-x86/xen.h | 20 +++++++++++++++++++-
 4 files changed, 51 insertions(+), 3 deletions(-)
tools/libxl/libxl_x86.c +4 -2
index ed2bd38..f04433a 100644
@@ -5,8 +5,10 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
                                       libxl_domain_config *d_config,
                                       xc_domain_configuration_t *xc_config)
 {
-    /* No specific configuration right now */
-
+    if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM)
+        xc_config->emulation_flags = (EMU_LAPIC | EMU_HPET | EMU_PMTIMER |
+                                      EMU_RTC | EMU_IOAPIC | EMU_PIC |
+                                      EMU_PMU | EMU_VGA | EMU_IOMMU);
     return 0;
 }
 
xen/arch/x86/domain.c +15 -0
index a112953..d684f49 100644
@@ -528,6 +528,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
 {
     int i, paging_initialised = 0;
     int rc = -ENOMEM;
+    uint32_t emulation_mask;
 
     d->arch.s3_integrity = !!(domcr_flags & DOMCRF_s3_integrity);
 
@@ -550,6 +551,20 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                d->domain_id);
     }
 
+    if ( is_hvm_domain(d) )
+    {
+        emulation_mask = (EMU_LAPIC | EMU_HPET | EMU_PMTIMER | EMU_RTC |
+                          EMU_IOAPIC | EMU_PIC | EMU_PMU | EMU_VGA | EMU_IOMMU);
+        if ( (config->emulation_flags & emulation_mask) != emulation_mask )
+        {
+            printk(XENLOG_G_ERR "Xen does not allow HVM creation with the "
+                   "current selection of emulators: 0x%x.\n",
+                   config->emulation_flags);
+            return -EPERM;
+        }
+        d->arch.emulation_flags = config->emulation_flags;
+    }
+
     if ( has_hvm_container_domain(d) )
     {
         d->arch.hvm_domain.hap_enabled =
xen/include/asm-x86/domain.h +13 -0
index 96bde65..502379e 100644
@@ -356,8 +356,21 @@ struct arch_domain
 
     /* Mem_access emulation control */
     bool_t mem_access_emulate_enabled;
+
+    /* Emulated devices enabled bitmap. */
+    uint32_t emulation_flags;
 } __cacheline_aligned;
 
+#define has_vlapic(d)       (d->arch.emulation_flags & EMU_LAPIC)
+#define has_vhpet(d)        (d->arch.emulation_flags & EMU_HPET)
+#define has_vpmtimer(d)     (d->arch.emulation_flags & EMU_PMTIMER)
+#define has_vrtc(d)         (d->arch.emulation_flags & EMU_RTC)
+#define has_vioapic(d)      (d->arch.emulation_flags & EMU_IOAPIC)
+#define has_vpic(d)         (d->arch.emulation_flags & EMU_PIC)
+#define has_vpmu(d)         (d->arch.emulation_flags & EMU_PMU)
+#define has_vvga(d)         (d->arch.emulation_flags & EMU_VGA)
+#define has_viommu(d)       (d->arch.emulation_flags & EMU_IOMMU)
+
 #define has_arch_pdevs(d)    (!list_empty(&(d)->arch.pdev_list))
 
 #define gdt_ldt_pt_idx(v) \
xen/include/public/arch-x86/xen.h +19 -1
index 2ecc9c9..6b387a3 100644
@@ -268,7 +268,25 @@ typedef struct arch_shared_info arch_shared_info_t;
  * XEN_DOMCTL_INTERFACE_VERSION.
  */
 struct xen_arch_domainconfig {
-    char dummy;
+#define _EMU_LAPIC                  0
+#define EMU_LAPIC                   (1U<<_EMU_LAPIC)
+#define _EMU_HPET                   1
+#define EMU_HPET                    (1U<<_EMU_HPET)
+#define _EMU_PMTIMER                2
+#define EMU_PMTIMER                 (1U<<_EMU_PMTIMER)
+#define _EMU_RTC                    3
+#define EMU_RTC                     (1U<<_EMU_RTC)
+#define _EMU_IOAPIC                 4
+#define EMU_IOAPIC                  (1U<<_EMU_IOAPIC)
+#define _EMU_PIC                    5
+#define EMU_PIC                     (1U<<_EMU_PIC)
+#define _EMU_PMU                    6
+#define EMU_PMU                     (1U<<_EMU_PMU)
+#define _EMU_VGA                    7
+#define EMU_VGA                     (1U<<_EMU_VGA)
+#define _EMU_IOMMU                  8
+#define EMU_IOMMU                   (1U<<_EMU_IOMMU)
+    uint32_t emulation_flags;
 };
 #endif
 
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 31/32 libxc: switch xc_dom_elfloader to be used with HVMlite domains

In reply to Roger Pau Monne

Allow xc_dom_elfloader to report a guest type as hvm-3.0-x86_32 if it's running inside of a HVM container and has the PHYS32_ENTRY elfnote set.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>

---
Only xc_dom_elfloader has been switched to support HVMlite, other loaders should also be switched once we have a HVMlite compatible kernel that uses them.

---
 tools/libxc/xc_dom_elfloader.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/libxc/xc_dom_elfloader.c +4 -0
index 6ce1062..2f05015 100644
@@ -57,6 +57,10 @@ static char *xc_dom_guest_type(struct xc_dom_image *dom,
 {
     uint64_t machine = elf_uval(elf, elf->ehdr, e_machine);
 
+    if ( dom->container_type == XC_DOM_HVM_CONTAINER &&
+         dom->parms.phys_entry != UNSET_ADDR )
+        return "hvm-3.0-x86_32";
+
     switch ( machine )
     {
     case EM_386:
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 25/32 xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

In reply to Roger Pau Monne

Allow the usage of the VCPUOP_initialise, VCPUOP_up, VCPUOP_down and VCPUOP_is_up hypercalls from HVM guests.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/hvm.c | 8 ++++++++
 1 file changed, 8 insertions(+)
xen/arch/x86/hvm/hvm.c +8 -0
index 75a5566..350e409 100644
@@ -4808,6 +4808,10 @@ static long hvm_vcpu_op(
     case VCPUOP_stop_singleshot_timer:
     case VCPUOP_register_vcpu_info:
     case VCPUOP_register_vcpu_time_memory_area:
+    case VCPUOP_initialise:
+    case VCPUOP_up:
+    case VCPUOP_down:
+    case VCPUOP_is_up:
         rc = do_vcpu_op(cmd, vcpuid, arg);
         break;
     default:
@@ -4866,6 +4870,10 @@ static long hvm_vcpu_op_compat32(
     case VCPUOP_stop_singleshot_timer:
     case VCPUOP_register_vcpu_info:
     case VCPUOP_register_vcpu_time_memory_area:
+    case VCPUOP_initialise:
+    case VCPUOP_up:
+    case VCPUOP_down:
+    case VCPUOP_is_up:
         rc = compat_vcpu_op(cmd, vcpuid, arg);
         break;
     default:
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 12/32 xen/x86: allow disabling the emulated local apic

In reply to Roger Pau Monne
Cc Boris Ostrovsky <[email protected]>
Cc Suravee Suthikulpanit <[email protected]>
Cc Aravind Gopalakrishnan <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
Cc Jun Nakajima <[email protected]>
Cc Eddie Dong <[email protected]>
Cc Kevin Tian <[email protected]>
---
 xen/arch/x86/hvm/svm/svm.c  | 16 +++++++++-------
 xen/arch/x86/hvm/vlapic.c   | 30 +++++++++++++++++++++++++-----
 xen/arch/x86/hvm/vmsi.c     |  6 ++++++
 xen/arch/x86/hvm/vmx/vmcs.c | 14 ++++++++++++++
 xen/arch/x86/hvm/vmx/vmx.c  |  9 ++++++++-
 5 files changed, 62 insertions(+), 13 deletions(-)
xen/arch/x86/hvm/svm/svm.c +9 -7
index a02f983..46062dd 100644
@@ -1036,6 +1036,7 @@ static void noreturn svm_do_resume(struct vcpu *v)
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
     bool_t debug_state = v->domain->debugger_attached;
     bool_t vcpu_guestmode = 0;
+    struct vlapic *vlapic = vcpu_vlapic(v);
 
     if ( nestedhvm_enabled(v->domain) && nestedhvm_vcpu_in_guestmode(v) )
         vcpu_guestmode = 1;
@@ -1059,14 +1060,14 @@ static void noreturn svm_do_resume(struct vcpu *v)
         hvm_asid_flush_vcpu(v);
     }
 
-    if ( !vcpu_guestmode )
+    if ( !vcpu_guestmode && !vlapic_hw_disabled(vlapic) )
     {
         vintr_t intr;
 
         /* Reflect the vlapic's TPR in the hardware vtpr */
         intr = vmcb_get_vintr(vmcb);
         intr.fields.tpr =
-            (vlapic_get_reg(vcpu_vlapic(v), APIC_TASKPRI) & 0xFF) >> 4;
+            (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4;
         vmcb_set_vintr(vmcb, intr);
     }
 
@@ -2295,6 +2296,7 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
     int inst_len, rc;
     vintr_t intr;
     bool_t vcpu_guestmode = 0;
+    struct vlapic *vlapic = vcpu_vlapic(v);
 
     hvm_invalidate_regs_fields(regs);
 
@@ -2312,11 +2314,11 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
      * NB. We need to preserve the low bits of the TPR to make checked builds
      * of Windows work, even though they don't actually do anything.
      */
-    if ( !vcpu_guestmode ) {
+    if ( !vcpu_guestmode && !vlapic_hw_disabled(vlapic) ) {
         intr = vmcb_get_vintr(vmcb);
-        vlapic_set_reg(vcpu_vlapic(v), APIC_TASKPRI,
+        vlapic_set_reg(vlapic, APIC_TASKPRI,
                    ((intr.fields.tpr & 0x0F) << 4) |
-                   (vlapic_get_reg(vcpu_vlapic(v), APIC_TASKPRI) & 0x0F));
+                   (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0x0F));
     }
 
     exit_reason = vmcb->exitcode;
@@ -2698,14 +2700,14 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
     }
 
   out:
-    if ( vcpu_guestmode )
+    if ( vcpu_guestmode || vlapic_hw_disabled(vlapic) )
         /* Don't clobber TPR of the nested guest. */
         return;
 
     /* The exit may have updated the TPR: reflect this in the hardware vtpr */
     intr = vmcb_get_vintr(vmcb);
     intr.fields.tpr =
-        (vlapic_get_reg(vcpu_vlapic(v), APIC_TASKPRI) & 0xFF) >> 4;
+        (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4;
     vmcb_set_vintr(vmcb, intr);
 }
 
xen/arch/x86/hvm/vlapic.c +25 -5
index 5472f79..ff648b9 100644
@@ -994,6 +994,9 @@ static void set_x2apic_id(struct vlapic *vlapic)
 
 bool_t vlapic_msr_set(struct vlapic *vlapic, uint64_t value)
 {
+    if ( !has_vlapic(vlapic_domain(vlapic)) )
+        return 0;
+
     if ( (vlapic->hw.apic_base_msr ^ value) & MSR_IA32_APICBASE_ENABLE )
     {
         if ( unlikely(value & MSR_IA32_APICBASE_EXTD) )
@@ -1043,8 +1046,7 @@ void vlapic_tdt_msr_set(struct vlapic *vlapic, uint64_t value)
     uint64_t guest_tsc;
     struct vcpu *v = vlapic_vcpu(vlapic);
 
-    /* may need to exclude some other conditions like vlapic->hw.disabled */
-    if ( !vlapic_lvtt_tdt(vlapic) )
+    if ( !vlapic_lvtt_tdt(vlapic) || vlapic_hw_disabled(vlapic) )
     {
         HVM_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER, "ignore tsc deadline msr write");
         return;
@@ -1119,6 +1121,9 @@ static int __vlapic_accept_pic_intr(struct vcpu *v)
 
 int vlapic_accept_pic_intr(struct vcpu *v)
 {
+    if ( vlapic_hw_disabled(vcpu_vlapic(v)) )
+        return 0;
+
     TRACE_2D(TRC_HVM_EMUL_LAPIC_PIC_INTR,
              (v == v->domain->arch.hvm_domain.i8259_target),
              v ? __vlapic_accept_pic_intr(v) : -1);
@@ -1266,6 +1271,9 @@ static int lapic_save_hidden(struct domain *d, hvm_domain_context_t *h)
     struct vlapic *s;
     int rc = 0;
 
+    if ( !has_vlapic(d) )
+        return 0;
+
     for_each_vcpu ( d, v )
     {
         s = vcpu_vlapic(v);
@@ -1282,6 +1290,9 @@ static int lapic_save_regs(struct domain *d, hvm_domain_context_t *h)
     struct vlapic *s;
     int rc = 0;
 
+    if ( !has_vlapic(d) )
+        return 0;
+
     for_each_vcpu ( d, v )
     {
         if ( hvm_funcs.sync_pir_to_irr )
@@ -1329,7 +1340,10 @@ static int lapic_load_hidden(struct domain *d, hvm_domain_context_t *h)
     uint16_t vcpuid;
     struct vcpu *v;
     struct vlapic *s;
-    
+
+    if ( !has_vlapic(d) )
+        return 0;
+
     /* Which vlapic to load? */
     vcpuid = hvm_load_instance(h); 
     if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
@@ -1361,7 +1375,10 @@ static int lapic_load_regs(struct domain *d, hvm_domain_context_t *h)
     uint16_t vcpuid;
     struct vcpu *v;
     struct vlapic *s;
-    
+
+    if ( !has_vlapic(d) )
+        return 0;
+
     /* Which vlapic to load? */
     vcpuid = hvm_load_instance(h); 
     if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
@@ -1400,7 +1417,7 @@ int vlapic_init(struct vcpu *v)
 
     HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "%d", v->vcpu_id);
 
-    if ( is_pvh_vcpu(v) )
+    if ( is_pvh_vcpu(v) || !has_vlapic(v->domain) )
     {
         vlapic->hw.disabled = VLAPIC_HW_DISABLED;
         return 0;
@@ -1453,6 +1470,9 @@ void vlapic_destroy(struct vcpu *v)
 {
     struct vlapic *vlapic = vcpu_vlapic(v);
 
+    if ( !has_vlapic(vlapic_domain(vlapic)) )
+        return;
+
     tasklet_kill(&vlapic->init_sipi.tasklet);
     TRACE_0D(TRC_HVM_EMUL_LAPIC_STOP_TIMER);
     destroy_periodic_time(&vlapic->pt);
xen/arch/x86/hvm/vmsi.c +6 -0
index bf6090e..264e54d 100644
@@ -483,6 +483,9 @@ found:
 
 void msixtbl_init(struct domain *d)
 {
+    if ( !has_vlapic(d) )
+        return;
+
     register_mmio_handler(d, &msixtbl_mmio_ops);
 }
 
@@ -491,6 +494,9 @@ void msixtbl_pt_cleanup(struct domain *d)
     struct msixtbl_entry *entry, *temp;
     unsigned long flags;
 
+    if ( !has_vlapic(d) )
+        return;
+
     /* msixtbl_list_lock must be acquired with irq_disabled for check_lock() */
     local_irq_save(flags); 
     spin_lock(&d->arch.hvm_domain.msixtbl_list_lock);
xen/arch/x86/hvm/vmx/vmcs.c +14 -0
index 4c5ceb5..8df6b71 100644
@@ -992,6 +992,20 @@ static int construct_vmcs(struct vcpu *v)
         ASSERT(!(v->arch.hvm_vmx.exec_control & CPU_BASED_RDTSC_EXITING));
     }
 
+    if ( !has_vlapic(d) )
+    {
+        /* Disable virtual apics, TPR */
+        v->arch.hvm_vmx.secondary_exec_control &=
+            ~(SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES
+              | SECONDARY_EXEC_APIC_REGISTER_VIRT
+              | SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY);
+        v->arch.hvm_vmx.exec_control &= ~CPU_BASED_TPR_SHADOW;
+
+        /* In turn, disable posted interrupts. */
+        __vmwrite(PIN_BASED_VM_EXEC_CONTROL,
+                  vmx_pin_based_exec_control & ~PIN_BASED_POSTED_INTERRUPT);
+    }
+
     vmx_update_cpu_exec_control(v);
 
     __vmwrite(VM_EXIT_CONTROLS, vmexit_ctl);
xen/arch/x86/hvm/vmx/vmx.c +8 -1
index fc29b89..1e1aca3 100644
@@ -88,6 +88,9 @@ static int vmx_domain_initialise(struct domain *d)
 {
     int rc;
 
+    if ( !has_vlapic(d) )
+        return 0;
+
     if ( (rc = vmx_alloc_vlapic_mapping(d)) != 0 )
         return rc;
 
@@ -96,6 +99,9 @@ static int vmx_domain_initialise(struct domain *d)
 
 static void vmx_domain_destroy(struct domain *d)
 {
+    if ( !has_vlapic(d) )
+        return;
+
     vmx_free_vlapic_mapping(d);
 }
 
@@ -2240,7 +2246,8 @@ static void vmx_install_vlapic_mapping(struct vcpu *v)
 {
     paddr_t virt_page_ma, apic_page_ma;
 
-    if ( !cpu_has_vmx_virtualize_apic_accesses )
+    if ( !cpu_has_vmx_virtualize_apic_accesses ||
+         v->domain->arch.hvm_domain.vmx.apic_access_mfn == 0 )
         return;
 
     virt_page_ma = page_to_maddr(vcpu_vlapic(v)->regs_page);
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 18/32 xen/x86: allow disabling the emulated pmu

In reply to Roger Pau Monne
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/vpmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/vpmu.c +1 -1
index c3273ee..776661d 100644
@@ -233,7 +233,7 @@ void vpmu_initialise(struct vcpu *v)
     uint8_t vendor = current_cpu_data.x86_vendor;
     int ret;
 
-    if ( is_pvh_vcpu(v) )
+    if ( is_pvh_vcpu(v) || !has_vpmu(v->domain) )
         return;
 
     ASSERT(!vpmu->flags && !vpmu->context);
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 24/32 xen: allow HVM guests to use XENMEM_memory_map

In reply to Roger Pau Monne

Enable this hypercall for HVM guests in order to fetch the e820 memory map in the absence of an emulated BIOS. The memory map is populated and notified to Xen in arch_setup_meminit_hvm.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 tools/libxc/xc_dom_x86.c | 29 ++++++++++++++++++++++++++++-
 xen/arch/x86/hvm/hvm.c   |  2 --
 xen/arch/x86/mm.c        |  6 ------
 3 files changed, 28 insertions(+), 9 deletions(-)
tools/libxc/xc_dom_x86.c +28 -1
index 336eab4..45b1f03 100644
@@ -1113,6 +1113,7 @@ static int check_mmio_hole(uint64_t start, uint64_t memsize,
         return 1;
 }
 
+#define MAX_E820_ENTRIES    128
 static int meminit_hvm(struct xc_dom_image *dom)
 {
     unsigned long i, vmemid, nr_pages = dom->total_pages;
@@ -1133,6 +1134,8 @@ static int meminit_hvm(struct xc_dom_image *dom)
     unsigned int nr_vmemranges, nr_vnodes;
     xc_interface *xch = dom->xch;
     uint32_t domid = dom->guest_domid;
+    struct e820entry entries[MAX_E820_ENTRIES];
+    int e820_index = 0;
 
     if ( nr_pages > target_pages )
         memflags |= XENMEMF_populate_on_demand;
@@ -1183,6 +1186,13 @@ static int meminit_hvm(struct xc_dom_image *dom)
         vnode_to_pnode = dom->vnode_to_pnode;
     }
 
+    /* Add one additional memory range to account for the VGA hole */
+    if ( (nr_vmemranges + (dom->emulation ? 1 : 0)) > MAX_E820_ENTRIES )
+    {
+        DOMPRINTF("Too many memory ranges");
+        goto error_out;
+    }
+
     total_pages = 0;
     p2m_size = 0;
     for ( i = 0; i < nr_vmemranges; i++ )
@@ -1271,9 +1281,13 @@ static int meminit_hvm(struct xc_dom_image *dom)
      * Under 2MB mode, we allocate pages in batches of no more than 8MB to 
      * ensure that we can be preempted and hence dom0 remains responsive.
      */
-    if ( dom->emulation )
+    if ( dom->emulation ) {
         rc = xc_domain_populate_physmap_exact(
             xch, domid, 0xa0, 0, memflags, &dom->p2m_host[0x00]);
+        entries[e820_index].addr = 0;
+        entries[e820_index].size = 0xa0 << PAGE_SHIFT;
+        entries[e820_index++].type = E820_RAM;
+    }
 
     stat_normal_pages = 0;
     for ( vmemid = 0; vmemid < nr_vmemranges; vmemid++ )
@@ -1300,6 +1314,12 @@ static int meminit_hvm(struct xc_dom_image *dom)
         else
             cur_pages = vmemranges[vmemid].start >> PAGE_SHIFT;
 
+                /* Build an e820 map. */
+        entries[e820_index].addr = cur_pages << PAGE_SHIFT;
+        entries[e820_index].size = vmemranges[vmemid].end -
+                                   entries[e820_index].addr;
+        entries[e820_index++].type = E820_RAM;
+
         while ( (rc == 0) && (end_pages > cur_pages) )
         {
             /* Clip count to maximum 1GB extent. */
@@ -1417,6 +1437,13 @@ static int meminit_hvm(struct xc_dom_image *dom)
     DPRINTF("  2MB PAGES: 0x%016lx\n", stat_2mb_pages);
     DPRINTF("  1GB PAGES: 0x%016lx\n", stat_1gb_pages);
 
+    rc = xc_domain_set_memory_map(xch, domid, entries, e820_index);
+    if ( rc != 0 )
+    {
+        DOMPRINTF("unable to set memory map.");
+        goto error_out;
+    }
+
     rc = 0;
     goto out;
  error_out:
xen/arch/x86/hvm/hvm.c +0 -2
index 9c6e7fd..75a5566 100644
@@ -4765,7 +4765,6 @@ static long hvm_memory_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
     switch ( cmd & MEMOP_CMD_MASK )
     {
-    case XENMEM_memory_map:
     case XENMEM_machine_memory_map:
     case XENMEM_machphys_mapping:
         return -ENOSYS;
@@ -4841,7 +4840,6 @@ static long hvm_memory_op_compat32(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 
     switch ( cmd & MEMOP_CMD_MASK )
     {
-    case XENMEM_memory_map:
     case XENMEM_machine_memory_map:
     case XENMEM_machphys_mapping:
         return -ENOSYS;
xen/arch/x86/mm.c +0 -6
index fd151c6..92eccd0 100644
@@ -4717,12 +4717,6 @@ long arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
             return rc;
         }
 
-        if ( is_hvm_domain(d) )
-        {
-            rcu_unlock_domain(d);
-            return -EPERM;
-        }
-
         e820 = xmalloc_array(e820entry_t, fmap.map.nr_entries);
         if ( e820 == NULL )
         {
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 26/32 xenconsole: try to attach to PV console if HVM fails

In reply to Roger Pau Monne

HVM guests have always used the emulated serial console by default, but if the emulated serial pty cannot be fetched from xenstore try to use the PV console instead.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/console/client/main.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tools/console/client/main.c +8 -3
index f4c783b..c92553e 100644
@@ -279,7 +279,7 @@ int main(int argc, char **argv)
 		{ 0 },
 
 	};
-	char *dom_path = NULL, *path = NULL;
+	char *dom_path = NULL, *path = NULL, *test = NULL;
 	int spty, xsfd;
 	struct xs_handle *xs;
 	char *end;
@@ -357,9 +357,14 @@ int main(int argc, char **argv)
 	path = malloc(strlen(dom_path) + strlen("/device/console/0/tty") + 5);
 	if (path == NULL)
 		err(ENOMEM, "malloc");
-	if (type == CONSOLE_SERIAL)
+	if (type == CONSOLE_SERIAL) {
 		snprintf(path, strlen(dom_path) + strlen("/serial/0/tty") + 5, "%s/serial/%d/tty", dom_path, num);
-	else {
+		test = xs_read(xs, XBT_NULL, path, NULL);
+		free(test);
+		if (test == NULL)
+			goto pv_console;
+	} else {
+pv_console:
 		if (num == 0)
 			snprintf(path, strlen(dom_path) + strlen("/console/tty") + 1, "%s/console/tty", dom_path);
 		else
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 19/32 xen/x86: allow disabling the emulated VGA

In reply to Roger Pau Monne
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/stdvga.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/x86/hvm/stdvga.c +6 -0
index f13983e..87d0725 100644
@@ -546,6 +546,9 @@ void stdvga_init(struct domain *d)
     void *p;
     int i;
 
+    if ( !has_vvga(d) )
+        return;
+
     memset(s, 0, sizeof(*s));
     spin_lock_init(&s->lock);
     
@@ -581,6 +584,9 @@ void stdvga_deinit(struct domain *d)
     struct hvm_hw_stdvga *s = &d->arch.hvm_domain.stdvga;
     int i;
 
+    if ( !has_vvga(d) )
+        return;
+
     for ( i = 0; i != ARRAY_SIZE(s->vram_page); i++ )
     {
         if ( s->vram_page[i] == NULL )
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v3 29/32 libxc/xen: introduce HVM_PARAM_FIRST_FREE_PFN

In reply to Roger Pau Monne

This HVM parameter returns the first free pfn after all the special pages. It can be used by guests to figure out the first free memory address after the kernel, ramdisk and special pages. This is interesting for compatibility reasons in case more special pages are later added, older guests can still use this parameter to figure out the first free address, ignoring newly added special pages.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 tools/libxc/xc_dom_x86.c        | 2 ++
 xen/arch/x86/hvm/hvm.c          | 1 +
 xen/include/public/hvm/params.h | 5 ++++-
 3 files changed, 7 insertions(+), 1 deletion(-)
tools/libxc/xc_dom_x86.c +2 -0
index 41ff7a4..74c3819 100644
@@ -573,6 +573,8 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
                      special_pfn(SPECIALPAGE_ACCESS, dom));
     xc_hvm_param_set(xch, domid, HVM_PARAM_SHARING_RING_PFN,
                      special_pfn(SPECIALPAGE_SHARING, dom));
+    xc_hvm_param_set(xch, domid, HVM_PARAM_FIRST_FREE_PFN,
+                     special_pfn(NR_SPECIAL_PAGES, dom));
 
     if ( dom->cmdline )
     {
xen/arch/x86/hvm/hvm.c +1 -0
index efe7232..2b190e9 100644
@@ -5918,6 +5918,7 @@ static int hvm_allow_get_param(struct domain *d,
     case HVM_PARAM_CONSOLE_PFN:
     case HVM_PARAM_CONSOLE_EVTCHN:
     case HVM_PARAM_CMDLINE_PFN:
+    case HVM_PARAM_FIRST_FREE_PFN:
         break;
     /*
      * The following parameters must not be read by the guest
xen/include/public/hvm/params.h +4 -1
index b7f8839..47e38a8 100644
@@ -190,6 +190,9 @@
 /* PFN of the command line. */
 #define HVM_PARAM_CMDLINE_PFN 35
 
-#define HVM_NR_PARAMS          36
+/* First free PFN after the special pages. */
+#define HVM_PARAM_FIRST_FREE_PFN 36
+
+#define HVM_NR_PARAMS          37
 
 #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

Re: [PATCH v3 27/32] libxc: change the position of the special pages

In reply to Roger Pau Monne

El 03/07/15 a les 13.35, Roger Pau Monne ha escrit:

Quoted 12 lines

Change the physical memory address of the special pages when there are no emulated devices. On HVM guests the special pages have always been reserved so that they end at the 0xff000 pfn, but there are some problems with this approach when used without emulated devices:

- If we want to allow HVMlite to be used for Dom0 those special pages cannot be placed inside of the MMIO hole or else they may clash with MMIO regions of physical devices passed-through to Dom0.
- If there's no emulated devices the guests needs to access the console page and the command line very early during boot. This is a problem for FreeBSD at least, since the early page tables only map memory up to 1GiB.

Quoted 3 lines

So instead append the special pages after the kernel and ramdisk. The guest must make sure it figures out the position of those pages very early during boot, since the region is not marked as reserved in the memory map.

After thinking a little bit about this, I don't think this is the right solution. Placing all the special pages after the kernel/ramdisk will make it quite hard to use bootloaders like pvgrub inside of HVMlite guests. I will see if I can come up with a better way to solve this, comments welcome.

Roger.

#117 lore raw
In reply to Roger Pau Monne
Quoted 2 lines · Roger Pau Monne

And for the FreeBSD part:

Have you thought at all about what the Linux support for this mode would look like?

I started briefly looking today but don't really have time to look into it properly. I do think we want to use as much of the native/HVM code as possible and avoid the PV path (the current Linux PVH code uses too much of the PV entry point, IMO).

David

#118 lore raw

El 03/07/15 a les 18.19, David Vrabel ha escrit:

Quoted 11 lines · Roger Pau Monne
Quoted 2 lines

And for the FreeBSD part:

Have you thought at all about what the Linux support for this mode would look like?

I started briefly looking today but don't really have time to look into it properly. I do think we want to use as much of the native/HVM code as possible and avoid the PV path (the current Linux PVH code uses too much of the PV entry point, IMO).

I'm afraid I'm not that familiar with the native Linux entry point in order to know how much of that can be reused. Does the amd64 kernel contain a 32bit entry point or the kernel is expected to be launched in long mode with some page tables already setup?

Iff Linux on i386/amd64 already contains a 32bit protected mode without paging entry point then I guess most of the code can be reused.

Note that FreeBSD/amd64 didn't have any of this (the kernel is launched in long mode with some initial page tables setup by the loader), so the code needed for Linux should be similar to the one on FreeBSD or even less if there's an entry point that we can reuse:

http://xenbits.xen.org/gitweb/?p=people/royger/freebsd.git;a=blob;f=sys/amd64/amd64/xen-locore32.S;h=fd73d150009ab21059d4df219e6a62cc40d5994e;hb=refs/heads/new_entry_point_v2

Roger.

Reviewed-by on v3 1/32
#2 lore raw

Re: [PATCH v3 01/32] libxc: split x86 HVM setup_guest into smaller logical functions

In reply to Roger Pau Monne
Quoted 8 lines · Roger Pau Monne

This is just a preparatory change to clean up the code in setup_guest. Should not introduce any functional changes.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Quoted 6 lines
tools/libxc/xc_hvm_build_x86.c +2 -0
@@ -576,6 +584,44 @@ static int setup_guest(xc_interface *xch,
         goto error_out;
     }
 
+    /* Insert JMP <rel32> instruction at address 0x0 to reach entry point. */
+    entry_eip = elf_uval(&elf, elf.ehdr, e_entry);

tools/libxc/xc_hvm_build_x86.c static int setup_guest(xc_interface *xch, · line 598

Quoted 10 lines
tools/libxc/xc_hvm_build_x86.c +10 -0
+    if ( entry_eip != 0 )
+    {
+        char *page0 = xc_map_foreign_range(
+            xch, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, 0);
+        if ( page0 == NULL )
+            goto error_out;
+        page0[0] = 0xe9;
+        *(uint32_t *)&page0[1] = entry_eip - 5;
+        munmap(page0, PAGE_SIZE);
+    }

With this series eventually enabling DOMCTL_setvcpucontext properly for HVM vcpus, this above juggling can be replaced by setting the starting eip appropriately, which is neater than stuffing a hand-coded instruction in at 0.

~Andrew

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

Reviewed-by on v3 2/32
#5 lore raw

Re: [PATCH v3 02/32] libxc: unify xc_dom_p2m_{host/guest}

In reply to Roger Pau Monne
Quoted 9 lines · Roger Pau Monne

Unify both functions into xc_dom_p2m. Should not introduce any functional change.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Samuel Thibault <[email protected]>

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

Reviewed-by on v3 3/32
#8 lore raw

Re: [PATCH v3 03/32] libxc: introduce the notion of a container type

In reply to Roger Pau Monne
Quoted 9 lines · Roger Pau Monne

Introduce the notion of a container type into xc_dom_image. This will be needed by later changes that will also use xc_dom_image in order to build HVM guests.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>

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

#11 lore raw

Re: [PATCH v3 04/32] libxc: introduce a domain loader for HVM guest firmware

In reply to Roger Pau Monne
Quoted 9 lines · Roger Pau Monne

Introduce a very simple (and dummy) domain loader to be used to load the firmware (hvmloader) into HVM guests. Since hmvloader is just a 32bit elf executable the loader is fairly simple.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>

Looks plausible.

I would s/__FUNCTION__/__func__/g throughout, and there are several coding style issues which could do with fixing.

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

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

Reviewed-by on v3 5/32
#14 lore raw

Re: [PATCH v3 05/32] libxc: make arch_setup_meminit a xc_dom_arch hook

In reply to Roger Pau Monne
Quoted 8 lines · Roger Pau Monne

This allows having different arch_setup_meminit implementations based on the guest type. It should not introduce any functional changes.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>

However, would you mind doing a cleanup patch which changes the use of __init. Confusingly given its precedent in hypervisor code, xc_dom.h has "#define __init __attribute__ ((constructor))". At a first guess, 'initcall' or even just 'constructor' would be more appropriate names.

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

#18 lore raw

Re: [PATCH v3 06/32] libxc: make arch_setup_boot{init/late} xc_dom_arch hooks

In reply to Roger Pau Monne
Quoted 31 lines · Roger Pau Monne
tools/libxc/xc_dom_x86.c +0 -23
index 6fb4aee..993954e 100644
@@ -926,41 +926,7 @@ static int meminit_pv(struct xc_dom_image *dom)
 
 /* ------------------------------------------------------------------------ */
 
-static struct xc_dom_arch xc_dom_32_pae = {
-    .guest_type = "xen-3.0-x86_32p",
-    .native_protocol = XEN_IO_PROTO_ABI_X86_32,
-    .page_shift = PAGE_SHIFT_X86,
-    .sizeof_pfn = 4,
-    .alloc_magic_pages = alloc_magic_pages,
-    .count_pgtables = count_pgtables_x86_32_pae,
-    .setup_pgtables = setup_pgtables_x86_32_pae,
-    .start_info = start_info_x86_32,
-    .shared_info = shared_info_x86_32,
-    .vcpu = vcpu_x86_32,
-    .meminit = meminit_pv,
-};
-
-static struct xc_dom_arch xc_dom_64 = {
-    .guest_type = "xen-3.0-x86_64",
-    .native_protocol = XEN_IO_PROTO_ABI_X86_64,
-    .page_shift = PAGE_SHIFT_X86,
-    .sizeof_pfn = 8,
-    .alloc_magic_pages = alloc_magic_pages,
-    .count_pgtables = count_pgtables_x86_64,
-    .setup_pgtables = setup_pgtables_x86_64,
-    .start_info = start_info_x86_64,

tools/libxc/xc_dom_x86.c static int meminit_pv(struct xc_dom_image *dom) · line 961

Quoted 10 lines
tools/libxc/xc_dom_x86.c +0 -10
-    .shared_info = shared_info_x86_64,
-    .vcpu = vcpu_x86_64,
-    .meminit = meminit_pv,
-};
-
-static void __init register_arch_hooks(void)
-{
-    xc_dom_register_arch_hooks(&xc_dom_32_pae);
-    xc_dom_register_arch_hooks(&xc_dom_64);
-}

Instead of moving this lot twice in two consecutive patches, have patch 5 move them to their eventual location, which makes this patch much smaller.

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

#21 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monne
Quoted 15 lines · Roger Pau Monne

Add checks for ignored vcpu fields in HVM mode. HVM vCPUs (BSP and APs) are always started in 32bit protected mode with paging disabled.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/domain.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
xen/arch/x86/domain.c +0 -0
index a8fe046..a112953 100644

xen/arch/x86/domain.c int arch_set_info_guest( · line 801

Quoted 7 lines
xen/arch/x86/domain.c +4 -0
@@ -795,6 +795,15 @@ int arch_set_info_guest(
               c.nat->fs_base || c.nat->gs_base_user)) )
             return -EINVAL;
     }
+    else if ( is_hvm_domain(d) )
+    {
+        if ( c(ctrlreg[0]) || c(ctrlreg[1]) || c(ctrlreg[2]) ||
+             c(ctrlreg[3]) || c(ctrlreg[4]) || c(ctrlreg[5]) ||

I am not sure that the cr0 and cr4 checks are sensible. While the new ABI doesn't need them, there is nothing inherently wrong with setting them via this interface.

Quoted 9 lines
xen/arch/x86/domain.c +5 -0
+             c(ctrlreg[6]) || c(ctrlreg[7]) || c(ldt_base) ||
+             c(ldt_ents) || c(kernel_ss) || c(kernel_sp) ||
+             c(gdt_ents) )
+            return -EINVAL;
+    }
 
     v->fpu_initialised = !!(flags & VGCF_I387_VALID);
 

xen/arch/x86/domain.c int arch_set_info_guest( · line 1069

Quoted 6 lines
xen/arch/x86/domain.c +0 -3
@@ -1064,15 +1073,14 @@ int arch_set_info_guest(
     if ( v->vcpu_id == 0 )
         update_domain_wallclock_time(d);
 
-    /* Don't redo final setup */
-    v->is_initialised = 1;
-

Is this a bugfix, or spurious movement?

~Andrew

xen/arch/x86/domain.c int arch_set_info_guest( · line 1086

Quoted 11 lines
xen/arch/x86/domain.c +2 -0
     if ( paging_mode_enabled(d) )
         paging_update_paging_modes(v);
 
     update_cr3(v);
 
  out:
+    /* Don't redo final setup */
+    v->is_initialised = 1;
     if ( flags & VGCF_online )
         clear_bit(_VPF_down, &v->pause_flags);
     else

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

#70 lore raw

Re: [PATCH v3 08/32] libxc: introduce a xc_dom_arch for hvm-3.0-x86_32 guests

In reply to Roger Pau Monne
Quoted 9 lines · Roger Pau Monne

This xc_dom_arch will be used in order to build HVM domains. The code is based on the existing xc_hvm_populate_memory and xc_hvm_populate_params functions.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>

Similar review to patch 5. One bug - see below.

Quoted 63 lines
---
 tools/libxc/include/xc_dom.h |   6 +
 tools/libxc/xc_dom_x86.c     | 541 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 536 insertions(+), 11 deletions(-)
tools/libxc/include/xc_dom.h +6 -0
index 42533a5..68b052c 100644
@@ -189,6 +189,12 @@ struct xc_dom_image {
     } container_type;
 
     /* HVM specific fields. */
+    xen_pfn_t target_pages;
+    xen_pfn_t mmio_start;
+    xen_pfn_t mmio_size;
+    xen_pfn_t lowmem_end;
+    xen_pfn_t highmem_end;
+
     /* Extra ACPI tables passed to HVMLOADER */
     struct xc_hvm_firmware_module acpi_module;
 
tools/libxc/xc_dom_x86.c +22 -2
index 993954e..6573b94 100644
@@ -40,10 +40,29 @@
 
 /* ------------------------------------------------------------------------ */
 
-#define SUPERPAGE_PFN_SHIFT  9
-#define SUPERPAGE_NR_PFNS    (1UL << SUPERPAGE_PFN_SHIFT)
 #define SUPERPAGE_BATCH_SIZE 512
 
+#define SUPERPAGE_2MB_SHIFT   9
+#define SUPERPAGE_2MB_NR_PFNS (1UL << SUPERPAGE_2MB_SHIFT)
+#define SUPERPAGE_1GB_SHIFT   18
+#define SUPERPAGE_1GB_NR_PFNS (1UL << SUPERPAGE_1GB_SHIFT)
+
+#define VGA_HOLE_SIZE (0x20)
+
+#define SPECIALPAGE_PAGING   0
+#define SPECIALPAGE_ACCESS   1
+#define SPECIALPAGE_SHARING  2
+#define SPECIALPAGE_BUFIOREQ 3
+#define SPECIALPAGE_XENSTORE 4
+#define SPECIALPAGE_IOREQ    5
+#define SPECIALPAGE_IDENT_PT 6
+#define SPECIALPAGE_CONSOLE  7
+#define NR_SPECIAL_PAGES     8
+#define special_pfn(x) (0xff000u - NR_SPECIAL_PAGES + (x))
+
+#define NR_IOREQ_SERVER_PAGES 8
+#define ioreq_server_pfn(x) (special_pfn(0) - NR_IOREQ_SERVER_PAGES + (x))
+
 #define bits_to_mask(bits)       (((xen_vaddr_t)1 << (bits))-1)
 #define round_down(addr, mask)   ((addr) & ~(mask))
 #define round_up(addr, mask)     ((addr) | (mask))
@@ -462,6 +481,135 @@ static int alloc_magic_pages(struct xc_dom_image *dom)
     return 0;
 }
 
+static void build_hvm_info(void *hvm_info_page, struct xc_dom_image *dom)

tools/libxc/xc_dom_x86.c static int alloc_magic_pages(struct xc_dom_image *dom) · line 494

Quoted 10 lines
tools/libxc/xc_dom_x86.c +10 -0
+{
+    struct hvm_info_table *hvm_info = (struct hvm_info_table *)
+        (((unsigned char *)hvm_info_page) + HVM_INFO_OFFSET);
+    uint8_t sum;
+    int i;
+
+    memset(hvm_info_page, 0, PAGE_SIZE);
+
+    /* Fill in the header. */
+    strncpy(hvm_info->signature, "HVM INFO", 8);

Please apply c/s b9dbe33 to this code. (Said changeset was since your submission, but please don't reintroduce the bug).

~Andrew

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

#76 lore raw

Re: [PATCH v3 10/32] libxc: remove dead HVM building code

In reply to Roger Pau Monne
Quoted 8 lines · Roger Pau Monne

Remove xc_hvm_build_x86.c and xc_hvm_build_arm.c since xc_hvm_build is not longer used in order to create HVM guests.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>

In principle, very much +1

However, I suspect this wants functional testing from the ARM folks.

~Andrew

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

#79 lore raw

Re: [PATCH v3 11/32] xen/x86: add bitmap of enabled emulated devices

In reply to Roger Pau Monne
Quoted 15 lines · Roger Pau Monne
xen/arch/x86/domain.c +1 -0
index a112953..d684f49 100644
@@ -528,6 +528,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
 {
     int i, paging_initialised = 0;
     int rc = -ENOMEM;
+    uint32_t emulation_mask;
 
     d->arch.s3_integrity = !!(domcr_flags & DOMCRF_s3_integrity);
 
@@ -550,6 +551,20 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                d->domain_id);
     }

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 562

Quoted 10 lines
xen/arch/x86/domain.c +9 -0
 
+    if ( is_hvm_domain(d) )
+    {
+        emulation_mask = (EMU_LAPIC | EMU_HPET | EMU_PMTIMER | EMU_RTC |
+                          EMU_IOAPIC | EMU_PIC | EMU_PMU | EMU_VGA | EMU_IOMMU);
+        if ( (config->emulation_flags & emulation_mask) != emulation_mask )
+        {
+            printk(XENLOG_G_ERR "Xen does not allow HVM creation with the "
+                   "current selection of emulators: 0x%x.\n",
+                   config->emulation_flags);

Please put "d%d" in the error message to identify which domain has the bad configuration.

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 563

Quoted 1 line
xen/arch/x86/domain.c +1 -0
+            return -EPERM;

EPERM feels wrong here. It is not a lack of permissions causing the issue. EINVAL/EOPNOTSUPP perhaps?

Quoted 19 lines
xen/arch/x86/domain.c +4 -0
+        }
+        d->arch.emulation_flags = config->emulation_flags;
+    }
+
     if ( has_hvm_container_domain(d) )
     {
         d->arch.hvm_domain.hap_enabled =
xen/include/asm-x86/domain.h +3 -0
index 96bde65..502379e 100644
@@ -356,8 +356,21 @@ struct arch_domain
 
     /* Mem_access emulation control */
     bool_t mem_access_emulate_enabled;
+
+    /* Emulated devices enabled bitmap. */
+    uint32_t emulation_flags;
 } __cacheline_aligned;

xen/include/asm-x86/domain.h struct arch_domain · line 372

Quoted 10 lines
xen/include/asm-x86/domain.h +9 -0
 
+#define has_vlapic(d)       (d->arch.emulation_flags & EMU_LAPIC)
+#define has_vhpet(d)        (d->arch.emulation_flags & EMU_HPET)
+#define has_vpmtimer(d)     (d->arch.emulation_flags & EMU_PMTIMER)
+#define has_vrtc(d)         (d->arch.emulation_flags & EMU_RTC)
+#define has_vioapic(d)      (d->arch.emulation_flags & EMU_IOAPIC)
+#define has_vpic(d)         (d->arch.emulation_flags & EMU_PIC)
+#define has_vpmu(d)         (d->arch.emulation_flags & EMU_PMU)
+#define has_vvga(d)         (d->arch.emulation_flags & EMU_VGA)
+#define has_viommu(d)       (d->arch.emulation_flags & EMU_IOMMU)

(d) should be bracketed in the expansion.

Quoted 21 lines
xen/include/asm-x86/domain.h +1 -0
+
 #define has_arch_pdevs(d)    (!list_empty(&(d)->arch.pdev_list))
 
 #define gdt_ldt_pt_idx(v) \
xen/include/public/arch-x86/xen.h +8 -1
index 2ecc9c9..6b387a3 100644
@@ -268,7 +268,25 @@ typedef struct arch_shared_info arch_shared_info_t;
  * XEN_DOMCTL_INTERFACE_VERSION.
  */
 struct xen_arch_domainconfig {
-    char dummy;
+#define _EMU_LAPIC                  0
+#define EMU_LAPIC                   (1U<<_EMU_LAPIC)
+#define _EMU_HPET                   1
+#define EMU_HPET                    (1U<<_EMU_HPET)
+#define _EMU_PMTIMER                2
+#define EMU_PMTIMER                 (1U<<_EMU_PMTIMER)
+#define _EMU_RTC                    3
+#define EMU_RTC                     (1U<<_EMU_RTC)

xen/include/public/arch-x86/xen.h typedef struct arch_shared_info arch_shared_info_t; · line 288

Quoted 10 lines
xen/include/public/arch-x86/xen.h +10 -0
+#define _EMU_IOAPIC                 4
+#define EMU_IOAPIC                  (1U<<_EMU_IOAPIC)
+#define _EMU_PIC                    5
+#define EMU_PIC                     (1U<<_EMU_PIC)
+#define _EMU_PMU                    6
+#define EMU_PMU                     (1U<<_EMU_PMU)
+#define _EMU_VGA                    7
+#define EMU_VGA                     (1U<<_EMU_VGA)
+#define _EMU_IOMMU                  8
+#define EMU_IOMMU                   (1U<<_EMU_IOMMU)

These are all in the public API, so absolutely needs a XEN_ prefix, and likely an X86 one as well.

xen/include/public/arch-x86/xen.h typedef struct arch_shared_info arch_shared_info_t; · line 289

Quoted 1 line
xen/include/public/arch-x86/xen.h +1 -0
+    uint32_t emulation_flags;

Either state that this is ignored for domain types other than HVM, or have arch_domain_create() confirm that it is 0.

~Andrew

#80 lore raw

Re: [PATCH v3 11/32] xen/x86: add bitmap of enabled emulated devices

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 06.07.15 at 16:10, <[email protected]> wrote:
Quoted 4 lines · Roger Pau Monne
xen/arch/x86/domain.c +0 -0
@@ -550,6 +551,20 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                d->domain_id);
     }
 
Quoted 12 lines

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 562

Quoted 9 lines
xen/arch/x86/domain.c +9 -0
+    if ( is_hvm_domain(d) )
+    {
+        emulation_mask = (EMU_LAPIC | EMU_HPET | EMU_PMTIMER | EMU_RTC |
+                          EMU_IOAPIC | EMU_PIC | EMU_PMU | EMU_VGA | EMU_IOMMU);
+        if ( (config->emulation_flags & emulation_mask) != emulation_mask )
+        {
+            printk(XENLOG_G_ERR "Xen does not allow HVM creation with the "
+                   "current selection of emulators: 0x%x.\n",
+                   config->emulation_flags);

Please put "d%d" in the error message to identify which domain has the bad configuration.

Plus please use %#x instead of 0x%x.

Quoted 4 lines

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 563

Quoted 1 line
xen/arch/x86/domain.c +1 -0
+            return -EPERM;

EPERM feels wrong here. It is not a lack of permissions causing the issue. EINVAL/EOPNOTSUPP perhaps?

Indeed, -EOPNOTSUPP.

Jan

#119 lore raw
In reply to Roger Pau Monné
Quoted 13 lines · Roger Pau Monné

El 03/07/15 a les 18.19, David Vrabel ha escrit:

Quoted 11 lines · Roger Pau Monne
Quoted 2 lines

And for the FreeBSD part:

Have you thought at all about what the Linux support for this mode would look like?

I started briefly looking today but don't really have time to look into it properly. I do think we want to use as much of the native/HVM code as possible and avoid the PV path (the current Linux PVH code uses too much of the PV entry point, IMO).

Quoted 4 lines

I'm afraid I'm not that familiar with the native Linux entry point in order to know how much of that can be reused. Does the amd64 kernel contain a 32bit entry point or the kernel is expected to be launched in long mode with some page tables already setup?

It does : arch/x86/kernel/head_64[32].S:startup_32

The problem is that it depends to have the boot_params (a Linux structure) filled out.

Which then calls 'default_entry' [32-bit] or 'startup_64', and then it goes off somewhere (there is a lot of EFI code in there).

Anyhow it eventually ends up:

x86_64_start_kernel -> x86_64_start_reservations

But the problem is that during this execution none of the pvops get set to the Xen ones (which we need to tell the kernel that there is almost no hardware).

One could change initial_code to some xen_x86_64_start_kernel that would be similar to xen_startup - in that it would set up the basic pvops structures and then call x86_64_start_kernel.

In essence something like:
startup_32
\-> startup_64 [in compressed/head_64.S]

      \-> startup_64 [ head_64.S]
         \-> secondary_startup_64
            \-> jmpq *initial_code [which is by default x86_64_start_kernel]

[if I got the assmebler call chain correctly figured out]

Quoted 2 lines

Iff Linux on i386/amd64 already contains a 32bit protected mode without paging entry point then I guess most of the code can be reused.

Yes except that we would have to have before then to fill out the boot_params to get use going, setup the initial stack.

The during the bootup we would need to swap over to an Xen entry point so that it can neuter most of the pvops calls.

Quoted 5 lines

Note that FreeBSD/amd64 didn't have any of this (the kernel is launched in long mode with some initial page tables setup by the loader), so the code needed for Linux should be similar to the one on FreeBSD or even less if there's an entry point that we can reuse:a

The Linux kernel can also start in 32/64-bit mode with page tables (thanks to EFI)

Quoted 9 lines

http://xenbits.xen.org/gitweb/?p=people/royger/freebsd.git;a=blob;f=sys/amd64/amd64/xen-locore32.S;h=fd73d150009ab21059d4df219e6a62cc40d5994e;hb=refs/heads/new_entry_point_v2

Roger.

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

#120 lore raw
Quoted 30 lines
Quoted 9 lines
Quoted 4 lines

I started briefly looking today but don't really have time to look into it properly. I do think we want to use as much of the native/HVM code as possible and avoid the PV path (the current Linux PVH code uses too much of the PV entry point, IMO).

I'm afraid I'm not that familiar with the native Linux entry point in order to know how much of that can be reused. Does the amd64 kernel contain a 32bit entry point or the kernel is expected to be launched in long mode with some page tables already setup?

It does : arch/x86/kernel/head_64[32].S:startup_32

The problem is that it depends to have the boot_params (a Linux structure) filled out.

Which then calls 'default_entry' [32-bit] or 'startup_64', and then it goes off somewhere (there is a lot of EFI code in there).

Anyhow it eventually ends up:

x86_64_start_kernel -> x86_64_start_reservations

But the problem is that during this execution none of the pvops get set to the Xen ones (which we need to tell the kernel that there is almost no hardware).

One could change initial_code to some xen_x86_64_start_kernel that would be similar to xen_startup - in that it would set up the basic pvops structures and then call x86_64_start_kernel.

Quoted 6 lines

In essence something like:
startup_32
\-> startup_64 [in compressed/head_64.S]

      \-> startup_64 [ head_64.S]
         \-> secondary_startup_64
            \-> jmpq *initial_code [which is by default x86_64_start_kernel]
                   \-> x86_64_start_reservations
Quoted 3 lines

[if I got the assmebler call chain correctly figured out]

Just to give an comparison, the PV entry point is:

xen_start_kernel [copies appropiate things to boot_parms - such as command line, makes
tons of hypercalls to set appropiate tweaks in boot_params]
\-> x86_64_start_reservations

If we were to hook up to the above one, we would need:

xen_no_paging_start_kernel [copy minimum amount of things we need on the bootparams
to keep on going, sets initial_code to our xen_secondary_start]
\- startup_32

	\-> startup_64
            \-> secondary_startup_64
		 -> jmpq *initial_code
			\-> xen_secondary_start [set pvops, copies rest of bootparams,
                                                 etc]
				\-> x86_64_start_kernel
					\-> x86_64_start_reservation

If we were to borrow from what Roger has [http://xenbits.xen.org/gitweb/?p=people/royger/freebsd.git;a=blob;f=sys/amd64/amd64/xen-locore32.S;h=fd73d150009ab21059d4df219e6a62cc40d5994e;hb=refs/heads/new_entry_point_v2]
we would do:

xen_no_paging_start_kernel [xen_start32 copy of FreeBSD]
\-> xen_secondary_start [sets pvops, copies rest of params, etc]

    \-> x86_64_start_reservation

But that to me looks quite similar to the PV path, except more code, and also x86 folks asking us why we aren't using the baremetal boot paths.

We could omit some of this if the toolstack/hyprecall knew the Linux boot_params similar to how GRUB2 knows it. And just populate that. But then if we are doing that, why not just go the simple route and use the Xen PV entry point.

#23 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monne
Quoted 2 lines · Roger Pau Monne

Add checks for ignored vcpu fields in HVM mode. HVM vCPUs (BSP and APs) are always started in 32bit protected mode with paging disabled.

Please mention that only the HVM guests which use the VCPU_xx hypercalls are the ones that are involved in this.

Quoted 54 lines
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/domain.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
xen/arch/x86/domain.c +11 -3
index a8fe046..a112953 100644
@@ -795,6 +795,15 @@ int arch_set_info_guest(
               c.nat->fs_base || c.nat->gs_base_user)) )
             return -EINVAL;
     }
+    else if ( is_hvm_domain(d) )
+    {
+        if ( c(ctrlreg[0]) || c(ctrlreg[1]) || c(ctrlreg[2]) ||
+             c(ctrlreg[3]) || c(ctrlreg[4]) || c(ctrlreg[5]) ||
+             c(ctrlreg[6]) || c(ctrlreg[7]) || c(ldt_base) ||
+             c(ldt_ents) || c(kernel_ss) || c(kernel_sp) ||
+             c(gdt_ents) )
+            return -EINVAL;
+    }
 
     v->fpu_initialised = !!(flags & VGCF_I387_VALID);
 
@@ -1064,15 +1073,14 @@ int arch_set_info_guest(
     if ( v->vcpu_id == 0 )
         update_domain_wallclock_time(d);
 
-    /* Don't redo final setup */
-    v->is_initialised = 1;
-
     if ( paging_mode_enabled(d) )
         paging_update_paging_modes(v);
 
     update_cr3(v);
 
  out:
+    /* Don't redo final setup */
+    v->is_initialised = 1;
     if ( flags & VGCF_online )
         clear_bit(_VPF_down, &v->pause_flags);
     else
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monne
Quoted 2 lines · Roger Pau Monne

Add checks for ignored vcpu fields in HVM mode. HVM vCPUs (BSP and APs) are always started in 32bit protected mode with paging disabled.

This is kind of odd in the placement of the series. The next couple of patches deal with the restructure of the HVM guests and the previous ones were too.

And it is quite salient on the PVH/HVMLite protocol. I would think you would want to also update the documentation/misc/pvh as part of this patch. Perhaps move this further out in the patch series?

Quoted 54 lines
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/domain.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
xen/arch/x86/domain.c +11 -3
index a8fe046..a112953 100644
@@ -795,6 +795,15 @@ int arch_set_info_guest(
               c.nat->fs_base || c.nat->gs_base_user)) )
             return -EINVAL;
     }
+    else if ( is_hvm_domain(d) )
+    {
+        if ( c(ctrlreg[0]) || c(ctrlreg[1]) || c(ctrlreg[2]) ||
+             c(ctrlreg[3]) || c(ctrlreg[4]) || c(ctrlreg[5]) ||
+             c(ctrlreg[6]) || c(ctrlreg[7]) || c(ldt_base) ||
+             c(ldt_ents) || c(kernel_ss) || c(kernel_sp) ||
+             c(gdt_ents) )
+            return -EINVAL;
+    }
 
     v->fpu_initialised = !!(flags & VGCF_I387_VALID);
 
@@ -1064,15 +1073,14 @@ int arch_set_info_guest(
     if ( v->vcpu_id == 0 )
         update_domain_wallclock_time(d);
 
-    /* Don't redo final setup */
-    v->is_initialised = 1;
-
     if ( paging_mode_enabled(d) )
         paging_update_paging_modes(v);
 
     update_cr3(v);
 
  out:
+    /* Don't redo final setup */
+    v->is_initialised = 1;
     if ( flags & VGCF_online )
         clear_bit(_VPF_down, &v->pause_flags);
     else
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

Re: [PATCH v3 29/32] libxc/xen: introduce HVM_PARAM_FIRST_FREE_PFN

In reply to Roger Pau Monne
Quoted 1 line · Roger Pau Monne

This HVM parameter returns the first free pfn after all the special pages.

Could you describe how the layout of PFNs is now for the HVM guests?

Is there some document that outlines it? I know that for PV we do have it as part of the start_info structure but not sure about HVM?

Quoted 2 lines

It can be used by guests to figure out the first free memory address after the kernel, ramdisk and special pages. This is interesting for compatibility

So you mention it here, perhaps there should be an document mentioning this. Or the header for the PFNs?

Quoted 3 lines

reasons in case more special pages are later added, older guests can still use this parameter to figure out the first free address, ignoring newly added special pages.

And presumarily figure out the 'special PFN's and mark them as reserved? Are those PFNs in the E820 as RESERVED?

We should also put some restrictions in the code then to make sure that there will never be any HVM_PARAM_*PFN _after_ this PFN.

And document that somewhere.

Quoted 62 lines
Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 tools/libxc/xc_dom_x86.c        | 2 ++
 xen/arch/x86/hvm/hvm.c          | 1 +
 xen/include/public/hvm/params.h | 5 ++++-
 3 files changed, 7 insertions(+), 1 deletion(-)
tools/libxc/xc_dom_x86.c +2 -0
index 41ff7a4..74c3819 100644
@@ -573,6 +573,8 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
                      special_pfn(SPECIALPAGE_ACCESS, dom));
     xc_hvm_param_set(xch, domid, HVM_PARAM_SHARING_RING_PFN,
                      special_pfn(SPECIALPAGE_SHARING, dom));
+    xc_hvm_param_set(xch, domid, HVM_PARAM_FIRST_FREE_PFN,
+                     special_pfn(NR_SPECIAL_PAGES, dom));
 
     if ( dom->cmdline )
     {
xen/arch/x86/hvm/hvm.c +1 -0
index efe7232..2b190e9 100644
@@ -5918,6 +5918,7 @@ static int hvm_allow_get_param(struct domain *d,
     case HVM_PARAM_CONSOLE_PFN:
     case HVM_PARAM_CONSOLE_EVTCHN:
     case HVM_PARAM_CMDLINE_PFN:
+    case HVM_PARAM_FIRST_FREE_PFN:
         break;
     /*
      * The following parameters must not be read by the guest
xen/include/public/hvm/params.h +4 -1
index b7f8839..47e38a8 100644
@@ -190,6 +190,9 @@
 /* PFN of the command line. */
 #define HVM_PARAM_CMDLINE_PFN 35
 
-#define HVM_NR_PARAMS          36
+/* First free PFN after the special pages. */
+#define HVM_PARAM_FIRST_FREE_PFN 36
+
+#define HVM_NR_PARAMS          37
 
 #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

Re: [PATCH v3 27/32] libxc: change the position of the special pages

In reply to Roger Pau Monné
Quoted 17 lines · Roger Pau Monné

El 03/07/15 a les 13.35, Roger Pau Monne ha escrit:

Quoted 12 lines

Change the physical memory address of the special pages when there are no emulated devices. On HVM guests the special pages have always been reserved so that they end at the 0xff000 pfn, but there are some problems with this approach when used without emulated devices:

- If we want to allow HVMlite to be used for Dom0 those special pages cannot be placed inside of the MMIO hole or else they may clash with MMIO regions of physical devices passed-through to Dom0.
- If there's no emulated devices the guests needs to access the console page and the command line very early during boot. This is a problem for FreeBSD at least, since the early page tables only map memory up to 1GiB.

Quoted 3 lines

So instead append the special pages after the kernel and ramdisk. The guest must make sure it figures out the position of those pages very early during boot, since the region is not marked as reserved in the memory map.

Quoted 5 lines

After thinking a little bit about this, I don't think this is the right solution. Placing all the special pages after the kernel/ramdisk will make it quite hard to use bootloaders like pvgrub inside of HVMlite guests. I will see if I can come up with a better way to solve this, comments welcome.

Could stick at the start of memory, mark it as E820_RESV or such. Or at 16MB or such?

Quoted 7 lines

Roger.

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

#110 lore raw

Re: [PATCH v3 31/32] libxc: switch xc_dom_elfloader to be used with HVMlite domains

In reply to Roger Pau Monne
Quoted 21 lines · Roger Pau Monne

Allow xc_dom_elfloader to report a guest type as hvm-3.0-x86_32 if it's running inside of a HVM container and has the PHYS32_ENTRY elfnote set.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>

---
Only xc_dom_elfloader has been switched to support HVMlite, other loaders should also be switched once we have a HVMlite compatible kernel that uses them.

---
 tools/libxc/xc_dom_elfloader.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/libxc/xc_dom_elfloader.c +0 -0
index 6ce1062..2f05015 100644

tools/libxc/xc_dom_elfloader.c static char *xc_dom_guest_type(struct xc_dom_image *dom, · line 62

Quoted 6 lines
tools/libxc/xc_dom_elfloader.c +3 -0
@@ -57,6 +57,10 @@ static char *xc_dom_guest_type(struct xc_dom_image *dom,
 {
     uint64_t machine = elf_uval(elf, elf->ehdr, e_machine);
 
+    if ( dom->container_type == XC_DOM_HVM_CONTAINER &&
+         dom->parms.phys_entry != UNSET_ADDR )
+        return "hvm-3.0-x86_32";

why not 'hvm-lite-1.0-x86_64' since it is new protocol?

Quoted 12 lines
tools/libxc/xc_dom_elfloader.c +1 -0
+
     switch ( machine )
     {
     case EM_386:
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monne
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 03.07.15 at 13:34, <[email protected]> wrote:
xen/arch/x86/domain.c +0 -0
@@ -795,6 +795,15 @@ int arch_set_info_guest(
               c.nat->fs_base || c.nat->gs_base_user)) )
             return -EINVAL;

xen/arch/x86/domain.c int arch_set_info_guest( · line 806

Quoted 10 lines
xen/arch/x86/domain.c +9 -0
     }
+    else if ( is_hvm_domain(d) )
+    {
+        if ( c(ctrlreg[0]) || c(ctrlreg[1]) || c(ctrlreg[2]) ||
+             c(ctrlreg[3]) || c(ctrlreg[4]) || c(ctrlreg[5]) ||
+             c(ctrlreg[6]) || c(ctrlreg[7]) || c(ldt_base) ||
+             c(ldt_ents) || c(kernel_ss) || c(kernel_sp) ||
+             c(gdt_ents) )
+            return -EINVAL;
+    }

In addition to what Andrew said - is the use of c() here really correct considering

    compat = is_pv_32bit_domain(d);

#define c(fld) (compat ? (c.cmp->fld) : (c.nat->fld))

near the beginning of the function?

Jan

#98 lore raw

Re: [PATCH v3 26/32] xenconsole: try to attach to PV console if HVM fails

In reply to Roger Pau Monne
Quoted 28 lines · Roger Pau Monne

HVM guests have always used the emulated serial console by default, but if the emulated serial pty cannot be fetched from xenstore try to use the PV console instead.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/console/client/main.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tools/console/client/main.c +1 -1
index f4c783b..c92553e 100644
@@ -279,7 +279,7 @@ int main(int argc, char **argv)
 		{ 0 },
 
 	};
-	char *dom_path = NULL, *path = NULL;
+	char *dom_path = NULL, *path = NULL, *test = NULL;
 	int spty, xsfd;
 	struct xs_handle *xs;
 	char *end;
@@ -357,9 +357,14 @@ int main(int argc, char **argv)
 	path = malloc(strlen(dom_path) + strlen("/device/console/0/tty") + 5);

tools/console/client/main.c int main(int argc, char **argv) · line 365

Quoted 10 lines
tools/console/client/main.c +5 -2
 	if (path == NULL)
 		err(ENOMEM, "malloc");
-	if (type == CONSOLE_SERIAL)
+	if (type == CONSOLE_SERIAL) {
 		snprintf(path, strlen(dom_path) + strlen("/serial/0/tty") + 5, "%s/serial/%d/tty", dom_path, num);
-	else {
+		test = xs_read(xs, XBT_NULL, path, NULL);
+		free(test);
+		if (test == NULL)
+			goto pv_console;

instead of using labels I would probably do:

        if (test == NULL)
            type = CONSOLE_PV;
    }
    if (type == CONSOLE_PV) {
        ...

tools/console/client/main.c int main(int argc, char **argv) · line 370

Quoted 5 lines
tools/console/client/main.c +2 -0
+	} else {
+pv_console:
 		if (num == 0)
 			snprintf(path, strlen(dom_path) + strlen("/console/tty") + 1, "%s/console/tty", dom_path);
 		else

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

#22 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Andrew Cooper

El 06/07/15 a les 14.58, Andrew Cooper ha escrit:

Quoted 11 lines · Roger Pau Monne
Quoted 10 lines

Add checks for ignored vcpu fields in HVM mode. HVM vCPUs (BSP and APs) are always started in 32bit protected mode with paging disabled.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/domain.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
Quoted 16 lines

xen/arch/x86/domain.c int arch_set_info_guest( · line 801

Quoted 12 lines
xen/arch/x86/domain.c +4 -0
index a8fe046..a112953 100644
@@ -795,6 +795,15 @@ int arch_set_info_guest(
               c.nat->fs_base || c.nat->gs_base_user)) )
             return -EINVAL;
     }
+    else if ( is_hvm_domain(d) )
+    {
+        if ( c(ctrlreg[0]) || c(ctrlreg[1]) || c(ctrlreg[2]) ||
+             c(ctrlreg[3]) || c(ctrlreg[4]) || c(ctrlreg[5]) ||

I am not sure that the cr0 and cr4 checks are sensible. While the new ABI doesn't need them, there is nothing inherently wrong with setting them via this interface.

They will be ignored anyway, so I think the right thing to do is to notify the caller that setting CR4 and CR0 is not possible.

IMHO this should be as limited as possible, and CR0/CR4 can be easily setup by the startup AP code in the guest.

Quoted 12 lines
Quoted 12 lines
xen/arch/x86/domain.c +5 -0
+             c(ctrlreg[6]) || c(ctrlreg[7]) || c(ldt_base) ||
+             c(ldt_ents) || c(kernel_ss) || c(kernel_sp) ||
+             c(gdt_ents) )
+            return -EINVAL;
+    }
 
     v->fpu_initialised = !!(flags & VGCF_I387_VALID);
 
@@ -1064,15 +1073,14 @@ int arch_set_info_guest(
     if ( v->vcpu_id == 0 )
         update_domain_wallclock_time(d);
 
Quoted 5 lines

xen/arch/x86/domain.c int arch_set_info_guest( · line 1069

Quoted 3 lines
xen/arch/x86/domain.c +0 -3
-    /* Don't redo final setup */
-    v->is_initialised = 1;
-

Is this a bugfix, or spurious movement?

Since this hypercall was never used before with HVM guests we need to move the is_initialized setting to the "out" label, so it's also set for HVM guests (HVM guests jump to the out label after setting the user and debug registers).

Roger.

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

#25 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Konrad Rzeszutek Wilk

El 10/07/15 a les 20.47, Konrad Rzeszutek Wilk ha escrit:

Quoted 7 lines · Roger Pau Monne
Quoted 2 lines

Add checks for ignored vcpu fields in HVM mode. HVM vCPUs (BSP and APs) are always started in 32bit protected mode with paging disabled.

This is kind of odd in the placement of the series. The next couple of patches deal with the restructure of the HVM guests and the previous ones were too.

This patch is placed here because the next patch in this series makes use of it (see the vcpu_hvm function in "libxc: introduce a xc_dom_arch for hvm-3.0-x86_32 guests").

Quoted 3 lines

And it is quite salient on the PVH/HVMLite protocol. I would think you would want to also update the documentation/misc/pvh as part of this patch. Perhaps move this further out in the patch series?

Yes, documentation needs to be updated. I was waiting to have the full boot protocol nailed down before doing so.

Roger.

#27 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Jan Beulich

El 13/07/15 a les 16.01, Jan Beulich ha escrit:

Quoted 20 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 03.07.15 at 13:34, <[email protected]> wrote:
xen/arch/x86/domain.c +0 -0
@@ -795,6 +795,15 @@ int arch_set_info_guest(
               c.nat->fs_base || c.nat->gs_base_user)) )
             return -EINVAL;

xen/arch/x86/domain.c int arch_set_info_guest( · line 806

Quoted 10 lines
xen/arch/x86/domain.c +9 -0
     }
+    else if ( is_hvm_domain(d) )
+    {
+        if ( c(ctrlreg[0]) || c(ctrlreg[1]) || c(ctrlreg[2]) ||
+             c(ctrlreg[3]) || c(ctrlreg[4]) || c(ctrlreg[5]) ||
+             c(ctrlreg[6]) || c(ctrlreg[7]) || c(ldt_base) ||
+             c(ldt_ents) || c(kernel_ss) || c(kernel_sp) ||
+             c(gdt_ents) )
+            return -EINVAL;
+    }

In addition to what Andrew said - is the use of c() here really correct considering

Quoted 5 lines
    compat = is_pv_32bit_domain(d);

#define c(fld) (compat ? (c.cmp->fld) : (c.nat->fld))

near the beginning of the function?

I've been thinking about this. Since HVM vCPUs are always started in 32bit mode, I would ideally like to use the vcpu_guest_context_x86_32_t struct to set the vCPU context. This means that for HVM guests "compat" should always be true.

The problem is that inside of the guest there's no notion of vcpu_guest_context_x86_32_t or vcpu_guest_context_x86_64_t, there's only vcpu_guest_context, which defaults to the native bitness of the guest. So if your guest is running in 64bit mode vcpu_guest_context is aliased to vcpu_guest_context_x86_64_t by default.

TBH I'm not sure about the best way to solve this. Should vcpu_guest_context_x86_32_t and vcpu_guest_context_x86_64_t be exposed to the guest like it's done for the tools?

Roger.

#81 lore raw

Re: [PATCH v3 11/32] xen/x86: add bitmap of enabled emulated devices

In reply to Andrew Cooper

El 06/07/15 a les 16.10, Andrew Cooper ha escrit:

Quoted 30 lines · Roger Pau Monne
Quoted 15 lines
xen/arch/x86/domain.c +1 -0
index a112953..d684f49 100644
@@ -528,6 +528,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
 {
     int i, paging_initialised = 0;
     int rc = -ENOMEM;
+    uint32_t emulation_mask;
 
     d->arch.s3_integrity = !!(domcr_flags & DOMCRF_s3_integrity);
 
@@ -550,6 +551,20 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                d->domain_id);
     }

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 562

Quoted 10 lines
xen/arch/x86/domain.c +9 -0
 
+    if ( is_hvm_domain(d) )
+    {
+        emulation_mask = (EMU_LAPIC | EMU_HPET | EMU_PMTIMER | EMU_RTC |
+                          EMU_IOAPIC | EMU_PIC | EMU_PMU | EMU_VGA | EMU_IOMMU);
+        if ( (config->emulation_flags & emulation_mask) != emulation_mask )
+        {
+            printk(XENLOG_G_ERR "Xen does not allow HVM creation with the "
+                   "current selection of emulators: 0x%x.\n",
+                   config->emulation_flags);

Please put "d%d" in the error message to identify which domain has the bad configuration.

Quoted 4 lines

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 563

Quoted 1 line
xen/arch/x86/domain.c +1 -0
+            return -EPERM;

EPERM feels wrong here. It is not a lack of permissions causing the issue. EINVAL/EOPNOTSUPP perhaps?

EOPNOTSUPP looks better indeed.

Quoted 67 lines
Quoted 19 lines
xen/arch/x86/domain.c +4 -0
+        }
+        d->arch.emulation_flags = config->emulation_flags;
+    }
+
     if ( has_hvm_container_domain(d) )
     {
         d->arch.hvm_domain.hap_enabled =
xen/include/asm-x86/domain.h +3 -0
index 96bde65..502379e 100644
@@ -356,8 +356,21 @@ struct arch_domain
 
     /* Mem_access emulation control */
     bool_t mem_access_emulate_enabled;
+
+    /* Emulated devices enabled bitmap. */
+    uint32_t emulation_flags;
 } __cacheline_aligned;

xen/include/asm-x86/domain.h struct arch_domain · line 372

Quoted 10 lines
xen/include/asm-x86/domain.h +9 -0
 
+#define has_vlapic(d)       (d->arch.emulation_flags & EMU_LAPIC)
+#define has_vhpet(d)        (d->arch.emulation_flags & EMU_HPET)
+#define has_vpmtimer(d)     (d->arch.emulation_flags & EMU_PMTIMER)
+#define has_vrtc(d)         (d->arch.emulation_flags & EMU_RTC)
+#define has_vioapic(d)      (d->arch.emulation_flags & EMU_IOAPIC)
+#define has_vpic(d)         (d->arch.emulation_flags & EMU_PIC)
+#define has_vpmu(d)         (d->arch.emulation_flags & EMU_PMU)
+#define has_vvga(d)         (d->arch.emulation_flags & EMU_VGA)
+#define has_viommu(d)       (d->arch.emulation_flags & EMU_IOMMU)

(d) should be bracketed in the expansion.

Quoted 21 lines
xen/include/asm-x86/domain.h +1 -0
+
 #define has_arch_pdevs(d)    (!list_empty(&(d)->arch.pdev_list))
 
 #define gdt_ldt_pt_idx(v) \
xen/include/public/arch-x86/xen.h +8 -1
index 2ecc9c9..6b387a3 100644
@@ -268,7 +268,25 @@ typedef struct arch_shared_info arch_shared_info_t;
  * XEN_DOMCTL_INTERFACE_VERSION.
  */
 struct xen_arch_domainconfig {
-    char dummy;
+#define _EMU_LAPIC                  0
+#define EMU_LAPIC                   (1U<<_EMU_LAPIC)
+#define _EMU_HPET                   1
+#define EMU_HPET                    (1U<<_EMU_HPET)
+#define _EMU_PMTIMER                2
+#define EMU_PMTIMER                 (1U<<_EMU_PMTIMER)
+#define _EMU_RTC                    3
+#define EMU_RTC                     (1U<<_EMU_RTC)

xen/include/public/arch-x86/xen.h typedef struct arch_shared_info arch_shared_info_t; · line 288

Quoted 10 lines
xen/include/public/arch-x86/xen.h +10 -0
+#define _EMU_IOAPIC                 4
+#define EMU_IOAPIC                  (1U<<_EMU_IOAPIC)
+#define _EMU_PIC                    5
+#define EMU_PIC                     (1U<<_EMU_PIC)
+#define _EMU_PMU                    6
+#define EMU_PMU                     (1U<<_EMU_PMU)
+#define _EMU_VGA                    7
+#define EMU_VGA                     (1U<<_EMU_VGA)
+#define _EMU_IOMMU                  8
+#define EMU_IOMMU                   (1U<<_EMU_IOMMU)

These are all in the public API, so absolutely needs a XEN_ prefix, and likely an X86 one as well.

Quoted 4 lines

xen/include/public/arch-x86/xen.h typedef struct arch_shared_info arch_shared_info_t; · line 289

Quoted 1 line
xen/include/public/arch-x86/xen.h +1 -0
+    uint32_t emulation_flags;

Either state that this is ignored for domain types other than HVM, or have arch_domain_create() confirm that it is 0.

IMHO adding a check to arch_domain_create is TRTTD.

Roger.

#99 lore raw

Re: [PATCH v3 26/32] xenconsole: try to attach to PV console if HVM fails

In reply to Stefano Stabellini

El 14/07/15 a les 15.46, Stefano Stabellini ha escrit:

Quoted 42 lines · Roger Pau Monne
Quoted 28 lines

HVM guests have always used the emulated serial console by default, but if the emulated serial pty cannot be fetched from xenstore try to use the PV console instead.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/console/client/main.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tools/console/client/main.c +1 -1
index f4c783b..c92553e 100644
@@ -279,7 +279,7 @@ int main(int argc, char **argv)
 		{ 0 },
 
 	};
-	char *dom_path = NULL, *path = NULL;
+	char *dom_path = NULL, *path = NULL, *test = NULL;
 	int spty, xsfd;
 	struct xs_handle *xs;
 	char *end;
@@ -357,9 +357,14 @@ int main(int argc, char **argv)
 	path = malloc(strlen(dom_path) + strlen("/device/console/0/tty") + 5);

tools/console/client/main.c int main(int argc, char **argv) · line 365

Quoted 10 lines
tools/console/client/main.c +5 -2
 	if (path == NULL)
 		err(ENOMEM, "malloc");
-	if (type == CONSOLE_SERIAL)
+	if (type == CONSOLE_SERIAL) {
 		snprintf(path, strlen(dom_path) + strlen("/serial/0/tty") + 5, "%s/serial/%d/tty", dom_path, num);
-	else {
+		test = xs_read(xs, XBT_NULL, path, NULL);
+		free(test);
+		if (test == NULL)
+			goto pv_console;

instead of using labels I would probably do:

Quoted 5 lines
        if (test == NULL)
            type = CONSOLE_PV;
    }
    if (type == CONSOLE_PV) {
        ...

Yes thanks, that's much more clearer than using labels.

Roger.

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

#77 lore raw

Re: [PATCH v3 10/32] libxc: remove dead HVM building code

In reply to Andrew Cooper

El 06/07/15 a les 15.46, Andrew Cooper ha escrit:

Quoted 10 lines · Roger Pau Monne
Quoted 8 lines

Remove xc_hvm_build_x86.c and xc_hvm_build_arm.c since xc_hvm_build is not longer used in order to create HVM guests.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Quoted 3 lines

In principle, very much +1

However, I suspect this wants functional testing from the ARM folks.

Yes, although xc_hvm_build_arm.c just contained dummy stubs to fill the interface.

Roger.

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

#103 lore raw

Re: [PATCH v3 27/32] libxc: change the position of the special pages

In reply to Konrad Rzeszutek Wilk

El 10/07/15 a les 21.06, Konrad Rzeszutek Wilk ha escrit:

Quoted 18 lines · Roger Pau Monné
Quoted 17 lines

El 03/07/15 a les 13.35, Roger Pau Monne ha escrit:

Quoted 15 lines

Change the physical memory address of the special pages when there are no emulated devices. On HVM guests the special pages have always been reserved so that they end at the 0xff000 pfn, but there are some problems with this approach when used without emulated devices:

- If we want to allow HVMlite to be used for Dom0 those special pages cannot be placed inside of the MMIO hole or else they may clash with MMIO regions of physical devices passed-through to Dom0.
- If there's no emulated devices the guests needs to access the console page and the command line very early during boot. This is a problem for FreeBSD at least, since the early page tables only map memory up to 1GiB.

So instead append the special pages after the kernel and ramdisk. The guest must make sure it figures out the position of those pages very early during boot, since the region is not marked as reserved in the memory map.

Quoted 8 lines
Quoted 5 lines

After thinking a little bit about this, I don't think this is the right solution. Placing all the special pages after the kernel/ramdisk will make it quite hard to use bootloaders like pvgrub inside of HVMlite guests. I will see if I can come up with a better way to solve this, comments welcome.

Could stick at the start of memory, mark it as E820_RESV or such. Or at 16MB or such?

I was thinking about leaving the already existing special pages as they are now (just below the 4GiB), and placing the command line and module info just after the kernel and initramfs, so the memory layout looks like:

Command line string
+
| Module list
| +
0GiB | | 4GiB

+---+--------+-------+v-+v-+----------------------------+--+
|   |        |       |  |  |                            |  |
|   |        |       |  |  |                            |  |
|   | Kernel |Modules|  |  |                            |  |
|   |        |       |  |  |                            |  |
+---+--------+-------+--+--+----------------------------+--+
                                                         Console page,
                                                         Xenstore page,
                                                         ...

Roger.

#107 lore raw

Re: [PATCH v3 29/32] libxc/xen: introduce HVM_PARAM_FIRST_FREE_PFN

In reply to Konrad Rzeszutek Wilk

El 10/07/15 a les 21.05, Konrad Rzeszutek Wilk ha escrit:

Quoted 18 lines · Roger Pau Monne
Quoted 1 line

This HVM parameter returns the first free pfn after all the special pages.

Could you describe how the layout of PFNs is now for the HVM guests?

Is there some document that outlines it? I know that for PV we do have it as part of the start_info structure but not sure about HVM?

Quoted 2 lines

It can be used by guests to figure out the first free memory address after the kernel, ramdisk and special pages. This is interesting for compatibility

So you mention it here, perhaps there should be an document mentioning this. Or the header for the PFNs?

Quoted 3 lines

reasons in case more special pages are later added, older guests can still use this parameter to figure out the first free address, ignoring newly added special pages.

Quoted 5 lines

And presumarily figure out the 'special PFN's and mark them as reserved? Are those PFNs in the E820 as RESERVED?

We should also put some restrictions in the code then to make sure that there will never be any HVM_PARAM_*PFN _after_ this PFN.

I don't think we need this any longer, with the new approach that I've described in the previous email (see the reply to "libxc: change the position of the special pages") there's no need to introduce this new HVMPARAM, and the special pages will be marked as "reserved" in the memory map, with the exception of the command line and the module list special pages, that are appended after the kernel/initramfs.

Roger.

#111 lore raw

Re: [PATCH v3 31/32] libxc: switch xc_dom_elfloader to be used with HVMlite domains

In reply to Konrad Rzeszutek Wilk

El 10/07/15 a les 21.07, Konrad Rzeszutek Wilk ha escrit:

Quoted 25 lines · Roger Pau Monne
Quoted 24 lines

Allow xc_dom_elfloader to report a guest type as hvm-3.0-x86_32 if it's running inside of a HVM container and has the PHYS32_ENTRY elfnote set.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>

---
Only xc_dom_elfloader has been switched to support HVMlite, other loaders should also be switched once we have a HVMlite compatible kernel that uses them.

---
 tools/libxc/xc_dom_elfloader.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/libxc/xc_dom_elfloader.c +0 -0
index 6ce1062..2f05015 100644
@@ -57,6 +57,10 @@ static char *xc_dom_guest_type(struct xc_dom_image *dom,
 {
     uint64_t machine = elf_uval(elf, elf->ehdr, e_machine);
 
Quoted 5 lines

tools/libxc/xc_dom_elfloader.c static char *xc_dom_guest_type(struct xc_dom_image *dom, · line 62

Quoted 3 lines
tools/libxc/xc_dom_elfloader.c +3 -0
+    if ( dom->container_type == XC_DOM_HVM_CONTAINER &&
+         dom->parms.phys_entry != UNSET_ADDR )
+        return "hvm-3.0-x86_32";

why not 'hvm-lite-1.0-x86_64' since it is new protocol?

Because it shares the code paths with the HVM builder. We could introduce a new type, but I don't see any value in doing it, it's just going to be a copy of hvm-3.0-x86_32.

Roger.

#28 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monné
Quoted 39 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 12:25, <[email protected]> wrote:

El 13/07/15 a les 16.01, Jan Beulich ha escrit:

Quoted 20 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 03.07.15 at 13:34, <[email protected]> wrote:
xen/arch/x86/domain.c +0 -0
@@ -795,6 +795,15 @@ int arch_set_info_guest(
               c.nat->fs_base || c.nat->gs_base_user)) )
             return -EINVAL;

xen/arch/x86/domain.c int arch_set_info_guest( · line 806

Quoted 10 lines
xen/arch/x86/domain.c +9 -0
     }
+    else if ( is_hvm_domain(d) )
+    {
+        if ( c(ctrlreg[0]) || c(ctrlreg[1]) || c(ctrlreg[2]) ||
+             c(ctrlreg[3]) || c(ctrlreg[4]) || c(ctrlreg[5]) ||
+             c(ctrlreg[6]) || c(ctrlreg[7]) || c(ldt_base) ||
+             c(ldt_ents) || c(kernel_ss) || c(kernel_sp) ||
+             c(gdt_ents) )
+            return -EINVAL;
+    }

In addition to what Andrew said - is the use of c() here really correct considering

Quoted 5 lines
    compat = is_pv_32bit_domain(d);

#define c(fld) (compat ? (c.cmp->fld) : (c.nat->fld))

near the beginning of the function?

I've been thinking about this. Since HVM vCPUs are always started in 32bit mode, I would ideally like to use the vcpu_guest_context_x86_32_t struct to set the vCPU context. This means that for HVM guests "compat" should always be true.

The problem is that inside of the guest there's no notion of vcpu_guest_context_x86_32_t or vcpu_guest_context_x86_64_t, there's only vcpu_guest_context, which defaults to the native bitness of the guest. So if your guest is running in 64bit mode vcpu_guest_context is aliased to vcpu_guest_context_x86_64_t by default.

Quoted 3 lines

TBH I'm not sure about the best way to solve this. Should vcpu_guest_context_x86_32_t and vcpu_guest_context_x86_64_t be exposed to the guest like it's done for the tools?

Why? We're in arch_set_info_guest(), which is unreachable for a HVM guest on itself. Or is this in preparation of allowing HVM guests to use VCPUOP_initialise? In that case, exposing might be an option, but remember that the compat mode layout even today is used only for PV guests. So I'd rather avoid exposing both layouts to guests, and do translation instead inside the hypervisor.

Jan

#29 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 54 lines · Jan Beulich
Quoted 49 lines
Quoted 2 lines
Quoted 2 lines · On 23.07.15 at 12:25, <[email protected]> wrote:

El 13/07/15 a les 16.01, Jan Beulich ha escrit:

Quoted 23 lines
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 03.07.15 at 13:34, <[email protected]> wrote:
xen/arch/x86/domain.c +3 -0
@@ -795,6 +795,15 @@ int arch_set_info_guest(
               c.nat->fs_base || c.nat->gs_base_user)) )
             return -EINVAL;
     }
+    else if ( is_hvm_domain(d) )
+    {
+        if ( c(ctrlreg[0]) || c(ctrlreg[1]) || c(ctrlreg[2]) 
||
+             c(ctrlreg[3]) || c(ctrlreg[4]) || c(ctrlreg[5]) 
||

xen/arch/x86/domain.c int arch_set_info_guest( · line 806

Quoted 5 lines
xen/arch/x86/domain.c +5 -0
+             c(ctrlreg[6]) || c(ctrlreg[7]) || c(ldt_base) ||
+             c(ldt_ents) || c(kernel_ss) || c(kernel_sp) ||
+             c(gdt_ents) )
+            return -EINVAL;
+    }

In addition to what Andrew said - is the use of c() here really correct
considering

Quoted 5 lines
    compat = is_pv_32bit_domain(d);

#define c(fld) (compat ? (c.cmp->fld) : (c.nat->fld))

near the beginning of the function?

I've been thinking about this. Since HVM vCPUs are always started in
32bit mode, I would ideally like to use the vcpu_guest_context_x86_32_t
struct to set the vCPU context. This means that for HVM guests "compat"
should always be true.

The problem is that inside of the guest there's no notion of vcpu_guest_context_x86_32_t or vcpu_guest_context_x86_64_t, there's only
vcpu_guest_context, which defaults to the native bitness of the guest.
So if your guest is running in 64bit mode vcpu_guest_context is aliased
to vcpu_guest_context_x86_64_t by default.

Quoted 4 lines

TBH I'm not sure about the best way to solve this. Should vcpu_guest_context_x86_32_t and vcpu_guest_context_x86_64_t be exposed
to the guest like it's done for the tools?

Quoted 6 lines

Why? We're in arch_set_info_guest(), which is unreachable for a HVM guest on itself. Or is this in preparation of allowing HVM guests to use VCPUOP_initialise? In that case, exposing might be an option, but remember that the compat mode layout even today is used only for PV guests. So I'd rather avoid exposing both layouts to guests, and do translation instead inside the hypervisor.

On ARM we deliberately arranged that the vcpu_guest_context was the same for both arm32 and arm64. Moving to PVH seems like an ideal opportunity to do something similar for x86, if not by standardising on the x86_64 layout then by declaring a new struct which can encompass both and declaring the old ones PV legacy.

Ian.

#30 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

El 23/07/15 a les 13.41, Ian Campbell ha escrit:

Quoted 62 lines · Jan Beulich
Quoted 54 lines
Quoted 49 lines
Quoted 2 lines
Quoted 2 lines · On 23.07.15 at 12:25, <[email protected]> wrote:

El 13/07/15 a les 16.01, Jan Beulich ha escrit:

Quoted 23 lines
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 03.07.15 at 13:34, <[email protected]> wrote:
xen/arch/x86/domain.c +3 -0
@@ -795,6 +795,15 @@ int arch_set_info_guest(
               c.nat->fs_base || c.nat->gs_base_user)) )
             return -EINVAL;
     }
+    else if ( is_hvm_domain(d) )
+    {
+        if ( c(ctrlreg[0]) || c(ctrlreg[1]) || c(ctrlreg[2]) 
||
+             c(ctrlreg[3]) || c(ctrlreg[4]) || c(ctrlreg[5]) 
||

xen/arch/x86/domain.c int arch_set_info_guest( · line 806

Quoted 5 lines
xen/arch/x86/domain.c +5 -0
+             c(ctrlreg[6]) || c(ctrlreg[7]) || c(ldt_base) ||
+             c(ldt_ents) || c(kernel_ss) || c(kernel_sp) ||
+             c(gdt_ents) )
+            return -EINVAL;
+    }

In addition to what Andrew said - is the use of c() here really correct
considering

Quoted 5 lines
    compat = is_pv_32bit_domain(d);

#define c(fld) (compat ? (c.cmp->fld) : (c.nat->fld))

near the beginning of the function?

I've been thinking about this. Since HVM vCPUs are always started in
32bit mode, I would ideally like to use the vcpu_guest_context_x86_32_t
struct to set the vCPU context. This means that for HVM guests "compat"
should always be true.

The problem is that inside of the guest there's no notion of vcpu_guest_context_x86_32_t or vcpu_guest_context_x86_64_t, there's only
vcpu_guest_context, which defaults to the native bitness of the guest.
So if your guest is running in 64bit mode vcpu_guest_context is aliased
to vcpu_guest_context_x86_64_t by default.

Quoted 4 lines

TBH I'm not sure about the best way to solve this. Should vcpu_guest_context_x86_32_t and vcpu_guest_context_x86_64_t be exposed
to the guest like it's done for the tools?

Quoted 6 lines

Why? We're in arch_set_info_guest(), which is unreachable for a HVM guest on itself. Or is this in preparation of allowing HVM guests to use VCPUOP_initialise? In that case, exposing might be an option, but remember that the compat mode layout even today is used only for PV guests. So I'd rather avoid exposing both layouts to guests, and do translation instead inside the hypervisor.

Quoted 5 lines

On ARM we deliberately arranged that the vcpu_guest_context was the same for both arm32 and arm64. Moving to PVH seems like an ideal opportunity to do something similar for x86, if not by standardising on the x86_64 layout then by declaring a new struct which can encompass both and declaring the old ones PV legacy.

IMHO introducing a new structure that gets rid of all the PV-only fields seems like a good option:

struct vcpu_hvm_context {
#define _VGCF_online 5
#define VGCF_online (1<<_VGCF_online)

    uint32_t flags;                         /* VGCF_* flags                 */
    struct cpu_hvm_user_regs user_regs;     /* User-level CPU registers     */

/* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
uint32_t ctrlreg[8]; /* CR0-CR7 (control registers) */
uint32_t debugreg[8]; /* DB0-DB7 (debug registers) */
};

I'm also seriously considering getting rid of ctrlreg and debugreg. Since HVM VCPUs will always be started in 32bit flat mode, it doesn't make sense IMHO to have both the 32 and the 64 version of the registers, so cpu_hvm_user_regs is always going to be:

struct cpu_hvm_user_regs {
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;
    uint32_t esi;
    uint32_t edi;
    uint32_t ebp;
    uint32_t eax;
    uint32_t eip;
    uint32_t esp;
    uint32_t eflags;
    uint16_t cs;
    uint16_t ss;
    uint16_t es;
    uint16_t ds;
    uint16_t fs;
    uint16_t gs;
};

We could however do something similar to what's done in ARM and have a union of both the 32 and the 64bit registers in case we want to start the vCPU in 64bit mode sometime in the future.

Roger.

#31 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 42 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 17:10, <[email protected]> wrote:

IMHO introducing a new structure that gets rid of all the PV-only fields seems like a good option:

struct vcpu_hvm_context {
#define _VGCF_online 5
#define VGCF_online (1<<_VGCF_online)
uint32_t flags; /* VGCF_* flags
*/
struct cpu_hvm_user_regs user_regs; /* User-level CPU registers
*/
/* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
uint32_t ctrlreg[8]; /* CR0-CR7 (control registers)
*/
uint32_t debugreg[8]; /* DB0-DB7 (debug registers)
*/
};

I'm also seriously considering getting rid of ctrlreg and debugreg. Since HVM VCPUs will always be started in 32bit flat mode, it doesn't make sense IMHO to have both the 32 and the 64 version of the registers, so cpu_hvm_user_regs is always going to be:

struct cpu_hvm_user_regs {
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;
    uint32_t esi;
    uint32_t edi;
    uint32_t ebp;
    uint32_t eax;
    uint32_t eip;
    uint32_t esp;
    uint32_t eflags;
    uint16_t cs;
    uint16_t ss;
    uint16_t es;
    uint16_t ds;
    uint16_t fs;
    uint16_t gs;
};
Quoted 3 lines

We could however do something similar to what's done in ARM and have a union of both the 32 and the 64bit registers in case we want to start the vCPU in 64bit mode sometime in the future.

What you gave above is suitable only for VCPUOP_initialise afaict. Did you intend this to be the case?

Jan

#32 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

El 23/07/15 a les 17.32, Jan Beulich ha escrit:

Quoted 42 lines
Quoted 42 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 17:10, <[email protected]> wrote:

IMHO introducing a new structure that gets rid of all the PV-only fields seems like a good option:

struct vcpu_hvm_context {
#define _VGCF_online 5
#define VGCF_online (1<<_VGCF_online)
uint32_t flags; /* VGCF_* flags
*/
struct cpu_hvm_user_regs user_regs; /* User-level CPU registers
*/
/* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
uint32_t ctrlreg[8]; /* CR0-CR7 (control registers)
*/
uint32_t debugreg[8]; /* DB0-DB7 (debug registers)
*/
};

I'm also seriously considering getting rid of ctrlreg and debugreg. Since HVM VCPUs will always be started in 32bit flat mode, it doesn't make sense IMHO to have both the 32 and the 64 version of the registers, so cpu_hvm_user_regs is always going to be:

struct cpu_hvm_user_regs {
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;
    uint32_t esi;
    uint32_t edi;
    uint32_t ebp;
    uint32_t eax;
    uint32_t eip;
    uint32_t esp;
    uint32_t eflags;
    uint16_t cs;
    uint16_t ss;
    uint16_t es;
    uint16_t ds;
    uint16_t fs;
    uint16_t gs;
};
Quoted 6 lines
Quoted 3 lines

We could however do something similar to what's done in ARM and have a union of both the 32 and the 64bit registers in case we want to start the vCPU in 64bit mode sometime in the future.

What you gave above is suitable only for VCPUOP_initialise afaict. Did you intend this to be the case?

Certainly not, this should also be used by XEN_DOMCTL_setvcpucontext. I'm afraid I'm missing something obvious, but I don't see why this couldn't be used by XEN_DOMCTL_setvcpucontext TBH, can you please clarify?

Roger.

#33 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 48 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 17:48, <[email protected]> wrote:

El 23/07/15 a les 17.32, Jan Beulich ha escrit:

Quoted 46 lines
Quoted 45 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 17:10, <[email protected]> wrote:

IMHO introducing a new structure that gets rid of all the PV-only fields seems like a good option:

struct vcpu_hvm_context {
#define _VGCF_online 5
#define VGCF_online (1<<_VGCF_online)
uint32_t flags; /* VGCF_* flags
*/
struct cpu_hvm_user_regs user_regs; /* User-level CPU registers
*/
/* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
uint32_t ctrlreg[8]; /* CR0-CR7 (control registers)
*/
uint32_t debugreg[8]; /* DB0-DB7 (debug registers)
*/
};

I'm also seriously considering getting rid of ctrlreg and debugreg. Since HVM VCPUs will always be started in 32bit flat mode, it doesn't make sense IMHO to have both the 32 and the 64 version of the registers, so cpu_hvm_user_regs is always going to be:

struct cpu_hvm_user_regs {
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;
    uint32_t esi;
    uint32_t edi;
    uint32_t ebp;
    uint32_t eax;
    uint32_t eip;
    uint32_t esp;
    uint32_t eflags;
    uint16_t cs;
    uint16_t ss;
    uint16_t es;
    uint16_t ds;
    uint16_t fs;
    uint16_t gs;
};

We could however do something similar to what's done in ARM and have a union of both the 32 and the 64bit registers in case we want to start the vCPU in 64bit mode sometime in the future.

Quoted 6 lines
Quoted 2 lines

What you gave above is suitable only for VCPUOP_initialise afaict. Did you intend this to be the case?

Certainly not, this should also be used by XEN_DOMCTL_setvcpucontext. I'm afraid I'm missing something obvious, but I don't see why this couldn't be used by XEN_DOMCTL_setvcpucontext TBH, can you please clarify?

Just like for HVM (and even more so with the plan to allow PVH to freely switch between 32- and 64-bit modes) the full 64-bit context should be got and set in a single domctl imo. If the caller was to first figure out what bitness a to be migrated guest was paused in (and that may differ between vCPU-s), things would likely become quite ugly. Not to speak of the need for a 64-bit tool stack to then have a way to specify which format the structure is in for a "set" operation.

Jan

#34 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monné
Quoted 55 lines · Roger Pau Monné

El 23/07/15 a les 17.32, Jan Beulich ha escrit:

Quoted 54 lines
Quoted 53 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 17:10, <[email protected]> wrote:

IMHO introducing a new structure that gets rid of all the PV-only

fields seems like a good option:

struct vcpu_hvm_context {
#define _VGCF_online 5
#define VGCF_online (1<<_VGCF_online)
uint32_t flags; /* VGCF_* flags

*/
struct cpu_hvm_user_regs user_regs; /* User-level CPU
registers
*/
/* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
uint32_t ctrlreg[8]; /* CR0-CR7 (control
registers)
*/
uint32_t debugreg[8]; /* DB0-DB7 (debug
registers)
*/
};

I'm also seriously considering getting rid of ctrlreg and debugreg.
Since HVM VCPUs will always be started in 32bit flat mode, it doesn't
make sense IMHO to have both the 32 and the 64 version of the registers, so cpu_hvm_user_regs is always going to be:

struct cpu_hvm_user_regs {
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;
    uint32_t esi;
    uint32_t edi;
    uint32_t ebp;
    uint32_t eax;
    uint32_t eip;
    uint32_t esp;
    uint32_t eflags;
    uint16_t cs;
    uint16_t ss;
    uint16_t es;
    uint16_t ds;
    uint16_t fs;
    uint16_t gs;
};

We could however do something similar to what's done in ARM and have
a union of both the 32 and the 64bit registers in case we want to start the vCPU in 64bit mode sometime in the future.

Quoted 7 lines
Quoted 2 lines

What you gave above is suitable only for VCPUOP_initialise afaict. Did you intend this to be the case?

Certainly not, this should also be used by XEN_DOMCTL_setvcpucontext. I'm afraid I'm missing something obvious, but I don't see why this couldn't be used by XEN_DOMCTL_setvcpucontext TBH, can you please clarify?

set/getvcpucontext need to pickle all state for save/restore/migration, not just the start of day state.

Ian.

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

#35 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 55 lines · Ian Campbell
Quoted 54 lines · Roger Pau Monné

El 23/07/15 a les 17.32, Jan Beulich ha escrit:

Quoted 53 lines
Quoted 53 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 17:10, <[email protected]> wrote:

IMHO introducing a new structure that gets rid of all the PV-only

fields seems like a good option:

struct vcpu_hvm_context {
#define _VGCF_online 5
#define VGCF_online (1<<_VGCF_online)
uint32_t flags; /* VGCF_* flags

*/
struct cpu_hvm_user_regs user_regs; /* User-level CPU
registers
*/
/* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
uint32_t ctrlreg[8]; /* CR0-CR7 (control
registers)
*/
uint32_t debugreg[8]; /* DB0-DB7 (debug
registers)
*/
};

I'm also seriously considering getting rid of ctrlreg and debugreg.
Since HVM VCPUs will always be started in 32bit flat mode, it doesn't
make sense IMHO to have both the 32 and the 64 version of the registers, so cpu_hvm_user_regs is always going to be:

struct cpu_hvm_user_regs {
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;
    uint32_t esi;
    uint32_t edi;
    uint32_t ebp;
    uint32_t eax;
    uint32_t eip;
    uint32_t esp;
    uint32_t eflags;
    uint16_t cs;
    uint16_t ss;
    uint16_t es;
    uint16_t ds;
    uint16_t fs;
    uint16_t gs;
};

We could however do something similar to what's done in ARM and have
a union of both the 32 and the 64bit registers in case we want to start the vCPU in 64bit mode sometime in the future.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

What you gave above is suitable only for VCPUOP_initialise afaict. Did you intend this to be the case?

Certainly not, this should also be used by XEN_DOMCTL_setvcpucontext. I'm afraid I'm missing something obvious, but I don't see why this couldn't be used by XEN_DOMCTL_setvcpucontext TBH, can you please clarify?

set/getvcpucontext need to pickle all state for save/restore/migration, not just the start of day state.

HVM migration doesn't use set/getvcpucontext.

I would expect an HVMLite-based-PVH to follow suit and just use set/gethvmcontext.

(In fact, while doing migration v2 I was half thinking of making PV follow HVM suit somewhat, to simplify the toolstack side of things)

~Andrew

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

#36 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 63 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 18:15, <[email protected]> wrote:
Quoted 61 lines · Ian Campbell
Quoted 60 lines · Roger Pau Monné

El 23/07/15 a les 17.32, Jan Beulich ha escrit:

Quoted 49 lines
Quoted 49 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 17:10, <[email protected]> wrote:

IMHO introducing a new structure that gets rid of all the PV-only

fields seems like a good option:

struct vcpu_hvm_context {
#define _VGCF_online 5
#define VGCF_online (1<<_VGCF_online)
uint32_t flags; /* VGCF_* flags

*/
struct cpu_hvm_user_regs user_regs; /* User-level CPU
registers
*/
/* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
uint32_t ctrlreg[8]; /* CR0-CR7 (control
registers)
*/
uint32_t debugreg[8]; /* DB0-DB7 (debug
registers)
*/
};

I'm also seriously considering getting rid of ctrlreg and debugreg.
Since HVM VCPUs will always be started in 32bit flat mode, it doesn't
make sense IMHO to have both the 32 and the 64 version of the registers, so cpu_hvm_user_regs is always going to be:

struct cpu_hvm_user_regs {
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;
    uint32_t esi;
    uint32_t edi;
    uint32_t ebp;
    uint32_t eax;
    uint32_t eip;
    uint32_t esp;
    uint32_t eflags;
    uint16_t cs;
    uint16_t ss;
    uint16_t es;
    uint16_t ds;
    uint16_t fs;
    uint16_t gs;
};
Quoted 6 lines
Quoted 4 lines

We could however do something similar to what's done in ARM and have
a union of both the 32 and the 64bit registers in case we want to start the vCPU in 64bit mode sometime in the future.

What you gave above is suitable only for VCPUOP_initialise afaict. Did you intend this to be the case?

Certainly not, this should also be used by XEN_DOMCTL_setvcpucontext. I'm afraid I'm missing something obvious, but I don't see why this couldn't be used by XEN_DOMCTL_setvcpucontext TBH, can you please clarify?

Quoted 7 lines
Quoted 2 lines

set/getvcpucontext need to pickle all state for save/restore/migration, not just the start of day state.

HVM migration doesn't use set/getvcpucontext.

I would expect an HVMLite-based-PVH to follow suit and just use set/gethvmcontext.

Oh, right, but that doesn't mean the respective domctl-s should produce unconsumable data, or have to guess how to interpret what gets passed in. I.e. at the very minimum the domctl-s then should be disallowed for PVH if they can#t be made work right.

Jan

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

#37 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 63 lines · Jan Beulich
Quoted 63 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 18:15, <[email protected]> wrote:
Quoted 61 lines · Ian Campbell
Quoted 60 lines · Roger Pau Monné

El 23/07/15 a les 17.32, Jan Beulich ha escrit:

Quoted 49 lines
Quoted 49 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 17:10, <[email protected]> wrote:

IMHO introducing a new structure that gets rid of all the PV-only

fields seems like a good option:

struct vcpu_hvm_context {
#define _VGCF_online 5
#define VGCF_online (1<<_VGCF_online)
uint32_t flags; /* VGCF_* flags

*/
struct cpu_hvm_user_regs user_regs; /* User-level CPU
registers
*/
/* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
uint32_t ctrlreg[8]; /* CR0-CR7 (control
registers)
*/
uint32_t debugreg[8]; /* DB0-DB7 (debug
registers)
*/
};

I'm also seriously considering getting rid of ctrlreg and debugreg.
Since HVM VCPUs will always be started in 32bit flat mode, it doesn't
make sense IMHO to have both the 32 and the 64 version of the registers, so cpu_hvm_user_regs is always going to be:

struct cpu_hvm_user_regs {
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;
    uint32_t esi;
    uint32_t edi;
    uint32_t ebp;
    uint32_t eax;
    uint32_t eip;
    uint32_t esp;
    uint32_t eflags;
    uint16_t cs;
    uint16_t ss;
    uint16_t es;
    uint16_t ds;
    uint16_t fs;
    uint16_t gs;
};
Quoted 6 lines
Quoted 4 lines

We could however do something similar to what's done in ARM and have
a union of both the 32 and the 64bit registers in case we want to start the vCPU in 64bit mode sometime in the future.

What you gave above is suitable only for VCPUOP_initialise afaict. Did you intend this to be the case?

Certainly not, this should also be used by XEN_DOMCTL_setvcpucontext. I'm afraid I'm missing something obvious, but I don't see why this couldn't be used by XEN_DOMCTL_setvcpucontext TBH, can you please clarify?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

set/getvcpucontext need to pickle all state for save/restore/migration, not just the start of day state.

HVM migration doesn't use set/getvcpucontext.

I would expect an HVMLite-based-PVH to follow suit and just use set/gethvmcontext.

Oh, right, but that doesn't mean the respective domctl-s should produce unconsumable data

Indeed.

Quoted 3 lines

, or have to guess how to interpret
what gets passed in. I.e. at the very minimum the domctl-s then should be disallowed for PVH if they can#t be made work right.

They should be able to work with any vcpu.

In particular, it would be nice to start hvmloader with a hypercall to set eip properly, rather than mapping gfn 0 and writing a jump instruction into memory.

Having said that, in a virtual environment it would be nice if vcpu 1 could be started by vcpu 0 on straight in long at a given rip, rsp and cr3.

The reason for starting vcpu 0 in 32bit flat mode is to move mode knowledge out of the domain builder and into the domain, but once the guest specific loader is running, there is nothing to say it shouldn't be able to skip 32bit AP trampolines entirely.

Perhaps what we want is a new VCPU_initialise op, rather than attempting to retrofit an HVM view of the world onto a PV-specific hypercall.

~Andrew

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

#39 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Jan Beulich

El 23/07/15 a les 18.19, Jan Beulich ha escrit:

Quoted 68 lines
Quoted 68 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 18:15, <[email protected]> wrote:
Quoted 55 lines · Ian Campbell
Quoted 54 lines · Roger Pau Monné

El 23/07/15 a les 17.32, Jan Beulich ha escrit:

Quoted 53 lines
Quoted 53 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 17:10, <[email protected]> wrote:

IMHO introducing a new structure that gets rid of all the PV-only

fields seems like a good option:

struct vcpu_hvm_context {
#define _VGCF_online 5
#define VGCF_online (1<<_VGCF_online)
uint32_t flags; /* VGCF_* flags

*/
struct cpu_hvm_user_regs user_regs; /* User-level CPU
registers
*/
/* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
uint32_t ctrlreg[8]; /* CR0-CR7 (control
registers)
*/
uint32_t debugreg[8]; /* DB0-DB7 (debug
registers)
*/
};

I'm also seriously considering getting rid of ctrlreg and debugreg.
Since HVM VCPUs will always be started in 32bit flat mode, it doesn't
make sense IMHO to have both the 32 and the 64 version of the registers, so cpu_hvm_user_regs is always going to be:

struct cpu_hvm_user_regs {
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;
    uint32_t esi;
    uint32_t edi;
    uint32_t ebp;
    uint32_t eax;
    uint32_t eip;
    uint32_t esp;
    uint32_t eflags;
    uint16_t cs;
    uint16_t ss;
    uint16_t es;
    uint16_t ds;
    uint16_t fs;
    uint16_t gs;
};

We could however do something similar to what's done in ARM and have
a union of both the 32 and the 64bit registers in case we want to start the vCPU in 64bit mode sometime in the future.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

What you gave above is suitable only for VCPUOP_initialise afaict. Did you intend this to be the case?

Certainly not, this should also be used by XEN_DOMCTL_setvcpucontext. I'm afraid I'm missing something obvious, but I don't see why this couldn't be used by XEN_DOMCTL_setvcpucontext TBH, can you please clarify?

set/getvcpucontext need to pickle all state for save/restore/migration, not just the start of day state.

HVM migration doesn't use set/getvcpucontext.

Quoted 7 lines
Quoted 2 lines

I would expect an HVMLite-based-PVH to follow suit and just use set/gethvmcontext.

Oh, right, but that doesn't mean the respective domctl-s should produce unconsumable data, or have to guess how to interpret what gets passed in. I.e. at the very minimum the domctl-s then should be disallowed for PVH if they can#t be made work right.

Right, the problem is that if I introduce this new vcpu_context structure plain HVM guests are also going to use it.

This is not a problem with the VCPU_initialize op, because it was not available to HVM guests. But it's going to be a problem for XEN_DOMCTL_{get/set}vcpucontext consumers, since the structure taken/returned by the hypercall is going to change when the target is a HVM guest, and this is a can of worms I might prefer to avoid opening.

One partial solution would be to allow the usage of this new struct only for the VCPU_initialize hypercall for HVM guests, and keep using the old structures for the domctls, aiming at removing them once PV support is dropped from Xen, but that looks half-baked IMHO.

Roger.

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

#38 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Andrew Cooper

El 23/07/15 a les 18.49, Andrew Cooper ha escrit:

Quoted 79 lines · Jan Beulich
Quoted 63 lines
Quoted 63 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 18:15, <[email protected]> wrote:
Quoted 61 lines · Ian Campbell
Quoted 60 lines · Roger Pau Monné

El 23/07/15 a les 17.32, Jan Beulich ha escrit:

Quoted 49 lines
Quoted 49 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 17:10, <[email protected]> wrote:

IMHO introducing a new structure that gets rid of all the PV-only

fields seems like a good option:

struct vcpu_hvm_context {
#define _VGCF_online 5
#define VGCF_online (1<<_VGCF_online)
uint32_t flags; /* VGCF_* flags

*/
struct cpu_hvm_user_regs user_regs; /* User-level CPU
registers
*/
/* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
uint32_t ctrlreg[8]; /* CR0-CR7 (control
registers)
*/
uint32_t debugreg[8]; /* DB0-DB7 (debug
registers)
*/
};

I'm also seriously considering getting rid of ctrlreg and debugreg.
Since HVM VCPUs will always be started in 32bit flat mode, it doesn't
make sense IMHO to have both the 32 and the 64 version of the registers, so cpu_hvm_user_regs is always going to be:

struct cpu_hvm_user_regs {
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;
    uint32_t esi;
    uint32_t edi;
    uint32_t ebp;
    uint32_t eax;
    uint32_t eip;
    uint32_t esp;
    uint32_t eflags;
    uint16_t cs;
    uint16_t ss;
    uint16_t es;
    uint16_t ds;
    uint16_t fs;
    uint16_t gs;
};
Quoted 6 lines
Quoted 4 lines

We could however do something similar to what's done in ARM and have
a union of both the 32 and the 64bit registers in case we want to start the vCPU in 64bit mode sometime in the future.

What you gave above is suitable only for VCPUOP_initialise afaict. Did you intend this to be the case?

Certainly not, this should also be used by XEN_DOMCTL_setvcpucontext. I'm afraid I'm missing something obvious, but I don't see why this couldn't be used by XEN_DOMCTL_setvcpucontext TBH, can you please clarify?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

set/getvcpucontext need to pickle all state for save/restore/migration, not just the start of day state.

HVM migration doesn't use set/getvcpucontext.

I would expect an HVMLite-based-PVH to follow suit and just use set/gethvmcontext.

Oh, right, but that doesn't mean the respective domctl-s should produce unconsumable data

Indeed.

Quoted 3 lines

, or have to guess how to interpret
what gets passed in. I.e. at the very minimum the domctl-s then should be disallowed for PVH if they can#t be made work right.

Quoted 5 lines

They should be able to work with any vcpu.

In particular, it would be nice to start hvmloader with a hypercall to set eip properly, rather than mapping gfn 0 and writing a jump instruction into memory.

Yes, this is already done in patch #8, see the vcpu_hvm function.

Quoted 7 lines

Having said that, in a virtual environment it would be nice if vcpu 1 could be started by vcpu 0 on straight in long at a given rip, rsp and cr3.

The reason for starting vcpu 0 in 32bit flat mode is to move mode knowledge out of the domain builder and into the domain, but once the guest specific loader is running, there is nothing to say it shouldn't be able to skip 32bit AP trampolines entirely.

In the current version of the series both the BSP and the APs are started in the same way: 32bit flat mode. We already have code in place to start the APs with paging enabled and that's what PVH has been using.

Quoted 2 lines

Perhaps what we want is a new VCPU_initialise op, rather than attempting to retrofit an HVM view of the world onto a PV-specific hypercall.

IMHO, the problem is not with VCPU_initialise but with the domctls.

Roger.

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

#40 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monné
Quoted 83 lines · Roger Pau Monné

El 23/07/15 a les 18.19, Jan Beulich ha escrit:

Quoted 65 lines
Quoted 65 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 18:15, <[email protected]> wrote:
Quoted 63 lines · Ian Campbell
Quoted 54 lines · Roger Pau Monné

El 23/07/15 a les 17.32, Jan Beulich ha escrit:

Quoted 53 lines
Quoted 53 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 17:10, <[email protected]> wrote:

IMHO introducing a new structure that gets rid of all the PV-only

fields seems like a good option:

struct vcpu_hvm_context {
#define _VGCF_online 5
#define VGCF_online (1<<_VGCF_online)
uint32_t flags; /* VGCF_* flags

*/
struct cpu_hvm_user_regs user_regs; /* User-level CPU
registers
*/
/* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
uint32_t ctrlreg[8]; /* CR0-CR7 (control
registers)
*/
uint32_t debugreg[8]; /* DB0-DB7 (debug
registers)
*/
};

I'm also seriously considering getting rid of ctrlreg and debugreg.
Since HVM VCPUs will always be started in 32bit flat mode, it doesn't
make sense IMHO to have both the 32 and the 64 version of the registers, so cpu_hvm_user_regs is always going to be:

struct cpu_hvm_user_regs {
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;
    uint32_t esi;
    uint32_t edi;
    uint32_t ebp;
    uint32_t eax;
    uint32_t eip;
    uint32_t esp;
    uint32_t eflags;
    uint16_t cs;
    uint16_t ss;
    uint16_t es;
    uint16_t ds;
    uint16_t fs;
    uint16_t gs;
};

We could however do something similar to what's done in ARM and have
a union of both the 32 and the 64bit registers in case we want to start the vCPU in 64bit mode sometime in the future.

Quoted 6 lines
Quoted 2 lines

What you gave above is suitable only for VCPUOP_initialise afaict. Did you intend this to be the case?

Certainly not, this should also be used by XEN_DOMCTL_setvcpucontext. I'm afraid I'm missing something obvious, but I don't see why this couldn't be used by XEN_DOMCTL_setvcpucontext TBH, can you please clarify?

set/getvcpucontext need to pickle all state for save/restore/migration, not just the start of day state.

Quoted 8 lines
Quoted 4 lines

HVM migration doesn't use set/getvcpucontext.

I would expect an HVMLite-based-PVH to follow suit and just use set/gethvmcontext.

Oh, right, but that doesn't mean the respective domctl-s should produce unconsumable data, or have to guess how to interpret what gets passed in. I.e. at the very minimum the domctl-s then should be disallowed for PVH if they can#t be made work right.

Right, the problem is that if I introduce this new vcpu_context structure plain HVM guests are also going to use it.

This is not a problem with the VCPU_initialize op, because it was not available to HVM guests. But it's going to be a problem for XEN_DOMCTL_{get/set}vcpucontext consumers, since the structure taken/returned by the hypercall is going to change when the target is a HVM guest, and this is a can of worms I might prefer to avoid opening.

Quoted 4 lines

One partial solution would be to allow the usage of this new struct only for the VCPU_initialize hypercall for HVM guests, and keep using the old structures for the domctls, aiming at removing them once PV support is dropped from Xen, but that looks half-baked IMHO.

PV and HVM "vcpu state" are fundamentally different because they are fundamentally different kinds of guest. Lets not try and mash them together.

I would go with Jan's suggestion and make XEN_DOMCTL_{get/set}vcpucontext ineligible for use on HVM guests.

The state of an HVMLite vcpu can already be set with XEN_DOMCTL_sethvmcontext and a stream containing just a single hvm vcpu record, and retrieved with XEN_DOMCTL_gethvmcontext_partial.

~Andrew

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

#41 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 19:12, <[email protected]> wrote:

I would go with Jan's suggestion and make XEN_DOMCTL_{get/set}vcpucontext ineligible for use on HVM guests.

Plus, as you said earlier, a new VCPUOP_initialize.

Jan

#42 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

El 24/07/15 a les 10.22, Jan Beulich ha escrit:

Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 19:12, <[email protected]> wrote:

I would go with Jan's suggestion and make XEN_DOMCTL_{get/set}vcpucontext ineligible for use on HVM guests.

Plus, as you said earlier, a new VCPUOP_initialize.

(Adding the Linux maintainers to get their opinion on the interface)

Just to recap and to make sure I got all the points:

- vCPU initialization from the toolstack (BSP initialization) is going
to be done using XEN_DOMCTL_sethvmcontext.
- XEN_DOMCTL_{get/set}vcpucontext is going to return EOPNOTSUPP for
HVM guests.
- A new vcpu_guest_contatext (vcpu_hvm_context?) is going to be
introduced together with a a new VCPUOP_initialize hypercall (VCPUOP_hvm_initialize?).

The following is a layout proposal for the new vcpu_context:

struct vcpu_hvm_context {
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 0
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */

#define _VCPUHVM_MODE_64B              1
#define VCPUHVM_MODE_64B               (1<<_VCPUHVM_MODE_64B)
#define _VCPUHVM_online                2
#define VCPUHVM_online                 (1<<_VCPUHVM_online )
    uint32_t flags;                         /* VCPUHVM_* flags.   */
    struct cpu_hvm_regs user_regs;          /* CPU registers.     */

};

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Anonymous union includes both 32- and 64-bit names (e.g., ebp/rbp). */

# define __DECL_REG(n64, n32) union {          \
        uint64_t n64;                          \
        uint32_t n32;                          \
    }
#else
/* Non-gcc sources must always use the proper 64-bit name (e.g., rbp). */
#define __DECL_REG(n64, n32) uint64_t n64
#endif

#define __DECL_GP_REG(n) __DECL_REG(r##n, e##n)

struct cpu_hvm_regs {
    /* General purpose registers. */
    __DECL_GP_REG(bx);
    __DECL_GP_REG(cx);
    __DECL_GP_REG(dx);
    __DECL_GP_REG(si);
    __DECL_GP_REG(di);
    __DECL_GP_REG(bp);
    __DECL_GP_REG(ax);
    __DECL_GP_REG(ip);
    __DECL_GP_REG(sp);
    __DECL_GP_REG(flags);

    /* Control registers.         */
    uint64_t cr[8];
    /* Valid on amd64 only.       */
    uint64_t efer;

    /* Debug registers.           */
    uint64_t db[8];  
};

#undef __DECL_GP_REG
#undef __DECL_REG

Of course the APs will be allowed to start in any mode they wish, regardless of the mode the guest is currently running on.

Roger.

#43 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 11:59, <[email protected]> wrote:

Just to recap and to make sure I got all the points:

- vCPU initialization from the toolstack (BSP initialization) is going
to be done using XEN_DOMCTL_sethvmcontext.
- XEN_DOMCTL_{get/set}vcpucontext is going to return EOPNOTSUPP for
HVM guests.
- A new vcpu_guest_contatext (vcpu_hvm_context?) is going to be
introduced together with a a new VCPUOP_initialize hypercall (VCPUOP_hvm_initialize?).

Since the current one is called VCPUOP_initialise, why not just VCPUOP_initialize? Having "hvm" in the name when it's meant to also be used for PVH may end up being confusing.

Quoted 9 lines

The following is a layout proposal for the new vcpu_context:

struct vcpu_hvm_context {
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 0
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */
#define _VCPUHVM_MODE_64B 1
#define VCPUHVM_MODE_64B (1<<_VCPUHVM_MODE_64B)

16-bit mode?

Quoted 2 lines

#define _VCPUHVM_online 2
#define VCPUHVM_online (1<<_VCPUHVM_online )

What is this needed for?

Quoted 17 lines
    uint32_t flags;                         /* VCPUHVM_* flags.   */
    struct cpu_hvm_regs user_regs;          /* CPU registers.     */

};

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Anonymous union includes both 32- and 64-bit names (e.g., ebp/rbp). */

# define __DECL_REG(n64, n32) union {          \
        uint64_t n64;                          \
        uint32_t n32;                          \
    }
#else
/* Non-gcc sources must always use the proper 64-bit name (e.g., rbp). */
#define __DECL_REG(n64, n32) uint64_t n64
#endif

#define __DECL_GP_REG(n) __DECL_REG(r##n, e##n)

Quoted 11 lines
struct cpu_hvm_regs {
    /* General purpose registers. */
    __DECL_GP_REG(bx);
    __DECL_GP_REG(cx);
    __DECL_GP_REG(dx);
    __DECL_GP_REG(si);
    __DECL_GP_REG(di);
    __DECL_GP_REG(bp);
    __DECL_GP_REG(ax);
    __DECL_GP_REG(ip);
    __DECL_GP_REG(sp);

Please put GPRs in their natural order - no need to mimic the order in any existing structure.

Quoted 1 line
    __DECL_GP_REG(flags);

r8-r11, selector and descriptor registers, pseudo descriptor registers. Or else for all of them their default state would need to be spelled out.

Quoted 3 lines
    /* Control registers.         */
    uint64_t cr[8];
    /* Valid on amd64 only.       */

Fields valid/useful in one mode only should probably be put in union-ized sub-structures.

Jan

Quoted 13 lines
    uint64_t efer;

    /* Debug registers.           */
    uint64_t db[8];  
};

#undef __DECL_GP_REG
#undef __DECL_REG

Of course the APs will be allowed to start in any mode they wish, regardless of the mode the guest is currently running on.

Roger.

#62 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monné
Quoted 24 lines · Roger Pau Monné

El 24/07/15 a les 10.22, Jan Beulich ha escrit:

Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 19:12, <[email protected]> wrote:

I would go with Jan's suggestion and make XEN_DOMCTL_{get/set}vcpucontext ineligible for use on HVM guests.

Plus, as you said earlier, a new VCPUOP_initialize.

(Adding the Linux maintainers to get their opinion on the interface)

Just to recap and to make sure I got all the points:

- vCPU initialization from the toolstack (BSP initialization) is going
to be done using XEN_DOMCTL_sethvmcontext.
- XEN_DOMCTL_{get/set}vcpucontext is going to return EOPNOTSUPP for
HVM guests.
- A new vcpu_guest_contatext (vcpu_hvm_context?) is going to be
introduced together with a a new VCPUOP_initialize hypercall (VCPUOP_hvm_initialize?).

The following is a layout proposal for the new vcpu_context:

struct vcpu_hvm_context {
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 0
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */

Quoted 7 lines
#define _VCPUHVM_MODE_64B              1
#define VCPUHVM_MODE_64B               (1<<_VCPUHVM_MODE_64B)
#define _VCPUHVM_online                2
#define VCPUHVM_online                 (1<<_VCPUHVM_online )
     uint32_t flags;                         /* VCPUHVM_* flags.   */
     struct cpu_hvm_regs user_regs;          /* CPU registers.     */

};

To avoid making the 32bit (and optionally 16bit) massive as a side effect of 64bit, can I suggest

uint32_t flags;

union {
    cpu_hvm32_regs;
    cpu_hvm64_regs;
};

Which allows hvm32_regs to be a far smaller structure.

Quoted 36 lines

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Anonymous union includes both 32- and 64-bit names (e.g., ebp/rbp). */

# define __DECL_REG(n64, n32) union {          \
         uint64_t n64;                          \
         uint32_t n32;                          \
     }
#else
/* Non-gcc sources must always use the proper 64-bit name (e.g., rbp). */
#define __DECL_REG(n64, n32) uint64_t n64
#endif

#define __DECL_GP_REG(n) __DECL_REG(r##n, e##n)

struct cpu_hvm_regs {
     /* General purpose registers. */
     __DECL_GP_REG(bx);
     __DECL_GP_REG(cx);
     __DECL_GP_REG(dx);
     __DECL_GP_REG(si);
     __DECL_GP_REG(di);
     __DECL_GP_REG(bp);
     __DECL_GP_REG(ax);
     __DECL_GP_REG(ip);
     __DECL_GP_REG(sp);
     __DECL_GP_REG(flags);

     /* Control registers.         */
     uint64_t cr[8];
     /* Valid on amd64 only.       */
     uint64_t efer;

     /* Debug registers.           */
     uint64_t db[8];
};
Quoted 5 lines

#undef __DECL_GP_REG
#undef __DECL_REG

Of course the APs will be allowed to start in any mode they wish, regardless of the mode the guest is currently running on.

To start straight in 64bit, you need gdtr and cs as a minimum

With that in mind, room for each of the task registers, and segment selectors.

~Andrew

#63 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 11 lines · Andrew Cooper

To avoid making the 32bit (and optionally 16bit) massive as a side effect of 64bit, can I suggest

uint32_t flags;

union {
     cpu_hvm32_regs;
     cpu_hvm64_regs;
};

Which allows hvm32_regs to be a far smaller structure.

Given that you can't really know apriori which mode an HVM vcpu is in and that having to pick the right half of the union everywhere is faff for everyone on both sides of the API I'd suggest going with a single struct as far as possible Perhaps with a union to allow the use of 32- and 64-bit _names_ for things which are the same underlying register in different widths (rip/pc, eax/rax etc), but that would be it.

Ian.

#65 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Andrew Cooper
Quoted 39 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 13:11, <[email protected]> wrote:
Quoted 24 lines · Roger Pau Monné

El 24/07/15 a les 10.22, Jan Beulich ha escrit:

Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 23.07.15 at 19:12, <[email protected]> wrote:

I would go with Jan's suggestion and make XEN_DOMCTL_{get/set}vcpucontext ineligible for use on HVM guests.

Plus, as you said earlier, a new VCPUOP_initialize.

(Adding the Linux maintainers to get their opinion on the interface)

Just to recap and to make sure I got all the points:

- vCPU initialization from the toolstack (BSP initialization) is going
to be done using XEN_DOMCTL_sethvmcontext.
- XEN_DOMCTL_{get/set}vcpucontext is going to return EOPNOTSUPP for
HVM guests.
- A new vcpu_guest_contatext (vcpu_hvm_context?) is going to be
introduced together with a a new VCPUOP_initialize hypercall (VCPUOP_hvm_initialize?).

The following is a layout proposal for the new vcpu_context:

struct vcpu_hvm_context {
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 0
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */

Quoted 7 lines
#define _VCPUHVM_MODE_64B              1
#define VCPUHVM_MODE_64B               (1<<_VCPUHVM_MODE_64B)
#define _VCPUHVM_online                2
#define VCPUHVM_online                 (1<<_VCPUHVM_online )
     uint32_t flags;                         /* VCPUHVM_* flags.   */
     struct cpu_hvm_regs user_regs;          /* CPU registers.     */

};

To avoid making the 32bit (and optionally 16bit) massive as a side effect of 64bit, can I suggest

Quoted 7 lines

uint32_t flags;

union {
     cpu_hvm32_regs;
     cpu_hvm64_regs;
};

Which allows hvm32_regs to be a far smaller structure.

But that wouldn't help the size of the overall structure.

Jan

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

#64 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Ian Campbell
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 13:28, <[email protected]> wrote:
Quoted 10 lines · Andrew Cooper

To avoid making the 32bit (and optionally 16bit) massive as a side effect of 64bit, can I suggest

uint32_t flags;

union {
     cpu_hvm32_regs;
     cpu_hvm64_regs;
};
Quoted 8 lines
Quoted 1 line

Which allows hvm32_regs to be a far smaller structure.

Given that you can't really know apriori which mode an HVM vcpu is in and that having to pick the right half of the union everywhere is faff for everyone on both sides of the API I'd suggest going with a single struct as far as possible Perhaps with a union to allow the use of 32- and 64-bit _names_ for things which are the same underlying register in different widths (rip/pc, eax/rax etc), but that would be it.

While I had considered that too (not the least based on what you've said ARM has), it has its own downsides (the hypervisor needing to verify that everything that can't be represented is zero), which is why I wasn't certain whether to suggest that.

Jan

#66 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Andrew Cooper

El 24/07/15 a les 13.11, Andrew Cooper ha escrit:

Quoted 17 lines · Roger Pau Monné
Quoted 5 lines

struct vcpu_hvm_context {
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 0
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */

Quoted 7 lines
#define _VCPUHVM_MODE_64B              1
#define VCPUHVM_MODE_64B               (1<<_VCPUHVM_MODE_64B)
#define _VCPUHVM_online                2
#define VCPUHVM_online                 (1<<_VCPUHVM_online )
     uint32_t flags;                         /* VCPUHVM_* flags.   */
     struct cpu_hvm_regs user_regs;          /* CPU registers.     */

};

To avoid making the 32bit (and optionally 16bit) massive as a side effect of 64bit, can I suggest

Quoted 7 lines

uint32_t flags;

union {
    cpu_hvm32_regs;
    cpu_hvm64_regs;
};

Which allows hvm32_regs to be a far smaller structure.

But what's the benefit of this? vcpu_hvm_context is going to be equally large, and that's what we pass as the hypercall argument. This is mimicking the format of the structure that's already used on ARM, so I would rather keep it as is.

Quoted 39 lines
Quoted 39 lines

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Anonymous union includes both 32- and 64-bit names (e.g., ebp/rbp). */

# define __DECL_REG(n64, n32) union {          \
         uint64_t n64;                          \
         uint32_t n32;                          \
     }
#else
/* Non-gcc sources must always use the proper 64-bit name (e.g., rbp). */
#define __DECL_REG(n64, n32) uint64_t n64
#endif

#define __DECL_GP_REG(n) __DECL_REG(r##n, e##n)

struct cpu_hvm_regs {
     /* General purpose registers. */
     __DECL_GP_REG(bx);
     __DECL_GP_REG(cx);
     __DECL_GP_REG(dx);
     __DECL_GP_REG(si);
     __DECL_GP_REG(di);
     __DECL_GP_REG(bp);
     __DECL_GP_REG(ax);
     __DECL_GP_REG(ip);
     __DECL_GP_REG(sp);
     __DECL_GP_REG(flags);

     /* Control registers.         */
     uint64_t cr[8];
     /* Valid on amd64 only.       */
     uint64_t efer;

     /* Debug registers.           */
     uint64_t db[8];
};

#undef __DECL_GP_REG
#undef __DECL_REG

Quoted 7 lines
Quoted 2 lines

Of course the APs will be allowed to start in any mode they wish, regardless of the mode the guest is currently running on.

To start straight in 64bit, you need gdtr and cs as a minimum

With that in mind, room for each of the task registers, and segment selectors.

I was planning to say that on both 32 and 64 bits we start with a flat GDT (like we do for the BSP). But we can also arrange for this to be set by the user. So we would need to add the following fields:

     uint{16/32/64}_t gdtr;
     uint16_t ss, es, ds, fs, gs;
     uint16_t tr;

Roger.

#44 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Jan Beulich

El 24/07/15 a les 12.46, Jan Beulich ha escrit:

Quoted 11 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 11:59, <[email protected]> wrote:

Just to recap and to make sure I got all the points:

- vCPU initialization from the toolstack (BSP initialization) is going
to be done using XEN_DOMCTL_sethvmcontext.
- XEN_DOMCTL_{get/set}vcpucontext is going to return EOPNOTSUPP for
HVM guests.
- A new vcpu_guest_contatext (vcpu_hvm_context?) is going to be
introduced together with a a new VCPUOP_initialize hypercall (VCPUOP_hvm_initialize?).

Quoted 3 lines

Since the current one is called VCPUOP_initialise, why not just VCPUOP_initialize? Having "hvm" in the name when it's meant to also be used for PVH may end up being confusing.

Right.

Quoted 11 lines
Quoted 9 lines

The following is a layout proposal for the new vcpu_context:

struct vcpu_hvm_context {
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 0
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */
#define _VCPUHVM_MODE_64B 1
#define VCPUHVM_MODE_64B (1<<_VCPUHVM_MODE_64B)

16-bit mode?

I wasn't even considering that we would like to start the vCPUs in 16bit mode, but given that's how APs are started on bare metal I guess it makes sense to have it.

Quoted 5 lines
Quoted 3 lines

#define _VCPUHVM_online 2
#define VCPUHVM_online (1<<_VCPUHVM_online )

What is this needed for?

It clears the VPF_down bit of the vcpu pause_flags, but we can also do this using the VCPUOP_up hypercall so I'm just going to remove it.

Quoted 29 lines
Quoted 17 lines
    uint32_t flags;                         /* VCPUHVM_* flags.   */
    struct cpu_hvm_regs user_regs;          /* CPU registers.     */

};

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Anonymous union includes both 32- and 64-bit names (e.g., ebp/rbp). */

# define __DECL_REG(n64, n32) union {          \
        uint64_t n64;                          \
        uint32_t n32;                          \
    }
#else
/* Non-gcc sources must always use the proper 64-bit name (e.g., rbp). */
#define __DECL_REG(n64, n32) uint64_t n64
#endif

#define __DECL_GP_REG(n) __DECL_REG(r##n, e##n)

Quoted 11 lines
struct cpu_hvm_regs {
    /* General purpose registers. */
    __DECL_GP_REG(bx);
    __DECL_GP_REG(cx);
    __DECL_GP_REG(dx);
    __DECL_GP_REG(si);
    __DECL_GP_REG(di);
    __DECL_GP_REG(bp);
    __DECL_GP_REG(ax);
    __DECL_GP_REG(ip);
    __DECL_GP_REG(sp);
Quoted 2 lines

Please put GPRs in their natural order - no need to mimic the order in any existing structure.

Ack.

Quoted 4 lines
Quoted 1 line
    __DECL_GP_REG(flags);

r8-r11, selector and descriptor registers, pseudo descriptor registers. Or else for all of them their default state would need to be spelled out.

r8-r15 right?

Quoted 7 lines
Quoted 4 lines
    /* Control registers.         */
    uint64_t cr[8];
    /* Valid on amd64 only.       */

Fields valid/useful in one mode only should probably be put in union-ized sub-structures.

Do you mean something like:

    union {
        uint64_t efer;
        uint32_t __invalid32;
        uint16_t __invalid16;
    }

It seems kind of pointless IMHO, the reason to have the union is to be able to access the registers using the native nomenclature, but if a register doesn't exist in a specific bitness I don't see the point of adding such "invalid" names.

Or your idea was to put all the bitness specific registers inside of another separate structure and then unionize them? AFAICT the 16 and 32bit structures are going to be empty.

Roger.

#67 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monné
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 13:49, <[email protected]> wrote:

El 24/07/15 a les 13.11, Andrew Cooper ha escrit:

Quoted 4 lines

To start straight in 64bit, you need gdtr and cs as a minimum

With that in mind, room for each of the task registers, and segment selectors.

I was planning to say that on both 32 and 64 bits we start with a flat GDT (like we do for the BSP).

You'd have to explain what "flat GDT" actually is. There are flat segments, but I'm unaware of flat descriptor tables.

Jan

#45 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monné
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 14:11, <[email protected]> wrote:

El 24/07/15 a les 12.46, Jan Beulich ha escrit:

Quoted 5 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 11:59, <[email protected]> wrote:
    __DECL_GP_REG(flags);

r8-r11, selector and descriptor registers, pseudo descriptor registers. Or else for all of them their default state would need to be spelled out.

r8-r15 right?

Oh - of course.

Quoted 15 lines
Quoted 6 lines
Quoted 3 lines
    /* Control registers.         */
    uint64_t cr[8];
    /* Valid on amd64 only.       */

Fields valid/useful in one mode only should probably be put in union-ized sub-structures.

Do you mean something like:

    union {
        uint64_t efer;
        uint32_t __invalid32;
        uint16_t __invalid16;
    }
Quoted 4 lines

It seems kind of pointless IMHO, the reason to have the union is to be able to access the registers using the native nomenclature, but if a register doesn't exist in a specific bitness I don't see the point of adding such "invalid" names.

No - put side by side an item valid in only a subset modes and an item only valid outside of that subset.

Quoted 3 lines

Or your idea was to put all the bitness specific registers inside of another separate structure and then unionize them? AFAICT the 16 and 32bit structures are going to be empty.

How that? 64-bit mode e.g. doesn't need full descriptor data for many of the segment registers.

Jan

#46 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

El 24/07/15 a les 14.44, Jan Beulich ha escrit:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 14:11, <[email protected]> wrote:

It seems kind of pointless IMHO, the reason to have the union is to be able to access the registers using the native nomenclature, but if a register doesn't exist in a specific bitness I don't see the point of adding such "invalid" names.

No - put side by side an item valid in only a subset modes and an item only valid outside of that subset.

OK, let me see if I got that right.

Quoted 6 lines
Quoted 3 lines

Or your idea was to put all the bitness specific registers inside of another separate structure and then unionize them? AFAICT the 16 and 32bit structures are going to be empty.

How that? 64-bit mode e.g. doesn't need full descriptor data for many of the segment registers.

Please bear with me, but AFAIK cs, ds, es and ss still need to point to a GDT entry with a 0 base and a limit of 2^64.

What about the following layout:

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Anonymous union includes 16-, 32- and 64-bit names (e.g., bp/ebp/rbp). */

# define __DECL_REG(n64, n32, n16) union {     \
        uint64_t n64;                          \
        uint32_t n32;                          \
        uint16_t n16;                          \
    }
#else
/* Non-gcc sources must always use the proper 64-bit name (e.g., rbp). */
#define __DECL_REG(n64, n32, n16) uint64_t n64
#endif

#define __DECL_GP_REG(n) __DECL_REG(r##n, e##n, n)

struct cpu_x86_16 {
    /* Control registers. */
    uint32_t cr[8];
    /* Debug registers. */
    uint32_t dr[8];
    /* GDT descriptor address. */
    uint16_t gdtr;
};
struct cpu_x86_32 {
    /* Control registers. */
    uint32_t cr[8];
    /* Debug registers. */
    uint32_t dr[8];
    /* GDT descriptor address. */
    uint32_t gdtr;
};
struct cpu_x86_64 {
    /* Additional amd64 general purpose registers. */
    uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
    /* Control registers. */
    uint64_t cr[9];
    /* Debug registers. */
    uint64_t dr[8];
    /* Extended Feature Enable Register. */
    uint64_t efer;
    /* GDT descriptor address. */
    uint64_t gdtr;
};
struct cpu_hvm_regs {
    /* General purpose registers. */
    __DECL_GP_REG(ax);
    __DECL_GP_REG(bx);
    __DECL_GP_REG(cx);
    __DECL_GP_REG(dx);

    /* Index registers. */
    __DECL_GP_REG(di);
    __DECL_GP_REG(si);

    /* Pointer registers. */
    __DECL_GP_REG(bp);
    __DECL_GP_REG(sp);

    /* Instruction pointer. */
    __DECL_GP_REG(ip);

    /* Status register. */
    __DECL_GP_REG(flags);

    /* Segment registers. */
    uint16_t cs;
    uint16_t ds;
    uint16_t es;
    uint16_t ss;
    uint16_t fs;
    uint16_t gs;

    /* Task state segment. */
    uint16_t ts;

    /* Bitness specific registers. */
    union {
        struct cpu_x86_16 x86_16;
        struct cpu_x86_32 x86_32;
        struct cpu_x86_64 x86_64;
    };
};

struct vcpu_hvm_context {
/* 16bit fields of the strucutre will be used. */
#define _VCPUHVM_MODE_16B 0
#define VCPUHVM_MODE_16B (1<<_VCPUHVM_MODE_16B)
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 1
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */
#define _VCPUHVM_MODE_64B 2
#define VCPUHVM_MODE_64B (1<<_VCPUHVM_MODE_64B)

    uint32_t flags;                         /* VCPUHVM_* flags.   */
    struct cpu_hvm_regs user_regs;          /* CPU registers.     */

};

#undef __DECL_GP_REG
#undef __DECL_REG

#68 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Jan Beulich

El 24/07/15 a les 14.41, Jan Beulich ha escrit:

Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 13:49, <[email protected]> wrote:

El 24/07/15 a les 13.11, Andrew Cooper ha escrit:

Quoted 2 lines

To start straight in 64bit, you need gdtr and cs as a minimum

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

With that in mind, room for each of the task registers, and segment selectors.

I was planning to say that on both 32 and 64 bits we start with a flat GDT (like we do for the BSP).

You'd have to explain what "flat GDT" actually is. There are flat segments, but I'm unaware of flat descriptor tables.

Yes, what I meant was that all segment registers would point to a flat segment.

Roger.

#47 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monné
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 17:26, <[email protected]> wrote:

El 24/07/15 a les 14.44, Jan Beulich ha escrit:

Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 14:11, <[email protected]> wrote:

Or your idea was to put all the bitness specific registers inside of another separate structure and then unionize them? AFAICT the 16 and 32bit structures are going to be empty.

Quoted 5 lines
Quoted 2 lines

How that? 64-bit mode e.g. doesn't need full descriptor data for many of the segment registers.

Please bear with me, but AFAIK cs, ds, es and ss still need to point to a GDT entry with a 0 base and a limit of 2^64.

No, in 64-bit mode bases are implicitly zero (with the exception of fs and gs) and limits are implicitly 2^64-1 (which you can't even express in a descriptor table entry, and with the exception of AMD's Long Mode Segment Limit extension).

But looking at the code below I see that you're thinking of selector values only, which would imply that you expect the hypervisor to actually read descriptors from the descriptor tables. That's doable, but cumbersome.

Quoted 4 lines

What about the following layout:

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Anonymous union includes 16-, 32- and 64-bit names (e.g., bp/ebp/rbp). */

Quoted 9 lines
# define __DECL_REG(n64, n32, n16) union {     \
        uint64_t n64;                          \
        uint32_t n32;                          \
        uint16_t n16;                          \
    }
#else
/* Non-gcc sources must always use the proper 64-bit name (e.g., rbp). */
#define __DECL_REG(n64, n32, n16) uint64_t n64
#endif

Since you keep repeating this, I finally have to comment on it: This is a suitable model for where we use it currently. It's imo not suitable at all here - not the least because even non-gcc users should be allowed to use just a 32-bit field when they mean one. But the problem is also that for 16- and 32-bit mode a 64-bit register is meaningless: Equally well you could expose r8-r15 to them.

Quoted 9 lines

#define __DECL_GP_REG(n) __DECL_REG(r##n, e##n, n)

struct cpu_x86_16 {
    /* Control registers. */
    uint32_t cr[8];
    /* Debug registers. */
    uint32_t dr[8];
    /* GDT descriptor address. */
    uint16_t gdtr;

Even in 16-bit mode this is a 32-bit base address. And you're omitting the limit here an below (which is a required part namely when you expect the hypervisor to access this table).

Quoted 11 lines

};

struct cpu_x86_32 {
    /* Control registers. */
    uint32_t cr[8];
    /* Debug registers. */
    uint32_t dr[8];
    /* GDT descriptor address. */
    uint32_t gdtr;
};
Quoted 5 lines
struct cpu_x86_64 {
    /* Additional amd64 general purpose registers. */
    uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
    /* Control registers. */
    uint64_t cr[9];

[16]

Quoted 8 lines
    /* Debug registers. */
    uint64_t dr[8];
    /* Extended Feature Enable Register. */
    uint64_t efer;
    /* GDT descriptor address. */
    uint64_t gdtr;
};
Quoted 14 lines
struct cpu_hvm_regs {
    /* General purpose registers. */
    __DECL_GP_REG(ax);
    __DECL_GP_REG(bx);
    __DECL_GP_REG(cx);
    __DECL_GP_REG(dx);

    /* Index registers. */
    __DECL_GP_REG(di);
    __DECL_GP_REG(si);

    /* Pointer registers. */
    __DECL_GP_REG(bp);
    __DECL_GP_REG(sp);

Now didn't you agree to use the _natural_ order (i.e. according to the numbers used to encode registers e.g. in instructions)?

Quoted 10 lines

struct vcpu_hvm_context {
/* 16bit fields of the strucutre will be used. */
#define _VCPUHVM_MODE_16B 0
#define VCPUHVM_MODE_16B (1<<_VCPUHVM_MODE_16B)
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 1
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */
#define _VCPUHVM_MODE_64B 2
#define VCPUHVM_MODE_64B (1<<_VCPUHVM_MODE_64B)

As soon as we have three values here, a boolean flag approach doesn't make sense anymore.

Jan

#48 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

El 24/07/15 a les 17.49, Jan Beulich ha escrit:

Quoted 18 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 17:26, <[email protected]> wrote:

El 24/07/15 a les 14.44, Jan Beulich ha escrit:

Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 14:11, <[email protected]> wrote:

Or your idea was to put all the bitness specific registers inside of another separate structure and then unionize them? AFAICT the 16 and 32bit structures are going to be empty.

Quoted 5 lines
Quoted 2 lines

How that? 64-bit mode e.g. doesn't need full descriptor data for many of the segment registers.

Please bear with me, but AFAIK cs, ds, es and ss still need to point to a GDT entry with a 0 base and a limit of 2^64.

No, in 64-bit mode bases are implicitly zero (with the exception of fs and gs) and limits are implicitly 2^64-1 (which you can't even express in a descriptor table entry, and with the exception of AMD's Long Mode Segment Limit extension).

Quoted 4 lines

But looking at the code below I see that you're thinking of selector values only, which would imply that you expect the hypervisor to actually read descriptors from the descriptor tables. That's doable, but cumbersome.

See the comment in the bottom of the email.

Quoted 14 lines
Quoted 4 lines

What about the following layout:

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Anonymous union includes 16-, 32- and 64-bit names (e.g., bp/ebp/rbp). */

Quoted 9 lines
# define __DECL_REG(n64, n32, n16) union {     \
        uint64_t n64;                          \
        uint32_t n32;                          \
        uint16_t n16;                          \
    }
#else
/* Non-gcc sources must always use the proper 64-bit name (e.g., rbp). */
#define __DECL_REG(n64, n32, n16) uint64_t n64
#endif
Quoted 7 lines

Since you keep repeating this, I finally have to comment on it: This is a suitable model for where we use it currently. It's imo not suitable at all here - not the least because even non-gcc users should be allowed to use just a 32-bit field when they mean one. But the problem is also that for 16- and 32-bit mode a 64-bit register is meaningless: Equally well you could expose r8-r15 to them.

Sorry, I didn't get that feeling by reading your previous comments. So you would prefer to pack everything inside of the cpu_x86_<bitness> structures?

Quoted 10 lines
Quoted 9 lines

#define __DECL_GP_REG(n) __DECL_REG(r##n, e##n, n)

struct cpu_x86_16 {
    /* Control registers. */
    uint32_t cr[8];
    /* Debug registers. */
    uint32_t dr[8];
    /* GDT descriptor address. */
    uint16_t gdtr;
Quoted 3 lines

Even in 16-bit mode this is a 32-bit base address. And you're omitting the limit here an below (which is a required part namely when you expect the hypervisor to access this table).

Well, I had in mind that this would be the memory address where the GDTR base and limit is stored, just like the one you would use with the lgdt instruction, but please read below.

Quoted 11 lines
Quoted 11 lines

};

struct cpu_x86_32 {
    /* Control registers. */
    uint32_t cr[8];
    /* Debug registers. */
    uint32_t dr[8];
    /* GDT descriptor address. */
    uint32_t gdtr;
};
Quoted 7 lines
Quoted 5 lines
struct cpu_x86_64 {
    /* Additional amd64 general purpose registers. */
    uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
    /* Control registers. */
    uint64_t cr[9];

[16]

Why 16? Intel SDM section 2.5 only mentions cr8 as newly added in amd64. TBH, I'm not sure it makes much sense to be able to set cr8 from this interface, it can always be set by the guest OS and should not be required for booting.

Quoted 19 lines
Quoted 19 lines
    /* Debug registers. */
    uint64_t dr[8];
    /* Extended Feature Enable Register. */
    uint64_t efer;
    /* GDT descriptor address. */
    uint64_t gdtr;
};
struct cpu_hvm_regs {
    /* General purpose registers. */
    __DECL_GP_REG(ax);
    __DECL_GP_REG(bx);
    __DECL_GP_REG(cx);
    __DECL_GP_REG(dx);

    /* Index registers. */
    __DECL_GP_REG(di);
    __DECL_GP_REG(si);
Quoted 6 lines
Quoted 3 lines
    /* Pointer registers. */
    __DECL_GP_REG(bp);
    __DECL_GP_REG(sp);

Now didn't you agree to use the _natural_ order (i.e. according to the numbers used to encode registers e.g. in instructions)?

OK, sorry, I didn't understand it that way. I though you only wanted them properly sorted (so a, b, c...) and labelled.

Quoted 11 lines
Quoted 10 lines

struct vcpu_hvm_context {
/* 16bit fields of the strucutre will be used. */
#define _VCPUHVM_MODE_16B 0
#define VCPUHVM_MODE_16B (1<<_VCPUHVM_MODE_16B)
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 1
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */
#define _VCPUHVM_MODE_64B 2
#define VCPUHVM_MODE_64B (1<<_VCPUHVM_MODE_64B)

Quoted 2 lines

As soon as we have three values here, a boolean flag approach doesn't make sense anymore.

Yes, taking into account that only _one_ of them can be used at the same time.

I have the feeling that we are over engineering this interface. IMHO we should only allow the user to set the control registers, efer (on amd64) and the GP registers. Segment selectors would be set by Xen to point to a flat segment suitable for the mode the guest has selected. I think that should be enough to get the guest OS into it's entry point, and then it can do whatever it wants.

If that's not suitable, then my second option would be to allow the guest to set the base, limit and AR bytes of the selectors, but not load a GDT.

Roger.

#49 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 140 lines · Roger Pau Monné

El 24/07/15 a les 17.49, Jan Beulich ha escrit:

Quoted 18 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 17:26, <[email protected]> wrote:

El 24/07/15 a les 14.44, Jan Beulich ha escrit:

Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 24.07.15 at 14:11, <[email protected]> wrote:

Or your idea was to put all the bitness specific registers inside of another separate structure and then unionize them? AFAICT the 16 and 32bit structures are going to be empty.

Quoted 5 lines
Quoted 2 lines

How that? 64-bit mode e.g. doesn't need full descriptor data for many of the segment registers.

Please bear with me, but AFAIK cs, ds, es and ss still need to point to a GDT entry with a 0 base and a limit of 2^64.

No, in 64-bit mode bases are implicitly zero (with the exception of fs and gs) and limits are implicitly 2^64-1 (which you can't even express in a descriptor table entry, and with the exception of AMD's Long Mode Segment Limit extension).

Quoted 4 lines

But looking at the code below I see that you're thinking of selector values only, which would imply that you expect the hypervisor to actually read descriptors from the descriptor tables. That's doable, but cumbersome.

See the comment in the bottom of the email.

Quoted 14 lines
Quoted 4 lines

What about the following layout:

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Anonymous union includes 16-, 32- and 64-bit names (e.g., bp/ebp/rbp). */

Quoted 9 lines
# define __DECL_REG(n64, n32, n16) union {     \
        uint64_t n64;                          \
        uint32_t n32;                          \
        uint16_t n16;                          \
    }
#else
/* Non-gcc sources must always use the proper 64-bit name (e.g., rbp). */
#define __DECL_REG(n64, n32, n16) uint64_t n64
#endif
Quoted 7 lines

Since you keep repeating this, I finally have to comment on it: This is a suitable model for where we use it currently. It's imo not suitable at all here - not the least because even non-gcc users should be allowed to use just a 32-bit field when they mean one. But the problem is also that for 16- and 32-bit mode a 64-bit register is meaningless: Equally well you could expose r8-r15 to them.

Sorry, I didn't get that feeling by reading your previous comments. So you would prefer to pack everything inside of the cpu_x86_<bitness> structures?

Quoted 10 lines
Quoted 9 lines

#define __DECL_GP_REG(n) __DECL_REG(r##n, e##n, n)

struct cpu_x86_16 {
    /* Control registers. */
    uint32_t cr[8];
    /* Debug registers. */
    uint32_t dr[8];
    /* GDT descriptor address. */
    uint16_t gdtr;
Quoted 3 lines

Even in 16-bit mode this is a 32-bit base address. And you're omitting the limit here an below (which is a required part namely when you expect the hypervisor to access this table).

Well, I had in mind that this would be the memory address where the GDTR base and limit is stored, just like the one you would use with the lgdt instruction, but please read below.

Quoted 11 lines
Quoted 11 lines

};

struct cpu_x86_32 {
    /* Control registers. */
    uint32_t cr[8];
    /* Debug registers. */
    uint32_t dr[8];
    /* GDT descriptor address. */
    uint32_t gdtr;
};
Quoted 7 lines
Quoted 5 lines
struct cpu_x86_64 {
    /* Additional amd64 general purpose registers. */
    uint64_t r8, r9, r10, r11, r12, r13, r14, r15;
    /* Control registers. */
    uint64_t cr[9];

[16]

Why 16? Intel SDM section 2.5 only mentions cr8 as newly added in amd64. TBH, I'm not sure it makes much sense to be able to set cr8 from this interface, it can always be set by the guest OS and should not be required for booting.

Quoted 19 lines
Quoted 19 lines
    /* Debug registers. */
    uint64_t dr[8];
    /* Extended Feature Enable Register. */
    uint64_t efer;
    /* GDT descriptor address. */
    uint64_t gdtr;
};
struct cpu_hvm_regs {
    /* General purpose registers. */
    __DECL_GP_REG(ax);
    __DECL_GP_REG(bx);
    __DECL_GP_REG(cx);
    __DECL_GP_REG(dx);

    /* Index registers. */
    __DECL_GP_REG(di);
    __DECL_GP_REG(si);
Quoted 6 lines
Quoted 3 lines
    /* Pointer registers. */
    __DECL_GP_REG(bp);
    __DECL_GP_REG(sp);

Now didn't you agree to use the _natural_ order (i.e. according to the numbers used to encode registers e.g. in instructions)?

OK, sorry, I didn't understand it that way. I though you only wanted them properly sorted (so a, b, c...) and labelled.

Quoted 11 lines
Quoted 10 lines

struct vcpu_hvm_context {
/* 16bit fields of the strucutre will be used. */
#define _VCPUHVM_MODE_16B 0
#define VCPUHVM_MODE_16B (1<<_VCPUHVM_MODE_16B)
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 1
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */
#define _VCPUHVM_MODE_64B 2
#define VCPUHVM_MODE_64B (1<<_VCPUHVM_MODE_64B)

Quoted 2 lines

As soon as we have three values here, a boolean flag approach doesn't make sense anymore.

Yes, taking into account that only _one_ of them can be used at the same time.

Quoted 6 lines

I have the feeling that we are over engineering this interface. IMHO we should only allow the user to set the control registers, efer (on amd64) and the GP registers. Segment selectors would be set by Xen to point to a flat segment suitable for the mode the guest has selected. I think that should be enough to get the guest OS into it's entry point, and then it can do whatever it wants.

If you are doing that why not use the old interface?

Quoted 4 lines

If that's not suitable, then my second option would be to allow the guest to set the base, limit and AR bytes of the selectors, but not load a GDT.

They should be able to do any of those operations as a normal HVM guest I would think?

Quoted 2 lines

Roger.

#15 lore raw

Re: [PATCH v3 05/32] libxc: make arch_setup_meminit a xc_dom_arch hook

In reply to Andrew Cooper

El 06/07/15 a les 14.23, Andrew Cooper ha escrit:

Quoted 10 lines · Roger Pau Monne
Quoted 8 lines

This allows having different arch_setup_meminit implementations based on the guest type. It should not introduce any functional changes.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Quoted 6 lines

However, would you mind doing a cleanup patch which changes the use of __init. Confusingly given its precedent in hypervisor code, xc_dom.h has "#define __init __attribute__ ((constructor))". At a first guess, 'initcall' or even just 'constructor' would be more appropriate names.

Iff you don't mind, I would rather do that after this series. I'm already carrying a non-trivial amount of patches, and doing something like this in the middle of the series would be hard to maintain rebase wise.

Roger.

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

#50 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Konrad Rzeszutek Wilk

El 24/07/15 a les 19.36, Konrad Rzeszutek Wilk ha escrit:

Quoted 9 lines · Roger Pau Monné
Quoted 6 lines

I have the feeling that we are over engineering this interface. IMHO we should only allow the user to set the control registers, efer (on amd64) and the GP registers. Segment selectors would be set by Xen to point to a flat segment suitable for the mode the guest has selected. I think that should be enough to get the guest OS into it's entry point, and then it can do whatever it wants.

If you are doing that why not use the old interface?

Because the current structure contains quite a lot of PV fields, like the failsafe_callback, the GDT... Also the old structure is limited in a way that you can only use the x86-<bitness> format if your kernel is compiled with <bitness>, and we want to allow the vCPU to start in any mode, regardless of the mode the kernel is compiled with.

Quoted 7 lines
Quoted 4 lines

If that's not suitable, then my second option would be to allow the guest to set the base, limit and AR bytes of the selectors, but not load a GDT.

They should be able to do any of those operations as a normal HVM guest I would think?

Yes, hence I would like to limit setting anything that's not essential to boot.

Acked-by on v3 1/32
#3 lore raw

Re: [PATCH v3 01/32] libxc: split x86 HVM setup_guest into smaller logical functions

In reply to Roger Pau Monne
Quoted 8 lines · Roger Pau Monne

This is just a preparatory change to clean up the code in setup_guest. Should not introduce any functional changes.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Acked-by on v3 2/32
#6 lore raw

Re: [PATCH v3 02/32] libxc: unify xc_dom_p2m_{host/guest}

In reply to Roger Pau Monne
Quoted 9 lines · Roger Pau Monne

Unify both functions into xc_dom_p2m. Should not introduce any functional change.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Samuel Thibault <[email protected]>
Acked-by on v3 3/32
#9 lore raw

Re: [PATCH v3 03/32] libxc: introduce the notion of a container type

In reply to Roger Pau Monne
Quoted 9 lines · Roger Pau Monne

Introduce the notion of a container type into xc_dom_image. This will be needed by later changes that will also use xc_dom_image in order to build HVM guests.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Acked-by on v3 5/32
#16 lore raw

Re: [PATCH v3 05/32] libxc: make arch_setup_meminit a xc_dom_arch hook

In reply to Roger Pau Monne
Quoted 8 lines · Roger Pau Monne

This allows having different arch_setup_meminit implementations based on the guest type. It should not introduce any functional changes.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Acked-by on v3 4/32
#12 lore raw

Re: [PATCH v3 04/32] libxc: introduce a domain loader for HVM guest firmware

In reply to Roger Pau Monne
Quoted 9 lines · Roger Pau Monne

Introduce a very simple (and dummy) domain loader to be used to load the firmware (hvmloader) into HVM guests. Since hmvloader is just a 32bit elf executable the loader is fairly simple.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Acked-by on v3 6/32
#19 lore raw

Re: [PATCH v3 06/32] libxc: make arch_setup_boot{init/late} xc_dom_arch hooks

In reply to Roger Pau Monne
Quoted 7 lines · Roger Pau Monne

This should not introduce any functional change.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Quoted 26 lines

---

tools/libxc/xc_dom_x86.c +24 -0
+/* ------------------------------------------------------------------------ */
+
+static struct xc_dom_arch xc_dom_32_pae = {
+    .guest_type = "xen-3.0-x86_32p",
+    .native_protocol = XEN_IO_PROTO_ABI_X86_32,
+    .page_shift = PAGE_SHIFT_X86,
+    .sizeof_pfn = 4,
+    .alloc_magic_pages = alloc_magic_pages,
+    .count_pgtables = count_pgtables_x86_32_pae,
+    .setup_pgtables = setup_pgtables_x86_32_pae,
+    .start_info = start_info_x86_32,
+    .shared_info = shared_info_x86_32,
+    .vcpu = vcpu_x86_32,
+    .meminit = meminit_pv,
+    .bootearly = bootearly,
+    .bootlate = bootlate_pv,
+};
+
+static struct xc_dom_arch xc_dom_64 = {
+    .guest_type = "xen-3.0-x86_64",
+    .native_protocol = XEN_IO_PROTO_ABI_X86_64,
+    .page_shift = PAGE_SHIFT_X86,
+    .sizeof_pfn = 8,
+    .alloc_magic_pages = alloc_magic_pages,

tools/libxc/xc_dom_x86.c int arch_setup_bootlate(struct xc_dom_image *dom) · line 1074

Quoted 10 lines
tools/libxc/xc_dom_x86.c +10 -0
+    .count_pgtables = count_pgtables_x86_64,
+    .setup_pgtables = setup_pgtables_x86_64,
+    .start_info = start_info_x86_64,
+    .shared_info = shared_info_x86_64,
+    .vcpu = vcpu_x86_64,
+    .meminit = meminit_pv,
+    .bootearly = bootearly,
+    .bootlate = bootlate_pv,
+};
+

One thing I notice in this series is that these hunks are moved repeatedly in patches. Might be worth moving them right to the end / only adding new functions before them to reduce patch size.

Just an observation. Not a blocker for this series though. If it turns out hard to do just ignore that comment.

Quoted 11 lines
tools/libxc/xc_dom_x86.c +6 -0
+static void __init register_arch_hooks(void)
+{
+    xc_dom_register_arch_hooks(&xc_dom_32_pae);
+    xc_dom_register_arch_hooks(&xc_dom_64);
+}
+
 int xc_dom_feature_translated(struct xc_dom_image *dom)
 {
     /* Guests running inside HVM containers are always auto-translated. */
Signature · 1 line
1.9.5 (Apple Git-50.3)
#72 lore raw

Re: [PATCH v3 09/32] libxl: switch HVM domain building to use xc_dom_* helpers

In reply to Roger Pau Monne
Quoted 9 lines · Roger Pau Monne

Now that we have all the code in place HVM domain building in libxl can be switched to use the xc_dom_* family of functions, just like they are used in order to build PV guests.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>

Mostly looks good. Some nits below.

Quoted 11 lines
---
 tools/libxl/libxl_dom.c      | 224 +++++++++++++++++++++++++------------------
 tools/libxl/libxl_internal.h |   2 +-
 tools/libxl/libxl_vnuma.c    |  12 ++-
 3 files changed, 139 insertions(+), 99 deletions(-)
tools/libxl/libxl_dom.c +0 -0
index 2bae277..480b7e7 100644

tools/libxl/libxl_dom.c static int set_vnuma_info(libxl__gc *gc, uint32_t domid, · line 616

Quoted 8 lines
tools/libxl/libxl_dom.c +5 -0
@@ -609,6 +609,64 @@ static int set_vnuma_info(libxl__gc *gc, uint32_t domid,
     return rc;
 }
 
+static int libxl__build_dom(libxl__gc *gc, uint32_t domid,
+             libxl_domain_build_info *info, libxl__domain_build_state *state,
+             struct xc_dom_image *dom)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);

No need to have this line.

Quoted 41 lines
tools/libxl/libxl_dom.c +41 -0
+    uint64_t mem_kb;
+    int ret;
+
+    if ( (ret = xc_dom_boot_xen_init(dom, ctx->xch, domid)) != 0 ) {
+        LOGE(ERROR, "xc_dom_boot_xen_init failed");
+        goto out;
+    }
+#ifdef GUEST_RAM_BASE
+    if ( (ret = xc_dom_rambase_init(dom, GUEST_RAM_BASE)) != 0 ) {
+        LOGE(ERROR, "xc_dom_rambase failed");
+        goto out;
+    }
+#endif
+    if ( (ret = xc_dom_parse_image(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_parse_image failed");
+        goto out;
+    }
+    if ( (ret = libxl__arch_domain_init_hw_description(gc, info, state, dom)) != 0 ) {
+        LOGE(ERROR, "libxl__arch_domain_init_hw_description failed");
+        goto out;
+    }
+
+    mem_kb = dom->container_type == XC_DOM_HVM_CONTAINER ?
+             (info->max_memkb - info->video_memkb) : info->target_memkb;
+    if ( (ret = xc_dom_mem_init(dom, mem_kb / 1024)) != 0 ) {
+        LOGE(ERROR, "xc_dom_mem_init failed");
+        goto out;
+    }
+    if ( (ret = xc_dom_boot_mem_init(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_boot_mem_init failed");
+        goto out;
+    }
+    if ( (ret = libxl__arch_domain_finalise_hw_description(gc, info, dom)) != 0 ) {
+        LOGE(ERROR, "libxl__arch_domain_finalise_hw_description failed");
+        goto out;
+    }
+    if ( (ret = xc_dom_build_image(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_build_image failed");
+        goto out;
+    }
+    if ( (ret = xc_dom_boot_image(dom)) != 0 ) {

tools/libxl/libxl_dom.c static int set_vnuma_info(libxl__gc *gc, uint32_t domid, · line 667

Quoted 10 lines
tools/libxl/libxl_dom.c +10 -0
+        LOGE(ERROR, "xc_dom_boot_image failed");
+        goto out;
+    }
+    if ( (ret = xc_dom_gnttab_init(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_gnttab_init failed");
+        goto out;
+    }
+
+out:
+    return ret;

Please translate libxc error code to libxl error code.

Quoted 9 lines
tools/libxl/libxl_dom.c +2 -0
+}
+
 int libxl__build_pv(libxl__gc *gc, uint32_t domid,
              libxl_domain_build_info *info, libxl__domain_build_state *state)
 {
@@ -699,48 +757,9 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
             dom->vnode_to_pnode[i] = info->vnuma_nodes[i].pnode;
     }
 

[...]

tools/libxl/libxl_dom.c int libxl__build_hvm(libxl__gc *gc, uint32_t domid, · line 946

Quoted 10 lines
     }
tools/libxl/libxl_dom.c +1 -3
@@ -919,50 +943,60 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
               libxl__domain_build_state *state)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
-    struct xc_hvm_build_args args = {};
-    int ret, rc = ERROR_FAIL;
-    uint64_t mmio_start, lowmem_end, highmem_end;
+    int ret;

This should be rc.

Wei.

#94 lore raw

Re: [PATCH v3 23/32] libxc: allow creating domains without emulated devices.

In reply to Roger Pau Monne
Quoted 21 lines · Roger Pau Monne

Introduce a new flag in xc_dom_image that turns on and off the emulated devices. This prevents creating the VGA hole, the hvm_info page and the ioreq server pages. libxl unconditionally sets it to true for all HVM domains at the moment.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxc/include/xc_dom.h |  1 +
 tools/libxc/xc_dom_x86.c     | 71 +++++++++++++++++++++++++-------------------
 tools/libxl/libxl_dom.c      |  1 +
 3 files changed, 42 insertions(+), 31 deletions(-)
tools/libxc/include/xc_dom.h +0 -0
index 68b052c..7086f6e 100644

tools/libxc/include/xc_dom.h struct xc_dom_image { · line 198

Quoted 5 lines
tools/libxc/include/xc_dom.h +1 -0
@@ -194,6 +194,7 @@ struct xc_dom_image {
     xen_pfn_t mmio_size;
     xen_pfn_t lowmem_end;
     xen_pfn_t highmem_end;
+    bool emulation;
 

Can you document what this flag enables / disables?

Wei.

#113 lore raw

Re: [PATCH v3 32/32] libxl: allow the creation of HVM domains without a device model.

In reply to Roger Pau Monne
Quoted 45 lines · Roger Pau Monne

Replace the firmware loaded into HVM guests with an OS kernel. Since the HVM builder now uses the PV xc_dom_* set of functions this kernel will be parsed and loaded inside the guest like on PV, but the container is a pure HVM guest.

Also, if device_model_version is set to none unconditinally set the nic type to LIBXL_NIC_TYPE_VIF.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 docs/man/xl.cfg.pod.5       |  5 ++++
 tools/libxl/libxl.c         |  7 +++---
 tools/libxl/libxl_create.c  | 18 ++++++++++++++
 tools/libxl/libxl_dom.c     | 60 ++++++++++++++++++++++++++++++---------------
 tools/libxl/libxl_types.idl |  1 +
 tools/libxl/libxl_x86.c     |  4 ++-
 tools/libxl/xl_cmdimpl.c    |  2 ++
 7 files changed, 72 insertions(+), 25 deletions(-)
docs/man/xl.cfg.pod.5 +5 -0
index a3e0e2e..1270605 100644
@@ -1631,6 +1631,11 @@ This device-model is the default for Linux dom0.
 Use the device-model based upon the historical Xen fork of Qemu.
 This device-model is still the default for NetBSD dom0.
 
+=item B<none>
+
+Don't use any device model. This requires a kernel capable of booting
+in this mode.
+
 =back
 
 It is recommended to accept the default value for new guests.  If
tools/libxl/libxl.c +0 -0
index e9a2d26..a6690cf 100644
@@ -1590,11 +1590,10 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis)
 

tools/libxl/libxl.c void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis) · line 1596

Quoted 10 lines
tools/libxl/libxl.c +3 -4
     switch (libxl__domain_type(gc, domid)) {
     case LIBXL_DOMAIN_TYPE_HVM:
-        if (!libxl_get_stubdom_id(CTX, domid))
-            dm_present = 1;
-        else
+        if (libxl_get_stubdom_id(CTX, domid)) {
             dm_present = 0;
-        break;
+            break;
+        }

There is a path that dm_present contains garbage.

Quoted 36 lines
tools/libxl/libxl.c +0 -0
     case LIBXL_DOMAIN_TYPE_PV:
         pid = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "/local/domain/%d/image/device-model-pid", domid));
         dm_present = (pid != NULL);
tools/libxl/libxl_create.c +7 -0
index f366a09..1444e40 100644
@@ -164,6 +164,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
                 b_info->u.hvm.bios = LIBXL_BIOS_TYPE_ROMBIOS; break;
             case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
                 b_info->u.hvm.bios = LIBXL_BIOS_TYPE_SEABIOS; break;
+            case LIBXL_DEVICE_MODEL_VERSION_NONE:
+                break;
             default:return ERROR_INVAL;
             }
 
@@ -177,6 +179,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
             if (b_info->u.hvm.bios == LIBXL_BIOS_TYPE_ROMBIOS)
                 return ERROR_INVAL;
             break;
+        case LIBXL_DEVICE_MODEL_VERSION_NONE:
+            break;
         default:abort();
         }
 
@@ -278,6 +282,9 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
                 break;
             }
             break;
+        case LIBXL_DEVICE_MODEL_VERSION_NONE:
+            b_info->video_memkb = 0;
+            break;
         case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
         default:
             switch (b_info->u.hvm.vga.kind) {

tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 959

Quoted 8 lines
tools/libxl/libxl_create.c +5 -0
@@ -945,6 +952,11 @@ static void initiate_domain_create(libxl__egc *egc,
         ret = libxl__device_nic_setdefault(gc, &d_config->nics[i], domid);
         if (ret) goto error_out;
 
+        /* HVM guests without a device model only have PV nics. */
+        if (d_config->b_info.device_model_version ==
+            LIBXL_DEVICE_MODEL_VERSION_NONE)
+            d_config->nics[i].nictype = LIBXL_NIC_TYPE_VIF;
+

Better to check if users have asked for emulated NIC and bail.

Quoted 30 lines
tools/libxl/libxl_create.c +6 -0
         if (d_config->nics[i].devid > last_devid)
             last_devid = d_config->nics[i].devid;
     }
@@ -1293,6 +1305,12 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
         libxl__device_console_add(gc, domid, &console, state, &device);
         libxl__device_console_dispose(&console);
 
+        if (d_config->b_info.device_model_version ==
+            LIBXL_DEVICE_MODEL_VERSION_NONE) {
+            domcreate_devmodel_started(egc, &dcs->dmss.dm, 0);
+            return;
+        }
+
         libxl_device_vkb_init(&vkb);
         libxl__device_vkb_add(gc, domid, &vkb);
         libxl_device_vkb_dispose(&vkb);
tools/libxl/libxl_dom.c +0 -6
index 6ce4115..59854a1 100644
@@ -789,21 +789,23 @@ static int hvm_build_set_params(xc_interface *handle, uint32_t domid,
     uint64_t str_mfn, cons_mfn;
     int i;
 
-    va_map = xc_map_foreign_range(handle, domid,
-                                  XC_PAGE_SIZE, PROT_READ | PROT_WRITE,
-                                  HVM_INFO_PFN);
-    if (va_map == NULL)
-        return -1;
-

tools/libxl/libxl_dom.c static int hvm_build_set_params(xc_interface *handle, uint32_t domid, · line 792

Quoted 10 lines
tools/libxl/libxl_dom.c +1 -9
-    va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
-    va_hvm->apic_mode = libxl_defbool_val(info->u.hvm.apic);
-    va_hvm->nr_vcpus = info->max_vcpus;
-    memset(va_hvm->vcpu_online, 0, sizeof(va_hvm->vcpu_online));
-    memcpy(va_hvm->vcpu_online, info->avail_vcpus.map, info->avail_vcpus.size);
-    for (i = 0, sum = 0; i < va_hvm->length; i++)
-        sum += ((uint8_t *) va_hvm)[i];
-    va_hvm->checksum -= sum;
-    munmap(va_map, XC_PAGE_SIZE);
+    if ( info->device_model_version != LIBXL_DEVICE_MODEL_VERSION_NONE) {

Stray space.

Quoted 20 lines
tools/libxl/libxl_dom.c +16 -0
+        va_map = xc_map_foreign_range(handle, domid,
+                                      XC_PAGE_SIZE, PROT_READ | PROT_WRITE,
+                                      HVM_INFO_PFN);
+        if (va_map == NULL)
+            return -1;
+
+        va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
+        va_hvm->apic_mode = libxl_defbool_val(info->u.hvm.apic);
+        va_hvm->nr_vcpus = info->max_vcpus;
+        memset(va_hvm->vcpu_online, 0, sizeof(va_hvm->vcpu_online));
+        memcpy(va_hvm->vcpu_online, info->avail_vcpus.map, info->avail_vcpus.size);
+        for (i = 0, sum = 0; i < va_hvm->length; i++)
+            sum += ((uint8_t *) va_hvm)[i];
+        va_hvm->checksum -= sum;
+        munmap(va_map, XC_PAGE_SIZE);
+    }
 
     xc_hvm_param_get(handle, domid, HVM_PARAM_STORE_PFN, &str_mfn);
     xc_hvm_param_get(handle, domid, HVM_PARAM_CONSOLE_PFN, &cons_mfn);

tools/libxl/libxl_dom.c static int libxl__domain_firmware(libxl__gc *gc, · line 892

Quoted 7 lines
tools/libxl/libxl_dom.c +4 -0
@@ -884,6 +886,12 @@ static int libxl__domain_firmware(libxl__gc *gc,
         case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
             firmware = "hvmloader";
             break;
+        case LIBXL_DEVICE_MODEL_VERSION_NONE:
+            if (info->kernel == NULL) {
+                LOG(ERROR, "no device model requested without a kernel");
+                return ERROR_FAIL;

goto out

Maybe fix the other return as well...

Wei.

#73 lore raw

Re: [PATCH v3 09/32] libxl: switch HVM domain building to use xc_dom_* helpers

In reply to Wei Liu

El 28/07/15 a les 13.22, Wei Liu ha escrit:

Quoted 5 lines · Roger Pau Monne
Quoted 4 lines

Now that we have all the code in place HVM domain building in libxl can be switched to use the xc_dom_* family of functions, just like they are used in order to build PV guests.

Quoted 7 lines
Quoted 5 lines
Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>

Mostly looks good. Some nits below.

Thanks for the review.

Quoted 14 lines
Quoted 14 lines
---
 tools/libxl/libxl_dom.c      | 224 +++++++++++++++++++++++++------------------
 tools/libxl/libxl_internal.h |   2 +-
 tools/libxl/libxl_vnuma.c    |  12 ++-
 3 files changed, 139 insertions(+), 99 deletions(-)
tools/libxl/libxl_dom.c +0 -0
index 2bae277..480b7e7 100644
@@ -609,6 +609,64 @@ static int set_vnuma_info(libxl__gc *gc, uint32_t domid,
     return rc;
 }
 
Quoted 7 lines

tools/libxl/libxl_dom.c static int set_vnuma_info(libxl__gc *gc, uint32_t domid, · line 616

Quoted 5 lines
tools/libxl/libxl_dom.c +5 -0
+static int libxl__build_dom(libxl__gc *gc, uint32_t domid,
+             libxl_domain_build_info *info, libxl__domain_build_state *state,
+             struct xc_dom_image *dom)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);

No need to have this line.

But ctx is needed...

Quoted 4 lines

tools/libxl/libxl_dom.c static int set_vnuma_info(libxl__gc *gc, uint32_t domid, · line 620

Quoted 4 lines
tools/libxl/libxl_dom.c +4 -0
+    uint64_t mem_kb;
+    int ret;
+
+    if ( (ret = xc_dom_boot_xen_init(dom, ctx->xch, domid)) != 0 ) {
                                              ^ here.
Quoted 41 lines
Quoted 41 lines
tools/libxl/libxl_dom.c +41 -0
+        LOGE(ERROR, "xc_dom_boot_xen_init failed");
+        goto out;
+    }
+#ifdef GUEST_RAM_BASE
+    if ( (ret = xc_dom_rambase_init(dom, GUEST_RAM_BASE)) != 0 ) {
+        LOGE(ERROR, "xc_dom_rambase failed");
+        goto out;
+    }
+#endif
+    if ( (ret = xc_dom_parse_image(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_parse_image failed");
+        goto out;
+    }
+    if ( (ret = libxl__arch_domain_init_hw_description(gc, info, state, dom)) != 0 ) {
+        LOGE(ERROR, "libxl__arch_domain_init_hw_description failed");
+        goto out;
+    }
+
+    mem_kb = dom->container_type == XC_DOM_HVM_CONTAINER ?
+             (info->max_memkb - info->video_memkb) : info->target_memkb;
+    if ( (ret = xc_dom_mem_init(dom, mem_kb / 1024)) != 0 ) {
+        LOGE(ERROR, "xc_dom_mem_init failed");
+        goto out;
+    }
+    if ( (ret = xc_dom_boot_mem_init(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_boot_mem_init failed");
+        goto out;
+    }
+    if ( (ret = libxl__arch_domain_finalise_hw_description(gc, info, dom)) != 0 ) {
+        LOGE(ERROR, "libxl__arch_domain_finalise_hw_description failed");
+        goto out;
+    }
+    if ( (ret = xc_dom_build_image(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_build_image failed");
+        goto out;
+    }
+    if ( (ret = xc_dom_boot_image(dom)) != 0 ) {
+        LOGE(ERROR, "xc_dom_boot_image failed");
+        goto out;
+    }
+    if ( (ret = xc_dom_gnttab_init(dom)) != 0 ) {
Quoted 8 lines

tools/libxl/libxl_dom.c static int set_vnuma_info(libxl__gc *gc, uint32_t domid, · line 667

Quoted 6 lines
tools/libxl/libxl_dom.c +6 -0
+        LOGE(ERROR, "xc_dom_gnttab_init failed");
+        goto out;
+    }
+
+out:
+    return ret;

Please translate libxc error code to libxl error code.

Done, I have however just done:

return ret != 0 ? ERROR_FAIL : 0;

Not sure if we need/want a more complex error code translation here.

Quoted 12 lines
Quoted 9 lines
tools/libxl/libxl_dom.c +2 -0
+}
+
 int libxl__build_pv(libxl__gc *gc, uint32_t domid,
              libxl_domain_build_info *info, libxl__domain_build_state *state)
 {
@@ -699,48 +757,9 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,
             dom->vnode_to_pnode[i] = info->vnuma_nodes[i].pnode;
     }
 

[...]

Quoted 2 lines
     }
Quoted 10 lines

tools/libxl/libxl_dom.c int libxl__build_hvm(libxl__gc *gc, uint32_t domid, · line 946

Quoted 8 lines
tools/libxl/libxl_dom.c +1 -3
@@ -919,50 +943,60 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
               libxl__domain_build_state *state)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
-    struct xc_hvm_build_args args = {};
-    int ret, rc = ERROR_FAIL;
-    uint64_t mmio_start, lowmem_end, highmem_end;
+    int ret;

This should be rc.

Right, we don't call any libxc functions directly any longer, so only rc should be used.

Roger.

#74 lore raw

Re: [PATCH v3 09/32] libxl: switch HVM domain building to use xc_dom_* helpers

Quoted 38 lines · Roger Pau Monné

El 28/07/15 a les 13.22, Wei Liu ha escrit:

Quoted 5 lines · Roger Pau Monne
Quoted 4 lines

Now that we have all the code in place HVM domain building in libxl can be switched to use the xc_dom_* family of functions, just like they are used in order to build PV guests.

Quoted 7 lines
Quoted 5 lines
Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>

Mostly looks good. Some nits below.

Thanks for the review.

Quoted 14 lines
Quoted 14 lines
---
 tools/libxl/libxl_dom.c      | 224 +++++++++++++++++++++++++------------------
 tools/libxl/libxl_internal.h |   2 +-
 tools/libxl/libxl_vnuma.c    |  12 ++-
 3 files changed, 139 insertions(+), 99 deletions(-)
tools/libxl/libxl_dom.c +0 -0
index 2bae277..480b7e7 100644
@@ -609,6 +609,64 @@ static int set_vnuma_info(libxl__gc *gc, uint32_t domid,
     return rc;
 }
 
Quoted 7 lines

tools/libxl/libxl_dom.c static int set_vnuma_info(libxl__gc *gc, uint32_t domid, · line 616

Quoted 5 lines
tools/libxl/libxl_dom.c +5 -0
+static int libxl__build_dom(libxl__gc *gc, uint32_t domid,
+             libxl_domain_build_info *info, libxl__domain_build_state *state,
+             struct xc_dom_image *dom)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);

No need to have this line.

Quoted 7 lines

But ctx is needed...

Quoted 4 lines

tools/libxl/libxl_dom.c static int set_vnuma_info(libxl__gc *gc, uint32_t domid, · line 620

Quoted 4 lines
tools/libxl/libxl_dom.c +4 -0
+    uint64_t mem_kb;
+    int ret;
+
+    if ( (ret = xc_dom_boot_xen_init(dom, ctx->xch, domid)) != 0 ) {
                                              ^ here.

Use CTX macro here. Sorry I missed this.

Wei.

#114 lore raw

Re: [PATCH v3 32/32] libxl: allow the creation of HVM domains without a device model.

In reply to Wei Liu

El 28/07/15 a les 13.22, Wei Liu ha escrit:

Quoted 46 lines · Roger Pau Monne
Quoted 45 lines

Replace the firmware loaded into HVM guests with an OS kernel. Since the HVM builder now uses the PV xc_dom_* set of functions this kernel will be parsed and loaded inside the guest like on PV, but the container is a pure HVM guest.

Also, if device_model_version is set to none unconditinally set the nic type to LIBXL_NIC_TYPE_VIF.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 docs/man/xl.cfg.pod.5       |  5 ++++
 tools/libxl/libxl.c         |  7 +++---
 tools/libxl/libxl_create.c  | 18 ++++++++++++++
 tools/libxl/libxl_dom.c     | 60 ++++++++++++++++++++++++++++++---------------
 tools/libxl/libxl_types.idl |  1 +
 tools/libxl/libxl_x86.c     |  4 ++-
 tools/libxl/xl_cmdimpl.c    |  2 ++
 7 files changed, 72 insertions(+), 25 deletions(-)
docs/man/xl.cfg.pod.5 +5 -0
index a3e0e2e..1270605 100644
@@ -1631,6 +1631,11 @@ This device-model is the default for Linux dom0.
 Use the device-model based upon the historical Xen fork of Qemu.
 This device-model is still the default for NetBSD dom0.
 
+=item B<none>
+
+Don't use any device model. This requires a kernel capable of booting
+in this mode.
+
 =back
 
 It is recommended to accept the default value for new guests.  If
tools/libxl/libxl.c +0 -0
index e9a2d26..a6690cf 100644
@@ -1590,11 +1590,10 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis)
 
Quoted 12 lines

tools/libxl/libxl.c void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis) · line 1596

Quoted 10 lines
tools/libxl/libxl.c +3 -4
     switch (libxl__domain_type(gc, domid)) {
     case LIBXL_DOMAIN_TYPE_HVM:
-        if (!libxl_get_stubdom_id(CTX, domid))
-            dm_present = 1;
-        else
+        if (libxl_get_stubdom_id(CTX, domid)) {
             dm_present = 0;
-        break;
+            break;
+        }

There is a path that dm_present contains garbage.

Please take into account that I've removed the last break in LIBXL_DOMAIN_TYPE_HVM, so now the LIBXL_DOMAIN_TYPE_HVM case expands into the LIBXL_DOMAIN_TYPE_PV case.

Quoted 3 lines

tools/libxl/libxl.c void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis) · line 1599

Quoted 3 lines
tools/libxl/libxl.c +0 -0
     case LIBXL_DOMAIN_TYPE_PV:
         pid = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "/local/domain/%d/image/device-model-pid", domid));
         dm_present = (pid != NULL);

dm_present is set here for both PV and HVM guests without a stubdom.

Quoted 36 lines
Quoted 36 lines
tools/libxl/libxl_create.c +7 -0
index f366a09..1444e40 100644
@@ -164,6 +164,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
                 b_info->u.hvm.bios = LIBXL_BIOS_TYPE_ROMBIOS; break;
             case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
                 b_info->u.hvm.bios = LIBXL_BIOS_TYPE_SEABIOS; break;
+            case LIBXL_DEVICE_MODEL_VERSION_NONE:
+                break;
             default:return ERROR_INVAL;
             }
 
@@ -177,6 +179,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
             if (b_info->u.hvm.bios == LIBXL_BIOS_TYPE_ROMBIOS)
                 return ERROR_INVAL;
             break;
+        case LIBXL_DEVICE_MODEL_VERSION_NONE:
+            break;
         default:abort();
         }
 
@@ -278,6 +282,9 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
                 break;
             }
             break;
+        case LIBXL_DEVICE_MODEL_VERSION_NONE:
+            b_info->video_memkb = 0;
+            break;
         case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
         default:
             switch (b_info->u.hvm.vga.kind) {
@@ -945,6 +952,11 @@ static void initiate_domain_create(libxl__egc *egc,
         ret = libxl__device_nic_setdefault(gc, &d_config->nics[i], domid);
         if (ret) goto error_out;
 
Quoted 7 lines

tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 959

Quoted 5 lines
tools/libxl/libxl_create.c +5 -0
+        /* HVM guests without a device model only have PV nics. */
+        if (d_config->b_info.device_model_version ==
+            LIBXL_DEVICE_MODEL_VERSION_NONE)
+            d_config->nics[i].nictype = LIBXL_NIC_TYPE_VIF;
+

Better to check if users have asked for emulated NIC and bail.

IMHO, I think it would be better to move this to libxl__device_nic_setdefault and I will do so in the next version.

Quoted 73 lines
Quoted 30 lines
tools/libxl/libxl_create.c +6 -0
         if (d_config->nics[i].devid > last_devid)
             last_devid = d_config->nics[i].devid;
     }
@@ -1293,6 +1305,12 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
         libxl__device_console_add(gc, domid, &console, state, &device);
         libxl__device_console_dispose(&console);
 
+        if (d_config->b_info.device_model_version ==
+            LIBXL_DEVICE_MODEL_VERSION_NONE) {
+            domcreate_devmodel_started(egc, &dcs->dmss.dm, 0);
+            return;
+        }
+
         libxl_device_vkb_init(&vkb);
         libxl__device_vkb_add(gc, domid, &vkb);
         libxl_device_vkb_dispose(&vkb);
tools/libxl/libxl_dom.c +0 -6
index 6ce4115..59854a1 100644
@@ -789,21 +789,23 @@ static int hvm_build_set_params(xc_interface *handle, uint32_t domid,
     uint64_t str_mfn, cons_mfn;
     int i;
 
-    va_map = xc_map_foreign_range(handle, domid,
-                                  XC_PAGE_SIZE, PROT_READ | PROT_WRITE,
-                                  HVM_INFO_PFN);
-    if (va_map == NULL)
-        return -1;
-

tools/libxl/libxl_dom.c static int hvm_build_set_params(xc_interface *handle, uint32_t domid, · line 792

Quoted 10 lines
tools/libxl/libxl_dom.c +1 -9
-    va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
-    va_hvm->apic_mode = libxl_defbool_val(info->u.hvm.apic);
-    va_hvm->nr_vcpus = info->max_vcpus;
-    memset(va_hvm->vcpu_online, 0, sizeof(va_hvm->vcpu_online));
-    memcpy(va_hvm->vcpu_online, info->avail_vcpus.map, info->avail_vcpus.size);
-    for (i = 0, sum = 0; i < va_hvm->length; i++)
-        sum += ((uint8_t *) va_hvm)[i];
-    va_hvm->checksum -= sum;
-    munmap(va_map, XC_PAGE_SIZE);
+    if ( info->device_model_version != LIBXL_DEVICE_MODEL_VERSION_NONE) {

Stray space.

Quoted 20 lines
tools/libxl/libxl_dom.c +16 -0
+        va_map = xc_map_foreign_range(handle, domid,
+                                      XC_PAGE_SIZE, PROT_READ | PROT_WRITE,
+                                      HVM_INFO_PFN);
+        if (va_map == NULL)
+            return -1;
+
+        va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
+        va_hvm->apic_mode = libxl_defbool_val(info->u.hvm.apic);
+        va_hvm->nr_vcpus = info->max_vcpus;
+        memset(va_hvm->vcpu_online, 0, sizeof(va_hvm->vcpu_online));
+        memcpy(va_hvm->vcpu_online, info->avail_vcpus.map, info->avail_vcpus.size);
+        for (i = 0, sum = 0; i < va_hvm->length; i++)
+            sum += ((uint8_t *) va_hvm)[i];
+        va_hvm->checksum -= sum;
+        munmap(va_map, XC_PAGE_SIZE);
+    }
 
     xc_hvm_param_get(handle, domid, HVM_PARAM_STORE_PFN, &str_mfn);
     xc_hvm_param_get(handle, domid, HVM_PARAM_CONSOLE_PFN, &cons_mfn);

tools/libxl/libxl_dom.c static int libxl__domain_firmware(libxl__gc *gc, · line 892

Quoted 7 lines
tools/libxl/libxl_dom.c +4 -0
@@ -884,6 +886,12 @@ static int libxl__domain_firmware(libxl__gc *gc,
         case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
             firmware = "hvmloader";
             break;
+        case LIBXL_DEVICE_MODEL_VERSION_NONE:
+            if (info->kernel == NULL) {
+                LOG(ERROR, "no device model requested without a kernel");
+                return ERROR_FAIL;

goto out

Quoted 1 line

Maybe fix the other return as well...

While there I've done a fixup of all the error paths in the function, because AFAICT some of them were doing goto out without rc set.

Thanks, Roger.

#115 lore raw

Re: [PATCH v3 32/32] libxl: allow the creation of HVM domains without a device model.

On Wed, Jul 29, 2015 at 04:43:17PM +0200, Roger Pau Monné wrote:
[...]

Quoted 21 lines
Quoted 8 lines
Quoted 8 lines

It is recommended to accept the default value for new guests. If

tools/libxl/libxl.c +0 -0
index e9a2d26..a6690cf 100644
@@ -1590,11 +1590,10 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis)
 
Quoted 12 lines

tools/libxl/libxl.c void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis) · line 1596

Quoted 10 lines
tools/libxl/libxl.c +3 -4
     switch (libxl__domain_type(gc, domid)) {
     case LIBXL_DOMAIN_TYPE_HVM:
-        if (!libxl_get_stubdom_id(CTX, domid))
-            dm_present = 1;
-        else
+        if (libxl_get_stubdom_id(CTX, domid)) {
             dm_present = 0;
-        break;
+            break;
+        }

There is a path that dm_present contains garbage.

Quoted 4 lines

Please take into account that I've removed the last break in LIBXL_DOMAIN_TYPE_HVM, so now the LIBXL_DOMAIN_TYPE_HVM case expands into the LIBXL_DOMAIN_TYPE_PV case.

Oh yes.

Could use /* fall through */ to explicitly state this behaviour to avoid confusion and make Coverity happy.

Quoted 50 lines
Quoted 3 lines

tools/libxl/libxl.c void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis) · line 1599

Quoted 3 lines
tools/libxl/libxl.c +0 -0
     case LIBXL_DOMAIN_TYPE_PV:
         pid = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "/local/domain/%d/image/device-model-pid", domid));
         dm_present = (pid != NULL);

dm_present is set here for both PV and HVM guests without a stubdom.

Quoted 36 lines
Quoted 36 lines
tools/libxl/libxl_create.c +7 -0
index f366a09..1444e40 100644
@@ -164,6 +164,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
                 b_info->u.hvm.bios = LIBXL_BIOS_TYPE_ROMBIOS; break;
             case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
                 b_info->u.hvm.bios = LIBXL_BIOS_TYPE_SEABIOS; break;
+            case LIBXL_DEVICE_MODEL_VERSION_NONE:
+                break;
             default:return ERROR_INVAL;
             }
 
@@ -177,6 +179,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
             if (b_info->u.hvm.bios == LIBXL_BIOS_TYPE_ROMBIOS)
                 return ERROR_INVAL;
             break;
+        case LIBXL_DEVICE_MODEL_VERSION_NONE:
+            break;
         default:abort();
         }
 
@@ -278,6 +282,9 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
                 break;
             }
             break;
+        case LIBXL_DEVICE_MODEL_VERSION_NONE:
+            b_info->video_memkb = 0;
+            break;
         case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
         default:
             switch (b_info->u.hvm.vga.kind) {
@@ -945,6 +952,11 @@ static void initiate_domain_create(libxl__egc *egc,
         ret = libxl__device_nic_setdefault(gc, &d_config->nics[i], domid);
         if (ret) goto error_out;
 
Quoted 7 lines

tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 959

Quoted 5 lines
tools/libxl/libxl_create.c +5 -0
+        /* HVM guests without a device model only have PV nics. */
+        if (d_config->b_info.device_model_version ==
+            LIBXL_DEVICE_MODEL_VERSION_NONE)
+            d_config->nics[i].nictype = LIBXL_NIC_TYPE_VIF;
+

Better to check if users have asked for emulated NIC and bail.

Quoted 2 lines

IMHO, I think it would be better to move this to libxl__device_nic_setdefault and I will do so in the next version.

Yes, that's better.

Wei.

#116 lore raw

Re: [PATCH v3 32/32] libxl: allow the creation of HVM domains without a device model.

In reply to Roger Pau Monné
Quoted 4 lines · Roger Pau Monné
Quoted 1 line

There is a path that dm_present contains garbage.

Please take into account that I've removed the last break in LIBXL_DOMAIN_TYPE_HVM, so now the LIBXL_DOMAIN_TYPE_HVM case expands into the LIBXL_DOMAIN_TYPE_PV case.

As a general note, please mark deliberate fallthough cases with a comment, even if it is just /* fallthrough */

This is an aid to Coverity spotting accidental fallthrough.

~Andrew

#51 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monné
Quoted 23 lines · Roger Pau Monné
Quoted 11 lines
Quoted 11 lines

struct vcpu_hvm_context {
/* 16bit fields of the strucutre will be used. */
#define _VCPUHVM_MODE_16B 0
#define VCPUHVM_MODE_16B (1<<_VCPUHVM_MODE_16B)
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 1
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */
#define _VCPUHVM_MODE_64B 2
#define VCPUHVM_MODE_64B (1<<_VCPUHVM_MODE_64B)

Quoted 2 lines

As soon as we have three values here, a boolean flag approach doesn't make sense anymore.

Yes, taking into account that only _one_ of them can be used at the same time.

I have the feeling that we are over engineering this interface. IMHO we should only allow the user to set the control registers, efer (on amd64) and the GP registers. Segment selectors would be set by Xen to point to a flat segment suitable for the mode the guest has selected. I think that should be enough to get the guest OS into it's entry point, and then it can do whatever it wants.

Quoted 3 lines

If that's not suitable, then my second option would be to allow the guest to set the base, limit and AR bytes of the selectors, but not load a GDT.

In an ideal world, it would be nice to pass enough state to be able to point eip at the idle loop and have everything JustWork. However, this makes a lot of assumptions about exactly which state the vcpu wants to set up, which might include MSRs as well.

Therefore, an appropriate compromise is to be able to point eip at startup_cpu, running in the correct operating mode to avoid bouncing through trampolines.

Quoted 1 line

From that point of view, the minimum quantity of state required is:

CR{0,3,4}, EFER, cs/eip, ds, ss/esp, gdt{base,limit}. It would be natural to extend this to all the 8 base GPRs and the user segment selectors. (Note that EFER is needed even for 32bit paged entries if NX is set in the pagetables.)

In addition, a hint to Xen as to the eventual mode so it can widen its reads to start with rather than attempting to reverse engineer the operating mode and rereading half the structure later.

Specifying the gdt{base,limit} will require Xen to read the GDT to set up the entry attributes for the segment, as simply setting the selector is insufficient. A complicating factor is that VT-x and SVM have different representations for access rights. (For migration, VT-x's representation is mutated to match SVM.)

I really undecided between suggesting a gdt{base,limit} and Xen reading the access rights in an unambiguous fashon, vs specifying the internals and avoiding any peeking into domain memory.

It would be nice if the new cpus gs base could be set by the caller, which allows the new cpu straight access to its per-cpu data area (if gs is in use). This is not representable using the gdt method and would involve casing the GSBASE MSR if we were to go down the strict architectural route.

Therefore, I am leaning slightly towards the specify the internals side of things, which removes some complexity from the Xen side of the hypercall.

~Andrew

#52 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

El 03/08/15 a les 18.55, Andrew Cooper ha escrit:

Quoted 28 lines · Roger Pau Monné
Quoted 23 lines
Quoted 11 lines
Quoted 11 lines

struct vcpu_hvm_context {
/* 16bit fields of the strucutre will be used. */
#define _VCPUHVM_MODE_16B 0
#define VCPUHVM_MODE_16B (1<<_VCPUHVM_MODE_16B)
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 1
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */
#define _VCPUHVM_MODE_64B 2
#define VCPUHVM_MODE_64B (1<<_VCPUHVM_MODE_64B)

Quoted 2 lines

As soon as we have three values here, a boolean flag approach doesn't make sense anymore.

Yes, taking into account that only _one_ of them can be used at the same time.

I have the feeling that we are over engineering this interface. IMHO we should only allow the user to set the control registers, efer (on amd64) and the GP registers. Segment selectors would be set by Xen to point to a flat segment suitable for the mode the guest has selected. I think that should be enough to get the guest OS into it's entry point, and then it can do whatever it wants.

Quoted 3 lines

If that's not suitable, then my second option would be to allow the guest to set the base, limit and AR bytes of the selectors, but not load a GDT.

Quoted 8 lines

In an ideal world, it would be nice to pass enough state to be able to point eip at the idle loop and have everything JustWork. However, this makes a lot of assumptions about exactly which state the vcpu wants to set up, which might include MSRs as well.

Therefore, an appropriate compromise is to be able to point eip at startup_cpu, running in the correct operating mode to avoid bouncing through trampolines.

IMHO, allowing OSes to jump straight into the idle loop is putting a lot of burden in the Xen side of things. Also all OSes already contain AP startup code, we should be able to hook into this code at a suitable location, and that's what we should aim for.

Quoted 6 lines
Quoted 1 line

From that point of view, the minimum quantity of state required is:

CR{0,3,4}, EFER, cs/eip, ds, ss/esp, gdt{base,limit}. It would be natural to extend this to all the 8 base GPRs and the user segment selectors. (Note that EFER is needed even for 32bit paged entries if NX is set in the pagetables.)

Extending this to the rest of the GPR is needed for Linux to boot. The AP startup code of PVH Linux places the cpu id in a GPR for the boot stub to find it:

http://lxr.free-electrons.com/source/arch/x86/xen/smp.c#L420

Quoted 15 lines

In addition, a hint to Xen as to the eventual mode so it can widen its reads to start with rather than attempting to reverse engineer the operating mode and rereading half the structure later.

Specifying the gdt{base,limit} will require Xen to read the GDT to set up the entry attributes for the segment, as simply setting the selector is insufficient. A complicating factor is that VT-x and SVM have different representations for access rights. (For migration, VT-x's representation is mutated to match SVM.)

I really undecided between suggesting a gdt{base,limit} and Xen reading the access rights in an unambiguous fashon, vs specifying the internals and avoiding any peeking into domain memory.

Quoted 5 lines

It would be nice if the new cpus gs base could be set by the caller, which allows the new cpu straight access to its per-cpu data area (if gs is in use). This is not representable using the gdt method and would involve casing the GSBASE MSR if we were to go down the strict architectural route.

IMHO, this is out of the scope and I would rather allow the caller to set the internal (cached) part of the segment selectors.

Quoted 2 lines

Therefore, I am leaning slightly towards the specify the internals side of things, which removes some complexity from the Xen side of the hypercall.

I've updated the proposed structure, so now it looks like:

(I still need to figure out how to order the bits in the access rights (_ar) fields.)

struct vcpu_hvm_x86_16 {
    uint16_t ax;
    uint16_t cx;
    uint16_t dx;
    uint16_t bx;
    uint16_t sp;
    uint16_t bp;
    uint16_t si;
    uint16_t di;
    uint16_t ip;

    uint32_t cr[8];

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
};
struct vcpu_hvm_x86_32 {
    uint32_t eax;
    uint32_t ecx;
    uint32_t edx;
    uint32_t ebx;
    uint32_t esp;
    uint32_t ebp;
    uint32_t esi;
    uint32_t edi;
    uint32_t eip;

    uint32_t cr[8];
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
};
struct vcpu_hvm_x86_64 {
    uint64_t rax;
    uint64_t rcx;
    uint64_t rdx;
    uint64_t rbx;
    uint64_t rsp;
    uint64_t rbp;
    uint64_t rsi;
    uint64_t rdi;
    uint64_t r8;
    uint64_t r9;
    uint64_t r10;
    uint64_t r11;
    uint64_t r12;
    uint64_t r13;
    uint64_t r14;
    uint64_t r15;
    uint64_t rip;

    uint64_t cr[8];
    uint64_t efer;
};

typedef enum {

    VCPU_HVM_MODE_16B,       /* 16bit fields of the structure will be used. */
    VCPU_HVM_MODE_32B,       /* 32bit fields of the structure will be used. */
    VCPU_HVM_MODE_64B,       /* 64bit fields of the structure will be used. */

} vcpu_hvm_mode_t;

struct vcpu_hvm_context {
    vcpu_hvm_mode_t mode;

    /* CPU registers. */
    union {
        struct vcpu_hvm_x86_16 x86_16;
        struct vcpu_hvm_x86_32 x86_32;
        struct vcpu_hvm_x86_64 x86_64;
    };
};

typedef struct vcpu_hvm_context vcpu_hvm_context_t; DEFINE_XEN_GUEST_HANDLE(vcpu_hvm_context_t);

#53 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 74 lines · Roger Pau Monné

El 03/08/15 a les 18.55, Andrew Cooper ha escrit:

Quoted 26 lines · Roger Pau Monné
Quoted 22 lines
Quoted 10 lines
Quoted 10 lines

struct vcpu_hvm_context {
/* 16bit fields of the strucutre will be used. */
#define _VCPUHVM_MODE_16B 0
#define VCPUHVM_MODE_16B (1<<_VCPUHVM_MODE_16B)
/* 32bit fields of the structure will be used. */
#define _VCPUHVM_MODE_32B 1
#define VCPUHVM_MODE_32B (1<<_VCPUHVM_MODE_32B)
/* 64bit fields of the structure will be used. */
#define _VCPUHVM_MODE_64B 2
#define VCPUHVM_MODE_64B (1<<_VCPUHVM_MODE_64B)

Quoted 2 lines

As soon as we have three values here, a boolean flag approach doesn't make sense anymore.

Yes, taking into account that only _one_ of them can be used at the same time.

I have the feeling that we are over engineering this interface. IMHO we should only allow the user to set the control registers, efer (on amd64) and the GP registers. Segment selectors would be set by Xen to point to a flat segment suitable for the mode the guest has selected. I think that should be enough to get the guest OS into it's entry point, and then it can do whatever it wants.

Quoted 3 lines

If that's not suitable, then my second option would be to allow the guest to set the base, limit and AR bytes of the selectors, but not load a GDT.

Quoted 8 lines

In an ideal world, it would be nice to pass enough state to be able to point eip at the idle loop and have everything JustWork. However, this makes a lot of assumptions about exactly which state the vcpu wants to set up, which might include MSRs as well.

Therefore, an appropriate compromise is to be able to point eip at startup_cpu, running in the correct operating mode to avoid bouncing through trampolines.

IMHO, allowing OSes to jump straight into the idle loop is putting a lot of burden in the Xen side of things. Also all OSes already contain AP startup code, we should be able to hook into this code at a suitable location, and that's what we should aim for.

Quoted 6 lines
Quoted 1 line

From that point of view, the minimum quantity of state required is:

CR{0,3,4}, EFER, cs/eip, ds, ss/esp, gdt{base,limit}. It would be natural to extend this to all the 8 base GPRs and the user segment selectors. (Note that EFER is needed even for 32bit paged entries if NX is set in the pagetables.)

Extending this to the rest of the GPR is needed for Linux to boot. The AP startup code of PVH Linux places the cpu id in a GPR for the boot stub to find it:

http://lxr.free-electrons.com/source/arch/x86/xen/smp.c#L420

Quoted 14 lines

In addition, a hint to Xen as to the eventual mode so it can widen its reads to start with rather than attempting to reverse engineer the operating mode and rereading half the structure later.

Specifying the gdt{base,limit} will require Xen to read the GDT to set up the entry attributes for the segment, as simply setting the selector is insufficient. A complicating factor is that VT-x and SVM have different representations for access rights. (For migration, VT-x's representation is mutated to match SVM.)

I really undecided between suggesting a gdt{base,limit} and Xen reading the access rights in an unambiguous fashon, vs specifying the internals and avoiding any peeking into domain memory.

Quoted 5 lines

It would be nice if the new cpus gs base could be set by the caller, which allows the new cpu straight access to its per-cpu data area (if gs is in use). This is not representable using the gdt method and would involve casing the GSBASE MSR if we were to go down the strict architectural route.

IMHO, this is out of the scope and I would rather allow the caller to set the internal (cached) part of the segment selectors.

Quoted 6 lines
Quoted 2 lines

Therefore, I am leaning slightly towards the specify the internals side of things, which removes some complexity from the Xen side of the hypercall.

I've updated the proposed structure, so now it looks like:

(I still need to figure out how to order the bits in the access rights (_ar) fields.)

All struct's need a flags register.

Quoted 13 lines
struct vcpu_hvm_x86_16 {
    uint16_t ax;
    uint16_t cx;
    uint16_t dx;
    uint16_t bx;
    uint16_t sp;
    uint16_t bp;
    uint16_t si;
    uint16_t di;
    uint16_t ip;

    uint32_t cr[8];

Definitely no need for anything other than cr0 and 4 in 16 bit mode.

Quoted 12 lines
    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
};
Quoted 12 lines
struct vcpu_hvm_x86_32 {
    uint32_t eax;
    uint32_t ecx;
    uint32_t edx;
    uint32_t ebx;
    uint32_t esp;
    uint32_t ebp;
    uint32_t esi;
    uint32_t edi;
    uint32_t eip;

    uint32_t cr[8];

Don't need cr's 5-8.

Quoted 11 lines
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;

You need selector entries for each segment as well.

Quoted 15 lines

};

struct vcpu_hvm_x86_64 {
    uint64_t rax;
    uint64_t rcx;
    uint64_t rdx;
    uint64_t rbx;
    uint64_t rsp;
    uint64_t rbp;
    uint64_t rsi;
    uint64_t rdi;
    uint64_t r8;
    uint64_t r9;
    uint64_t r10;
    uint64_t r11;
Quoted 8 lines
    uint64_t r12;
    uint64_t r13;
    uint64_t r14;
    uint64_t r15;
    uint64_t rip;

    uint64_t cr[8];
    uint64_t efer;

What has happened to the segment information? It cannot be omitted completely, even in 64bit.

Quoted 10 lines

};

typedef enum {

    VCPU_HVM_MODE_16B,       /* 16bit fields of the structure will be used. */
    VCPU_HVM_MODE_32B,       /* 32bit fields of the structure will be used. */
    VCPU_HVM_MODE_64B,       /* 64bit fields of the structure will be used. */

} vcpu_hvm_mode_t;

struct vcpu_hvm_context {
    vcpu_hvm_mode_t mode;

The width of an enum is implementation defined, which makes them unsuitable in the public interface.

Quoted 7 lines
    /* CPU registers. */
    union {
        struct vcpu_hvm_x86_16 x86_16;
        struct vcpu_hvm_x86_32 x86_32;
        struct vcpu_hvm_x86_64 x86_64;
    };

We require C89 compatibility for the public interface, so no anonymous unions.

~Andrew

Quoted 5 lines

};
typedef struct vcpu_hvm_context vcpu_hvm_context_t; DEFINE_XEN_GUEST_HANDLE(vcpu_hvm_context_t);

#54 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

El 04/08/15 a les 20.08, Andrew Cooper ha escrit:

Quoted 9 lines · Roger Pau Monné
Quoted 6 lines
Quoted 2 lines

Therefore, I am leaning slightly towards the specify the internals side of things, which removes some complexity from the Xen side of the hypercall.

I've updated the proposed structure, so now it looks like:

(I still need to figure out how to order the bits in the access rights (_ar) fields.)

All struct's need a flags register.

I was unsure about adding the {e/r}flags register, I will add it in new versions.

Quoted 12 lines
Quoted 12 lines
struct vcpu_hvm_x86_16 {
    uint16_t ax;
    uint16_t cx;
    uint16_t dx;
    uint16_t bx;
    uint16_t sp;
    uint16_t bp;
    uint16_t si;
    uint16_t di;
    uint16_t ip;
Quoted 3 lines
Quoted 1 line
    uint32_t cr[8];

Definitely no need for anything other than cr0 and 4 in 16 bit mode.

Yes. Would you rather prefer to spell out the exact control registers that are going to be used instead of using an array?

For 16bit mode this is going to be CR0/CR4, for 32bit or long mode mode CR0/CR3/CR4.

Quoted 39 lines
Quoted 12 lines
    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
};
Quoted 12 lines
struct vcpu_hvm_x86_32 {
    uint32_t eax;
    uint32_t ecx;
    uint32_t edx;
    uint32_t ebx;
    uint32_t esp;
    uint32_t ebp;
    uint32_t esi;
    uint32_t edi;
    uint32_t eip;

    uint32_t cr[8];

Don't need cr's 5-8.

Quoted 11 lines
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
Quoted 1 line

You need selector entries for each segment as well.

Really? What's the point in having the selector if we don't have a GDT, and we allow loading the cached part, which is the relevant one.

Quoted 22 lines
Quoted 22 lines

};

struct vcpu_hvm_x86_64 {
    uint64_t rax;
    uint64_t rcx;
    uint64_t rdx;
    uint64_t rbx;
    uint64_t rsp;
    uint64_t rbp;
    uint64_t rsi;
    uint64_t rdi;
    uint64_t r8;
    uint64_t r9;
    uint64_t r10;
    uint64_t r11;
    uint64_t r12;
    uint64_t r13;
    uint64_t r14;
    uint64_t r15;
    uint64_t rip;
Quoted 5 lines
Quoted 2 lines
    uint64_t cr[8];
    uint64_t efer;

What has happened to the segment information? It cannot be omitted completely, even in 64bit.

I had in mind to set them to the values required for long mode:

base = 0
limit = 0xffff

and the attributes field for CS to:

ar = 0x29b (L bit set)

And for SS/DS:

ar = 0x093

But maybe it makes sense to allow setting them in case someone wants to start in compatibility mode.

Quoted 8 lines
Quoted 8 lines

};

typedef enum {

    VCPU_HVM_MODE_16B,       /* 16bit fields of the structure will be used. */
    VCPU_HVM_MODE_32B,       /* 32bit fields of the structure will be used. */
    VCPU_HVM_MODE_64B,       /* 64bit fields of the structure will be used. */

} vcpu_hvm_mode_t;

Quoted 5 lines
Quoted 2 lines
struct vcpu_hvm_context {
    vcpu_hvm_mode_t mode;

The width of an enum is implementation defined, which makes them unsuitable in the public interface.

Right, I'm going to change it to a uint32_t and the modes to defines.

Quoted 11 lines
Quoted 8 lines

    /* CPU registers. */
    union {
        struct vcpu_hvm_x86_16 x86_16;
        struct vcpu_hvm_x86_32 x86_32;
        struct vcpu_hvm_x86_64 x86_64;
    };

We require C89 compatibility for the public interface, so no anonymous unions.

Ack, thanks for the review.

Roger.

#55 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 11 lines · Roger Pau Monné

El 04/08/15 a les 20.08, Andrew Cooper ha escrit:

Quoted 8 lines · Roger Pau Monné
Quoted 6 lines
Quoted 2 lines

Therefore, I am leaning slightly towards the specify the internals side of things, which removes some complexity from the Xen side of the hypercall.

I've updated the proposed structure, so now it looks like:

(I still need to figure out how to order the bits in the access rights (_ar) fields.)

All struct's need a flags register.

I was unsure about adding the {e/r}flags register, I will add it in new versions.

For first-gen VT-x, CR0.PE in unable to be cleared. HVMLoader has to
do a dance with vm86 mode, which is where HVM_PARAM_IDENT_PT gets used.

I don't realistically expect this to be a problem for DMlite guests.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
struct vcpu_hvm_x86_16 {
    uint16_t ax;
    uint16_t cx;
    uint16_t dx;
    uint16_t bx;
    uint16_t sp;
    uint16_t bp;
    uint16_t si;
    uint16_t di;
    uint16_t ip;
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
    uint32_t cr[8];

Definitely no need for anything other than cr0 and 4 in 16 bit mode.

Yes. Would you rather prefer to spell out the exact control registers that are going to be used instead of using an array?

I would suggest so.

CRs 1,5-7 are unconditionally #UD to attempt to use. CR2 is useless until you enter the #PF handler. CR8 may (hardware dependent) have the TPR in it, which is useless until the IDT is set up and interrupts have been enabled.

Quoted 3 lines

For 16bit mode this is going to be CR0/CR4, for 32bit or long mode mode CR0/CR3/CR4.

Agreed.

Quoted 37 lines
Quoted 37 lines
Quoted 12 lines
    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
};
Quoted 12 lines
struct vcpu_hvm_x86_32 {
    uint32_t eax;
    uint32_t ecx;
    uint32_t edx;
    uint32_t ebx;
    uint32_t esp;
    uint32_t ebp;
    uint32_t esi;
    uint32_t edi;
    uint32_t eip;

    uint32_t cr[8];

Don't need cr's 5-8.

Quoted 11 lines
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
Quoted 3 lines
Quoted 1 line

You need selector entries for each segment as well.

Really? What's the point in having the selector if we don't have a GDT, and we allow loading the cached part, which is the relevant one.

push %cs; push 1f; lret

At all points when segment details are updated, it is the responsibility of software to ensure that the details match with the GDT/LDT entry. See for example the Intel and AMD manuals for syscall/sysenter where similar "updating segment details behind the scenes" occurs.

Quoted 33 lines
Quoted 22 lines
Quoted 22 lines

};

struct vcpu_hvm_x86_64 {
    uint64_t rax;
    uint64_t rcx;
    uint64_t rdx;
    uint64_t rbx;
    uint64_t rsp;
    uint64_t rbp;
    uint64_t rsi;
    uint64_t rdi;
    uint64_t r8;
    uint64_t r9;
    uint64_t r10;
    uint64_t r11;
    uint64_t r12;
    uint64_t r13;
    uint64_t r14;
    uint64_t r15;
    uint64_t rip;
Quoted 4 lines
Quoted 2 lines
    uint64_t cr[8];
    uint64_t efer;

What has happened to the segment information? It cannot be omitted completely, even in 64bit.

I had in mind to set them to the values required for long mode:

base = 0
limit = 0xffff

and the attributes field for CS to:

Quoted 8 lines

ar = 0x29b (L bit set)

And for SS/DS:

ar = 0x093

But maybe it makes sense to allow setting them in case someone wants to start in compatibility mode.

Agreed.

~Andrew

#56 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

El 05/08/15 a les 17.39, Andrew Cooper ha escrit:

Quoted 16 lines · Roger Pau Monné
Quoted 11 lines

El 04/08/15 a les 20.08, Andrew Cooper ha escrit:

Quoted 10 lines · Roger Pau Monné
Quoted 9 lines
    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
Quoted 3 lines
Quoted 1 line

You need selector entries for each segment as well.

Really? What's the point in having the selector if we don't have a GDT, and we allow loading the cached part, which is the relevant one.

Quoted 6 lines

push %cs; push 1f; lret

At all points when segment details are updated, it is the responsibility of software to ensure that the details match with the GDT/LDT entry. See for example the Intel and AMD manuals for syscall/sysenter where similar "updating segment details behind the scenes" occurs.

I would certainly expect the user to have loaded a proper GDT and reloaded the segments selectors before attempting to do something like the above.

I really don't mind adding a cs_sel, ds_sel, ss_sel and tr_sel, I just think it's quite pointless because it's common practice to load a GDT and then reload the segment selectors to point to the right entries.

Roger.

#57 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 22 lines · Roger Pau Monné

El 05/08/15 a les 17.39, Andrew Cooper ha escrit:

Quoted 13 lines · Roger Pau Monné
Quoted 12 lines

El 04/08/15 a les 20.08, Andrew Cooper ha escrit:

Quoted 11 lines · Roger Pau Monné
Quoted 9 lines
    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;

You need selector entries for each segment as well.

Quoted 8 lines
Quoted 2 lines

Really? What's the point in having the selector if we don't have a GDT, and we allow loading the cached part, which is the relevant one.

push %cs; push 1f; lret

At all points when segment details are updated, it is the responsibility of software to ensure that the details match with the GDT/LDT entry. See for example the Intel and AMD manuals for syscall/sysenter where similar "updating segment details behind the scenes" occurs.

Quoted 7 lines

I would certainly expect the user to have loaded a proper GDT and reloaded the segments selectors before attempting to do something like the above.

I really don't mind adding a cs_sel, ds_sel, ss_sel and tr_sel, I just think it's quite pointless because it's common practice to load a GDT and then reload the segment selectors to point to the right entries.

Consider what would happen if the vcpu hits mmio and bounces into Xen for emulation before reloading the segment selectors.

The segment selector information needs to be consistent, as it might not be the guest which is the next entity to observe the vcpu state.

~Andrew

#58 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

El 05/08/15 a les 18.46, Andrew Cooper ha escrit:

Quoted 27 lines · Roger Pau Monné
Quoted 26 lines

El 05/08/15 a les 17.39, Andrew Cooper ha escrit:

Quoted 13 lines · Roger Pau Monné
Quoted 12 lines

El 04/08/15 a les 20.08, Andrew Cooper ha escrit:

Quoted 11 lines · Roger Pau Monné
Quoted 9 lines
    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;

You need selector entries for each segment as well.

Quoted 8 lines
Quoted 2 lines

Really? What's the point in having the selector if we don't have a GDT, and we allow loading the cached part, which is the relevant one.

push %cs; push 1f; lret

At all points when segment details are updated, it is the responsibility of software to ensure that the details match with the GDT/LDT entry. See for example the Intel and AMD manuals for syscall/sysenter where similar "updating segment details behind the scenes" occurs.

I would certainly expect the user to have loaded a proper GDT and reloaded the segments selectors before attempting to do something like the above.

Quoted 6 lines
Quoted 3 lines

I really don't mind adding a cs_sel, ds_sel, ss_sel and tr_sel, I just think it's quite pointless because it's common practice to load a GDT and then reload the segment selectors to point to the right entries.

Consider what would happen if the vcpu hits mmio and bounces into Xen for emulation before reloading the segment selectors.

I hope Xen is just going to kill the guest.

Quoted 2 lines

The segment selector information needs to be consistent, as it might not be the guest which is the next entity to observe the vcpu state.

I guess I'm missing something, but AFAICT we already start the BSP in such "inconsistent" state, the cached part of the selectors is right but the selectors themselves don't point to valid GDT entries because there's no GDT loaded.

Roger.

#59 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

Quoted 28 lines · Roger Pau Monné

El 05/08/15 a les 18.46, Andrew Cooper ha escrit:

Quoted 27 lines · Roger Pau Monné
Quoted 26 lines

El 05/08/15 a les 17.39, Andrew Cooper ha escrit:

Quoted 13 lines · Roger Pau Monné
Quoted 12 lines

El 04/08/15 a les 20.08, Andrew Cooper ha escrit:

Quoted 11 lines · Roger Pau Monné
Quoted 9 lines
    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;

You need selector entries for each segment as well.

Quoted 8 lines
Quoted 2 lines

Really? What's the point in having the selector if we don't have a GDT, and we allow loading the cached part, which is the relevant one.

push %cs; push 1f; lret

At all points when segment details are updated, it is the responsibility of software to ensure that the details match with the GDT/LDT entry. See for example the Intel and AMD manuals for syscall/sysenter where similar "updating segment details behind the scenes" occurs.

I would certainly expect the user to have loaded a proper GDT and reloaded the segments selectors before attempting to do something like the above.

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

I really don't mind adding a cs_sel, ds_sel, ss_sel and tr_sel, I just think it's quite pointless because it's common practice to load a GDT and then reload the segment selectors to point to the right entries.

Consider what would happen if the vcpu hits mmio and bounces into Xen for emulation before reloading the segment selectors.

I hope Xen is just going to kill the guest.

I would hope for it to work properly.

Quoted 5 lines
Quoted 3 lines

The segment selector information needs to be consistent, as it might not be the guest which is the next entity to observe the vcpu state.

I guess I'm missing something, but AFAICT we already start the BSP in such "inconsistent" state,

So we do. (There are a number of inconsistencies in that area.)

Quoted 3 lines

the cached part of the selectors is right but
the selectors themselves don't point to valid GDT entries because there's no GDT loaded.

Hmm yes - you are correct.

On native, the cached part of the segment selectors only get updated with a segment selector is loaded, at which point the gdt/ldt must be valid.

However there is no requirement or need for the gdt/ldt to stay valid after the cached part has been loaded. Unreal mode relies on this.

Considering that the first thing any AP startup function will do is lgdt and reload the segment registers, we can do without maintaining selector consistency.

Sorry for the confusion.

~Andrew

#60 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Roger Pau Monné
Quoted 37 lines · Roger Pau Monné

El 05/08/15 a les 18.46, Andrew Cooper ha escrit:

Quoted 27 lines · Roger Pau Monné
Quoted 26 lines

El 05/08/15 a les 17.39, Andrew Cooper ha escrit:

Quoted 13 lines · Roger Pau Monné
Quoted 12 lines

El 04/08/15 a les 20.08, Andrew Cooper ha escrit:

Quoted 11 lines · Roger Pau Monné
Quoted 9 lines
    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;

You need selector entries for each segment as well.

Quoted 8 lines
Quoted 2 lines

Really? What's the point in having the selector if we don't have a GDT, and we allow loading the cached part, which is the relevant one.

push %cs; push 1f; lret

At all points when segment details are updated, it is the responsibility of software to ensure that the details match with the GDT/LDT entry. See for example the Intel and AMD manuals for syscall/sysenter where similar "updating segment details behind the scenes" occurs.

I would certainly expect the user to have loaded a proper GDT and reloaded the segments selectors before attempting to do something like the above.

Quoted 6 lines
Quoted 3 lines

I really don't mind adding a cs_sel, ds_sel, ss_sel and tr_sel, I just think it's quite pointless because it's common practice to load a GDT and then reload the segment selectors to point to the right entries.

Consider what would happen if the vcpu hits mmio and bounces into Xen for emulation before reloading the segment selectors.

I hope Xen is just going to kill the guest.

Quoted 7 lines
Quoted 2 lines

The segment selector information needs to be consistent, as it might not be the guest which is the next entity to observe the vcpu state.

I guess I'm missing something, but AFAICT we already start the BSP in such "inconsistent" state, the cached part of the selectors is right but the selectors themselves don't point to valid GDT entries because there's no GDT loaded.

Yes, and in extending this call to HVM it should be fine to do the same. It would be nice to have a document describing the CPU state that the HVM guest will find itself in after this call. (In particular that the segments will be set up but not the descriptor tables, and that the selectors may not be relied upon).

Cheers,

Tim.

#61 lore raw

Re: [PATCH v3 07/32] xen/x86: fix arch_set_info_guest for HVM guests

In reply to Andrew Cooper
Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 04.08.15 at 20:08, <[email protected]> wrote:
Quoted 4 lines · Roger Pau Monné
struct vcpu_hvm_x86_16 {
    uint16_t ax;
    uint16_t cx;
    uint16_t dx;
Quoted 8 lines
    uint16_t bx;
    uint16_t sp;
    uint16_t bp;
    uint16_t si;
    uint16_t di;
    uint16_t ip;

    uint32_t cr[8];

Definitely no need for anything other than cr0 and 4 in 16 bit mode.

Quoted 23 lines
    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
};
struct vcpu_hvm_x86_32 {
    uint32_t eax;
    uint32_t ecx;
    uint32_t edx;
    uint32_t ebx;
    uint32_t esp;
    uint32_t ebp;
    uint32_t esi;
    uint32_t edi;
    uint32_t eip;
Quoted 3 lines
Quoted 1 line
    uint32_t cr[8];

Don't need cr's 5-8.

I disagree with a number of things discussed so far (like the statement above), but I guess I'll better comment on v4 than continue this thread.

Jan

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