Skip to contentSkip to conversation

Introduce HVM without dm and new boot ABI

PATCH Superseded Roger Pau Monne 9 participants 99 messages Sep 4, 2015 – Sep 30, 2015 Arm/actions semi architecture

v6 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v6 cover Introduce HVM without dm and new boot ABI

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. This batch of patches can go in regardless of the status of the rest of the series IMHO, and in fact would help me quite a lot with the rebasing.
- Patches from 11 to 21 allow disabling the devices emulated inside of Xen.
- Patches from 21 to 29 introduce the creation of HVM guests without a device model and without the devices emulated inside of Xen.

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_v6

And for the FreeBSD part:

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

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

This FreeBSD kernel starts the APs in long mode. There are examples for starting the APs in other modes in the sys/x86/xen/pv.c file.

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>"

AW 01/29 libxc: split x86 HVM setup_guest into smaller
AW 02/29 libxc: unify xc_dom_p2m_{host/guest}
AW 03/29 libxc: introduce the notion of a container type
AW 04/29 libxc: introduce a domain loader for HVM guest
AW 05/29 libxc: make arch_setup_meminit a xc_dom_arch hook
AW 06/29 libxc: make arch_setup_boot{init/late} xc_dom_arch
AW 07/29 libxc: rework BSP initialization
AW M 08/29 libxc: introduce a xc_dom_arch for hvm-3.0-x86_32

 W    09/29 libxl: switch HVM domain building to use xc_dom_*
AW    10/29 libxc: remove dead HVM building code
A     11/29 xen/x86: add bitmap of enabled emulated devices
A B   12/29 xen/x86: allow disabling the emulated local apic
A     13/29 xen/x86: allow disabling the emulated HPET
A     14/29 xen/x86: allow disabling the pmtimer
A     15/29 xen/x86: allow disabling the emulated RTC
A     16/29 xen/x86: allow disabling the emulated IO APIC
A     17/29 xen/x86: allow disabling the emulated PIC
A     18/29 xen/x86: allow disabling the emulated pmu
A     19/29 xen/x86: allow disabling the emulated VGA
A     20/29 xen/x86: allow disabling the emulated IOMMU
A     21/29 xen/x86: allow disabling all emulated devices inside
AW    22/29 elfnotes: intorduce a new PHYS_ENTRY elfnote
AW    23/29 libxc: allow creating domains without emulated
    M 24/29 xen/x86: allow HVM guests to use hypercalls to bring
 W    25/29 xenconsole: try to attach to PV console if HVM fails
    M 26/29 libxc/xen: introduce a start info structure for
AW    27/29 libxc: switch xc_dom_elfloader to be used with
 W    28/29 libxl: allow the creation of HVM domains without a
   N  29/29 libxl: add support for migrating HVM guests without

A = Acked/Reviewed by Andrew Cooper.
W = Acked/Reviewed by Wei Liu.
B = Acked/Reviewed by Boris Ostrovsky.
N = New in this version.
M = Modified in this version.

Thanks, Roger.

#1 lore raw

PATCH v6 1/29 libxc: split x86 HVM setup_guest into smaller logical functions

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

---
Changes since v3:
- Add Andrew Cooper Reviewed-by.
- Add Wei Acked-by.

---
 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 ea250dd..4d3736b 100644
@@ -231,28 +231,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];
@@ -260,19 +252,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;
 
@@ -345,24 +324,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++ )
@@ -564,7 +525,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");
@@ -577,6 +585,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 )
@@ -665,34 +711,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;
 }
 
@@ -703,9 +727,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;
@@ -716,24 +739,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
#2 lore raw

PATCH v6 2/29 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]>

---
Changes since v3:
- Add Andrew Cooper Reviewed-by.
- Add Wei Acked-by.

---
 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 600aef6..9cf13e2 100644
@@ -375,19 +375,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 8e06406..7c30f96 100644
@@ -53,7 +53,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,
@@ -83,7 +83,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);
@@ -177,7 +177,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,
@@ -434,8 +434,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 a3abb99..5c1f043 100644
@@ -64,8 +64,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 3d40fa4..dc2f4aa 100644
@@ -247,7 +247,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 )
     {
@@ -279,7 +279,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++;
         }
 
@@ -291,7 +291,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++;
         }
 
@@ -299,7 +299,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 */
@@ -315,7 +315,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;
 
@@ -374,7 +374,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++;
         }
 
@@ -386,7 +386,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++;
         }
 
@@ -398,7 +398,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++;
         }
 
@@ -406,7 +406,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) )
@@ -489,9 +489,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 )
@@ -535,9 +535,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 )
@@ -621,7 +621,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);
@@ -647,7 +647,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 c2518a3..eab6b21 100644
@@ -738,8 +738,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
#3 lore raw

PATCH v6 3/29 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.

---
Changes since v3:
- Add Andrew Cooper Reviewed-by.
- Add Wei Acked-by.

---
 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 9cf13e2..bc55ec9 100644
@@ -179,6 +179,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 dc2f4aa..c7bfc0c 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 eab6b21..6101e5c 100644
@@ -619,6 +619,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
#4 lore raw

PATCH v6 4/29 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.

---
Changes since v3:
- s/__FUNCTION__/__func__/g
- Fix style errors in xc_dom_hvmloader.c.
- Add Andrew Cooper Reviewed-by.
- Add Wei Acked-by.

---
 tools/libxc/Makefile           |   1 +
 tools/libxc/include/xc_dom.h   |   8 ++
 tools/libxc/xc_dom_hvmloader.c | 313 +++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/libelf.h       |   1 +
 4 files changed, 323 insertions(+)
 create mode 100644 tools/libxc/xc_dom_hvmloader.c
tools/libxc/Makefile +1 -0
index a0f899b..baaadd6 100644
@@ -84,6 +84,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 bc55ec9..02d9d5c 100644
@@ -14,6 +14,7 @@
  */
 
 #include <xen/libelf/libelf.h>
+#include <xenguest.h>
 
 #define INVALID_P2M_ENTRY   ((xen_pfn_t)-1)
 
@@ -185,6 +186,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 +313 -0

313 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
#5 lore raw

PATCH v6 5/29 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.

---
Changes since v3:
- Add Andrew Cooper Reviewed-by.
- Move xc_dom_arch definitions to the end of the xc_dom_<arch>.c files in order to reduce the spurious diffs in the comming patches.
- Add Wei Acked-by.

---
 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 02d9d5c..c4b994f 100644
@@ -223,6 +223,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;
@@ -400,7 +403,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 7c30f96..bf2cd7b 100644
@@ -146,7 +146,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
#6 lore raw

PATCH v6 6/29 libxc: make arch_setup_boot{init/late} xc_dom_arch hooks

In reply to Roger Pau Monne

This should not introduce any functional change.

---
Changes since v3:
- Add Andrew Cooper Reviewed-by.
- Add Wei Acked-by.

---
 tools/libxc/include/xc_dom.h |  7 ++-----
 tools/libxc/xc_dom_arm.c     | 20 +++++++++++++-------
 tools/libxc/xc_dom_boot.c    |  4 ++--
 tools/libxc/xc_dom_x86.c     | 10 ++++++++--
 4 files changed, 25 insertions(+), 16 deletions(-)
tools/libxc/include/xc_dom.h +2 -5
index c4b994f..5c1bb0f 100644
@@ -222,6 +222,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);
@@ -401,11 +403,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 +13 -7
index 24776ba..7548dae 100644
@@ -489,13 +489,20 @@ static int meminit(struct xc_dom_image *dom)
     return 0;
 }
 
-int arch_setup_bootearly(struct xc_dom_image *dom)
+int xc_dom_feature_translated(struct xc_dom_image *dom)
+{
+    return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int bootearly(struct xc_dom_image *dom)
 {
     DOMPRINTF("%s: doing nothing", __FUNCTION__);
     return 0;
 }
 
-int arch_setup_bootlate(struct xc_dom_image *dom)
+static int bootlate(struct xc_dom_image *dom)
 {
     /* XXX
      *   map shared info
@@ -505,11 +512,6 @@ int arch_setup_bootlate(struct xc_dom_image *dom)
     return 0;
 }
 
-int xc_dom_feature_translated(struct xc_dom_image *dom)
-{
-    return 1;
-}
-
 /* ------------------------------------------------------------------------ */
 
 static struct xc_dom_arch xc_dom_32 = {
@@ -524,6 +526,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 = {
@@ -538,6 +542,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)
tools/libxc/xc_dom_boot.c +2 -2
index bf2cd7b..e6f7794 100644
@@ -208,7 +208,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 */
@@ -255,7 +255,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 +8 -2
index 07170c1..0f49e27 100644
@@ -924,7 +924,9 @@ static int meminit_pv(struct xc_dom_image *dom)
     return rc;
 }
 
-int arch_setup_bootearly(struct xc_dom_image *dom)
+/* ------------------------------------------------------------------------ */
+
+static int bootearly(struct xc_dom_image *dom)
 {
     DOMPRINTF("%s: doing nothing", __FUNCTION__);
     return 0;
@@ -963,7 +965,7 @@ static int map_grant_table_frames(struct xc_dom_image *dom)
     return 0;
 }
 
-int arch_setup_bootlate(struct xc_dom_image *dom)
+static int bootlate_pv(struct xc_dom_image *dom)
 {
     static const struct {
         char *guest;
@@ -1059,6 +1061,8 @@ static struct xc_dom_arch xc_dom_32_pae = {
     .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 = {
@@ -1073,6 +1077,8 @@ static struct xc_dom_arch xc_dom_64 = {
     .shared_info = shared_info_x86_64,
     .vcpu = vcpu_x86_64,
     .meminit = meminit_pv,
+    .bootearly = bootearly,
+    .bootlate = bootlate_pv,
 };
 
 static void __init register_arch_hooks(void)
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 v6 7/29 libxc: rework BSP initialization

In reply to Roger Pau Monne

Place the calls to xc_vcpu_setcontext and the allocation of the hypercall buffer into the arch-specific vcpu hooks. This is needed in order to introduce a new builder, so x86 HVM guests can initialize the BSP using XEN_DOMCTL_sethvmcontext instead of XEN_DOMCTL_setvcpucontext.

This patch should not introduce any functional change.

---
Changes since v5:
- Reword commit message to remove a reference to "next patch".

Changes since v4:
- Add Andrew Cooper Reviewed-by.

---
 tools/libxc/include/xc_dom.h |  2 +-
 tools/libxc/xc_dom_arm.c     | 22 +++++++++++++++++-----
 tools/libxc/xc_dom_boot.c    | 23 +----------------------
 tools/libxc/xc_dom_x86.c     | 26 ++++++++++++++++++++------
 4 files changed, 39 insertions(+), 34 deletions(-)
tools/libxc/include/xc_dom.h +1 -1
index 5c1bb0f..0245d24 100644
@@ -221,7 +221,7 @@ struct xc_dom_arch {
     /* arch-specific data structs setup */
     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 (*vcpu) (struct xc_dom_image * dom);
     int (*bootearly) (struct xc_dom_image * dom);
     int (*bootlate) (struct xc_dom_image * dom);
 
tools/libxc/xc_dom_arm.c +17 -5
index 7548dae..8865097 100644
@@ -119,9 +119,10 @@ static int shared_info_arm(struct xc_dom_image *dom, void *ptr)
 
 /* ------------------------------------------------------------------------ */
 
-static int vcpu_arm32(struct xc_dom_image *dom, void *ptr)
+static int vcpu_arm32(struct xc_dom_image *dom)
 {
-    vcpu_guest_context_t *ctxt = ptr;
+    vcpu_guest_context_any_t any_ctx;
+    vcpu_guest_context_t *ctxt = &any_ctx.c;
 
     DOMPRINTF_CALLED(dom->xch);
 
@@ -154,12 +155,18 @@ static int vcpu_arm32(struct xc_dom_image *dom, void *ptr)
     DOMPRINTF("Initial state CPSR %#"PRIx32" PC %#"PRIx32,
            ctxt->user_regs.cpsr, ctxt->user_regs.pc32);
 
-    return 0;
+    rc = xc_vcpu_setcontext(dom->xch, dom->guest_domid, 0, &any_ctx);
+    if ( rc != 0 )
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: SETVCPUCONTEXT failed (rc=%d)", __func__, rc);
+
+    return rc;
 }
 
-static int vcpu_arm64(struct xc_dom_image *dom, void *ptr)
+static int vcpu_arm64(struct xc_dom_image *dom)
 {
-    vcpu_guest_context_t *ctxt = ptr;
+    vcpu_guest_context_any_t any_ctx;
+    vcpu_guest_context_t *ctxt = &any_ctx.c;
 
     DOMPRINTF_CALLED(dom->xch);
     /* clear everything */
@@ -189,6 +196,11 @@ static int vcpu_arm64(struct xc_dom_image *dom, void *ptr)
     DOMPRINTF("Initial state CPSR %#"PRIx32" PC %#"PRIx64,
            ctxt->user_regs.cpsr, ctxt->user_regs.pc64);
 
+    rc = xc_vcpu_setcontext(dom->xch, dom->guest_domid, 0, &any_ctx);
+    if ( rc != 0 )
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: SETVCPUCONTEXT failed (rc=%d)", __func__, rc);
+
     return 0;
 }
 
tools/libxc/xc_dom_boot.c +1 -22
index e6f7794..791041b 100644
@@ -62,19 +62,6 @@ static int setup_hypercall_page(struct xc_dom_image *dom)
     return rc;
 }
 
-static int launch_vm(xc_interface *xch, domid_t domid,
-                     vcpu_guest_context_any_t *ctxt)
-{
-    int rc;
-
-    xc_dom_printf(xch, "%s: called, ctxt=%p", __FUNCTION__, ctxt);
-    rc = xc_vcpu_setcontext(xch, domid, 0, ctxt);
-    if ( rc != 0 )
-        xc_dom_panic(xch, XC_INTERNAL_ERROR,
-                     "%s: SETVCPUCONTEXT failed (rc=%d)", __FUNCTION__, rc);
-    return rc;
-}
-
 static int clear_page(struct xc_dom_image *dom, xen_pfn_t pfn)
 {
     xen_pfn_t dst;
@@ -197,14 +184,9 @@ void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn,
 
 int xc_dom_boot_image(struct xc_dom_image *dom)
 {
-    DECLARE_HYPERCALL_BUFFER(vcpu_guest_context_any_t, ctxt);
     xc_dominfo_t info;
     int rc;
 
-    ctxt = xc_hypercall_buffer_alloc(dom->xch, ctxt, sizeof(*ctxt));
-    if ( ctxt == NULL )
-        return -1;
-
     DOMPRINTF_CALLED(dom->xch);
 
     /* misc stuff*/
@@ -259,13 +241,10 @@ int xc_dom_boot_image(struct xc_dom_image *dom)
         return rc;
 
     /* let the vm run */
-    memset(ctxt, 0, sizeof(*ctxt));
-    if ( (rc = dom->arch_hooks->vcpu(dom, ctxt)) != 0 )
+    if ( (rc = dom->arch_hooks->vcpu(dom)) != 0 )
         return rc;
     xc_dom_unmap_all(dom);
-    rc = launch_vm(dom->xch, dom->guest_domid, ctxt);
 
-    xc_hypercall_buffer_free(dom->xch, ctxt);
     return rc;
 }
 
tools/libxc/xc_dom_x86.c +20 -6
index 0f49e27..ae8187f 100644
@@ -583,10 +583,12 @@ static int shared_info_x86_64(struct xc_dom_image *dom, void *ptr)
 
 /* ------------------------------------------------------------------------ */
 
-static int vcpu_x86_32(struct xc_dom_image *dom, void *ptr)
+static int vcpu_x86_32(struct xc_dom_image *dom)
 {
-    vcpu_guest_context_x86_32_t *ctxt = ptr;
+    vcpu_guest_context_any_t any_ctx;
+    vcpu_guest_context_x86_32_t *ctxt = &any_ctx.x32;
     xen_pfn_t cr3_pfn;
+    int rc;
 
     DOMPRINTF_CALLED(dom->xch);
 
@@ -626,13 +628,20 @@ static int vcpu_x86_32(struct xc_dom_image *dom, void *ptr)
     DOMPRINTF("%s: cr3: pfn 0x%" PRIpfn " mfn 0x%" PRIpfn "",
               __FUNCTION__, dom->pgtables_seg.pfn, cr3_pfn);
 
-    return 0;
+    rc = xc_vcpu_setcontext(dom->xch, dom->guest_domid, 0, &any_ctx);
+    if ( rc != 0 )
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: SETVCPUCONTEXT failed (rc=%d)", __func__, rc);
+
+    return rc;
 }
 
-static int vcpu_x86_64(struct xc_dom_image *dom, void *ptr)
+static int vcpu_x86_64(struct xc_dom_image *dom)
 {
-    vcpu_guest_context_x86_64_t *ctxt = ptr;
+    vcpu_guest_context_any_t any_ctx;
+    vcpu_guest_context_x86_64_t *ctxt = &any_ctx.x64;
     xen_pfn_t cr3_pfn;
+    int rc;
 
     DOMPRINTF_CALLED(dom->xch);
 
@@ -665,7 +674,12 @@ static int vcpu_x86_64(struct xc_dom_image *dom, void *ptr)
     ctxt->kernel_ss = ctxt->user_regs.ss;
     ctxt->kernel_sp = ctxt->user_regs.esp;
 
-    return 0;
+    rc = xc_vcpu_setcontext(dom->xch, dom->guest_domid, 0, &any_ctx);
+    if ( rc != 0 )
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: SETVCPUCONTEXT failed (rc=%d)", __func__, rc);
+
+    return rc;
 }
 
 /* ------------------------------------------------------------------------ */
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v6 8/29 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.

---
Changes since v5:
- Set tr limit to 0x67.
- Use "goto out" consistently in vcpu_hvm.
- Unconditionally call free(full_ctx) before exiting vcpu_hvm.
- Add Wei Liu Ack.

Changes since v4:
- Replace a malloc+memset with a calloc.
- Remove a != NULL check.
- Add Andrew Cooper Reviewed-by.

Changes since v3:
- Make sure c/s b9dbe33 is not reverted on this patch.
- Set the initial BSP state using {get/set}hvmcontext.

---
 tools/libxc/include/xc_dom.h |   6 +
 tools/libxc/xc_dom_x86.c     | 618 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 613 insertions(+), 11 deletions(-)
tools/libxc/include/xc_dom.h +6 -0
index 0245d24..cda40d9 100644
@@ -188,6 +188,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 +607 -11

699 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
#9 lore raw

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

Quoted 110 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.

---
Changes since v5:
- Set tr limit to 0x67.
- Use "goto out" consistently in vcpu_hvm.
- Unconditionally call free(full_ctx) before exiting vcpu_hvm.
- Add Wei Liu Ack.

Changes since v4:
- Replace a malloc+memset with a calloc.
- Remove a != NULL check.
- Add Andrew Cooper Reviewed-by.

Changes since v3:
- Make sure c/s b9dbe33 is not reverted on this patch.
- Set the initial BSP state using {get/set}hvmcontext.

---
 tools/libxc/include/xc_dom.h |   6 +
 tools/libxc/xc_dom_x86.c     | 618 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 613 insertions(+), 11 deletions(-)
tools/libxc/xc_dom_x86.c +73 -0
index ae8187f..f36b6f6 100644
 
+static int meminit_hvm(struct xc_dom_image *dom)
+{
+    unsigned long i, vmemid, nr_pages = dom->total_pages;
+    unsigned long p2m_size;
+    unsigned long target_pages = dom->target_pages;
+    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 = dom->claim_enabled;
+    uint64_t total_pages;
+    xen_vmemrange_t dummy_vmemrange[2];
+    unsigned int dummy_vnode_to_pnode[1];
+    xen_vmemrange_t *vmemranges;
+    unsigned int *vnode_to_pnode;
+    unsigned int nr_vmemranges, nr_vnodes;
+    xc_interface *xch = dom->xch;
+    uint32_t domid = dom->guest_domid;
+
+    if ( nr_pages > target_pages )
+        memflags |= XENMEMF_populate_on_demand;
+
+    if ( dom->nr_vmemranges == 0 )
+    {
+        /* Build dummy vnode information
+         *
+         * Guest physical address space layout:
+         * [0, hole_start) [hole_start, 4G) [4G, highmem_end)
+         *
+         * Of course if there is no high memory, the second vmemrange
+         * has no effect on the actual result.
+         */
+
+        dummy_vmemrange[0].start = 0;
+        dummy_vmemrange[0].end   = dom->lowmem_end;
+        dummy_vmemrange[0].flags = 0;
+        dummy_vmemrange[0].nid   = 0;
+        nr_vmemranges = 1;
+
+        if ( dom->highmem_end > (1ULL << 32) )
+        {
+            dummy_vmemrange[1].start = 1ULL << 32;
+            dummy_vmemrange[1].end   = dom->highmem_end;
+            dummy_vmemrange[1].flags = 0;
+            dummy_vmemrange[1].nid   = 0;
+
+            nr_vmemranges++;
+        }
+
+        dummy_vnode_to_pnode[0] = XC_NUMA_NO_NODE;
+        nr_vnodes = 1;
+        vmemranges = dummy_vmemrange;
+        vnode_to_pnode = dummy_vnode_to_pnode;
+    }
+    else
+    {
+        if ( nr_pages > target_pages )
+        {
+            DOMPRINTF("Cannot enable vNUMA and PoD at the same time");
+            goto error_out;
+        }
+
+        nr_vmemranges = dom->nr_vmemranges;
+        nr_vnodes = dom->nr_vnodes;
+        vmemranges = dom->vmemranges;
+        vnode_to_pnode = dom->vnode_to_pnode;
+    }
+
+    total_pages = 0;
+    p2m_size = 0;
+    for ( i = 0; i < nr_vmemranges; i++ )

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

Quoted 10 lines
tools/libxc/xc_dom_x86.c +10 -0
+    {
+        total_pages += ((vmemranges[i].end - vmemranges[i].start)
+                        >> PAGE_SHIFT);
+        p2m_size = p2m_size > (vmemranges[i].end >> PAGE_SHIFT) ?
+            p2m_size : (vmemranges[i].end >> PAGE_SHIFT);
+    }
+
+    if ( total_pages != nr_pages )
+    {
+        DOMPRINTF("vNUMA memory pages mismatch (0x%"PRIx64" != 0x%"PRIx64")",

nr_pages is unsigned long, so would need to be print with %lx.

Quoted 4 lines
tools/libxc/xc_dom_x86.c +4 -0
+               total_pages, nr_pages);
+        goto error_out;
+    }
+
Signature · 1 line
Anthony PERARD
#10 lore raw

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

El 18/09/15 a les 17.53, Anthony PERARD ha escrit:

Quoted 15 lines · Roger Pau Monne

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

Quoted 13 lines
tools/libxc/xc_dom_x86.c +13 -0
+    total_pages = 0;
+    p2m_size = 0;
+    for ( i = 0; i < nr_vmemranges; i++ )
+    {
+        total_pages += ((vmemranges[i].end - vmemranges[i].start)
+                        >> PAGE_SHIFT);
+        p2m_size = p2m_size > (vmemranges[i].end >> PAGE_SHIFT) ?
+            p2m_size : (vmemranges[i].end >> PAGE_SHIFT);
+    }
+
+    if ( total_pages != nr_pages )
+    {
+        DOMPRINTF("vNUMA memory pages mismatch (0x%"PRIx64" != 0x%"PRIx64")",
Quoted 1 line

nr_pages is unsigned long, so would need to be print with %lx.

Thanks, fixed now. This code is almost a verbatim copy of the code in xc_hvm_build_x86.c, so I guess you are also seeing this error there.

Roger.

#11 lore raw

PATCH v6 9/29 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]>

---
Changes since v4:
- Add Wei Liu Acked-by.

---
 tools/libxl/libxl_arch.h     |   2 +-
 tools/libxl/libxl_dm.c       |  18 ++--
 tools/libxl/libxl_dom.c      | 227 +++++++++++++++++++++++++------------------
 tools/libxl/libxl_internal.h |   4 +-
 tools/libxl/libxl_vnuma.c    |  12 ++-
 tools/libxl/libxl_x86.c      |   8 +-
 6 files changed, 155 insertions(+), 116 deletions(-)
tools/libxl/libxl_arch.h +1 -1
index bd030b6..34a853c 100644
@@ -60,6 +60,6 @@ _hidden
 int libxl__arch_domain_construct_memmap(libxl__gc *gc,
                                         libxl_domain_config *d_config,
                                         uint32_t domid,
-                                        struct xc_hvm_build_args *args);
+                                        struct xc_dom_image *dom);
 
 #endif
tools/libxl/libxl_dm.c +10 -8
index c84085e..16ad47a 100644
@@ -18,6 +18,8 @@
 #include "libxl_osdeps.h" /* must come before any other headers */
 
 #include "libxl_internal.h"
+
+#include <xc_dom.h>
 #include <xen/hvm/e820.h>
 
 static const char *libxl_tapif_script(libxl__gc *gc)
@@ -181,7 +183,7 @@ add_rdm_entry(libxl__gc *gc, libxl_domain_config *d_config,
 int libxl__domain_device_construct_rdm(libxl__gc *gc,
                                        libxl_domain_config *d_config,
                                        uint64_t rdm_mem_boundary,
-                                       struct xc_hvm_build_args *args)
+                                       struct xc_dom_image *dom)
 {
     int i, j, conflict, rc;
     struct xen_reserved_device_memory *xrdm = NULL;
@@ -189,7 +191,7 @@ int libxl__domain_device_construct_rdm(libxl__gc *gc,
     uint16_t seg;
     uint8_t bus, devfn;
     uint64_t rdm_start, rdm_size;
-    uint64_t highmem_end = args->highmem_end ? args->highmem_end : (1ull<<32);
+    uint64_t highmem_end = dom->highmem_end ? dom->highmem_end : (1ull<<32);
 
     /*
      * We just want to construct RDM once since RDM is specific to the
@@ -303,7 +305,7 @@ int libxl__domain_device_construct_rdm(libxl__gc *gc,
     for (i = 0; i < d_config->num_rdms; i++) {
         rdm_start = d_config->rdms[i].start;
         rdm_size = d_config->rdms[i].size;
-        conflict = overlaps_rdm(0, args->lowmem_end, rdm_start, rdm_size);
+        conflict = overlaps_rdm(0, dom->lowmem_end, rdm_start, rdm_size);
 
         if (!conflict)
             continue;
@@ -314,14 +316,14 @@ int libxl__domain_device_construct_rdm(libxl__gc *gc,
              * We will move downwards lowmem_end so we have to expand
              * highmem_end.
              */
-            highmem_end += (args->lowmem_end - rdm_start);
+            highmem_end += (dom->lowmem_end - rdm_start);
             /* Now move downwards lowmem_end. */
-            args->lowmem_end = rdm_start;
+            dom->lowmem_end = rdm_start;
         }
     }
 
     /* Sync highmem_end. */
-    args->highmem_end = highmem_end;
+    dom->highmem_end = highmem_end;
 
     /*
      * Finally we can take same policy to check lowmem(< 2G) and
@@ -331,11 +333,11 @@ int libxl__domain_device_construct_rdm(libxl__gc *gc,
         rdm_start = d_config->rdms[i].start;
         rdm_size = d_config->rdms[i].size;
         /* Does this entry conflict with lowmem? */
-        conflict = overlaps_rdm(0, args->lowmem_end,
+        conflict = overlaps_rdm(0, dom->lowmem_end,
                                 rdm_start, rdm_size);
         /* Does this entry conflict with highmem? */
         conflict |= overlaps_rdm((1ULL<<32),
-                                 args->highmem_end - (1ULL<<32),
+                                 dom->highmem_end - (1ULL<<32),
                                  rdm_start, rdm_size);
 
         if (!conflict)
tools/libxl/libxl_dom.c +130 -97

365 lines not on this page · raw message

tools/libxl/libxl_internal.h +2 -2
index 6ea6c83..ea89f1f 100644
@@ -1594,7 +1594,7 @@ _hidden int libxl__need_xenpv_qemu(libxl__gc *gc,
 _hidden int libxl__domain_device_construct_rdm(libxl__gc *gc,
                                    libxl_domain_config *d_config,
                                    uint64_t rdm_mem_guard,
-                                   struct xc_hvm_build_args *args);
+                                   struct xc_dom_image *dom);
 
 /*
  * This function will cause the whole libxl process to hang
@@ -3752,7 +3752,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);
 
tools/libxl/libxl_x86.c +5 -3
index 896f34c..9276126 100644
@@ -1,6 +1,8 @@
 #include "libxl_internal.h"
 #include "libxl_arch.h"
 
+#include <xc_dom.h>
+
 int libxl__arch_domain_prepare_config(libxl__gc *gc,
                                       libxl_domain_config *d_config,
                                       xc_domain_configuration_t *xc_config)
@@ -473,7 +475,7 @@ int libxl__arch_domain_map_irq(libxl__gc *gc, uint32_t domid, int irq)
 int libxl__arch_domain_construct_memmap(libxl__gc *gc,
                                         libxl_domain_config *d_config,
                                         uint32_t domid,
-                                        struct xc_hvm_build_args *args)
+                                        struct xc_dom_image *dom)
 {
     int rc = 0;
     unsigned int nr = 0, i;
@@ -481,7 +483,7 @@ int libxl__arch_domain_construct_memmap(libxl__gc *gc,
     unsigned int e820_entries = 1;
     struct e820entry *e820 = NULL;
     uint64_t highmem_size =
-                    args->highmem_end ? args->highmem_end - (1ull << 32) : 0;
+                    dom->highmem_end ? dom->highmem_end - (1ull << 32) : 0;
 
     /* Add all rdm entries. */
     for (i = 0; i < d_config->num_rdms; i++)
@@ -503,7 +505,7 @@ int libxl__arch_domain_construct_memmap(libxl__gc *gc,
 
     /* Low memory */
     e820[nr].addr = GUEST_LOW_MEM_START_DEFAULT;
-    e820[nr].size = args->lowmem_end - GUEST_LOW_MEM_START_DEFAULT;
+    e820[nr].size = dom->lowmem_end - GUEST_LOW_MEM_START_DEFAULT;
     e820[nr].type = E820_RAM;
     nr++;
 
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

Re: [PATCH v6 09/29] libxl: switch HVM domain building to use xc_dom_* helpers

Quoted 34 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]>

---
Changes since v4:
- Add Wei Liu Acked-by.

---
 tools/libxl/libxl_arch.h     |   2 +-
 tools/libxl/libxl_dm.c       |  18 ++--
 tools/libxl/libxl_dom.c      | 227 +++++++++++++++++++++++++------------------
 tools/libxl/libxl_internal.h |   4 +-
 tools/libxl/libxl_vnuma.c    |  12 ++-
 tools/libxl/libxl_x86.c      |   8 +-
 6 files changed, 155 insertions(+), 116 deletions(-)
tools/libxl/libxl_dom.c +0 -3
index 6101e5c..d2cf9e3 100644
@@ -912,52 +935,62 @@ 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;
-    uint64_t mmio_start, lowmem_end, highmem_end;

tools/libxl/libxl_dom.c int libxl__build_hvm(libxl__gc *gc, uint32_t domid, · line 947

Quoted 10 lines
tools/libxl/libxl_dom.c +9 -0
+    int rc;
+    uint64_t mmio_start, lowmem_end, highmem_end, mem_size;
     libxl_domain_build_info *const info = &d_config->b_info;
+    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");

'rc' is uninitialized at this point and is going to be used in out:.

Quoted 3 lines
tools/libxl/libxl_dom.c +3 -0
+        goto out;
+    }
+

[...]

Quoted 10 lines
tools/libxl/libxl_dom.c +3 -0
+    xc_dom_release(dom);
     return 0;
+
 out:
     assert(rc != 0);
+    if (dom != NULL) xc_dom_release(dom);
     return rc;
 }
Signature · 1 line
Anthony PERARD
#13 lore raw

Re: [PATCH v6 09/29] libxl: switch HVM domain building to use xc_dom_* helpers

El 18/09/15 a les 17.53, Anthony PERARD ha escrit:

Quoted 39 lines · Roger Pau Monne
Quoted 38 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.

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

---
Changes since v4:
- Add Wei Liu Acked-by.

---
 tools/libxl/libxl_arch.h     |   2 +-
 tools/libxl/libxl_dm.c       |  18 ++--
 tools/libxl/libxl_dom.c      | 227 +++++++++++++++++++++++++------------------
 tools/libxl/libxl_internal.h |   4 +-
 tools/libxl/libxl_vnuma.c    |  12 ++-
 tools/libxl/libxl_x86.c      |   8 +-
 6 files changed, 155 insertions(+), 116 deletions(-)
tools/libxl/libxl_dom.c +3 -3
index 6101e5c..d2cf9e3 100644
@@ -912,52 +935,62 @@ 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;
-    uint64_t mmio_start, lowmem_end, highmem_end;
+    int rc;
+    uint64_t mmio_start, lowmem_end, highmem_end, mem_size;
     libxl_domain_build_info *const info = &d_config->b_info;
+    struct xc_dom_image *dom = NULL;
Quoted 8 lines

tools/libxl/libxl_dom.c int libxl__build_hvm(libxl__gc *gc, uint32_t domid, · line 947

Quoted 6 lines
tools/libxl/libxl_dom.c +6 -0
+
+    xc_dom_loginit(ctx->xch);
+
+    dom = xc_dom_allocate(ctx->xch, NULL, NULL);
+    if (!dom) {
+        LOGE(ERROR, "xc_dom_allocate failed");

'rc' is uninitialized at this point and is going to be used in out:.

Yes, I'm sorry, I have no idea how I missed it. Anyway, as you say this is missing:

rc = ERROR_NOMEM;

before the goto.

Roger.

#14 lore raw

PATCH v6 10/29 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.

---
Changes since v4:
- Add Wei Liu Acked-by and Andrew Cooper Reviewed-by.

---
 tools/libxc/Makefile              |   2 -
 tools/libxc/include/xenguest.h    |  44 ---
 tools/libxc/xc_hvm_build_arm.c    |  48 ---
 tools/libxc/xc_hvm_build_x86.c    | 808 --------------------------------------
 tools/libxc/xg_private.c          |   9 -
 tools/python/xen/lowlevel/xc/xc.c |  81 ----
 6 files changed, 992 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 baaadd6..818f2e4 100644
@@ -91,9 +91,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 -48

48 lines not on this page · raw message

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

808 lines not on this page · raw message

tools/libxc/xg_private.c +0 -9
index 67946e1..d98f282 100644
@@ -187,15 +187,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
#15 lore raw

PATCH v6 11/29 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]>

---
Changes since v4:
- Add a check to make sure the emulation bitmap is sane (undefined bits are all 0s).
- Add Andrew Cooper Reviewed-by.

Changes since v3:
- Return EOPNOTSUPP instead of ENOPERM if an invalid emulation mask is used.
- Fix error messages (prefix them with d%d and use %#x instead of 0x%x).
- Clearly state in the public header that emulation_flags should only be used with HVM guests.
- Add a XEN_X86 prefix to the emulation flags defines.
- Properly parenthese the has_* marcos.

---
 tools/libxl/libxl_x86.c           |  8 ++++++--
 xen/arch/x86/domain.c             | 23 +++++++++++++++++++++++
 xen/include/asm-x86/domain.h      | 13 +++++++++++++
 xen/include/public/arch-x86/xen.h | 21 ++++++++++++++++++++-
 4 files changed, 62 insertions(+), 3 deletions(-)
tools/libxl/libxl_x86.c +6 -2
index 9276126..9ecd85d 100644
@@ -7,8 +7,12 @@ 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 = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                                      XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                      XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                      XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                      XEN_X86_EMU_IOMMU);
     return 0;
 }
 
xen/arch/x86/domain.c +23 -0
index 045f6ff..fe9504f 100644
@@ -555,6 +555,29 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                d->domain_id);
     }
 
+    if ( is_hvm_domain(d) )
+    {
+        uint32_t emulation_mask = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                                   XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                   XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                   XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                   XEN_X86_EMU_IOMMU);
+        if ( (config->emulation_flags & ~emulation_mask) != 0 )
+        {
+            printk(XENLOG_G_ERR "d%d: Invalid emulation bitmap: %#x.\n",
+                   d->domain_id, config->emulation_flags);
+            return -EINVAL;
+        }
+        if ( config->emulation_flags != emulation_mask )
+        {
+            printk(XENLOG_G_ERR "d%d: Xen does not allow HVM creation with the "
+                   "current selection of emulators: %#x.\n", d->domain_id,
+                   config->emulation_flags);
+            return -EOPNOTSUPP;
+        }
+        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 0fce09e..2527637 100644
@@ -387,8 +387,21 @@ struct arch_domain
     bool_t mem_access_emulate_enabled;
 
     struct monitor_write_data *event_write_data;
+
+    /* Emulated devices enabled bitmap. */
+    uint32_t emulation_flags;
 } __cacheline_aligned;
 
+#define has_vlapic(d)       ((d)->arch.emulation_flags & XEN_X86_EMU_LAPIC)
+#define has_vhpet(d)        ((d)->arch.emulation_flags & XEN_X86_EMU_HPET)
+#define has_vpmtimer(d)     ((d)->arch.emulation_flags & XEN_X86_EMU_PMTIMER)
+#define has_vrtc(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_RTC)
+#define has_vioapic(d)      ((d)->arch.emulation_flags & XEN_X86_EMU_IOAPIC)
+#define has_vpic(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_PIC)
+#define has_vpmu(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_PMU)
+#define has_vvga(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_VGA)
+#define has_viommu(d)       ((d)->arch.emulation_flags & XEN_X86_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 +20 -1
index 2ecc9c9..98cae41 100644
@@ -268,7 +268,26 @@ typedef struct arch_shared_info arch_shared_info_t;
  * XEN_DOMCTL_INTERFACE_VERSION.
  */
 struct xen_arch_domainconfig {
-    char dummy;
+#define _XEN_X86_EMU_LAPIC              0
+#define XEN_X86_EMU_LAPIC               (1U<<_XEN_X86_EMU_LAPIC)
+#define _XEN_X86_EMU_HPET               1
+#define XEN_X86_EMU_HPET                (1U<<_XEN_X86_EMU_HPET)
+#define _XEN_X86_EMU_PMTIMER            2
+#define XEN_X86_EMU_PMTIMER             (1U<<_XEN_X86_EMU_PMTIMER)
+#define _XEN_X86_EMU_RTC                3
+#define XEN_X86_EMU_RTC                 (1U<<_XEN_X86_EMU_RTC)
+#define _XEN_X86_EMU_IOAPIC             4
+#define XEN_X86_EMU_IOAPIC              (1U<<_XEN_X86_EMU_IOAPIC)
+#define _XEN_X86_EMU_PIC                5
+#define XEN_X86_EMU_PIC                 (1U<<_XEN_X86_EMU_PIC)
+#define _XEN_X86_EMU_PMU                6
+#define XEN_X86_EMU_PMU                 (1U<<_XEN_X86_EMU_PMU)
+#define _XEN_X86_EMU_VGA                7
+#define XEN_X86_EMU_VGA                 (1U<<_XEN_X86_EMU_VGA)
+#define _XEN_X86_EMU_IOMMU              8
+#define XEN_X86_EMU_IOMMU               (1U<<_XEN_X86_EMU_IOMMU)
+    /* For HVM guests only, this field is ignored for PV guests. */
+    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
#16 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

Quoted 56 lines · 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]>

---
Changes since v4:
- Add a check to make sure the emulation bitmap is sane (undefined bits are all 0s).
- Add Andrew Cooper Reviewed-by.

Changes since v3:
- Return EOPNOTSUPP instead of ENOPERM if an invalid emulation mask is used.
- Fix error messages (prefix them with d%d and use %#x instead of 0x%x).
- Clearly state in the public header that emulation_flags should only be used with HVM guests.
- Add a XEN_X86 prefix to the emulation flags defines.
- Properly parenthese the has_* marcos.

---
 tools/libxl/libxl_x86.c           |  8 ++++++--
 xen/arch/x86/domain.c             | 23 +++++++++++++++++++++++
 xen/include/asm-x86/domain.h      | 13 +++++++++++++
 xen/include/public/arch-x86/xen.h | 21 ++++++++++++++++++++-
 4 files changed, 62 insertions(+), 3 deletions(-)
tools/libxl/libxl_x86.c +6 -2
index 9276126..9ecd85d 100644
@@ -7,8 +7,12 @@ 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 = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                                      XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                      XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                      XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                      XEN_X86_EMU_IOMMU);
     return 0;
 }
 
xen/arch/x86/domain.c +0 -0
index 045f6ff..fe9504f 100644

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

Quoted 10 lines
xen/arch/x86/domain.c +7 -0
@@ -555,6 +555,29 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                d->domain_id);
     }
 
+    if ( is_hvm_domain(d) )
+    {
+        uint32_t emulation_mask = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                                   XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                   XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                   XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                   XEN_X86_EMU_IOMMU);

This is repetitive. Could you consolidate all these to

  #define XEN_X86_EMU_ALL ...

?

Or am I talking non-sense?

Wei.

#17 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

El 04/09/15 a les 14.25, Wei Liu ha escrit:

Quoted 19 lines · Roger Pau Monne
Quoted 5 lines
xen/arch/x86/domain.c +0 -0
index 045f6ff..fe9504f 100644

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

Quoted 10 lines
xen/arch/x86/domain.c +7 -0
@@ -555,6 +555,29 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                d->domain_id);
     }
 
+    if ( is_hvm_domain(d) )
+    {
+        uint32_t emulation_mask = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                                   XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                   XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                   XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                   XEN_X86_EMU_IOMMU);

This is repetitive. Could you consolidate all these to

Quoted 3 lines
  #define XEN_X86_EMU_ALL ...

?

That sounds fine, I would place it in the public header where all the XEN_X86_EMU_* are defined. I will wait for Andrew's opinion, since he already acked this patch.

Roger.

#18 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 15:51, <[email protected]> wrote:

El 04/09/15 a les 14.25, Wei Liu ha escrit:

Quoted 6 lines · Roger Pau Monne

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int

Quoted 5 lines
xen/arch/x86/domain.c +0 -0
index 045f6ff..fe9504f 100644
@@ -555,6 +555,29 @@ int arch_domain_create(struct domain *d, unsigned int 

domcr_flags,

Quoted 13 lines

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

Quoted 10 lines
xen/arch/x86/domain.c +7 -0
                d->domain_id);
     }
 
+    if ( is_hvm_domain(d) )
+    {
+        uint32_t emulation_mask = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                                   XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                   XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                   XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                   XEN_X86_EMU_IOMMU);

This is repetitive. Could you consolidate all these to

Quoted 7 lines
Quoted 3 lines
  #define XEN_X86_EMU_ALL ...

?

That sounds fine, I would place it in the public header where all the XEN_X86_EMU_* are defined. I will wait for Andrew's opinion, since he already acked this patch.

This doesn't belong in the public ABI, so if at all it should be added there inside #ifdef __XEN__. Alternatively (and perhaps preferably) this would go into another (internal) header.

Jan

#19 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 15:51, <[email protected]> wrote:

El 04/09/15 a les 14.25, Wei Liu ha escrit:

Quoted 6 lines · Roger Pau Monne

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int

Quoted 5 lines
xen/arch/x86/domain.c +0 -0
index 045f6ff..fe9504f 100644
@@ -555,6 +555,29 @@ int arch_domain_create(struct domain *d, unsigned int

domcr_flags,

Quoted 14 lines

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

Quoted 10 lines
xen/arch/x86/domain.c +7 -0
                 d->domain_id);
      }
 
+    if ( is_hvm_domain(d) )
+    {
+        uint32_t emulation_mask = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                                   XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                   XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                   XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                   XEN_X86_EMU_IOMMU);

This is repetitive. Could you consolidate all these to

   #define XEN_X86_EMU_ALL ...
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

?

That sounds fine, I would place it in the public header where all the XEN_X86_EMU_* are defined. I will wait for Andrew's opinion, since he already acked this patch.

This doesn't belong in the public ABI, so if at all it should be added there inside #ifdef __XEN__. Alternatively (and perhaps preferably) this would go into another (internal) header.

Agreed.

Having an ALL mask will be useful for checking invalid values, but this logic is going to get a bit more complicated as soon as we see about introducing situations which permit the use of the vLAPIC, and I don't see the ALL mask being useful anywhere else.

I am not fussed either way.

~Andrew

#20 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

In reply to Jan Beulich

El 04/09/15 a les 15.55, Jan Beulich ha escrit:

Quoted 26 lines
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 15:51, <[email protected]> wrote:

El 04/09/15 a les 14.25, Wei Liu ha escrit:

Quoted 6 lines · Roger Pau Monne

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int

Quoted 5 lines
xen/arch/x86/domain.c +0 -0
index 045f6ff..fe9504f 100644
@@ -555,6 +555,29 @@ int arch_domain_create(struct domain *d, unsigned int 

domcr_flags,

Quoted 16 lines

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

Quoted 10 lines
xen/arch/x86/domain.c +7 -0
                d->domain_id);
     }
 
+    if ( is_hvm_domain(d) )
+    {
+        uint32_t emulation_mask = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                                   XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                   XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                   XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                   XEN_X86_EMU_IOMMU);

This is repetitive. Could you consolidate all these to

  #define XEN_X86_EMU_ALL ...

?

Quoted 7 lines
Quoted 3 lines

That sounds fine, I would place it in the public header where all the XEN_X86_EMU_* are defined. I will wait for Andrew's opinion, since he already acked this patch.

This doesn't belong in the public ABI, so if at all it should be added there inside #ifdef __XEN__. Alternatively (and perhaps preferably) this would go into another (internal) header.

The definitions of XEN_X86_EMU_* and xen_arch_domainconfig are already protected with:

#if defined(__XEN__) || defined(__XEN_TOOLS__)

I don't mind putting them in a different header, but I think this needs to live in the public headers, and IMHO public/arch-x86/xen.h is probably the best place, specially taking into account that xen_arch_domainconfig is also defined there.

Unless someone objects and provides a more suitable location I'm going to define XEN_X86_EMU_ALL there also.

Roger.

#21 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

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

El 04/09/15 a les 14.25, Wei Liu ha escrit:

Quoted 19 lines · Roger Pau Monne
Quoted 5 lines
xen/arch/x86/domain.c +0 -0
index 045f6ff..fe9504f 100644

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

Quoted 10 lines
xen/arch/x86/domain.c +7 -0
@@ -555,6 +555,29 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                d->domain_id);
     }
 
+    if ( is_hvm_domain(d) )
+    {
+        uint32_t emulation_mask = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                                   XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                   XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                   XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                   XEN_X86_EMU_IOMMU);

This is repetitive. Could you consolidate all these to

Quoted 7 lines
Quoted 3 lines
  #define XEN_X86_EMU_ALL ...

?

That sounds fine, I would place it in the public header where all the XEN_X86_EMU_* are defined. I will wait for Andrew's opinion, since he already acked this patch.

Of course he has the final authority here. I don't want block this patch just for such cosmetic comment. :-)

Wei.

Quoted 2 lines

Roger.

Acked-by on v6 11/29
#22 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

In reply to Roger Pau Monne
Quoted 11 lines · 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]>
#23 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

In reply to Roger Pau Monne
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:
tools/libxl/libxl_x86.c +0 -0
@@ -7,8 +7,12 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
                                       libxl_domain_config *d_config,

tools/libxl/libxl_x86.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 15

Quoted 10 lines
tools/libxl/libxl_x86.c +6 -2
                                       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 = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                                      XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                      XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                      XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                      XEN_X86_EMU_IOMMU);

This calls for the elsewhere discussed XEN_X86_EMU_ALL to even be exposed to the tool stack.

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

Quoted 9 lines
xen/arch/x86/domain.c +3 -0
@@ -555,6 +555,29 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                d->domain_id);
     }
 
+    if ( is_hvm_domain(d) )
+    {
+        uint32_t emulation_mask = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |

const

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

Quoted 5 lines
xen/arch/x86/domain.c +5 -0
+                                   XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                   XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                   XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                   XEN_X86_EMU_IOMMU);
+        if ( (config->emulation_flags & ~emulation_mask) != 0 )

Missing blank line between declaration and statements.

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

Quoted 2 lines
xen/arch/x86/domain.c +2 -0
+        {
+            printk(XENLOG_G_ERR "d%d: Invalid emulation bitmap: %#x.\n",

Generally we have no full stops at the end of log messages.

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

Quoted 12 lines
xen/arch/x86/domain.c +12 -0
+                   d->domain_id, config->emulation_flags);
+            return -EINVAL;
+        }
+        if ( config->emulation_flags != emulation_mask )
+        {
+            printk(XENLOG_G_ERR "d%d: Xen does not allow HVM creation with the "
+                   "current selection of emulators: %#x.\n", d->domain_id,
+                   config->emulation_flags);
+            return -EOPNOTSUPP;
+        }
+        d->arch.emulation_flags = config->emulation_flags;
+    }

Isn't there an "else" missing here, validating that the flags are zero?

Jan

#24 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

El 16/09/15 a les 11.50, Jan Beulich ha escrit:

Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:
tools/libxl/libxl_x86.c +1 -2
@@ -7,8 +7,12 @@ 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)
Quoted 8 lines

tools/libxl/libxl_x86.c int libxl__arch_domain_prepare_config(libxl__gc *gc, · line 15

Quoted 5 lines
tools/libxl/libxl_x86.c +5 -0
+        xc_config->emulation_flags = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                                      XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                      XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                      XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                      XEN_X86_EMU_IOMMU);

This calls for the elsewhere discussed XEN_X86_EMU_ALL to even be exposed to the tool stack.

Done.

Quoted 11 lines

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

Quoted 9 lines
xen/arch/x86/domain.c +3 -0
@@ -555,6 +555,29 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                d->domain_id);
     }
 
+    if ( is_hvm_domain(d) )
+    {
+        uint32_t emulation_mask = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |

const

With the introduction of XEN_X86_EMU_ALL this is no longer needed.

Quoted 8 lines

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

Quoted 6 lines
xen/arch/x86/domain.c +5 -0
+                                   XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                   XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                   XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                   XEN_X86_EMU_IOMMU);
+        if ( (config->emulation_flags & ~emulation_mask) != 0 )

Missing blank line between declaration and statements.

emulation_mask is now gone, so no need for the newline any more.

Quoted 4 lines

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

Quoted 2 lines
xen/arch/x86/domain.c +2 -0
+        {
+            printk(XENLOG_G_ERR "d%d: Invalid emulation bitmap: %#x.\n",

Generally we have no full stops at the end of log messages.

Ack, I've removed them here and below, but I've noticed that other printks in arch_domain_create have full stops (that's probably why I've added them here).

Quoted 14 lines

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

Quoted 13 lines
xen/arch/x86/domain.c +12 -0
+                   d->domain_id, config->emulation_flags);
+            return -EINVAL;
+        }
+        if ( config->emulation_flags != emulation_mask )
+        {
+            printk(XENLOG_G_ERR "d%d: Xen does not allow HVM creation with the "
+                   "current selection of emulators: %#x.\n", d->domain_id,
+                   config->emulation_flags);
+            return -EOPNOTSUPP;
+        }
+        d->arch.emulation_flags = config->emulation_flags;
+    }
Quoted 1 line

Isn't there an "else" missing here, validating that the flags are zero?

The comment in xen/include/asm-x86/domain.h above the emulation_flags field already mentions that this field is ignored for PV guests. For example the x86 Dom0 building code calls arch_domain_create passing in a NULL xen_arch_domainconfig, so I think it's easier to just ignore this for PV guests.

Roger.

#25 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 23.09.15 at 14:35, <[email protected]> wrote:

El 16/09/15 a les 11.50, Jan Beulich ha escrit:

Quoted 14 lines
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:
xen/arch/x86/domain.c +12 -0
+                   d->domain_id, config->emulation_flags);
+            return -EINVAL;
+        }
+        if ( config->emulation_flags != emulation_mask )
+        {
+            printk(XENLOG_G_ERR "d%d: Xen does not allow HVM creation with the "
+                   "current selection of emulators: %#x.\n", d->domain_id,
+                   config->emulation_flags);
+            return -EOPNOTSUPP;
+        }
+        d->arch.emulation_flags = config->emulation_flags;
+    }
Quoted 7 lines
Quoted 1 line

Isn't there an "else" missing here, validating that the flags are zero?

The comment in xen/include/asm-x86/domain.h above the emulation_flags field already mentions that this field is ignored for PV guests. For example the x86 Dom0 building code calls arch_domain_create passing in a NULL xen_arch_domainconfig, so I think it's easier to just ignore this for PV guests.

Easier now, but perhaps more cumbersome if we ever want to assign that field some meaning for PV. It's a domctl, so not _that_ difficult to change, but you may have noticed that I generally ask for unused fields/bits to be validated to be zero, to allow using them later on. Anyway - not a big issue, I just wanted to point it out (and I might stumble across the missing else again during review of future revisions).

Jan

#26 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

El 23/09/15 a les 15.24, Jan Beulich ha escrit:

Quoted 24 lines
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 23.09.15 at 14:35, <[email protected]> wrote:

El 16/09/15 a les 11.50, Jan Beulich ha escrit:

Quoted 14 lines
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:
xen/arch/x86/domain.c +12 -0
+                   d->domain_id, config->emulation_flags);
+            return -EINVAL;
+        }
+        if ( config->emulation_flags != emulation_mask )
+        {
+            printk(XENLOG_G_ERR "d%d: Xen does not allow HVM creation with the "
+                   "current selection of emulators: %#x.\n", d->domain_id,
+                   config->emulation_flags);
+            return -EOPNOTSUPP;
+        }
+        d->arch.emulation_flags = config->emulation_flags;
+    }
Quoted 7 lines
Quoted 1 line

Isn't there an "else" missing here, validating that the flags are zero?

The comment in xen/include/asm-x86/domain.h above the emulation_flags field already mentions that this field is ignored for PV guests. For example the x86 Dom0 building code calls arch_domain_create passing in a NULL xen_arch_domainconfig, so I think it's easier to just ignore this for PV guests.

Quoted 7 lines

Easier now, but perhaps more cumbersome if we ever want to assign that field some meaning for PV. It's a domctl, so not _that_ difficult to change, but you may have noticed that I generally ask for unused fields/bits to be validated to be zero, to allow using them later on. Anyway - not a big issue, I just wanted to point it out (and I might stumble across the missing else again during review of future revisions).

OK, you convinced me. I've added a check to the start of arch_domain_create in order to make sure config is not NULL, and fixed the x86 callers of domain_create in order to make sure a non-null config is always provided.

Also dropped Andrew Cooper's reviewed-by tag, since the hypervisor side code has changed substantially.

Roger.

#27 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

In reply to Roger Pau Monne
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:
xen/include/asm-x86/domain.h +3 -0
@@ -387,8 +387,21 @@ struct arch_domain
     bool_t mem_access_emulate_enabled;
 
     struct monitor_write_data *event_write_data;
+
+    /* Emulated devices enabled bitmap. */
+    uint32_t emulation_flags;
 } __cacheline_aligned;

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

Quoted 10 lines
xen/include/asm-x86/domain.h +9 -0
 
+#define has_vlapic(d)       ((d)->arch.emulation_flags & XEN_X86_EMU_LAPIC)
+#define has_vhpet(d)        ((d)->arch.emulation_flags & XEN_X86_EMU_HPET)
+#define has_vpmtimer(d)     ((d)->arch.emulation_flags & XEN_X86_EMU_PMTIMER)
+#define has_vrtc(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_RTC)
+#define has_vioapic(d)      ((d)->arch.emulation_flags & XEN_X86_EMU_IOAPIC)
+#define has_vpic(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_PIC)
+#define has_vpmu(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_PMU)
+#define has_vvga(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_VGA)
+#define has_viommu(d)       ((d)->arch.emulation_flags & XEN_X86_EMU_IOMMU)

And btw, now that I saw a few uses of these - do they really all need to be has_v*() instead of just has_*()? Together with the macros taking a domain pointer it's quite obvious that talk is about virtual devices...

Jan

#28 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

El 16/09/15 a les 12.10, Jan Beulich ha escrit:

Quoted 12 lines
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:
xen/include/asm-x86/domain.h +3 -0
@@ -387,8 +387,21 @@ struct arch_domain
     bool_t mem_access_emulate_enabled;
 
     struct monitor_write_data *event_write_data;
+
+    /* Emulated devices enabled bitmap. */
+    uint32_t emulation_flags;
 } __cacheline_aligned;
 
Quoted 13 lines

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

Quoted 9 lines
xen/include/asm-x86/domain.h +9 -0
+#define has_vlapic(d)       ((d)->arch.emulation_flags & XEN_X86_EMU_LAPIC)
+#define has_vhpet(d)        ((d)->arch.emulation_flags & XEN_X86_EMU_HPET)
+#define has_vpmtimer(d)     ((d)->arch.emulation_flags & XEN_X86_EMU_PMTIMER)
+#define has_vrtc(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_RTC)
+#define has_vioapic(d)      ((d)->arch.emulation_flags & XEN_X86_EMU_IOAPIC)
+#define has_vpic(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_PIC)
+#define has_vpmu(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_PMU)
+#define has_vvga(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_VGA)
+#define has_viommu(d)       ((d)->arch.emulation_flags & XEN_X86_EMU_IOMMU)

And btw, now that I saw a few uses of these - do they really all need to be has_v*() instead of just has_*()? Together with the macros taking a domain pointer it's quite obvious that talk is about virtual devices...

IMHO, I prefer to have the "v" prefix, because that's how they are named inside of Xen, so it's more clear that we are actually disabling them, but I'm not going to fight for it.

#29 lore raw

Re: [PATCH v6 11/29] xen/x86: add bitmap of enabled emulated devices

Quoted 25 lines · Roger Pau Monné

El 16/09/15 a les 12.10, Jan Beulich ha escrit:

Quoted 12 lines
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:
xen/include/asm-x86/domain.h +3 -0
@@ -387,8 +387,21 @@ struct arch_domain
      bool_t mem_access_emulate_enabled;
 
      struct monitor_write_data *event_write_data;
+
+    /* Emulated devices enabled bitmap. */
+    uint32_t emulation_flags;
  } __cacheline_aligned;
 
Quoted 12 lines

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

Quoted 9 lines
xen/include/asm-x86/domain.h +9 -0
+#define has_vlapic(d)       ((d)->arch.emulation_flags & XEN_X86_EMU_LAPIC)
+#define has_vhpet(d)        ((d)->arch.emulation_flags & XEN_X86_EMU_HPET)
+#define has_vpmtimer(d)     ((d)->arch.emulation_flags & XEN_X86_EMU_PMTIMER)
+#define has_vrtc(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_RTC)
+#define has_vioapic(d)      ((d)->arch.emulation_flags & XEN_X86_EMU_IOAPIC)
+#define has_vpic(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_PIC)
+#define has_vpmu(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_PMU)
+#define has_vvga(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_VGA)
+#define has_viommu(d)       ((d)->arch.emulation_flags & XEN_X86_EMU_IOMMU)

And btw, now that I saw a few uses of these - do they really all need to be has_v*() instead of just has_*()? Together with the macros taking a domain pointer it's quite obvious that talk is about virtual devices...

Quoted 3 lines

IMHO, I prefer to have the "v" prefix, because that's how they are named inside of Xen, so it's more clear that we are actually disabling them, but I'm not going to fight for it.

I personally think it is clearer having the v in the name.

~Andrew

#30 lore raw

PATCH v6 12/29 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]>

---
Changes since v5:
- Add Boris Ostrovsky Reviewed-by.

Changes since v4:
- Split the is_pvh_domain check into two, so part of the code can be shared with the !has_lapic case.
- Add Andrew Cooper Acked-by.

---
 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 |  5 ++++-
 xen/arch/x86/hvm/vmx/vmx.c  |  9 ++++++++-
 5 files changed, 52 insertions(+), 14 deletions(-)
xen/arch/x86/hvm/svm/svm.c +9 -7
index 8de41fa..97dc507 100644
@@ -1035,6 +1035,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;
@@ -1058,14 +1059,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);
     }
 
@@ -2294,6 +2295,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);
 
@@ -2311,11 +2313,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;
@@ -2697,14 +2699,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 b893b40..e355679 100644
@@ -993,6 +993,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) )
@@ -1042,8 +1045,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;
@@ -1118,6 +1120,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);
@@ -1265,6 +1270,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);
@@ -1281,6 +1289,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 )
@@ -1328,7 +1339,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 )
@@ -1360,7 +1374,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 )
@@ -1399,7 +1416,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;
@@ -1452,6 +1469,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 ac838a9..e6a145d 100644
@@ -482,6 +482,9 @@ found:
 
 void msixtbl_init(struct domain *d)
 {
+    if ( !has_vlapic(d) )
+        return;
+
     INIT_LIST_HEAD(&d->arch.hvm_domain.msixtbl_list);
     spin_lock_init(&d->arch.hvm_domain.msixtbl_list_lock);
 
@@ -493,6 +496,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 +4 -1
index a0a97e7..4251b2c 100644
@@ -1002,7 +1002,7 @@ static int construct_vmcs(struct vcpu *v)
         ~(SECONDARY_EXEC_ENABLE_VM_FUNCTIONS |
           SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS);
 
-    if ( is_pvh_domain(d) )
+    if ( is_pvh_domain(d) || !has_vlapic(d) )
     {
         /* Disable virtual apics, TPR */
         v->arch.hvm_vmx.secondary_exec_control &=
@@ -1014,7 +1014,10 @@ static int construct_vmcs(struct vcpu *v)
         /* In turn, disable posted interrupts. */
         __vmwrite(PIN_BASED_VM_EXEC_CONTROL,
                   vmx_pin_based_exec_control & ~PIN_BASED_POSTED_INTERRUPT);
+    }
 
+    if ( is_pvh_domain(d) )
+    {
         /* Unrestricted guest (real mode for EPT) */
         v->arch.hvm_vmx.secondary_exec_control &=
             ~SECONDARY_EXEC_UNRESTRICTED_GUEST;
xen/arch/x86/hvm/vmx/vmx.c +8 -1
index 2582cdd..763b589 100644
@@ -89,6 +89,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;
 
@@ -97,6 +100,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);
 }
 
@@ -2393,7 +2399,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
#31 lore raw

Re: [PATCH v6 12/29] xen/x86: allow disabling the emulated local apic

Quoted 52 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +7 -5
@@ -1035,6 +1035,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;
@@ -1058,14 +1059,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);
     }
 
@@ -2294,6 +2295,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);
 
@@ -2311,11 +2313,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;

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_regs *regs) · line 2703

Quoted 6 lines
xen/arch/x86/hvm/svm/svm.c +1 -1
@@ -2697,14 +2699,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. */

The comment is now stale.

Also - aren't all the changes to this file (and perhaps othersfurther down) bug fixes in their own right?

xen/arch/x86/hvm/svm/svm.c void vlapic_tdt_msr_set(struct vlapic *vlapic, uint64_t value) · line 1050

Quoted 9 lines
xen/arch/x86/hvm/svm/svm.c +1 -2
@@ -1042,8 +1045,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");

The newly added condition needless triggers the HVM_DBG_LOG(). Please separate it.

Quoted 13 lines
xen/arch/x86/hvm/svm/svm.c +4 -1
@@ -1328,7 +1339,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 )

xen/arch/x86/hvm/svm/svm.c static int lapic_load_regs(struct domain *d, hvm_domain_context_t *h) · line 1379

Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +3 -1
@@ -1360,7 +1374,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;

I agree that the save side should return zero in that case, but aren't load attempts invalid (and hence warrant an error return)?

xen/arch/x86/hvm/svm/svm.c int vlapic_init(struct vcpu *v) · line 1419

Quoted 6 lines
xen/arch/x86/hvm/svm/svm.c +1 -1
@@ -1399,7 +1416,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) )

Isn't the latter alone sufficient?

xen/arch/x86/hvm/svm/svm.c void vlapic_destroy(struct vcpu *v) · line 1472

Quoted 5 lines
xen/arch/x86/hvm/svm/svm.c +1 -0
@@ -1452,6 +1469,9 @@ void vlapic_destroy(struct vcpu *v)
 {
     struct vlapic *vlapic = vcpu_vlapic(v);
 
+    if ( !has_vlapic(vlapic_domain(vlapic)) )

I think v->domain would be better here.

xen/arch/x86/hvm/vmsi.c found: · line 489

Quoted 11 lines
xen/arch/x86/hvm/vmsi.c +3 -0
@@ -482,6 +482,9 @@ found:
 
 void msixtbl_init(struct domain *d)
 {
+    if ( !has_vlapic(d) )
+        return;
+
     INIT_LIST_HEAD(&d->arch.hvm_domain.msixtbl_list);
     spin_lock_init(&d->arch.hvm_domain.msixtbl_list_lock);

Don't you also need to add guards to msixtbl_pt_{,un}register()?

xen/arch/x86/hvm/vmx/vmcs.c static int construct_vmcs(struct vcpu *v) · line 1005

Quoted 8 lines
xen/arch/x86/hvm/vmx/vmcs.c +1 -1
@@ -1002,7 +1002,7 @@ static int construct_vmcs(struct vcpu *v)
         ~(SECONDARY_EXEC_ENABLE_VM_FUNCTIONS |
           SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS);
 
-    if ( is_pvh_domain(d) )
+    if ( is_pvh_domain(d) || !has_vlapic(d) )

See above.

Jan

#32 lore raw

Re: [PATCH v6 12/29] xen/x86: allow disabling the emulated local apic

El 16/09/15 a les 12.05, Jan Beulich ha escrit:

Quoted 54 lines
Quoted 54 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:
xen/arch/x86/hvm/svm/svm.c +7 -5
@@ -1035,6 +1035,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;
@@ -1058,14 +1059,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);
     }
 
@@ -2294,6 +2295,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);
 
@@ -2311,11 +2313,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;
@@ -2697,14 +2699,14 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
     }
 
Quoted 6 lines

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_regs *regs) · line 2703

Quoted 4 lines
xen/arch/x86/hvm/svm/svm.c +1 -1
   out:
-    if ( vcpu_guestmode )
+    if ( vcpu_guestmode || vlapic_hw_disabled(vlapic) )
         /* Don't clobber TPR of the nested guest. */

The comment is now stale.

Thanks, I've removed it.

Quoted 2 lines

Also - aren't all the changes to this file (and perhaps othersfurther down) bug fixes in their own right?

Whether they should be considered bugs or not it's hard to tell. There was no code that executed this paths before with this configuration, and probably nobody considered running HVM guests without an emulated lapic a possibility, so I would argue that they are merely omissions.

Quoted 4 lines
Quoted 4 lines
xen/arch/x86/hvm/svm/svm.c +0 -0
@@ -1042,8 +1045,7 @@ void vlapic_tdt_msr_set(struct vlapic *vlapic, uint64_t value)
     uint64_t guest_tsc;
     struct vcpu *v = vlapic_vcpu(vlapic);
 
Quoted 8 lines

xen/arch/x86/hvm/svm/svm.c void vlapic_tdt_msr_set(struct vlapic *vlapic, uint64_t value) · line 1050

Quoted 5 lines
xen/arch/x86/hvm/svm/svm.c +1 -2
-    /* 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");

The newly added condition needless triggers the HVM_DBG_LOG(). Please separate it.

Done.

Quoted 15 lines
Quoted 15 lines
xen/arch/x86/hvm/svm/svm.c +4 -1
@@ -1328,7 +1339,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 )
@@ -1360,7 +1374,10 @@ static int lapic_load_regs(struct domain *d, hvm_domain_context_t *h)
     uint16_t vcpuid;
     struct vcpu *v;
Quoted 8 lines

xen/arch/x86/hvm/svm/svm.c static int lapic_load_regs(struct domain *d, hvm_domain_context_t *h) · line 1379

Quoted 5 lines
xen/arch/x86/hvm/svm/svm.c +3 -1
     struct vlapic *s;
-    
+
+    if ( !has_vlapic(d) )
+        return 0;

I agree that the save side should return zero in that case, but aren't load attempts invalid (and hence warrant an error return)?

Good point, ENODEV seems like the most appropriate error code here IMHO.

Quoted 8 lines

xen/arch/x86/hvm/svm/svm.c int vlapic_init(struct vcpu *v) · line 1419

Quoted 6 lines
xen/arch/x86/hvm/svm/svm.c +1 -1
@@ -1399,7 +1416,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) )

Isn't the latter alone sufficient?

Yes.

Quoted 7 lines

xen/arch/x86/hvm/svm/svm.c void vlapic_destroy(struct vcpu *v) · line 1472

Quoted 5 lines
xen/arch/x86/hvm/svm/svm.c +1 -0
@@ -1452,6 +1469,9 @@ void vlapic_destroy(struct vcpu *v)
 {
     struct vlapic *vlapic = vcpu_vlapic(v);
 
+    if ( !has_vlapic(vlapic_domain(vlapic)) )

I think v->domain would be better here.

TBH, I don't have a strong opinion, if you think v->domain is clearer I'm fine with that.

Quoted 4 lines
Quoted 4 lines
xen/arch/x86/hvm/vmsi.c +0 -0
@@ -482,6 +482,9 @@ found:
 
Quoted 9 lines

xen/arch/x86/hvm/vmsi.c found: · line 489

Quoted 7 lines
xen/arch/x86/hvm/vmsi.c +3 -0
 void msixtbl_init(struct domain *d)
 {
+    if ( !has_vlapic(d) )
+        return;
+
     INIT_LIST_HEAD(&d->arch.hvm_domain.msixtbl_list);
     spin_lock_init(&d->arch.hvm_domain.msixtbl_list_lock);

Don't you also need to add guards to msixtbl_pt_{,un}register()?

Yes, that's right. XEN_DOMCTL_bind_pt_irq (which calls msixtbl_pt_register) can be executed against HVM guests, and by extensions against HVMlite guests.

Quoted 10 lines

xen/arch/x86/hvm/vmx/vmcs.c static int construct_vmcs(struct vcpu *v) · line 1005

Quoted 8 lines
xen/arch/x86/hvm/vmx/vmcs.c +1 -1
@@ -1002,7 +1002,7 @@ static int construct_vmcs(struct vcpu *v)
         ~(SECONDARY_EXEC_ENABLE_VM_FUNCTIONS |
           SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS);
 
-    if ( is_pvh_domain(d) )
+    if ( is_pvh_domain(d) || !has_vlapic(d) )

See above.

Fixed.

Thanks for the thorough review!

Roger.

#33 lore raw

Re: [PATCH v6 12/29] xen/x86: allow disabling the emulated local apic

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

El 16/09/15 a les 12.05, Jan Beulich ha escrit:

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:

Also - aren't all the changes to this file (and perhaps othersfurther down) bug fixes in their own right?

Whether they should be considered bugs or not it's hard to tell. There was no code that executed this paths before with this configuration, and probably nobody considered running HVM guests without an emulated lapic a possibility, so I would argue that they are merely omissions.

Whether these were active or latent bugs doesn't really matter. What I'd prefer is for the code adjustments not directly related to the feature suppression you work on to be in their own patch, so that the two steps taken can be viewed as two steps. Particularly if it later turns out that one or more of those apparent latent bugs are found to be actively harming some special case, backporting that adjustment without the feature suppression parts would become a straightforward option.

Jan

#34 lore raw

Re: [PATCH v6 12/29] xen/x86: allow disabling the emulated local apic

El 24/09/15 a les 9.57, Jan Beulich ha escrit:

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

El 16/09/15 a les 12.05, Jan Beulich ha escrit:

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:

Also - aren't all the changes to this file (and perhaps othersfurther down) bug fixes in their own right?

Whether they should be considered bugs or not it's hard to tell. There was no code that executed this paths before with this configuration, and probably nobody considered running HVM guests without an emulated lapic a possibility, so I would argue that they are merely omissions.

Quoted 8 lines

Whether these were active or latent bugs doesn't really matter. What I'd prefer is for the code adjustments not directly related to the feature suppression you work on to be in their own patch, so that the two steps taken can be viewed as two steps. Particularly if it later turns out that one or more of those apparent latent bugs are found to be actively harming some special case, backporting that adjustment without the feature suppression parts would become a straightforward option.

Ack, I'm going to split some of the changes in this patch to a pre-patch.

Roger.

#35 lore raw

PATCH v6 13/29 xen/x86: allow disabling the emulated HPET

In reply to Roger Pau Monne

---
Changes in v4:
- Add Andrew Cooper Acked-by.

---
 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 edf9a17..266b587 100644
@@ -516,6 +516,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);
 
@@ -575,6 +578,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 */
@@ -633,6 +639,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);
@@ -660,6 +669,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)
@@ -667,6 +677,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 615fa89..1640b58 100644
@@ -1594,7 +1594,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
#36 lore raw

PATCH v6 14/29 xen/x86: allow disabling the pmtimer

In reply to Roger Pau Monne

---
Changes since v4:
- Add Andrew Cooper Acked-by.

---
 xen/arch/x86/hvm/pmtimer.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
xen/arch/x86/hvm/pmtimer.c +13 -0
index 07594e1..199a15e 100644
@@ -247,6 +247,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
@@ -271,6 +274,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 */
@@ -328,6 +334,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;
@@ -348,6 +357,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
#37 lore raw

PATCH v6 15/29 xen/x86: allow disabling the emulated RTC

In reply to Roger Pau Monne

---
Changes since v4:
- Add Andrew Cooper Acked-by.

---
 xen/arch/x86/hvm/rtc.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
xen/arch/x86/hvm/rtc.c +16 -0
index a9efeaf..bc93f66 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
#38 lore raw

PATCH v6 16/29 xen/x86: allow disabling the emulated IO APIC

In reply to Roger Pau Monne

---
Changes since v4:
- Add Andrew Cooper Acked-by.

---
 xen/arch/x86/hvm/vioapic.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
xen/arch/x86/hvm/vioapic.c +14 -0
index d348235..30a4a0f 100644
@@ -424,12 +424,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);
 }
 
@@ -448,6 +456,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;
@@ -462,6 +473,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
#39 lore raw

PATCH v6 17/29 xen/x86: allow disabling the emulated PIC

In reply to Roger Pau Monne

---
Changes since v4:
- Add Andrew Cooper Acked-by.

---
 xen/arch/x86/hvm/vpic.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vpic.c +10 -1
index 7c2edc8..5938f40 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
#40 lore raw

Re: [PATCH v6 17/29] xen/x86: allow disabling the emulated PIC

xen/arch/x86/hvm/vpic.c void vpic_reset(struct domain *d) · line 435

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:
xen/arch/x86/hvm/vpic.c +2 -0
@@ -425,6 +431,9 @@ void vpic_reset(struct domain *d)
 
 void vpic_init(struct domain *d)
 {
+    if ( !has_vpic(d) )
+        return;

vpic_reset() above this function as well as functions further down in the source file aren't static, yet you aren't adding guards to them. I think here and in other similar patches you should, in the commit message, give reasons for any one not obviously being excluded (e.g. because used only for handling intercepts which aren't getting enabled) from the set needing such.

Jan

#41 lore raw

Re: [PATCH v6 17/29] xen/x86: allow disabling the emulated PIC

El 21/09/15 a les 16.34, Jan Beulich ha escrit:

Quoted 14 lines

xen/arch/x86/hvm/vpic.c void vpic_reset(struct domain *d) · line 435

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:
xen/arch/x86/hvm/vpic.c +2 -0
@@ -425,6 +431,9 @@ void vpic_reset(struct domain *d)
 
 void vpic_init(struct domain *d)
 {
+    if ( !has_vpic(d) )
+        return;

vpic_reset() above this function as well as functions further down in the source file aren't static, yet you aren't adding guards to them. I think here and in other similar patches you should, in the commit message, give reasons for any one not obviously being excluded (e.g. because used only for handling intercepts which aren't getting enabled) from the set needing such.

I've gone through the patches and added appropriate guards or asserts to the public functions, depending on whether we are expecting them to be called or not. I've also fixed all the _load functions to return ENODEV if the device has been disabled (_save functions are just noops and return 0).

Roger.

#42 lore raw

PATCH v6 18/29 xen/x86: allow disabling the emulated pmu

In reply to Roger Pau Monne

---
Changes since v4:
- Add Andrew Cooper Acked-by.

---
 xen/arch/x86/cpu/vpmu.c | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/cpu/vpmu.c +3 -0
index 8af3df1..d5bb77d 100644
@@ -439,6 +439,9 @@ void vpmu_initialise(struct vcpu *v)
     int ret;
     bool_t is_priv_vpmu = is_hardware_domain(v->domain);
 
+    if ( !has_vpmu(v->domain) )
+        return;
+
     BUILD_BUG_ON(sizeof(struct xen_pmu_intel_ctxt) > XENPMU_CTXT_PAD_SZ);
     BUILD_BUG_ON(sizeof(struct xen_pmu_amd_ctxt) > XENPMU_CTXT_PAD_SZ);
     BUILD_BUG_ON(sizeof(struct xen_pmu_regs) > XENPMU_REGS_PAD_SZ);
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

Re: [PATCH v6 18/29] xen/x86: allow disabling the emulated pmu

Quoted 1 line
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:

Hmm - this seems questionable to me: Isn't the vPMU an optional feature anyway? I.e. doesn't need separate handling here? Boris?

Jan

Quoted 27 lines

---
Changes since v4:
- Add Andrew Cooper Acked-by.

---
 xen/arch/x86/cpu/vpmu.c | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/cpu/vpmu.c +3 -0
index 8af3df1..d5bb77d 100644
@@ -439,6 +439,9 @@ void vpmu_initialise(struct vcpu *v)
     int ret;
     bool_t is_priv_vpmu = is_hardware_domain(v->domain);
 
+    if ( !has_vpmu(v->domain) )
+        return;
+
     BUILD_BUG_ON(sizeof(struct xen_pmu_intel_ctxt) > XENPMU_CTXT_PAD_SZ);
     BUILD_BUG_ON(sizeof(struct xen_pmu_amd_ctxt) > XENPMU_CTXT_PAD_SZ);
     BUILD_BUG_ON(sizeof(struct xen_pmu_regs) > XENPMU_REGS_PAD_SZ);
Signature · 1 line
1.9.5 (Apple Git-50.3)

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

#44 lore raw

Re: [PATCH v6 18/29] xen/x86: allow disabling the emulated pmu

Quoted 3 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:

Hmm - this seems questionable to me: Isn't the vPMU an optional feature anyway? I.e. doesn't need separate handling here? Boris?

It is optional system-wise, not per-guest, which is what I think Roger is trying to do. I in fact wanted to add ability to disable VPMU per guest myself.

However, VPMU has nothing to do with device model so I don't think it should be part of this series from that perspective.

-boris

Quoted 22 lines

Jan

Quoted 19 lines

---
Changes since v4:
- Add Andrew Cooper Acked-by.

---
  xen/arch/x86/cpu/vpmu.c | 3 +++
  1 file changed, 3 insertions(+)
xen/arch/x86/cpu/vpmu.c +0 -0
index 8af3df1..d5bb77d 100644
@@ -439,6 +439,9 @@ void vpmu_initialise(struct vcpu *v)
      int ret;
      bool_t is_priv_vpmu = is_hardware_domain(v->domain);
 
Quoted 9 lines
Quoted 8 lines
xen/arch/x86/cpu/vpmu.c +3 -0
+    if ( !has_vpmu(v->domain) )
+        return;
+
      BUILD_BUG_ON(sizeof(struct xen_pmu_intel_ctxt) > XENPMU_CTXT_PAD_SZ);
      BUILD_BUG_ON(sizeof(struct xen_pmu_amd_ctxt) > XENPMU_CTXT_PAD_SZ);
      BUILD_BUG_ON(sizeof(struct xen_pmu_regs) > XENPMU_REGS_PAD_SZ);
Signature · 1 line
1.9.5 (Apple Git-50.3)

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

#45 lore raw

Re: [PATCH v6 18/29] xen/x86: allow disabling the emulated pmu

El 21/09/15 a les 16.48, Boris Ostrovsky ha escrit:

Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:

Hmm - this seems questionable to me: Isn't the vPMU an optional feature anyway? I.e. doesn't need separate handling here? Boris?

It is optional system-wise, not per-guest, which is what I think Roger is trying to do. I in fact wanted to add ability to disable VPMU per guest myself.

However, VPMU has nothing to do with device model so I don't think it should be part of this series from that perspective.

vpmu is enabled globally on the xen command line, there's no way to disable it on a per-guest basis, so AFAICS it will be enabled for HMVlite guests which is wrong because we don't have a vlapic.

IMHO, there's no need to add a flag to specifically disable the vpmu, we can just decide whether to enable it based on vlapic presence and the global vpmu flag.

Roger.

#46 lore raw

Re: [PATCH v6 18/29] xen/x86: allow disabling the emulated pmu

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 25.09.15 at 17:07, <[email protected]> wrote:

El 21/09/15 a les 16.48, Boris Ostrovsky ha escrit:

Quoted 9 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:

Hmm - this seems questionable to me: Isn't the vPMU an optional feature anyway? I.e. doesn't need separate handling here? Boris?

It is optional system-wise, not per-guest, which is what I think Roger is trying to do. I in fact wanted to add ability to disable VPMU per guest myself.

Quoted 6 lines
Quoted 2 lines

However, VPMU has nothing to do with device model so I don't think it should be part of this series from that perspective.

vpmu is enabled globally on the xen command line, there's no way to disable it on a per-guest basis, so AFAICS it will be enabled for HMVlite guests which is wrong because we don't have a vlapic.

Hmm, Boris specifically enabled vPMU to be available to all three kinds of guests, and PVH in it s current shape doesn't have a vLAPIC either. So making such a connection seems wrong to me.

Jan

#47 lore raw

Re: [PATCH v6 18/29] xen/x86: allow disabling the emulated pmu

El 25/09/15 a les 17.13, Jan Beulich ha escrit:

Quoted 14 lines
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 25.09.15 at 17:07, <[email protected]> wrote:

El 21/09/15 a les 16.48, Boris Ostrovsky ha escrit:

Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:

Hmm - this seems questionable to me: Isn't the vPMU an optional feature anyway? I.e. doesn't need separate handling here? Boris?

It is optional system-wise, not per-guest, which is what I think Roger is trying to do. I in fact wanted to add ability to disable VPMU per guest myself.

However, VPMU has nothing to do with device model so I don't think it should be part of this series from that perspective.

Quoted 7 lines
Quoted 3 lines

vpmu is enabled globally on the xen command line, there's no way to disable it on a per-guest basis, so AFAICS it will be enabled for HMVlite guests which is wrong because we don't have a vlapic.

Hmm, Boris specifically enabled vPMU to be available to all three kinds of guests, and PVH in it s current shape doesn't have a vLAPIC either. So making such a connection seems wrong to me.

IMHO, I would prefer the vPMU support in HVMlite guests to be tied to a vlapic presence, so we can do it the HVM way instead of having to do hypercalls.

One think that could work is changing the is_hvm_* calls in vpmu.c to has_vlapic. This way HVMlite guests could still use the PV vPMU interface, but once a lapic is enabled we could use the native way.

Roger.

#48 lore raw

Re: [PATCH v6 18/29] xen/x86: allow disabling the emulated pmu

Quoted 19 lines · Roger Pau Monné

El 25/09/15 a les 17.13, Jan Beulich ha escrit:

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

El 21/09/15 a les 16.48, Boris Ostrovsky ha escrit:

Quoted 8 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:08, <[email protected]> wrote:

Hmm - this seems questionable to me: Isn't the vPMU an optional feature anyway? I.e. doesn't need separate handling here? Boris?

It is optional system-wise, not per-guest, which is what I think Roger is trying to do. I in fact wanted to add ability to disable VPMU per guest myself.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

However, VPMU has nothing to do with device model so I don't think it should be part of this series from that perspective.

vpmu is enabled globally on the xen command line, there's no way to disable it on a per-guest basis, so AFAICS it will be enabled for HMVlite guests which is wrong because we don't have a vlapic.

Hmm, Boris specifically enabled vPMU to be available to all three kinds of guests, and PVH in it s current shape doesn't have a vLAPIC either. So making such a connection seems wrong to me.

Quoted 7 lines

IMHO, I would prefer the vPMU support in HVMlite guests to be tied to a vlapic presence, so we can do it the HVM way instead of having to do hypercalls.

One think that could work is changing the is_hvm_* calls in vpmu.c to has_vlapic. This way HVMlite guests could still use the PV vPMU interface, but once a lapic is enabled we could use the native way.

Yes, I think that would work.

-boris

#49 lore raw

PATCH v6 19/29 xen/x86: allow disabling the emulated VGA

In reply to Roger Pau Monne

---
Changes since v4:
- Add Andrew Cooper Acked-by.

---
 xen/arch/x86/hvm/stdvga.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/x86/hvm/stdvga.c +6 -0
index f50bff7..a3296bd 100644
@@ -555,6 +555,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);
     
@@ -594,6 +597,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
#50 lore raw

PATCH v6 20/29 xen/x86: allow disabling the emulated IOMMU

In reply to Roger Pau Monne
Cc Suravee Suthikulpanit <[email protected]>
Cc Aravind Gopalakrishnan <[email protected]>

---
Changes since v4:
- Add Andrew Cooper Acked-by.

---
 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 e74f469..b4e75ac 100644
@@ -887,7 +887,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
Acked-by on v6 20/29
#51 lore raw

Re: [PATCH v6 20/29] xen/x86: allow disabling the emulated IOMMU

Quoted 16 lines · Roger Pau Monne
Cc Suravee Suthikulpanit <[email protected]>
Cc Aravind Gopalakrishnan <[email protected]>

---
Changes since v4:
- Add Andrew Cooper Acked-by.

---
  xen/drivers/passthrough/amd/iommu_guest.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
xen/drivers/passthrough/amd/iommu_guest.c +0 -0
index e74f469..b4e75ac 100644

xen/drivers/passthrough/amd/iommu_guest.c int guest_iommu_init(struct domain* d) · line 894

Quoted 9 lines
xen/drivers/passthrough/amd/iommu_guest.c +2 -1
@@ -887,7 +887,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);

Thanks,
-Aravind.

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

#52 lore raw

PATCH v6 21/29 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.

---
Changes since v5:
- Add Andrew Cooper Reviewed-by.

---
 xen/arch/x86/domain.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/domain.c +2 -1
index fe9504f..8fe95f7 100644
@@ -568,7 +568,8 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != emulation_mask )
+        if ( config->emulation_flags != emulation_mask &&
+             config->emulation_flags != 0 )
         {
             printk(XENLOG_G_ERR "d%d: Xen does not allow HVM creation with the "
                    "current selection of emulators: %#x.\n", d->domain_id,
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v6 22/29 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.

---
Changes since v4:
- Add Andrew Cooper Reviewed-by and Wei Liu Acked-by.

---
 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 f929968..365e058 100644
@@ -119,6 +119,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* */
 
@@ -212,6 +213,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
#54 lore raw

Re: [PATCH v6 22/29] elfnotes: intorduce a new PHYS_ENTRY elfnote

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:09, <[email protected]> wrote:

xen/include/public/elfnote.h line 209

Quoted 10 lines
xen/include/public/elfnote.h +7 -0
@@ -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 comment reads as if this was the case for all kinds of guests, yet I suppose it doesn't apply to PV ones. This should be made explicit if so.

Jan

#55 lore raw

Re: [PATCH v6 22/29] elfnotes: intorduce a new PHYS_ENTRY elfnote

El 21/09/15 a les 16.47, Jan Beulich ha escrit:

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:09, <[email protected]> wrote:
xen/include/public/elfnote.h +0 -0
@@ -200,9 +200,18 @@
 #define XEN_ELFNOTE_SUPPORTED_FEATURES 17
 
Quoted 12 lines

xen/include/public/elfnote.h line 209

Quoted 8 lines
xen/include/public/elfnote.h +7 -0
 /*
+ * 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 comment reads as if this was the case for all kinds of guests, yet I suppose it doesn't apply to PV ones. This should be made explicit if so.

Yes, what about the following:

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 inside of an HVM container.

Roger.

#56 lore raw

Re: [PATCH v6 22/29] elfnotes: intorduce a new PHYS_ENTRY elfnote

Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 28.09.15 at 12:35, <[email protected]> wrote:

El 21/09/15 a les 16.47, Jan Beulich ha escrit:

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:09, <[email protected]> wrote:
xen/include/public/elfnote.h +0 -0
@@ -200,9 +200,18 @@
 #define XEN_ELFNOTE_SUPPORTED_FEATURES 17
 
Quoted 12 lines

xen/include/public/elfnote.h line 209

Quoted 8 lines
xen/include/public/elfnote.h +7 -0
 /*
+ * 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 comment reads as if this was the case for all kinds of guests, yet I suppose it doesn't apply to PV ones. This should be made explicit if so.

Quoted 5 lines

Yes, what about the following:

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 inside of an HVM container.

Depends: If the note's presence means this and only this entry point will be used, then okay. If, however, normal PV and/or HVM operation of such a guest is still intended to be possible, then I think this is still too vague. Perhaps

32bit entry point into the kernel. When requested to launch the guest kernel in a HVM container, Xen will use this entry point to launch the guest in 32bit protected mode with paging disabled. Ignored otherwise.

Jan

#57 lore raw

Re: [PATCH v6 22/29] elfnotes: intorduce a new PHYS_ENTRY elfnote

Quoted 29 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 28.09.15 at 12:35, <[email protected]> wrote:

El 21/09/15 a les 16.47, Jan Beulich ha escrit:

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:09, <[email protected]> wrote:
xen/include/public/elfnote.h +0 -0
@@ -200,9 +200,18 @@
 #define XEN_ELFNOTE_SUPPORTED_FEATURES 17
 
Quoted 11 lines

xen/include/public/elfnote.h line 209

Quoted 8 lines
xen/include/public/elfnote.h +7 -0
 /*
+ * 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 comment reads as if this was the case for all kinds of guests, yet I suppose it doesn't apply to PV ones. This should be made explicit if so.

Quoted 5 lines

Yes, what about the following:

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 inside of an HVM container.

Depends: If the note's presence means this and only this entry point will be used, then okay. If, however, normal PV and/or HVM operation of such a guest is still intended to be possible, then I think this is still too vague. Perhaps

Quoted 4 lines

32bit entry point into the kernel. When requested to launch the guest kernel in a HVM container, Xen will use this entry point to launch the guest in 32bit protected mode with paging disabled. Ignored otherwise.

A multi-mode binary seems very likely, certainly for the near future.

As such, this param is an indication of supporting DMLite. The guest kernel knows it was started in DMLite mode if this is the entry point used.

If another entry point is used, the guest was not started in DMLite mode.

~Andrew

#58 lore raw

PATCH v6 23/29 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.

---
Changes since v5:
- Add Andrew Cooper Reviewed-by.

Changes since v4:
- Store the size of the VGA hole inside of the xc_dom_image struct and set it from libxl.
- Rename dom->emulation to dom->device_model (no functional change).
- Add Wei Liu Acked-by.

Changes since v3:
- Explain the meaning of the "emulation" xc_dom_image field.

---
 tools/libxc/include/xc_dom.h |  4 +++
 tools/libxc/xc_dom_x86.c     | 73 ++++++++++++++++++++++++--------------------
 tools/libxl/libxl_dom.c      |  2 ++
 tools/libxl/libxl_internal.h |  1 +
 4 files changed, 47 insertions(+), 33 deletions(-)
tools/libxc/include/xc_dom.h +4 -0
index cda40d9..507b323 100644
@@ -193,6 +193,10 @@ struct xc_dom_image {
     xen_pfn_t mmio_size;
     xen_pfn_t lowmem_end;
     xen_pfn_t highmem_end;
+    xen_pfn_t vga_hole_size;
+
+    /* If unset disables the setup of the IOREQ pages. */
+    bool device_model;
 
     /* Extra ACPI tables passed to HVMLOADER */
     struct xc_hvm_firmware_module acpi_module;
tools/libxc/xc_dom_x86.c +40 -33

119 lines not on this page · raw message

tools/libxl/libxl_dom.c +2 -0
index d2cf9e3..4a214e7 100644
@@ -987,6 +987,8 @@ 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->vga_hole_size = LIBXL_VGA_HOLE_SIZE
+    dom->device_model = true;
 
     rc = libxl__domain_device_construct_rdm(gc, d_config,
                                             info->u.hvm.rdm_mem_boundary_memkb*1024,
tools/libxl/libxl_internal.h +1 -0
index ea89f1f..294d442 100644
@@ -100,6 +100,7 @@
 #define LIBXL_HVM_EXTRA_MEMORY 2048
 #define LIBXL_MIN_DOM0_MEM (128*1024)
 #define LIBXL_INVALID_GFN (~(uint64_t)0)
+#define LIBXL_VGA_HOLE_SIZE 0x20
 /* use 0 as the domid of the toolstack domain for now */
 #define LIBXL_TOOLSTACK_DOMID 0
 #define QEMU_SIGNATURE "DeviceModelRecord0002"
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

PATCH v6 24/29 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.

This patch introduces a new structure (vcpu_hvm_context) that should be used in conjuction with the VCPUOP_initialise hypercall in order to initialize vCPUs for HVM guests.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Stefano Stabellini <[email protected]>

---
Changes since v5:
- Fix a coding style issue.
- Merge the code from wip-dmlite-v5-refactor by Andrew in order to reduce bloat.
- Print the offending %cr3 in case of error when using shadow.
- Reduce the scope of local variables in arch_initialize_vcpu.
- s/current->domain/v->domain/g in arch_initialize_vcpu.
- Expand the comment in public/vcpu.h to document the usage of vcpu_hvm_context for HVM guests.
- Add myself as the copyright holder for the public hvm_vcpu.h header.

Changes since v4:
- Don't assume mode is 64B, add an explicit check.
- Don't set TF_kernel_mode, it is only needed for PV guests.
- Don't set CR0_ET unconditionally.

---
 xen/arch/arm/domain.c             |  24 +++++
 xen/arch/x86/domain.c             | 196 ++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/hvm/hvm.c            |   8 ++
 xen/common/domain.c               |  17 +---
 xen/include/public/hvm/hvm_vcpu.h | 170 +++++++++++++++++++++++++++++++++
 xen/include/public/vcpu.h         |   6 +-
 xen/include/xen/domain.h          |   2 +
 7 files changed, 405 insertions(+), 18 deletions(-)
 create mode 100644 xen/include/public/hvm/hvm_vcpu.h
xen/arch/arm/domain.c +24 -0
index b2bfc7d..b554e00 100644
@@ -752,6 +752,30 @@ int arch_set_info_guest(
     return 0;
 }
 
+int arch_initialize_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
+{
+    struct vcpu_guest_context *ctxt;
+    struct domain *d = v->domain;
+    int rc;
+
+    if ( (ctxt = alloc_vcpu_guest_context()) == NULL )
+        return -ENOMEM;
+
+    if ( copy_from_guest(ctxt, arg, 1) )
+    {
+        free_vcpu_guest_context(ctxt);
+        return -EFAULT;
+    }
+
+    domain_lock(d);
+    rc = v->is_initialised ? -EEXIST : arch_set_info_guest(v, ctxt);
+    domain_unlock(d);
+
+    free_vcpu_guest_context(ctxt);
+
+    return rc;
+}
+
 int arch_vcpu_reset(struct vcpu *v)
 {
     vcpu_end_shutdown_deferral(v);
xen/arch/x86/domain.c +196 -0

208 lines not on this page · raw message

xen/arch/x86/hvm/hvm.c +8 -0
index 1640b58..8856c72 100644
@@ -4980,6 +4980,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:
@@ -5038,6 +5042,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:
xen/common/domain.c +1 -16
index 1b9fcfc..2b41741 100644
@@ -1173,7 +1173,6 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     struct domain *d = current->domain;
     struct vcpu *v;
-    struct vcpu_guest_context *ctxt;
     long rc = 0;
 
     if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
@@ -1185,21 +1184,7 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( v->vcpu_info == &dummy_vcpu_info )
             return -EINVAL;
 
-        if ( (ctxt = alloc_vcpu_guest_context()) == NULL )
-            return -ENOMEM;
-
-        if ( copy_from_guest(ctxt, arg, 1) )
-        {
-            free_vcpu_guest_context(ctxt);
-            return -EFAULT;
-        }
-
-        domain_lock(d);
-        rc = v->is_initialised ? -EEXIST : arch_set_info_guest(v, ctxt);
-        domain_unlock(d);
-
-        free_vcpu_guest_context(ctxt);
-
+        rc = arch_initialize_vcpu(v, arg);
         if ( rc == -ERESTART )
             rc = hypercall_create_continuation(__HYPERVISOR_vcpu_op, "iuh",
                                                cmd, vcpuid, arg);
xen/include/public/hvm/hvm_vcpu.h new file +170 -0

170 lines not on this page · raw message

xen/include/public/vcpu.h +4 -2
index 898b89f..692b87a 100644
@@ -41,8 +41,10 @@
  * Initialise a VCPU. Each VCPU can be initialised only once. A 
  * newly-initialised VCPU will not run until it is brought up by VCPUOP_up.
  * 
- * @extra_arg == pointer to vcpu_guest_context structure containing initial
- *               state for the VCPU.
+ * @extra_arg == For PV or ARM guests this is a pointer to a vcpu_guest_context
+ *               structure containing the initial state for the VCPU. For x86
+ *               HVM based guests this is a pointer to a vcpu_hvm_context
+ *               structure.
  */
 #define VCPUOP_initialise            0
 
xen/include/xen/domain.h +2 -0
index 848db8a..21690be 100644
@@ -68,6 +68,8 @@ void arch_domain_unpause(struct domain *d);
 int arch_set_info_guest(struct vcpu *, vcpu_guest_context_u);
 void arch_get_info_guest(struct vcpu *, vcpu_guest_context_u);
 
+int arch_initialize_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg);
+
 int domain_relinquish_resources(struct domain *d);
 
 void dump_pageframe_info(struct domain *d);
Signature · 7 lines
1.9.5 (Apple Git-50.3)


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

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:09, <[email protected]> wrote:

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

This patch introduces a new structure (vcpu_hvm_context) that should be used in conjuction with the VCPUOP_initialise hypercall in order to initialize vCPUs for HVM guests.

So this bi-modal thing doesn't look too bad, but a concern I have is with the now different contexts used by XEN_DOMCTL_setvcpucontext and VCPUOP_initialise.

Quoted 19 lines
xen/arch/arm/domain.c +13 -0
@@ -752,6 +752,30 @@ int arch_set_info_guest(
     return 0;
 }
 
+int arch_initialize_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
+{
+    struct vcpu_guest_context *ctxt;
+    struct domain *d = v->domain;
+    int rc;
+
+    if ( (ctxt = alloc_vcpu_guest_context()) == NULL )
+        return -ENOMEM;
+
+    if ( copy_from_guest(ctxt, arg, 1) )
+    {
+        free_vcpu_guest_context(ctxt);
+        return -EFAULT;

xen/arch/arm/domain.c int arch_set_info_guest( · line 777

Quoted 10 lines
xen/arch/arm/domain.c +10 -0
+    }
+
+    domain_lock(d);
+    rc = v->is_initialised ? -EEXIST : arch_set_info_guest(v, ctxt);
+    domain_unlock(d);
+
+    free_vcpu_guest_context(ctxt);
+
+    return rc;
+}

I wonder whether this shouldn't instead be kept in common code, with arch code calling it as needed (e.g. as default_initialize_vcpu()), since afaict the code is now duplicate with the x86 side PV handling.

Quoted 10 lines
xen/arch/arm/domain.c +6 -0
@@ -1140,6 +1141,201 @@ int arch_set_info_guest(
 #undef c
 }
 
+/* Called by VCPUOP_initialise for HVM guests. */
+static int arch_set_info_hvm_guest(struct vcpu *v, vcpu_hvm_context_t *ctx)
+{
+    struct cpu_user_regs *uregs = &v->arch.user_regs;
+    struct segment_register cs, ds, ss, tr;
+

xen/arch/arm/domain.c int arch_set_info_guest( · line 1159

Quoted 10 lines
xen/arch/arm/domain.c +10 -0
+#define SEG(s, r)                                                       \
+    (struct segment_register){ .base = (r)->s ## _base,                 \
+            .limit = (r)->s ## _limit, .attr.bytes = (r)->s ## _ar }
+
+    switch ( ctx->mode )
+    {
+    default:
+        return -EINVAL;
+
+    case VCPU_HVM_MODE_16B:

I think "MODE" is misleading here, not just because of the register size issue (see further down) but also because you don't seem to enforce the respective mode to be chosen in cs_ar. I'm also missing at least some simple consistency checks (like CS.DPL == SS.DPL, rIP within CS limit, rSP within SS limit); leaving these to the first VM entry would likely result in much harder to analyze issues in case of bad input.

Quoted 80 lines
xen/arch/arm/domain.c +80 -0
+    {
+        const struct vcpu_hvm_x86_16 *regs = &ctx->cpu_regs.x86_16;
+
+        uregs->rax    = regs->ax;
+        uregs->rcx    = regs->cx;
+        uregs->rdx    = regs->dx;
+        uregs->rbx    = regs->bx;
+        uregs->rsp    = regs->sp;
+        uregs->rbp    = regs->bp;
+        uregs->rsi    = regs->si;
+        uregs->rdi    = regs->di;
+        uregs->rip    = regs->ip;
+        uregs->rflags = regs->flags;
+
+        v->arch.hvm_vcpu.guest_cr[0] = regs->cr0;
+        v->arch.hvm_vcpu.guest_cr[4] = regs->cr4;
+
+        cs = SEG(cs, regs);
+        ds = SEG(ds, regs);
+        ss = SEG(ss, regs);
+        tr = SEG(tr, regs);
+    }
+    break;
+
+    case VCPU_HVM_MODE_32B:
+    {
+        const struct vcpu_hvm_x86_32 *regs = &ctx->cpu_regs.x86_32;
+
+        uregs->rax    = regs->eax;
+        uregs->rcx    = regs->ecx;
+        uregs->rdx    = regs->edx;
+        uregs->rbx    = regs->ebx;
+        uregs->rsp    = regs->esp;
+        uregs->rbp    = regs->ebp;
+        uregs->rsi    = regs->esi;
+        uregs->rdi    = regs->edi;
+        uregs->rip    = regs->eip;
+        uregs->rflags = regs->eflags;
+
+        v->arch.hvm_vcpu.guest_cr[0] = regs->cr0;
+        v->arch.hvm_vcpu.guest_cr[3] = regs->cr3;
+        v->arch.hvm_vcpu.guest_cr[4] = regs->cr4;
+        v->arch.hvm_vcpu.guest_efer  = regs->efer;
+
+        cs = SEG(cs, regs);
+        ds = SEG(ds, regs);
+        ss = SEG(ss, regs);
+        tr = SEG(tr, regs);
+    }
+    break;
+
+    case VCPU_HVM_MODE_64B:
+    {
+        const struct vcpu_hvm_x86_64 *regs = &ctx->cpu_regs.x86_64;
+
+        uregs->rax    = regs->rax;
+        uregs->rcx    = regs->rcx;
+        uregs->rdx    = regs->rdx;
+        uregs->rbx    = regs->rbx;
+        uregs->rsp    = regs->rsp;
+        uregs->rbp    = regs->rbp;
+        uregs->rsi    = regs->rsi;
+        uregs->rdi    = regs->rdi;
+        uregs->rip    = regs->rip;
+        uregs->rflags = regs->rflags;
+        uregs->r8     = regs->r8;
+        uregs->r9     = regs->r9;
+        uregs->r10    = regs->r10;
+        uregs->r11    = regs->r11;
+        uregs->r12    = regs->r12;
+        uregs->r13    = regs->r13;
+        uregs->r14    = regs->r14;
+        uregs->r15    = regs->r15;
+
+        v->arch.hvm_vcpu.guest_cr[0] = regs->cr0;
+        v->arch.hvm_vcpu.guest_cr[3] = regs->cr3;
+        v->arch.hvm_vcpu.guest_cr[4] = regs->cr4;
+        v->arch.hvm_vcpu.guest_efer  = regs->efer;
+
+        cs = SEG(cs, regs);

xen/arch/arm/domain.c int arch_set_info_guest( · line 1249

Quoted 10 lines
xen/arch/arm/domain.c +10 -0
+        ds = SEG(ds, regs);
+        ss = SEG(ss, regs);
+        tr = SEG(tr, regs);
+    }
+    break;
+
+    }
+
+    if ( !paging_mode_hap(v->domain) )
+        v->arch.guest_table = pagetable_null();

A comment with the reason for this would be nice. I can't immediately see why this is here.

Quoted 6 lines
xen/arch/arm/domain.c +6 -0
+    hvm_update_guest_cr(v, 0);
+    hvm_update_guest_cr(v, 4);
+
+    if ( (ctx->mode == VCPU_HVM_MODE_32B) ||
+         (ctx->mode == VCPU_HVM_MODE_64B) )
+    {

xen/arch/arm/domain.c int arch_set_info_guest( · line 1265

Quoted 10 lines
xen/arch/arm/domain.c +10 -0
+        hvm_update_guest_cr(v, 3);
+        hvm_update_guest_efer(v);
+    }
+
+    if ( hvm_paging_enabled(v) && !paging_mode_hap(v->domain) )
+    {
+        /* Shadow-mode CR3 change. Check PDBR and update refcounts. */
+        struct page_info *page = get_page_from_gfn(v->domain,
+                                 v->arch.hvm_vcpu.guest_cr[3] >> PAGE_SHIFT,
+                                 NULL, P2M_ALLOC);

P2M_ALLOC but not P2M_UNSHARE?

Quoted 13 lines
xen/arch/arm/domain.c +13 -0
+        if ( !page )
+        {
+            gdprintk(XENLOG_ERR, "Invalid CR3: %#lx\n",
+                     v->arch.hvm_vcpu.guest_cr[3]);
+            domain_crash(v->domain);
+            return -EINVAL;
+        }
+
+        v->arch.guest_table = pagetable_from_page(page);
+    }
+
+    hvm_set_segment_register(v, x86_seg_cs, &cs);
+    hvm_set_segment_register(v, x86_seg_ds, &ds);

xen/arch/arm/domain.c int arch_set_info_guest( · line 1288

Quoted 10 lines
xen/arch/arm/domain.c +10 -0
+    hvm_set_segment_register(v, x86_seg_ss, &ss);
+    hvm_set_segment_register(v, x86_seg_tr, &tr);
+
+    /* Sync AP's TSC with BSP's. */
+    v->arch.hvm_vcpu.cache_tsc_offset =
+        v->domain->vcpu[0]->arch.hvm_vcpu.cache_tsc_offset;
+    hvm_funcs.set_tsc_offset(v, v->arch.hvm_vcpu.cache_tsc_offset,
+                             v->domain->arch.hvm_domain.sync_tsc);
+
+    v->arch.hvm_vcpu.msr_tsc_adjust = 0;

The need for this one I also can't see right away - another comment perhaps?

xen/arch/arm/domain.c int arch_set_info_guest( · line 1292

Quoted 4 lines
xen/arch/arm/domain.c +4 -0
+    paging_update_paging_modes(v);
+
+    v->is_initialised = 1;
+    set_bit(_VPF_down, &v->pause_flags);

No VGCF_online equivalent?

xen/arch/arm/domain.c int arch_set_info_guest( · line 1294

Quoted 2 lines
xen/arch/arm/domain.c +2 -0
+    return 0;
+#undef SEG

I think this should move up (right after the switch() using it).

Quoted 23 lines
xen/arch/arm/domain.c +23 -0
+#ifndef __XEN_PUBLIC_HVM_HVM_VCPU_H__
+#define __XEN_PUBLIC_HVM_HVM_VCPU_H__
+
+#include "../xen.h"
+
+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;
+    uint16_t flags;
+
+    uint32_t cr0;
+    uint32_t cr4;
+
+    uint32_t cs_base;
+    uint32_t ds_base;
+    uint32_t ss_base;

xen/arch/arm/domain.c int arch_set_info_guest( · line 1327

Quoted 10 lines
xen/arch/arm/domain.c +10 -0
+    uint32_t tr_base;
+    uint32_t cs_limit;
+    uint32_t ds_limit;
+    uint32_t ss_limit;
+    uint32_t tr_limit;
+    uint16_t cs_ar;
+    uint16_t ds_ar;
+    uint16_t ss_ar;
+    uint16_t tr_ar;
+};

I doubt this is very useful: While one ought to be able to start a guest in 16-bit mode, its GPRs still are supposed to be 32 bits wide. The mode used really would depend on the cs_ar setting. (Having the structure just for a 16-bit IP would seem insane.)

xen/arch/arm/domain.c int arch_set_info_guest( · line 1338

Quoted 11 lines
xen/arch/arm/domain.c +11 -0
+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;
+    uint16_t eflags;

uint32_t for sure.

xen/arch/arm/domain.c int arch_set_info_guest(

Quoted 4 lines
xen/arch/arm/domain.c +4 -0
+    uint32_t cr0;
+    uint32_t cr3;
+    uint32_t cr4;
+    uint64_t efer;

What again was the point of having EFER here?

xen/arch/arm/domain.c

Quoted 3 lines
xen/arch/arm/domain.c +3 -0
+    uint32_t cs_base;
+    uint32_t ds_base;
+    uint32_t ss_base;

I continue to question why we have DS here, but not ES (and maybe FS and GS too). I.e. either just CS and SS (which are architecturally required) or at least all four traditional x86 segment registers. And you're also clearly not targeting minimal state, or else there likely wouldn't be a need for e.g. R8-R15 in the 64-bit variant.

Quoted 23 lines
xen/arch/arm/domain.c +23 -0
+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 rflags;
+
+    uint64_t cr0;
+    uint64_t cr3;
+    uint64_t cr4;

xen/arch/arm/domain.c

Quoted 10 lines
xen/arch/arm/domain.c +10 -0
+    uint64_t efer;
+
+    uint32_t cs_base;
+    uint32_t ds_base;
+    uint32_t ss_base;
+    uint32_t tr_base;
+    uint32_t cs_limit;
+    uint32_t ds_limit;
+    uint32_t ss_limit;
+    uint32_t tr_limit;

I can see the need for the TR ones here, but what's the point of the CS, SS, and DS ones?

Quoted 12 lines

+/*
+ * The layout of the _ar fields of the segment registers is the
+ * following:
+ *
+ * Bits [0,3]: type (bits 40-43).

+ * Bit      4: s    (descriptor type, bit 44).
+ * Bit  [5,6]: dpl  (descriptor privilege level, bits 45-46).
+ * Bit      7: p    (segment-present, bit 47).
+ * Bit      8: avl  (available for system software, bit 52).
+ * Bit      9: l    (64-bit code segment, bit 53).
+ * Bit     10: db   (meaning depends on the segment, bit 54).
+ * Bit     11: g    (granularity, bit 55)
Quoted 4 lines

+ *
+ * A more complete description of the meaning of this fields can be
+ * obtained from the Intel SDM, Volume 3, section 3.4.5.
+ */

Please make explicit what state bits 12-15 are expected to be in (hopefully they're being checked to be zero rather than getting ignored).

Please also clarify whether the limit specified for the various segment registers is the one present in descriptor tables (subject to scaling by the g bit) or (more likely) the byte granular one. In any event I suppose certain restrictions apply.

Jan

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

#61 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 6 lines · Jan Beulich

xen/include/public/hvm/hvm_vcpu.h line 72

Quoted 4 lines
xen/include/public/hvm/hvm_vcpu.h new file +4 -0
+    uint32_t cr0;
+    uint32_t cr3;
+    uint32_t cr4;
+    uint64_t efer;

What again was the point of having EFER here?

EFER.NX must match what the BSP chose to set up in the pagetables pointed to in %cr3, or a triple fault will occur.

~Andrew

#62 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 25.09.15 at 17:16, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich

xen/include/public/hvm/hvm_vcpu.h line 72

Quoted 4 lines
xen/include/public/hvm/hvm_vcpu.h new file +4 -0
+    uint32_t cr0;
+    uint32_t cr3;
+    uint32_t cr4;
+    uint64_t efer;

What again was the point of having EFER here?

EFER.NX must match what the BSP chose to set up in the pagetables pointed to in %cr3, or a triple fault will occur.

That is assuming the AP is to start up on shared page tables, which is not a given. Hence a comment seems warranted to state that this is there to allow such a usage by the guest.

Jan

#63 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

In reply to Jan Beulich

El 21/09/15 a les 17.44, Jan Beulich ha escrit:

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:09, <[email protected]> wrote:

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

This patch introduces a new structure (vcpu_hvm_context) that should be used in conjuction with the VCPUOP_initialise hypercall in order to initialize vCPUs for HVM guests.

Quoted 6 lines
Quoted 2 lines

So this bi-modal thing doesn't look too bad, but a concern I have is with the now different contexts used by XEN_DOMCTL_setvcpucontext and VCPUOP_initialise.

Yes, that's far from ideal. I was going to say that XEN_DOMCTL_{set/get}vcpucontext should return EOPNOTSUPP when executed against HVM guests, but that's going to break current toolstack code that relies on this in order to perform suspend/resume of HVM guests (and gdbsx would probably also be affected).

If you feel that would be a better solution I could fix current tools code in order to use XEN_DOMCTL_{get/set}hvmcontext instead of XEN_DOMCTL_{set/get}vcpucontext when dealing with HVM guests.

Quoted 25 lines
Quoted 25 lines
xen/arch/arm/domain.c +19 -0
@@ -752,6 +752,30 @@ int arch_set_info_guest(
     return 0;
 }
 
+int arch_initialize_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
+{
+    struct vcpu_guest_context *ctxt;
+    struct domain *d = v->domain;
+    int rc;
+
+    if ( (ctxt = alloc_vcpu_guest_context()) == NULL )
+        return -ENOMEM;
+
+    if ( copy_from_guest(ctxt, arg, 1) )
+    {
+        free_vcpu_guest_context(ctxt);
+        return -EFAULT;
+    }
+
+    domain_lock(d);
+    rc = v->is_initialised ? -EEXIST : arch_set_info_guest(v, ctxt);
+    domain_unlock(d);
+
Quoted 8 lines

xen/arch/arm/domain.c int arch_set_info_guest( · line 777

Quoted 4 lines
xen/arch/arm/domain.c +4 -0
+    free_vcpu_guest_context(ctxt);
+
+    return rc;
+}

I wonder whether this shouldn't instead be kept in common code, with arch code calling it as needed (e.g. as default_initialize_vcpu()), since afaict the code is now duplicate with the x86 side PV handling.

Ack.

Quoted 21 lines
Quoted 10 lines
xen/arch/arm/domain.c +6 -0
@@ -1140,6 +1141,201 @@ int arch_set_info_guest(
 #undef c
 }
 
+/* Called by VCPUOP_initialise for HVM guests. */
+static int arch_set_info_hvm_guest(struct vcpu *v, vcpu_hvm_context_t *ctx)
+{
+    struct cpu_user_regs *uregs = &v->arch.user_regs;
+    struct segment_register cs, ds, ss, tr;
+

xen/arch/arm/domain.c int arch_set_info_guest( · line 1159

Quoted 10 lines
xen/arch/arm/domain.c +10 -0
+#define SEG(s, r)                                                       \
+    (struct segment_register){ .base = (r)->s ## _base,                 \
+            .limit = (r)->s ## _limit, .attr.bytes = (r)->s ## _ar }
+
+    switch ( ctx->mode )
+    {
+    default:
+        return -EINVAL;
+
+    case VCPU_HVM_MODE_16B:
Quoted 7 lines

I think "MODE" is misleading here, not just because of the register size issue (see further down) but also because you don't seem to enforce the respective mode to be chosen in cs_ar. I'm also missing at least some simple consistency checks (like CS.DPL == SS.DPL, rIP within CS limit, rSP within SS limit); leaving these to the first VM entry would likely result in much harder to analyze issues in case of bad input.

See the comment about the 16bit registers in vcpu_hvm_context_t.

Quoted 85 lines
Quoted 85 lines
xen/arch/arm/domain.c +85 -0
+    {
+        const struct vcpu_hvm_x86_16 *regs = &ctx->cpu_regs.x86_16;
+
+        uregs->rax    = regs->ax;
+        uregs->rcx    = regs->cx;
+        uregs->rdx    = regs->dx;
+        uregs->rbx    = regs->bx;
+        uregs->rsp    = regs->sp;
+        uregs->rbp    = regs->bp;
+        uregs->rsi    = regs->si;
+        uregs->rdi    = regs->di;
+        uregs->rip    = regs->ip;
+        uregs->rflags = regs->flags;
+
+        v->arch.hvm_vcpu.guest_cr[0] = regs->cr0;
+        v->arch.hvm_vcpu.guest_cr[4] = regs->cr4;
+
+        cs = SEG(cs, regs);
+        ds = SEG(ds, regs);
+        ss = SEG(ss, regs);
+        tr = SEG(tr, regs);
+    }
+    break;
+
+    case VCPU_HVM_MODE_32B:
+    {
+        const struct vcpu_hvm_x86_32 *regs = &ctx->cpu_regs.x86_32;
+
+        uregs->rax    = regs->eax;
+        uregs->rcx    = regs->ecx;
+        uregs->rdx    = regs->edx;
+        uregs->rbx    = regs->ebx;
+        uregs->rsp    = regs->esp;
+        uregs->rbp    = regs->ebp;
+        uregs->rsi    = regs->esi;
+        uregs->rdi    = regs->edi;
+        uregs->rip    = regs->eip;
+        uregs->rflags = regs->eflags;
+
+        v->arch.hvm_vcpu.guest_cr[0] = regs->cr0;
+        v->arch.hvm_vcpu.guest_cr[3] = regs->cr3;
+        v->arch.hvm_vcpu.guest_cr[4] = regs->cr4;
+        v->arch.hvm_vcpu.guest_efer  = regs->efer;
+
+        cs = SEG(cs, regs);
+        ds = SEG(ds, regs);
+        ss = SEG(ss, regs);
+        tr = SEG(tr, regs);
+    }
+    break;
+
+    case VCPU_HVM_MODE_64B:
+    {
+        const struct vcpu_hvm_x86_64 *regs = &ctx->cpu_regs.x86_64;
+
+        uregs->rax    = regs->rax;
+        uregs->rcx    = regs->rcx;
+        uregs->rdx    = regs->rdx;
+        uregs->rbx    = regs->rbx;
+        uregs->rsp    = regs->rsp;
+        uregs->rbp    = regs->rbp;
+        uregs->rsi    = regs->rsi;
+        uregs->rdi    = regs->rdi;
+        uregs->rip    = regs->rip;
+        uregs->rflags = regs->rflags;
+        uregs->r8     = regs->r8;
+        uregs->r9     = regs->r9;
+        uregs->r10    = regs->r10;
+        uregs->r11    = regs->r11;
+        uregs->r12    = regs->r12;
+        uregs->r13    = regs->r13;
+        uregs->r14    = regs->r14;
+        uregs->r15    = regs->r15;
+
+        v->arch.hvm_vcpu.guest_cr[0] = regs->cr0;
+        v->arch.hvm_vcpu.guest_cr[3] = regs->cr3;
+        v->arch.hvm_vcpu.guest_cr[4] = regs->cr4;
+        v->arch.hvm_vcpu.guest_efer  = regs->efer;
+
+        cs = SEG(cs, regs);
+        ds = SEG(ds, regs);
+        ss = SEG(ss, regs);
+        tr = SEG(tr, regs);
+    }
+    break;
Quoted 8 lines

xen/arch/arm/domain.c int arch_set_info_guest( · line 1249

Quoted 5 lines
xen/arch/arm/domain.c +5 -0
+
+    }
+
+    if ( !paging_mode_hap(v->domain) )
+        v->arch.guest_table = pagetable_null();

A comment with the reason for this would be nice. I can't immediately see why this is here.

guest_table contains uninitialized data at this point, which makes pagetable_is_null return false. Other places where guest_table is set check if previous guest_table is null or not, and if it's not null Xen will try to free it, causing a bug. hvm_vcpu_reset_state does something similar when setting the initial vCPU state.

I will add a comment to point this out.

Quoted 10 lines
Quoted 10 lines
xen/arch/arm/domain.c +10 -0
+    hvm_update_guest_cr(v, 0);
+    hvm_update_guest_cr(v, 4);
+
+    if ( (ctx->mode == VCPU_HVM_MODE_32B) ||
+         (ctx->mode == VCPU_HVM_MODE_64B) )
+    {
+        hvm_update_guest_cr(v, 3);
+        hvm_update_guest_efer(v);
+    }
+
Quoted 8 lines

xen/arch/arm/domain.c int arch_set_info_guest( · line 1265

Quoted 6 lines
xen/arch/arm/domain.c +6 -0
+    if ( hvm_paging_enabled(v) && !paging_mode_hap(v->domain) )
+    {
+        /* Shadow-mode CR3 change. Check PDBR and update refcounts. */
+        struct page_info *page = get_page_from_gfn(v->domain,
+                                 v->arch.hvm_vcpu.guest_cr[3] >> PAGE_SHIFT,
+                                 NULL, P2M_ALLOC);

P2M_ALLOC but not P2M_UNSHARE?

This is a copy of what's done in hvm_set_cr3 when shadow mode is enabled.

Quoted 18 lines
Quoted 18 lines
xen/arch/arm/domain.c +18 -0
+        if ( !page )
+        {
+            gdprintk(XENLOG_ERR, "Invalid CR3: %#lx\n",
+                     v->arch.hvm_vcpu.guest_cr[3]);
+            domain_crash(v->domain);
+            return -EINVAL;
+        }
+
+        v->arch.guest_table = pagetable_from_page(page);
+    }
+
+    hvm_set_segment_register(v, x86_seg_cs, &cs);
+    hvm_set_segment_register(v, x86_seg_ds, &ds);
+    hvm_set_segment_register(v, x86_seg_ss, &ss);
+    hvm_set_segment_register(v, x86_seg_tr, &tr);
+
+    /* Sync AP's TSC with BSP's. */
+    v->arch.hvm_vcpu.cache_tsc_offset =
Quoted 8 lines

xen/arch/arm/domain.c int arch_set_info_guest( · line 1288

Quoted 5 lines
xen/arch/arm/domain.c +5 -0
+        v->domain->vcpu[0]->arch.hvm_vcpu.cache_tsc_offset;
+    hvm_funcs.set_tsc_offset(v, v->arch.hvm_vcpu.cache_tsc_offset,
+                             v->domain->arch.hvm_domain.sync_tsc);
+
+    v->arch.hvm_vcpu.msr_tsc_adjust = 0;

The need for this one I also can't see right away - another comment perhaps?

AFAICT we need to initialize this to a sane value, like it's done in hvm_vcpu_reset_state.

Quoted 6 lines

xen/arch/arm/domain.c int arch_set_info_guest( · line 1292

Quoted 4 lines
xen/arch/arm/domain.c +4 -0
+    paging_update_paging_modes(v);
+
+    v->is_initialised = 1;
+    set_bit(_VPF_down, &v->pause_flags);

No VGCF_online equivalent?

No, this interface doesn't allow to setup the vCPU state and start it at the same time. Users will have to call VCPUOP_up after VCPUOP_initialise in order to start the vCPU. vcpu_hvm_context doesn't even have the "flags" field any more, where this used to be set.

Quoted 4 lines

xen/arch/arm/domain.c int arch_set_info_guest( · line 1294

Quoted 2 lines
xen/arch/arm/domain.c +2 -0
+    return 0;
+#undef SEG

I think this should move up (right after the switch() using it).

Ok, I don't mind.

Quoted 30 lines
Quoted 30 lines
xen/arch/arm/domain.c +30 -0
+#ifndef __XEN_PUBLIC_HVM_HVM_VCPU_H__
+#define __XEN_PUBLIC_HVM_HVM_VCPU_H__
+
+#include "../xen.h"
+
+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;
+    uint16_t flags;
+
+    uint32_t cr0;
+    uint32_t cr4;
+
+    uint32_t cs_base;
+    uint32_t ds_base;
+    uint32_t ss_base;
+    uint32_t tr_base;
+    uint32_t cs_limit;
+    uint32_t ds_limit;
+    uint32_t ss_limit;
+    uint32_t tr_limit;
+    uint16_t cs_ar;
+    uint16_t ds_ar;
Quoted 8 lines

xen/arch/arm/domain.c int arch_set_info_guest( · line 1327

Quoted 3 lines
xen/arch/arm/domain.c +3 -0
+    uint16_t ss_ar;
+    uint16_t tr_ar;
+};

I doubt this is very useful: While one ought to be able to start a guest in 16-bit mode, its GPRs still are supposed to be 32 bits wide. The mode used really would depend on the cs_ar setting. (Having the structure just for a 16-bit IP would seem insane.)

So, would you prefer to go just with the 64-bit structure and the mode is simply set by the value of the control registers / segment selectors?

Quoted 12 lines

xen/arch/arm/domain.c int arch_set_info_guest( · line 1338

Quoted 11 lines
xen/arch/arm/domain.c +11 -0
+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;
+    uint16_t eflags;
Quoted 1 line

uint32_t for sure.

Right.

Quoted 7 lines

xen/arch/arm/domain.c int arch_set_info_guest(

Quoted 5 lines
xen/arch/arm/domain.c +4 -0
+    uint32_t cr0;
+    uint32_t cr3;
+    uint32_t cr4;
+    uint64_t efer;

What again was the point of having EFER here?

For the NX bit.

Quoted 9 lines

xen/arch/arm/domain.c

Quoted 3 lines
xen/arch/arm/domain.c +3 -0
+    uint32_t cs_base;
+    uint32_t ds_base;
+    uint32_t ss_base;

I continue to question why we have DS here, but not ES (and maybe FS and GS too). I.e. either just CS and SS (which are architecturally required) or at least all four traditional x86 segment registers. And you're also clearly not targeting minimal state, or else there likely wouldn't be a need for e.g. R8-R15 in the 64-bit variant.

I'm fine with removing r8-15. Regarding the segment selectors, I don't have a problem with only allowing CS and SS to be set, or all of them including FS and GS. But I would like to get a consensus on this, we have already gone back and forth several times regarding how this structure should look like, and TBH, I was hoping that this was the last time.

Andrew, Jan, what would you prefer, either DS is removed or ES, FS and GS are also added?

Quoted 28 lines
Quoted 28 lines
xen/arch/arm/domain.c +28 -0
+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 rflags;
+
+    uint64_t cr0;
+    uint64_t cr3;
+    uint64_t cr4;
+    uint64_t efer;
+
+    uint32_t cs_base;
+    uint32_t ds_base;
+    uint32_t ss_base;
Quoted 8 lines

xen/arch/arm/domain.c

Quoted 5 lines
xen/arch/arm/domain.c +5 -0
+    uint32_t tr_base;
+    uint32_t cs_limit;
+    uint32_t ds_limit;
+    uint32_t ss_limit;
+    uint32_t tr_limit;

I can see the need for the TR ones here, but what's the point of the CS, SS, and DS ones?

In case the guest wants to start in 64bit compatibility mode?

Quoted 17 lines
Quoted 12 lines

+/*
+ * The layout of the _ar fields of the segment registers is the
+ * following:
+ *
+ * Bits [0,3]: type (bits 40-43).

+ * Bit      4: s    (descriptor type, bit 44).
+ * Bit  [5,6]: dpl  (descriptor privilege level, bits 45-46).
+ * Bit      7: p    (segment-present, bit 47).
+ * Bit      8: avl  (available for system software, bit 52).
+ * Bit      9: l    (64-bit code segment, bit 53).
+ * Bit     10: db   (meaning depends on the segment, bit 54).
+ * Bit     11: g    (granularity, bit 55)
Quoted 4 lines

+ *
+ * A more complete description of the meaning of this fields can be
+ * obtained from the Intel SDM, Volume 3, section 3.4.5.
+ */

Quoted 3 lines

Please make explicit what state bits 12-15 are expected to be in (hopefully they're being checked to be zero rather than getting ignored).

I will add a comment regarding the 12-15 bits. IMHO, that checking should be done in hvm_set_segment_register, and is not part of this patch.

Quoted 4 lines

Please also clarify whether the limit specified for the various segment registers is the one present in descriptor tables (subject to scaling by the g bit) or (more likely) the byte granular one. In any event I suppose certain restrictions apply.

Limit is not subject to the g bit, the limit set here it's the one that ends up present in the descriptor tables (or in this case in the cached part of the selectors). IMHO that's implicit, and it's what's done on bare metal.

Roger.

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

#64 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 28.09.15 at 18:09, <[email protected]> wrote:

El 21/09/15 a les 17.44, Jan Beulich ha escrit:

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:09, <[email protected]> wrote:

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

This patch introduces a new structure (vcpu_hvm_context) that should be used in conjuction with the VCPUOP_initialise hypercall in order to initialize vCPUs for HVM guests.

Quoted 6 lines
Quoted 2 lines

So this bi-modal thing doesn't look too bad, but a concern I have is with the now different contexts used by XEN_DOMCTL_setvcpucontext and VCPUOP_initialise.

Yes, that's far from ideal. I was going to say that XEN_DOMCTL_{set/get}vcpucontext should return EOPNOTSUPP when executed against HVM guests, but that's going to break current toolstack code that relies on this in order to perform suspend/resume of HVM guests (and gdbsx would probably also be affected).

Quoted 3 lines

If you feel that would be a better solution I could fix current tools code in order to use XEN_DOMCTL_{get/set}hvmcontext instead of XEN_DOMCTL_{set/get}vcpucontext when dealing with HVM guests.

That might be a follow-up thing, subject to the tools maintainers agreeing.

Quoted 11 lines
Quoted 5 lines

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

Quoted 2 lines
xen/arch/x86/domain.c +2 -0
+    if ( !paging_mode_hap(v->domain) )
+        v->arch.guest_table = pagetable_null();

A comment with the reason for this would be nice. I can't immediately see why this is here.

guest_table contains uninitialized data at this point, which makes pagetable_is_null return false. Other places where guest_table is set check if previous guest_table is null or not, and if it's not null Xen will try to free it, causing a bug. hvm_vcpu_reset_state does something similar when setting the initial vCPU state.

Truly uninitialized is not possible, as struct vcpu starts out zeroed. Hence if anything the field may hold left over data, in which case the store would better go where the reference becomes dangling.

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
xen/arch/x86/domain.c +10 -0
+    hvm_update_guest_cr(v, 0);
+    hvm_update_guest_cr(v, 4);
+
+    if ( (ctx->mode == VCPU_HVM_MODE_32B) ||
+         (ctx->mode == VCPU_HVM_MODE_64B) )
+    {
+        hvm_update_guest_cr(v, 3);
+        hvm_update_guest_efer(v);
+    }
+
Quoted 8 lines

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

Quoted 6 lines
xen/arch/x86/domain.c +6 -0
+    if ( hvm_paging_enabled(v) && !paging_mode_hap(v->domain) )
+    {
+        /* Shadow-mode CR3 change. Check PDBR and update refcounts. */
+        struct page_info *page = get_page_from_gfn(v->domain,
+                                 v->arch.hvm_vcpu.guest_cr[3] >> PAGE_SHIFT,
+                                 NULL, P2M_ALLOC);

P2M_ALLOC but not P2M_UNSHARE?

Quoted 1 line

This is a copy of what's done in hvm_set_cr3 when shadow mode is enabled.

As said on IRC - sadly we have to mem-sharing maintainer to ask. I wonder whether the past or current x86/mm maintainer would know
- Tim, George?

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
xen/arch/x86/domain.c +7 -0
+    /* Sync AP's TSC with BSP's. */
+    v->arch.hvm_vcpu.cache_tsc_offset =
+        v->domain->vcpu[0]->arch.hvm_vcpu.cache_tsc_offset;
+    hvm_funcs.set_tsc_offset(v, v->arch.hvm_vcpu.cache_tsc_offset,
+                             v->domain->arch.hvm_domain.sync_tsc);
+
+    v->arch.hvm_vcpu.msr_tsc_adjust = 0;
Quoted 5 lines
Quoted 2 lines

The need for this one I also can't see right away - another comment perhaps?

AFAICT we need to initialize this to a sane value, like it's done in hvm_vcpu_reset_state.

As said above - struct vcpu starts out zeroed, so unless stale data is being left here, "initialize" would at least not be the right term.

Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
xen/include/public/hvm/hvm_vcpu.h new file +30 -0
+#ifndef __XEN_PUBLIC_HVM_HVM_VCPU_H__
+#define __XEN_PUBLIC_HVM_HVM_VCPU_H__
+
+#include "../xen.h"
+
+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;
+    uint16_t flags;
+
+    uint32_t cr0;
+    uint32_t cr4;
+
+    uint32_t cs_base;
+    uint32_t ds_base;
+    uint32_t ss_base;
+    uint32_t tr_base;
+    uint32_t cs_limit;
+    uint32_t ds_limit;
+    uint32_t ss_limit;
+    uint32_t tr_limit;
+    uint16_t cs_ar;
+    uint16_t ds_ar;
Quoted 8 lines

xen/include/public/hvm/hvm_vcpu.h line 55

Quoted 3 lines
xen/include/public/hvm/hvm_vcpu.h new file +3 -0
+    uint16_t ss_ar;
+    uint16_t tr_ar;
+};

I doubt this is very useful: While one ought to be able to start a guest in 16-bit mode, its GPRs still are supposed to be 32 bits wide. The mode used really would depend on the cs_ar setting. (Having the structure just for a 16-bit IP would seem insane.)

Quoted 2 lines

So, would you prefer to go just with the 64-bit structure and the mode is simply set by the value of the control registers / segment selectors?

No, you certainly want a 32- and a 64-bit layout, for the benefit of 32- and 64-bit guests.

Quoted 10 lines
Quoted 9 lines

xen/include/public/hvm/hvm_vcpu.h line 45

Quoted 3 lines
xen/include/public/hvm/hvm_vcpu.h new file +3 -0
+    uint32_t cs_base;
+    uint32_t ds_base;
+    uint32_t ss_base;

I continue to question why we have DS here, but not ES (and maybe FS and GS too). I.e. either just CS and SS (which are architecturally required) or at least all four traditional x86 segment registers. And you're also clearly not targeting minimal state, or else there likely wouldn't be a need for e.g. R8-R15 in the 64-bit variant.

Quoted 6 lines

I'm fine with removing r8-15. Regarding the segment selectors, I don't have a problem with only allowing CS and SS to be set, or all of them including FS and GS. But I would like to get a consensus on this, we have already gone back and forth several times regarding how this structure should look like, and TBH, I was hoping that this was the last time.

Was there back and forth? I only recall always having asked for consistency here, just like spelled out above.

Quoted 2 lines

Andrew, Jan, what would you prefer, either DS is removed or ES, FS and GS are also added?

I voiced my opinion. Andrew?

Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
xen/include/public/hvm/hvm_vcpu.h new file +28 -0
+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 rflags;
+
+    uint64_t cr0;
+    uint64_t cr3;
+    uint64_t cr4;
+    uint64_t efer;
+
+    uint32_t cs_base;
+    uint32_t ds_base;
+    uint32_t ss_base;
Quoted 8 lines

xen/include/public/hvm/hvm_vcpu.h line 50

Quoted 5 lines
xen/include/public/hvm/hvm_vcpu.h new file +5 -0
+    uint32_t tr_base;
+    uint32_t cs_limit;
+    uint32_t ds_limit;
+    uint32_t ss_limit;
+    uint32_t tr_limit;

I can see the need for the TR ones here, but what's the point of the CS, SS, and DS ones?

Quoted 1 line

In case the guest wants to start in 64bit compatibility mode?

Hmm, yes. But couldn't that be done using the 32-bit mode layout?

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines

+/*
+ * The layout of the _ar fields of the segment registers is the
+ * following:
+ *
+ * Bits [0,3]: type (bits 40-43).

+ * Bit      4: s    (descriptor type, bit 44).
+ * Bit  [5,6]: dpl  (descriptor privilege level, bits 45-46).
+ * Bit      7: p    (segment-present, bit 47).
+ * Bit      8: avl  (available for system software, bit 52).
+ * Bit      9: l    (64-bit code segment, bit 53).
+ * Bit     10: db   (meaning depends on the segment, bit 54).
+ * Bit     11: g    (granularity, bit 55)

+ *
+ * A more complete description of the meaning of this fields can be
+ * obtained from the Intel SDM, Volume 3, section 3.4.5.
+ */

Quoted 6 lines
Quoted 3 lines

Please make explicit what state bits 12-15 are expected to be in (hopefully they're being checked to be zero rather than getting ignored).

I will add a comment regarding the 12-15 bits. IMHO, that checking should be done in hvm_set_segment_register, and is not part of this patch.

Well - is there an existing path like the one being added here where these values come from an untrusted source (which isn't to say that when coming from a trusted source checking wouldn't be worthwhile)? I wasn't able to spot any.

Quoted 9 lines
Quoted 4 lines

Please also clarify whether the limit specified for the various segment registers is the one present in descriptor tables (subject to scaling by the g bit) or (more likely) the byte granular one. In any event I suppose certain restrictions apply.

Limit is not subject to the g bit, the limit set here it's the one that ends up present in the descriptor tables (or in this case in the cached part of the selectors). IMHO that's implicit, and it's what's done on bare metal.

See - you're mixing things up: In descriptor tables, the (20-bit) limit is always subject to scaling due to G=1. And since we're talking about documentation of an interface here, "implicit" is not an option. (I wonder, btw, whether VMENTRY checks would fail when a limit value isn't in line with the G bit. I didn't check the manual...)

With both of the above points my main goal is to convert an unrecoverable error (guest death) to a recoverable one (the vCPU issuing the hypercall receiving an error indication).

Jan

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

#65 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 28.09.15 at 18:09, <[email protected]> wrote:

El 21/09/15 a les 17.44, Jan Beulich ha escrit:

Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:09, <[email protected]> wrote:
xen/arch/x86/domain.c +6 -0
+    if ( hvm_paging_enabled(v) && !paging_mode_hap(v->domain) )
+    {
+        /* Shadow-mode CR3 change. Check PDBR and update refcounts. */
+        struct page_info *page = get_page_from_gfn(v->domain,
+                                 v->arch.hvm_vcpu.guest_cr[3] >> PAGE_SHIFT,
+                                 NULL, P2M_ALLOC);
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

P2M_ALLOC but not P2M_UNSHARE?

This is a copy of what's done in hvm_set_cr3 when shadow mode is enabled.

As said on IRC - sadly we have to mem-sharing maintainer to ask. I wonder whether the past or current x86/mm maintainer would know
- Tim, George?

Memory sharing requires HAP, so it makes no difference here. Seems like it ought to be P2M_UNSHARE, though, for consistency.

Tim.

#66 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

In reply to Jan Beulich
Quoted 15 lines · Jan Beulich
Quoted 9 lines
Quoted 9 lines

xen/include/public/hvm/hvm_vcpu.h line 45

Quoted 4 lines
xen/include/public/hvm/hvm_vcpu.h new file +3 -0
+    uint32_t cs_base;
+    uint32_t ds_base;
+    uint32_t ss_base;

I continue to question why we have DS here, but not ES (and maybe FS and GS too). I.e. either just CS and SS (which are architecturally required) or at least all four traditional x86 segment registers. And you're also clearly not targeting minimal state, or else there likely wouldn't be a need for e.g. R8-R15 in the 64-bit variant.

Quoted 6 lines

I'm fine with removing r8-15. Regarding the segment selectors, I don't have a problem with only allowing CS and SS to be set, or all of them including FS and GS. But I would like to get a consensus on this, we have already gone back and forth several times regarding how this structure should look like, and TBH, I was hoping that this was the last time.

Quoted 6 lines

Was there back and forth? I only recall always having asked for consistency here, just like spelled out above.

Quoted 2 lines

Andrew, Jan, what would you prefer, either DS is removed or ES, FS and GS are also added?

I voiced my opinion. Andrew?

DS clearly needs initialising to provide a sane environment in the newly running vcpu. Expecting %cs or %ss overrides until a new GDT is loaded is unreasonable IMO.

Therefore, we are back to the question of whether to provide all segment registers, or specify a flat layout without specific selector values. I would prefer the former to the latter.

~Andrew

#67 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 12:00, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 9 lines
Quoted 9 lines

xen/include/public/hvm/hvm_vcpu.h line 45

Quoted 4 lines
xen/include/public/hvm/hvm_vcpu.h new file +3 -0
+    uint32_t cs_base;
+    uint32_t ds_base;
+    uint32_t ss_base;

I continue to question why we have DS here, but not ES (and maybe FS and GS too). I.e. either just CS and SS (which are architecturally required) or at least all four traditional x86 segment registers. And you're also clearly not targeting minimal state, or else there likely wouldn't be a need for e.g. R8-R15 in the 64-bit variant.

Quoted 6 lines

I'm fine with removing r8-15. Regarding the segment selectors, I don't have a problem with only allowing CS and SS to be set, or all of them including FS and GS. But I would like to get a consensus on this, we have already gone back and forth several times regarding how this structure should look like, and TBH, I was hoping that this was the last time.

Was there back and forth? I only recall always having asked for consistency here, just like spelled out above.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Andrew, Jan, what would you prefer, either DS is removed or ES, FS and GS are also added?

I voiced my opinion. Andrew?

DS clearly needs initialising to provide a sane environment in the newly running vcpu. Expecting %cs or %ss overrides until a new GDT is loaded is unreasonable IMO.

I don't view this as unreasonable: You want to load a GDT first thing anyway. And I see nothing wrong with that one instruction carrying an override (and even then only on 32-bit, as a nul DS is fine on 64-bit).

Quoted 3 lines

Therefore, we are back to the question of whether to provide all segment registers, or specify a flat layout without specific selector values. I would prefer the former to the latter.

If we don't go the CS+SS only route, then yes, I'd too prefer completing the set (I would probably agree with not adding FS and GS, and even recommend against it in the 64-bit variant, but I do insist on ES in that case).

Jan

#68 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 12:00, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 8 lines
Quoted 8 lines

xen/include/public/hvm/hvm_vcpu.h line 45

Quoted 3 lines
xen/include/public/hvm/hvm_vcpu.h new file +3 -0
+    uint32_t cs_base;
+    uint32_t ds_base;
+    uint32_t ss_base;

I continue to question why we have DS here, but not ES (and maybe FS and GS too). I.e. either just CS and SS (which are architecturally required) or at least all four traditional x86 segment registers. And you're also clearly not targeting minimal state, or else there likely wouldn't be a need for e.g. R8-R15 in the 64-bit variant.

Quoted 6 lines

I'm fine with removing r8-15. Regarding the segment selectors, I don't have a problem with only allowing CS and SS to be set, or all of them including FS and GS. But I would like to get a consensus on this, we have already gone back and forth several times regarding how this structure should look like, and TBH, I was hoping that this was the last time.

Was there back and forth? I only recall always having asked for consistency here, just like spelled out above.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

Andrew, Jan, what would you prefer, either DS is removed or ES, FS and GS are also added?

I voiced my opinion. Andrew?

DS clearly needs initialising to provide a sane environment in the newly running vcpu. Expecting %cs or %ss overrides until a new GDT is loaded is unreasonable IMO.

I don't view this as unreasonable: You want to load a GDT first thing anyway.

True. The main question is whether the GDT will be at a fixed linear address. I expect this to be the case in any non-contrived situation.

Quoted 3 lines

And I see nothing wrong with that one instruction carrying an override (and even then only on 32-bit, as a nul DS is fine on 64-bit).

Ah yes.

Quoted 8 lines
Quoted 4 lines

Therefore, we are back to the question of whether to provide all segment registers, or specify a flat layout without specific selector values. I would prefer the former to the latter.

If we don't go the CS+SS only route, then yes, I'd too prefer completing the set (I would probably agree with not adding FS and GS, and even recommend against it in the 64-bit variant, but I do insist on ES in that case).

I would still err on the CS/SS/DS/ES side given a straight choice. It offers more flexibility for rarer usecases.

~Andrew

#69 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 12:25, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 12:00, <[email protected]> wrote:

Therefore, we are back to the question of whether to provide all segment registers, or specify a flat layout without specific selector values. I would prefer the former to the latter.

Quoted 7 lines
Quoted 4 lines

If we don't go the CS+SS only route, then yes, I'd too prefer completing the set (I would probably agree with not adding FS and GS, and even recommend against it in the 64-bit variant, but I do insist on ES in that case).

I would still err on the CS/SS/DS/ES side given a straight choice. It offers more flexibility for rarer usecases.

Okay, all four of them then for 32-bit, and just CS and SS for 64-bit?

Jan

#70 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 12:25, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 12:00, <[email protected]> wrote:

Therefore, we are back to the question of whether to provide all segment registers, or specify a flat layout without specific selector values. I would prefer the former to the latter.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

If we don't go the CS+SS only route, then yes, I'd too prefer completing the set (I would probably agree with not adding FS and GS, and even recommend against it in the 64-bit variant, but I do insist on ES in that case).

I would still err on the CS/SS/DS/ES side given a straight choice. It offers more flexibility for rarer usecases.

Okay, all four of them then for 32-bit, and just CS and SS for 64-bit?

Is SS needed for 64bit? It is expected to be NUL just like DS and ES.

~Andrew

#71 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 12:37, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 12:25, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 12:00, <[email protected]> wrote:

Therefore, we are back to the question of whether to provide all segment registers, or specify a flat layout without specific selector values. I would prefer the former to the latter.

If we don't go the CS+SS only route, then yes, I'd too prefer completing the set (I would probably agree with not adding FS and GS, and even recommend against it in the 64-bit variant, but I do insist on ES in that case).

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

I would still err on the CS/SS/DS/ES side given a straight choice. It offers more flexibility for rarer usecases.

Okay, all four of them then for 32-bit, and just CS and SS for 64-bit?

Is SS needed for 64bit? It is expected to be NUL just like DS and ES.

Indeed, we should be able to get away without it. And for CS all we'd need would be a selector.

Jan

#72 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

El 29/09/15 a les 12.48, Jan Beulich ha escrit:

Quoted 12 lines
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 12:37, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 12:25, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 12:00, <[email protected]> wrote:

Therefore, we are back to the question of whether to provide all segment registers, or specify a flat layout without specific selector values. I would prefer the former to the latter.

If we don't go the CS+SS only route, then yes, I'd too prefer completing the set (I would probably agree with not adding FS and GS, and even recommend against it in the 64-bit variant, but I do insist on ES in that case).

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

I would still err on the CS/SS/DS/ES side given a straight choice. It offers more flexibility for rarer usecases.

Okay, all four of them then for 32-bit, and just CS and SS for 64-bit?

Is SS needed for 64bit? It is expected to be NUL just like DS and ES.

Indeed, we should be able to get away without it. And for CS all we'd need would be a selector.

Ok thanks, so we seem to have a consensus. Before posting a new revision, does the following vcpu_hvm_context look fine to both of you:

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 eflags;

    uint32_t cr0;
    uint32_t cr3;
    uint32_t cr4;

    /*
     * EFER should only be used to set the NXE bit (if required)
     * when starting a vCPU in 32bit mode with paging enabled.
     */
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t es_base;
    uint32_t tr_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint32_t es_limit;
    uint32_t tr_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
    uint16_t es_ar;
    uint16_t tr_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 rip;
    uint64_t rflags;

    uint64_t cr0;
    uint64_t cr3;
    uint64_t cr4;
    uint64_t efer;

    /*
     * Setting the CS attributes field is allowed in order to
     * start in compatibility mode.
     */
    uint16_t cs_ar;
};

struct vcpu_hvm_context {
#define VCPU_HVM_MODE_32B 0 /* 32bit fields of the structure will be used. */

#define VCPU_HVM_MODE_64B 1  /* 64bit fields of the structure will be used. */
    uint32_t mode;

    /* CPU registers. */
    union {
        struct vcpu_hvm_x86_32 x86_32;
        struct vcpu_hvm_x86_64 x86_64;
    } cpu_regs;
};

Thanks, Roger.

#73 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 56 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 16:01, <[email protected]> wrote:

Ok thanks, so we seem to have a consensus. Before posting a new revision, does the following vcpu_hvm_context look fine to both of you:

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 eflags;

    uint32_t cr0;
    uint32_t cr3;
    uint32_t cr4;

    /*
     * EFER should only be used to set the NXE bit (if required)
     * when starting a vCPU in 32bit mode with paging enabled.
     */
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t es_base;
    uint32_t tr_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint32_t es_limit;
    uint32_t tr_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
    uint16_t es_ar;
    uint16_t tr_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 rip;
    uint64_t rflags;

    uint64_t cr0;
Quoted 8 lines
    uint64_t cr3;
    uint64_t cr4;
    uint64_t efer;

    /*
     * Setting the CS attributes field is allowed in order to
     * start in compatibility mode.
     */

Hmm, as said before it would seem to me that this would better (or also) be allowed to work by specifying a suitable 32-bit register state. Remember that in compatibility mode base and limit matter again, and I think you also can't start with a nul SS.

Quoted 2 lines
    uint16_t cs_ar;
};

No tr_* here?

Also, what are the selector values going to be? Do you intend to pass zero there?

Jan

#74 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

El 29/09/15 a les 17.29, Jan Beulich ha escrit:

Quoted 65 lines
Quoted 56 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 16:01, <[email protected]> wrote:

Ok thanks, so we seem to have a consensus. Before posting a new revision, does the following vcpu_hvm_context look fine to both of you:

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 eflags;

    uint32_t cr0;
    uint32_t cr3;
    uint32_t cr4;

    /*
     * EFER should only be used to set the NXE bit (if required)
     * when starting a vCPU in 32bit mode with paging enabled.
     */
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t es_base;
    uint32_t tr_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint32_t es_limit;
    uint32_t tr_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
    uint16_t es_ar;
    uint16_t tr_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 rip;
    uint64_t rflags;

    uint64_t cr0;
Quoted 8 lines
    uint64_t cr3;
    uint64_t cr4;
    uint64_t efer;

    /*
     * Setting the CS attributes field is allowed in order to
     * start in compatibility mode.
     */
Quoted 4 lines

Hmm, as said before it would seem to me that this would better (or also) be allowed to work by specifying a suitable 32-bit register state. Remember that in compatibility mode base and limit matter again, and I think you also can't start with a nul SS.

Yes, I should add back all the registers here, so it looks like:

     uint32_t cs_base;
     uint32_t ds_base;
     uint32_t ss_base;
     uint32_t es_base;
     uint32_t cs_limit;
     uint32_t ds_limit;
     uint32_t ss_limit;
     uint32_t es_limit;
     uint16_t cs_ar;
     uint16_t ds_ar;
     uint16_t ss_ar;
     uint16_t es_ar;
Quoted 4 lines
Quoted 2 lines
    uint16_t cs_ar;
};

No tr_* here?

Is it necessary? for long or compatibility mode tr is always going to be:

tr_base = 0;
tr_limit = 0x67;
tr_ar = 0x8b;

The attributes field is always going to be 0x8b for compat or long mode, the base and the limit might be different, but the guest should change that by itself.

Quoted 2 lines

Also, what are the selector values going to be? Do you intend to pass zero there?

Do you mean the visible part of the selectors? With the current implementation the value of the "sel" field in the segment_register struct is left uninitialized, so it's undefined. I could set them to 0, but what's the point in doing it?

Roger.

#75 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 74 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 18:01, <[email protected]> wrote:

El 29/09/15 a les 17.29, Jan Beulich ha escrit:

Quoted 65 lines
Quoted 56 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 16:01, <[email protected]> wrote:

Ok thanks, so we seem to have a consensus. Before posting a new revision, does the following vcpu_hvm_context look fine to both of you:

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 eflags;

    uint32_t cr0;
    uint32_t cr3;
    uint32_t cr4;

    /*
     * EFER should only be used to set the NXE bit (if required)
     * when starting a vCPU in 32bit mode with paging enabled.
     */
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t es_base;
    uint32_t tr_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint32_t es_limit;
    uint32_t tr_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
    uint16_t es_ar;
    uint16_t tr_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 rip;
    uint64_t rflags;

    uint64_t cr0;
Quoted 8 lines
    uint64_t cr3;
    uint64_t cr4;
    uint64_t efer;

    /*
     * Setting the CS attributes field is allowed in order to
     * start in compatibility mode.
     */
Quoted 4 lines

Hmm, as said before it would seem to me that this would better (or also) be allowed to work by specifying a suitable 32-bit register state. Remember that in compatibility mode base and limit matter again, and I think you also can't start with a nul SS.

Yes, I should add back all the registers here, so it looks like:

Quoted 12 lines
     uint32_t cs_base;
     uint32_t ds_base;
     uint32_t ss_base;
     uint32_t es_base;
     uint32_t cs_limit;
     uint32_t ds_limit;
     uint32_t ss_limit;
     uint32_t es_limit;
     uint16_t cs_ar;
     uint16_t ds_ar;
     uint16_t ss_ar;
     uint16_t es_ar;

Or specify that compat mode entry is via using 32-bit register state.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
    uint16_t cs_ar;
};

No tr_* here?

Is it necessary? for long or compatibility mode tr is always going to be:

Quoted 7 lines

tr_base = 0;
tr_limit = 0x67;
tr_ar = 0x8b;

The attributes field is always going to be 0x8b for compat or long mode, the base and the limit might be different, but the guest should change that by itself.

Please explain why you have it in the 32-bit register state, but not in the 64-bit one. I said before that we should aim at being as consistent as possible. (And btw I do not think that tr_base being zero makes any sense.)

Quoted 7 lines
Quoted 2 lines

Also, what are the selector values going to be? Do you intend to pass zero there?

Do you mean the visible part of the selectors? With the current implementation the value of the "sel" field in the segment_register struct is left uninitialized, so it's undefined. I could set them to 0, but what's the point in doing it?

We should never leave things uninitialized; leaving things unspecified may be okay, but I don't see why we shouldn't spell out what we intend to do, unless we foresee it to change later on.

Jan

#76 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

El 29/09/15 a les 18.20, Jan Beulich ha escrit:

Quoted 87 lines
Quoted 74 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 18:01, <[email protected]> wrote:

El 29/09/15 a les 17.29, Jan Beulich ha escrit:

Quoted 65 lines
Quoted 56 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 16:01, <[email protected]> wrote:

Ok thanks, so we seem to have a consensus. Before posting a new revision, does the following vcpu_hvm_context look fine to both of you:

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 eflags;

    uint32_t cr0;
    uint32_t cr3;
    uint32_t cr4;

    /*
     * EFER should only be used to set the NXE bit (if required)
     * when starting a vCPU in 32bit mode with paging enabled.
     */
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t es_base;
    uint32_t tr_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint32_t es_limit;
    uint32_t tr_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
    uint16_t es_ar;
    uint16_t tr_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 rip;
    uint64_t rflags;

    uint64_t cr0;
Quoted 8 lines
    uint64_t cr3;
    uint64_t cr4;
    uint64_t efer;

    /*
     * Setting the CS attributes field is allowed in order to
     * start in compatibility mode.
     */
Quoted 4 lines

Hmm, as said before it would seem to me that this would better (or also) be allowed to work by specifying a suitable 32-bit register state. Remember that in compatibility mode base and limit matter again, and I think you also can't start with a nul SS.

Yes, I should add back all the registers here, so it looks like:

Quoted 12 lines
     uint32_t cs_base;
     uint32_t ds_base;
     uint32_t ss_base;
     uint32_t es_base;
     uint32_t cs_limit;
     uint32_t ds_limit;
     uint32_t ss_limit;
     uint32_t es_limit;
     uint16_t cs_ar;
     uint16_t ds_ar;
     uint16_t ss_ar;
     uint16_t es_ar;
Quoted 1 line

Or specify that compat mode entry is via using 32-bit register state.

Yes, that should also work. If that's the preference then I guess we can remove all the selectors stuff from the 64bit structure.

Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 2 lines
    uint16_t cs_ar;
};

No tr_* here?

Is it necessary? for long or compatibility mode tr is always going to be:

tr_base = 0;
tr_limit = 0x67;
tr_ar = 0x8b;

Quoted 6 lines
Quoted 3 lines

The attributes field is always going to be 0x8b for compat or long mode, the base and the limit might be different, but the guest should change that by itself.

Please explain why you have it in the 32-bit register state, but not in the 64-bit one.

Because the 32bit register state can be used to start a CPU in real mode, and the TS type in real mode is different from the ones in protected mode and long mode.

Quoted 3 lines

I said before that we should aim at being as
consistent as possible. (And btw I do not think that tr_base being zero makes any sense.)

We don't actually have a TSS anywhere, does it really matter if base is set to 0?

In fact allowing the user to set tr_base and tr_limit is kind of pointless, it's impossible to load a TSS from this interface. So AFAICT what really matters is tr_ar only.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Also, what are the selector values going to be? Do you intend to pass zero there?

Do you mean the visible part of the selectors? With the current implementation the value of the "sel" field in the segment_register struct is left uninitialized, so it's undefined. I could set them to 0, but what's the point in doing it?

Quoted 4 lines

We should never leave things uninitialized; leaving things unspecified may be okay, but I don't see why we shouldn't spell out what we intend to do, unless we foresee it to change later on.

Ack, I don't see a problem in setting them to 0, but anyway there's no GDT loaded, so the selector value itself is pointless (the cached part is what really matters).

Roger.

#77 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

El 29/09/15 a les 18.49, Roger Pau Monné ha escrit:

Quoted 11 lines

El 29/09/15 a les 18.20, Jan Beulich ha escrit:

Quoted 3 lines

I said before that we should aim at being as
consistent as possible. (And btw I do not think that tr_base being zero makes any sense.)

We don't actually have a TSS anywhere, does it really matter if base is set to 0?

In fact allowing the user to set tr_base and tr_limit is kind of pointless, it's impossible to load a TSS from this interface. So AFAICT what really matters is tr_ar only.

Please ignore the excerpt above, it's wrong. A user can indeed place a valid TSS in memory and load it on the vcpu using this interface.

Roger.

#78 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

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

El 29/09/15 a les 18.20, Jan Beulich ha escrit:

Quoted 16 lines
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 18:01, <[email protected]> wrote:

Yes, I should add back all the registers here, so it looks like:

     uint32_t cs_base;
     uint32_t ds_base;
     uint32_t ss_base;
     uint32_t es_base;
     uint32_t cs_limit;
     uint32_t ds_limit;
     uint32_t ss_limit;
     uint32_t es_limit;
     uint16_t cs_ar;
     uint16_t ds_ar;
     uint16_t ss_ar;
     uint16_t es_ar;
Quoted 4 lines
Quoted 1 line

Or specify that compat mode entry is via using 32-bit register state.

Yes, that should also work. If that's the preference then I guess we can remove all the selectors stuff from the 64bit structure.

That's my preference (with the EFER comment then accordingly updated). Andrew?

Jan

#79 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

El 30/09/15 a les 12.03, Jan Beulich ha escrit:

Quoted 18 lines
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 18:49, <[email protected]> wrote:

El 29/09/15 a les 18.20, Jan Beulich ha escrit:

Quoted 16 lines
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 18:01, <[email protected]> wrote:

Yes, I should add back all the registers here, so it looks like:

     uint32_t cs_base;
     uint32_t ds_base;
     uint32_t ss_base;
     uint32_t es_base;
     uint32_t cs_limit;
     uint32_t ds_limit;
     uint32_t ss_limit;
     uint32_t es_limit;
     uint16_t cs_ar;
     uint16_t ds_ar;
     uint16_t ss_ar;
     uint16_t es_ar;
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Or specify that compat mode entry is via using 32-bit register state.

Yes, that should also work. If that's the preference then I guess we can remove all the selectors stuff from the 64bit structure.

That's my preference (with the EFER comment then accordingly updated). Andrew?

This is what I currently have prototyped according to the comments, it should allow starting the vCPU in all possible modes AFAICT.

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 eflags;

    uint32_t cr0;
    uint32_t cr3;
    uint32_t cr4;

    /*
     * EFER should only be used to set the NXE bit (if required)
     * when starting a vCPU in 32bit mode with paging enabled or
     * to set the LME/LMA bits in order to start the vCPU in
     * compatibility mode.
     */
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t es_base;
    uint32_t tr_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint32_t es_limit;
    uint32_t tr_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
    uint16_t es_ar;
    uint16_t tr_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 rip;
    uint64_t rflags;

    uint64_t cr0;
    uint64_t cr3;
    uint64_t cr4;
    uint64_t efer;

    /*
     * Using VCPU_HVM_MODE_64B implies that the vCPU is launched
     * directly in long mode, so the type of the cached part
     * of the TR register is set to describe a 64-bit TSS (Busy).
     * The cached part of the CS register will also have the L bit
     * set (64-bit code segment).
     *
     * If the user wants to launch the vCPU in compatibility mode
     * the 32-bit structure should be used instead.
     */
};

struct vcpu_hvm_context {
#define VCPU_HVM_MODE_32B 0 /* 32bit fields of the structure will be used. */

#define VCPU_HVM_MODE_64B 1  /* 64bit fields of the structure will be used. */
    uint32_t mode;

    /* CPU registers. */
    union {
        struct vcpu_hvm_x86_32 x86_32;
        struct vcpu_hvm_x86_64 x86_64;
    } cpu_regs;
};

Roger.

#80 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 108 lines · Roger Pau Monné

El 30/09/15 a les 12.03, Jan Beulich ha escrit:

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

El 29/09/15 a les 18.20, Jan Beulich ha escrit:

Quoted 15 lines
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 29.09.15 at 18:01, <[email protected]> wrote:

Yes, I should add back all the registers here, so it looks like:

     uint32_t cs_base;
     uint32_t ds_base;
     uint32_t ss_base;
     uint32_t es_base;
     uint32_t cs_limit;
     uint32_t ds_limit;
     uint32_t ss_limit;
     uint32_t es_limit;
     uint16_t cs_ar;
     uint16_t ds_ar;
     uint16_t ss_ar;
     uint16_t es_ar;
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Or specify that compat mode entry is via using 32-bit register state.

Yes, that should also work. If that's the preference then I guess we can remove all the selectors stuff from the 64bit structure.

That's my preference (with the EFER comment then accordingly updated). Andrew?

This is what I currently have prototyped according to the comments, it should allow starting the vCPU in all possible modes AFAICT.

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 eflags;

    uint32_t cr0;
    uint32_t cr3;
    uint32_t cr4;

    /*
     * EFER should only be used to set the NXE bit (if required)
     * when starting a vCPU in 32bit mode with paging enabled or
     * to set the LME/LMA bits in order to start the vCPU in
     * compatibility mode.
     */
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t es_base;
    uint32_t tr_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint32_t es_limit;
    uint32_t tr_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
    uint16_t es_ar;
    uint16_t tr_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 rip;
    uint64_t rflags;

    uint64_t cr0;
    uint64_t cr3;
    uint64_t cr4;
    uint64_t efer;

    /*
     * Using VCPU_HVM_MODE_64B implies that the vCPU is launched
     * directly in long mode, so the type of the cached part
     * of the TR register is set to describe a 64-bit TSS (Busy).
     * The cached part of the CS register will also have the L bit
     * set (64-bit code segment).
     *
     * If the user wants to launch the vCPU in compatibility mode
     * the 32-bit structure should be used instead.
     */
};

struct vcpu_hvm_context {
#define VCPU_HVM_MODE_32B 0 /* 32bit fields of the structure will be used. */

#define VCPU_HVM_MODE_64B 1  /* 64bit fields of the structure will be used. */
    uint32_t mode;

    /* CPU registers. */
    union {
        struct vcpu_hvm_x86_32 x86_32;
        struct vcpu_hvm_x86_64 x86_64;
    } cpu_regs;
};
Quoted 1 line

Roger.

Looks good to me.

~Andrew

#81 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

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

This is what I currently have prototyped according to the comments, it should allow starting the vCPU in all possible modes AFAICT.

Looks okay, one more comment:

Quoted 56 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 eflags;

    uint32_t cr0;
    uint32_t cr3;
    uint32_t cr4;

    /*
     * EFER should only be used to set the NXE bit (if required)
     * when starting a vCPU in 32bit mode with paging enabled or
     * to set the LME/LMA bits in order to start the vCPU in
     * compatibility mode.
     */
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t es_base;
    uint32_t tr_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint32_t es_limit;
    uint32_t tr_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
    uint16_t es_ar;
    uint16_t tr_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 rip;
    uint64_t rflags;

    uint64_t cr0;
    uint64_t cr3;
    uint64_t cr4;
Quoted 8 lines
    uint64_t efer;

    /*
     * Using VCPU_HVM_MODE_64B implies that the vCPU is launched
     * directly in long mode, so the type of the cached part
     * of the TR register is set to describe a 64-bit TSS (Busy).
     * The cached part of the CS register will also have the L bit
     * set (64-bit code segment).

I'd leave out mentioning TR here (or else it'll be odd not to mention e.g. LDTR too). Perhaps just "..., so the cached parts of the segment registers get set to match that environment"?

Jan

#82 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

El 30/09/15 a les 13.54, Jan Beulich ha escrit:

Quoted 71 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.09.15 at 13:37, <[email protected]> wrote:

This is what I currently have prototyped according to the comments, it should allow starting the vCPU in all possible modes AFAICT.

Looks okay, one more comment:

Quoted 56 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 eflags;

    uint32_t cr0;
    uint32_t cr3;
    uint32_t cr4;

    /*
     * EFER should only be used to set the NXE bit (if required)
     * when starting a vCPU in 32bit mode with paging enabled or
     * to set the LME/LMA bits in order to start the vCPU in
     * compatibility mode.
     */
    uint64_t efer;

    uint32_t cs_base;
    uint32_t ds_base;
    uint32_t ss_base;
    uint32_t es_base;
    uint32_t tr_base;
    uint32_t cs_limit;
    uint32_t ds_limit;
    uint32_t ss_limit;
    uint32_t es_limit;
    uint32_t tr_limit;
    uint16_t cs_ar;
    uint16_t ds_ar;
    uint16_t ss_ar;
    uint16_t es_ar;
    uint16_t tr_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 rip;
    uint64_t rflags;

    uint64_t cr0;
    uint64_t cr3;
    uint64_t cr4;
Quoted 8 lines
    uint64_t efer;

    /*
     * Using VCPU_HVM_MODE_64B implies that the vCPU is launched
     * directly in long mode, so the type of the cached part
     * of the TR register is set to describe a 64-bit TSS (Busy).
     * The cached part of the CS register will also have the L bit
     * set (64-bit code segment).
Quoted 3 lines

I'd leave out mentioning TR here (or else it'll be odd not to mention e.g. LDTR too). Perhaps just "..., so the cached parts of the segment registers get set to match that environment"?

That sounds fine. I'm going to update the patch and the FreeBSD part in order to test it. Since we also spoke about adding sanity checks, I wonder whether I should add those checks now, or leave them for a later patch. IMHO those checks are only useful for developers.

For VCPU_HVM_MODE_32B:
- rIP within CS limit.
- Check that CS.DPL == SS.DPL.
- rSP within SS limit.

TBH I don't think we should enforce the last two checks, starting with an invalid stack should be fine as long as the user knows it. Maybe print a warning/debug message in this case?

For VCPU_HVM_MODE_64B:
- Check that cr0 has paging enabled.
- Check that cr4 has pae enabled.
- Check that efer has the LMA/LME bits set.

Those should be always enforced for long mode.

Roger.

#83 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 30.09.15 at 14:19, <[email protected]> wrote:

El 30/09/15 a les 13.54, Jan Beulich ha escrit:

Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 30.09.15 at 13:37, <[email protected]> wrote:

/*
* Using VCPU_HVM_MODE_64B implies that the vCPU is launched
* directly in long mode, so the type of the cached part
* of the TR register is set to describe a 64-bit TSS (Busy).
* The cached part of the CS register will also have the L bit
* set (64-bit code segment).

Quoted 8 lines
Quoted 3 lines

I'd leave out mentioning TR here (or else it'll be odd not to mention e.g. LDTR too). Perhaps just "..., so the cached parts of the segment registers get set to match that environment"?

That sounds fine. I'm going to update the patch and the FreeBSD part in order to test it. Since we also spoke about adding sanity checks, I wonder whether I should add those checks now, or leave them for a later patch. IMHO those checks are only useful for developers.

Fundamentally, checks done here should include everything that would otherwise lead to the domain getting killed due to failed VMENTRY. I.e. both sets below may need extending.

Quoted 8 lines

For VCPU_HVM_MODE_32B:
- rIP within CS limit.
- Check that CS.DPL == SS.DPL.
- rSP within SS limit.

TBH I don't think we should enforce the last two checks, starting with an invalid stack should be fine as long as the user knows it. Maybe print a warning/debug message in this case?

I wouldn't check ESP at all. As to the two DPLs to, I don't think you could launch a guest with these disagreeing.

Quoted 6 lines

For VCPU_HVM_MODE_64B:
- Check that cr0 has paging enabled.
- Check that cr4 has pae enabled.
- Check that efer has the LMA/LME bits set.

Those should be always enforced for long mode.

Agreed, plus RIP being canonical.

Jan

#84 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 31 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 30.09.15 at 14:19, <[email protected]> wrote:

El 30/09/15 a les 13.54, Jan Beulich ha escrit:

Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 30.09.15 at 13:37, <[email protected]> wrote:

/*
* Using VCPU_HVM_MODE_64B implies that the vCPU is launched
* directly in long mode, so the type of the cached part
* of the TR register is set to describe a 64-bit TSS (Busy).
* The cached part of the CS register will also have the L bit
* set (64-bit code segment).

Quoted 7 lines
Quoted 3 lines

I'd leave out mentioning TR here (or else it'll be odd not to mention e.g. LDTR too). Perhaps just "..., so the cached parts of the segment registers get set to match that environment"?

That sounds fine. I'm going to update the patch and the FreeBSD part in order to test it. Since we also spoke about adding sanity checks, I wonder whether I should add those checks now, or leave them for a later patch. IMHO those checks are only useful for developers.

Fundamentally, checks done here should include everything that would otherwise lead to the domain getting killed due to failed VMENTRY. I.e. both sets below may need extending.

Quoted 8 lines

For VCPU_HVM_MODE_32B:
- rIP within CS limit.
- Check that CS.DPL == SS.DPL.
- rSP within SS limit.

TBH I don't think we should enforce the last two checks, starting with an invalid stack should be fine as long as the user knows it. Maybe print a warning/debug message in this case?

I wouldn't check ESP at all. As to the two DPLs to, I don't think you could launch a guest with these disagreeing.

Quoted 7 lines
Quoted 6 lines

For VCPU_HVM_MODE_64B:
- Check that cr0 has paging enabled.
- Check that cr4 has pae enabled.
- Check that efer has the LMA/LME bits set.

Those should be always enforced for long mode.

Agreed, plus RIP being canonical.

LMA is a read-only bit with inconsistent semantics between Intel and AMD.

In particular, on Intel, LMA is not visible until LME has been set, which means that the typical setup of

mov $MSR_EFER, %ecx
rdmsr
bts $_EFER_LME, %eax
wrmsr

Causes Xen to observe LME but not LMA when intercepting the wrmsr.

I think all you need to check is CR0.PG, CR4.PAE and EFER.LME (and guest X86_FEATURE_LM). LMA will then leak through in subsequent rdmsr's

~Andrew

#85 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

El 30/09/15 a les 14.50, Andrew Cooper ha escrit:

Quoted 50 lines · Jan Beulich
Quoted 31 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 30.09.15 at 14:19, <[email protected]> wrote:

El 30/09/15 a les 13.54, Jan Beulich ha escrit:

Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 30.09.15 at 13:37, <[email protected]> wrote:

/*
* Using VCPU_HVM_MODE_64B implies that the vCPU is launched
* directly in long mode, so the type of the cached part
* of the TR register is set to describe a 64-bit TSS (Busy).
* The cached part of the CS register will also have the L bit
* set (64-bit code segment).

Quoted 7 lines
Quoted 3 lines

I'd leave out mentioning TR here (or else it'll be odd not to mention e.g. LDTR too). Perhaps just "..., so the cached parts of the segment registers get set to match that environment"?

That sounds fine. I'm going to update the patch and the FreeBSD part in order to test it. Since we also spoke about adding sanity checks, I wonder whether I should add those checks now, or leave them for a later patch. IMHO those checks are only useful for developers.

Fundamentally, checks done here should include everything that would otherwise lead to the domain getting killed due to failed VMENTRY. I.e. both sets below may need extending.

Quoted 8 lines

For VCPU_HVM_MODE_32B:
- rIP within CS limit.
- Check that CS.DPL == SS.DPL.
- rSP within SS limit.

TBH I don't think we should enforce the last two checks, starting with an invalid stack should be fine as long as the user knows it. Maybe print a warning/debug message in this case?

I wouldn't check ESP at all. As to the two DPLs to, I don't think you could launch a guest with these disagreeing.

Quoted 7 lines
Quoted 6 lines

For VCPU_HVM_MODE_64B:
- Check that cr0 has paging enabled.
- Check that cr4 has pae enabled.
- Check that efer has the LMA/LME bits set.

Those should be always enforced for long mode.

Agreed, plus RIP being canonical.

LMA is a read-only bit with inconsistent semantics between Intel and AMD.

In particular, on Intel, LMA is not visible until LME has been set, which means that the typical setup of

mov $MSR_EFER, %ecx
rdmsr
bts $_EFER_LME, %eax
wrmsr

Quoted 4 lines

Causes Xen to observe LME but not LMA when intercepting the wrmsr.

I think all you need to check is CR0.PG, CR4.PAE and EFER.LME (and guest X86_FEATURE_LM). LMA will then leak through in subsequent rdmsr's

Although you don't need to set LMA in real hardware, AFAICT you need to set it when using this interface, because hvm_update_guest_efer doesn't set LMA if LME is enabled, which causes the vmentry to fail.

Roger.

#86 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

In reply to Jan Beulich

El 30/09/15 a les 14.35, Jan Beulich ha escrit:

Quoted 6 lines · On 30.09.15 at 14:19, <[email protected]> wrote:
Quoted 5 lines

For VCPU_HVM_MODE_32B:
- rIP within CS limit.
- Check that CS.DPL == SS.DPL.
- rSP within SS limit.

Quoted 6 lines
Quoted 3 lines

TBH I don't think we should enforce the last two checks, starting with an invalid stack should be fine as long as the user knows it. Maybe print a warning/debug message in this case?

I wouldn't check ESP at all. As to the two DPLs to, I don't think you could launch a guest with these disagreeing.

I think we should basically check that the DPL of the CS segment is equal or greater than the DPL of all the other segments (ds, ss and es).

Roger.

#87 lore raw

Re: [PATCH v6 24/29] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 30.09.15 at 16:23, <[email protected]> wrote:

El 30/09/15 a les 14.35, Jan Beulich ha escrit:

Quoted 10 lines · On 30.09.15 at 14:19, <[email protected]> wrote:
Quoted 8 lines

For VCPU_HVM_MODE_32B:
- rIP within CS limit.
- Check that CS.DPL == SS.DPL.
- rSP within SS limit.

TBH I don't think we should enforce the last two checks, starting with an invalid stack should be fine as long as the user knows it. Maybe print a warning/debug message in this case?

Quoted 5 lines
Quoted 2 lines

I wouldn't check ESP at all. As to the two DPLs to, I don't think you could launch a guest with these disagreeing.

I think we should basically check that the DPL of the CS segment is equal or greater than the DPL of all the other segments (ds, ss and es).

Except that for SS it needs to be equal.

Jan

#88 lore raw

PATCH v6 25/29 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]>

---
Changes since v4:
- Add Wei Liu Acked-by.

Changes since v3:
- Drop the usage of a label and instead use if conditions.

---
 tools/console/client/main.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
tools/console/client/main.c +9 -3
index f130a60..d006fdc 100644
@@ -333,7 +333,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;
@@ -415,9 +415,15 @@ 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)
+			type = CONSOLE_PV;
+	}
+	if (type == CONSOLE_PV) {
+
 		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 v6 26/29 libxc/xen: introduce a start info structure for HVMlite guests

In reply to Roger Pau Monne

This structure contains the physical address of the command line, as well as the physical address of the list of loaded modules. The physical address of this structure is passed to the guest at boot time in the %ebx register.

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]>

---
Changes since v5:
- Change some of the calculations performed to get the total size of the start_info region.
- Replace the mention of HVMlite in a comment with PVH.
- Don't use 64bit integers in hvm_modlist_entry.

---
 tools/libxc/xc_dom_x86.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++-
 xen/include/public/xen.h | 19 ++++++++++++++
 2 files changed, 86 insertions(+), 1 deletion(-)
tools/libxc/xc_dom_x86.c +67 -1
index 2ef833e..3fffcba 100644
@@ -560,7 +560,70 @@ 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));
 
-    if ( dom->device_model )
+    if ( !dom->device_model )
+    {
+        struct xc_dom_seg seg;
+        struct hvm_start_info *start_info;
+        char *cmdline;
+        struct hvm_modlist_entry *modlist;
+        void *start_page;
+        size_t cmdline_size = 0;
+        size_t start_info_size = sizeof(*start_info);
+
+        if ( dom->cmdline )
+        {
+            cmdline_size = ROUNDUP(strlen(dom->cmdline) + 1, 8);
+            start_info_size += cmdline_size;
+
+        }
+        if ( dom->ramdisk_blob )
+            start_info_size += sizeof(*modlist); /* Limited to one module. */
+
+        rc = xc_dom_alloc_segment(dom, &seg, "HVMlite start info", 0,
+                                  start_info_size);
+        if ( rc != 0 )
+        {
+            DOMPRINTF("Unable to reserve memory for the start info");
+            goto out;
+        }
+
+        start_page = xc_map_foreign_range(xch, domid, start_info_size,
+                                          PROT_READ | PROT_WRITE,
+                                          seg.pfn);
+        if ( start_page == NULL )
+        {
+            DOMPRINTF("Unable to map HVM start info page");
+            goto error_out;
+        }
+
+        start_info = start_page;
+        cmdline = start_page + sizeof(*start_info);
+        modlist = start_page + sizeof(*start_info) + cmdline_size;
+
+        if ( dom->cmdline )
+        {
+            strncpy(cmdline, dom->cmdline, MAX_GUEST_CMDLINE);
+            cmdline[MAX_GUEST_CMDLINE - 1] = '\0';
+            start_info->cmdline_paddr = (seg.pfn << PAGE_SHIFT) +
+                                ((xen_pfn_t)cmdline - (xen_pfn_t)start_info);
+        }
+
+        if ( dom->ramdisk_blob )
+        {
+            modlist[0].paddr = dom->ramdisk_seg.vstart - dom->parms.virt_base;
+            modlist[0].size = dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart;
+            start_info->modlist_paddr = (seg.pfn << PAGE_SHIFT) +
+                                ((xen_pfn_t)modlist - (xen_pfn_t)start_info);
+            start_info->nr_modules = 1;
+        }
+
+        start_info->magic = HVM_START_MAGIC_VALUE;
+
+        munmap(start_page, start_info_size);
+
+        dom->start_info_pfn = seg.pfn;
+    }
+    else
     {
         /*
          * Allocate and clear additional ioreq server pages. The default
@@ -917,6 +980,9 @@ static int vcpu_hvm(struct xc_dom_image *dom)
     /* Set the IP. */
     bsp_ctx.cpu.rip = dom->parms.phys_entry;
 
+    if ( dom->start_info_pfn )
+        bsp_ctx.cpu.rbx = dom->start_info_pfn << PAGE_SHIFT;
+
     /* Set the end descriptor. */
     bsp_ctx.end_d.typecode = HVM_SAVE_CODE(END);
     bsp_ctx.end_d.instance = 0;
xen/include/public/xen.h +19 -0
index ff5547e..0326ba6 100644
@@ -784,6 +784,25 @@ struct start_info {
 };
 typedef struct start_info start_info_t;
 
+/*
+ * Start of day structure passed to PVH guests in %ebx.
+ */
+struct hvm_start_info {
+#define HVM_START_MAGIC_VALUE 0x336ec578
+    uint32_t magic;             /* Contains the magic value 0x336ec578       */
+                                /* ("xEn3" with the 0x80 bit of the "E" set).*/
+    uint32_t flags;             /* SIF_xxx flags.                            */
+    uint32_t cmdline_paddr;     /* Physical address of the command line.     */
+    uint32_t nr_modules;        /* Number of modules passed to the kernel.   */
+    uint32_t modlist_paddr;     /* Physical address of an array of           */
+                                /* hvm_modlist_entry.                        */
+};
+
+struct hvm_modlist_entry {
+    uint32_t paddr;             /* Physical address of the module.           */
+    uint32_t size;              /* Size of the module in bytes.              */
+};
+
 /* New console union for dom0 introduced in 0x00030203. */
 #if __XEN_INTERFACE_VERSION__ < 0x00030203
 #define console_mfn    console.domU.mfn
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

Re: [PATCH v6 26/29] libxc/xen: introduce a start info structure for HVMlite guests

Quoted 11 lines · Roger Pau Monne

This structure contains the physical address of the command line, as well as the physical address of the list of loaded modules. The physical address of this structure is passed to the guest at boot time in the %ebx register.

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]>

This patch, though touches libxc, is in fact ABI.

I don't think I have comment on the ABI itself here.

The code looks good enough to me FWIW.

Wei.

#91 lore raw

Re: [PATCH v6 26/29] libxc/xen: introduce a start info structure for HVMlite guests

In reply to Roger Pau Monne
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:09, <[email protected]> wrote:

First of all - I suppose it is intentional for this to not consider the Dom0 side (yet)?

Quoted 42 lines
tools/libxc/xc_dom_x86.c +35 -1
@@ -560,7 +560,70 @@ 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));
 
-    if ( dom->device_model )
+    if ( !dom->device_model )
+    {
+        struct xc_dom_seg seg;
+        struct hvm_start_info *start_info;
+        char *cmdline;
+        struct hvm_modlist_entry *modlist;
+        void *start_page;
+        size_t cmdline_size = 0;
+        size_t start_info_size = sizeof(*start_info);
+
+        if ( dom->cmdline )
+        {
+            cmdline_size = ROUNDUP(strlen(dom->cmdline) + 1, 8);
+            start_info_size += cmdline_size;
+
+        }
+        if ( dom->ramdisk_blob )
+            start_info_size += sizeof(*modlist); /* Limited to one module. */
+
+        rc = xc_dom_alloc_segment(dom, &seg, "HVMlite start info", 0,
+                                  start_info_size);
+        if ( rc != 0 )
+        {
+            DOMPRINTF("Unable to reserve memory for the start info");
+            goto out;
+        }
+
+        start_page = xc_map_foreign_range(xch, domid, start_info_size,
+                                          PROT_READ | PROT_WRITE,
+                                          seg.pfn);
+        if ( start_page == NULL )
+        {
+            DOMPRINTF("Unable to map HVM start info page");
+            goto error_out;
+        }

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

Quoted 10 lines
tools/libxc/xc_dom_x86.c +10 -0
+
+        start_info = start_page;
+        cmdline = start_page + sizeof(*start_info);
+        modlist = start_page + sizeof(*start_info) + cmdline_size;
+
+        if ( dom->cmdline )
+        {
+            strncpy(cmdline, dom->cmdline, MAX_GUEST_CMDLINE);
+            cmdline[MAX_GUEST_CMDLINE - 1] = '\0';
+            start_info->cmdline_paddr = (seg.pfn << PAGE_SHIFT) +

Not knowing much about the tools interface used for allocation
above: Does that interface guarantee this shift (and another one below) to not overflow?

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

Quoted 1 line
tools/libxc/xc_dom_x86.c +1 -0
+                                ((xen_pfn_t)cmdline - (xen_pfn_t)start_info);

xen_pfn_t? Aren't these byte addresses?

xen/include/public/xen.h struct start_info { · line 789

Quoted 9 lines
xen/include/public/xen.h +3 -0
@@ -784,6 +784,25 @@ struct start_info {
 };
 typedef struct start_info start_info_t;
 
+/*
+ * Start of day structure passed to PVH guests in %ebx.
+ */

This is a single line comment.

Quoted 5 lines
xen/include/public/xen.h +5 -0
+struct hvm_start_info {
+#define HVM_START_MAGIC_VALUE 0x336ec578
+    uint32_t magic;             /* Contains the magic value 0x336ec578       */
+                                /* ("xEn3" with the 0x80 bit of the "E" set).*/
+    uint32_t flags;             /* SIF_xxx flags.                            */

xen/include/public/xen.h struct start_info { · line 804

Quoted 10 lines
xen/include/public/xen.h +10 -0
+    uint32_t cmdline_paddr;     /* Physical address of the command line.     */
+    uint32_t nr_modules;        /* Number of modules passed to the kernel.   */
+    uint32_t modlist_paddr;     /* Physical address of an array of           */
+                                /* hvm_modlist_entry.                        */
+};
+
+struct hvm_modlist_entry {
+    uint32_t paddr;             /* Physical address of the module.           */
+    uint32_t size;              /* Size of the module in bytes.              */
+};

Iirc this already went back and forth, but - is this meant to be an x86-specific interface? If not, should we really limit physical addresses to 32 bits here?

Also this now sits inside a XEN_HAVE_PV_GUEST_ENTRY conditional
- is that intended?

Jan

#92 lore raw

Re: [PATCH v6 26/29] libxc/xen: introduce a start info structure for HVMlite guests

El 21/09/15 a les 17.53, Jan Beulich ha escrit:

Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 04.09.15 at 14:09, <[email protected]> wrote:

First of all - I suppose it is intentional for this to not consider the Dom0 side (yet)?

Yes, let's leave Dom0 for a later patch series please, this is already big enough.

Quoted 48 lines
Quoted 48 lines
tools/libxc/xc_dom_x86.c +41 -1
@@ -560,7 +560,70 @@ 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));
 
-    if ( dom->device_model )
+    if ( !dom->device_model )
+    {
+        struct xc_dom_seg seg;
+        struct hvm_start_info *start_info;
+        char *cmdline;
+        struct hvm_modlist_entry *modlist;
+        void *start_page;
+        size_t cmdline_size = 0;
+        size_t start_info_size = sizeof(*start_info);
+
+        if ( dom->cmdline )
+        {
+            cmdline_size = ROUNDUP(strlen(dom->cmdline) + 1, 8);
+            start_info_size += cmdline_size;
+
+        }
+        if ( dom->ramdisk_blob )
+            start_info_size += sizeof(*modlist); /* Limited to one module. */
+
+        rc = xc_dom_alloc_segment(dom, &seg, "HVMlite start info", 0,
+                                  start_info_size);
+        if ( rc != 0 )
+        {
+            DOMPRINTF("Unable to reserve memory for the start info");
+            goto out;
+        }
+
+        start_page = xc_map_foreign_range(xch, domid, start_info_size,
+                                          PROT_READ | PROT_WRITE,
+                                          seg.pfn);
+        if ( start_page == NULL )
+        {
+            DOMPRINTF("Unable to map HVM start info page");
+            goto error_out;
+        }
+
+        start_info = start_page;
+        cmdline = start_page + sizeof(*start_info);
+        modlist = start_page + sizeof(*start_info) + cmdline_size;
+
+        if ( dom->cmdline )
Quoted 8 lines

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

Quoted 4 lines
tools/libxc/xc_dom_x86.c +4 -0
+        {
+            strncpy(cmdline, dom->cmdline, MAX_GUEST_CMDLINE);
+            cmdline[MAX_GUEST_CMDLINE - 1] = '\0';
+            start_info->cmdline_paddr = (seg.pfn << PAGE_SHIFT) +

Not knowing much about the tools interface used for allocation
above: Does that interface guarantee this shift (and another one below) to not overflow?

I can add a check to make sure pfn are always below the 4GB boundary.

Quoted 3 lines

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

Quoted 1 line
tools/libxc/xc_dom_x86.c +1 -0
+                                ((xen_pfn_t)cmdline - (xen_pfn_t)start_info);

xen_pfn_t? Aren't these byte addresses?

Right, these are not pfns.

Quoted 11 lines

xen/include/public/xen.h struct start_info { · line 789

Quoted 9 lines
xen/include/public/xen.h +3 -0
@@ -784,6 +784,25 @@ struct start_info {
 };
 typedef struct start_info start_info_t;
 
+/*
+ * Start of day structure passed to PVH guests in %ebx.
+ */

This is a single line comment.

Ack.

Quoted 11 lines
Quoted 11 lines
xen/include/public/xen.h +11 -0
+struct hvm_start_info {
+#define HVM_START_MAGIC_VALUE 0x336ec578
+    uint32_t magic;             /* Contains the magic value 0x336ec578       */
+                                /* ("xEn3" with the 0x80 bit of the "E" set).*/
+    uint32_t flags;             /* SIF_xxx flags.                            */
+    uint32_t cmdline_paddr;     /* Physical address of the command line.     */
+    uint32_t nr_modules;        /* Number of modules passed to the kernel.   */
+    uint32_t modlist_paddr;     /* Physical address of an array of           */
+                                /* hvm_modlist_entry.                        */
+};
+
Quoted 8 lines

xen/include/public/xen.h struct start_info { · line 804

Quoted 4 lines
xen/include/public/xen.h +4 -0
+struct hvm_modlist_entry {
+    uint32_t paddr;             /* Physical address of the module.           */
+    uint32_t size;              /* Size of the module in bytes.              */
+};

Iirc this already went back and forth, but - is this meant to be an x86-specific interface? If not, should we really limit physical addresses to 32 bits here?

That's what I though initially (x86 only), and nobody on the ARM side expressed interest in using it there. Ian, Stefano, do you foresee this being used for ARM also?

Quoted 2 lines

Also this now sits inside a XEN_HAVE_PV_GUEST_ENTRY conditional
- is that intended?

That's hard to tell, I would consider a guest/kernel using this structure a PV guest (PVH), but I'm not sure if we can make a clear cut here.

Roger.

#93 lore raw

PATCH v6 27/29 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.

---
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.
---
Changes since v5:
- Add Wei Liu Ack.

Changes since v4:
- Add Andrew Cooper Reviewed-by.

---
 tools/libxc/xc_dom_elfloader.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/libxc/xc_dom_elfloader.c +4 -0
index 66ea9d6..f3a0ed7 100644
@@ -56,6 +56,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
#94 lore raw

PATCH v6 28/29 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 or a device model for the specified domain is not present 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]>

---
Changes since v5:
- Add Wei Liu Acked-by.

Changes since v4:
- Set dom->mmio_size to match the size of the special pages if there's no device model for the guest. This implies moving NR_SPECIAL_PAGES and X86_HVM_END_SPECIAL_REGION to a public header so they can be known by libxl when creating the memory map.
- Reword the xl.cfg man page description of the "none" device model option.
- Use libxl__device_model_version_running instead of creating a new function.

Changes since v3:
- Add explicit /* fall through */ comments.
- Expand libxl__device_nic_setdefault so that it sets the right nic type for HVMlite guests.
- Remove stray space in hvm_build_set_params.
- Fix the error paths of libxl__domain_firmware.

---
 docs/man/xl.cfg.pod.5        |  5 +++
 tools/libxc/include/xc_dom.h |  2 ++
 tools/libxc/xc_dom_x86.c     | 15 ++++-----
 tools/libxl/libxl.c          | 44 ++++++++++++++++++--------
 tools/libxl/libxl_create.c   | 16 +++++++++-
 tools/libxl/libxl_dm.c       |  3 +-
 tools/libxl/libxl_dom.c      | 74 ++++++++++++++++++++++++++++++--------------
 tools/libxl/libxl_internal.h |  9 +++++-
 tools/libxl/libxl_types.idl  |  1 +
 tools/libxl/libxl_x86.c      |  9 ++++--
 tools/libxl/xl_cmdimpl.c     |  2 ++
 11 files changed, 131 insertions(+), 49 deletions(-)
docs/man/xl.cfg.pod.5 +5 -0
index 80e51bb..75d9949 100644
@@ -1741,6 +1741,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
+without emulated devices.
+
 =back
 
 It is recommended to accept the default value for new guests.  If
tools/libxc/include/xc_dom.h +2 -0
index 507b323..b89f8e3 100644
@@ -17,6 +17,8 @@
 #include <xenguest.h>
 
 #define INVALID_P2M_ENTRY   ((xen_pfn_t)-1)
+#define X86_HVM_NR_SPECIAL_PAGES    8
+#define X86_HVM_END_SPECIAL_REGION  0xff000u
 
 /* --- typedefs and structs ---------------------------------------- */
 
tools/libxc/xc_dom_x86.c +8 -7
index 3fffcba..09d70fc 100644
@@ -57,8 +57,8 @@
 #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 special_pfn(x) \
+    (X86_HVM_END_SPECIAL_REGION - X86_HVM_NR_SPECIAL_PAGES + (x))
 
 #define NR_IOREQ_SERVER_PAGES 8
 #define ioreq_server_pfn(x) (special_pfn(0) - NR_IOREQ_SERVER_PAGES + (x))
@@ -516,7 +516,7 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
     void *hvm_info_page;
     uint32_t *ident_pt, domid = dom->guest_domid;
     int rc;
-    xen_pfn_t special_array[NR_SPECIAL_PAGES];
+    xen_pfn_t special_array[X86_HVM_NR_SPECIAL_PAGES];
     xen_pfn_t ioreq_server_array[NR_IOREQ_SERVER_PAGES];
     xc_interface *xch = dom->xch;
 
@@ -531,18 +531,19 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
     }
 
     /* Allocate and clear special pages. */
-    for ( i = 0; i < NR_SPECIAL_PAGES; i++ )
+    for ( i = 0; i < X86_HVM_NR_SPECIAL_PAGES; i++ )
         special_array[i] = special_pfn(i);
 
-    rc = xc_domain_populate_physmap_exact(xch, domid, NR_SPECIAL_PAGES, 0, 0,
-                                          special_array);
+    rc = xc_domain_populate_physmap_exact(xch, domid, X86_HVM_NR_SPECIAL_PAGES,
+                                          0, 0, special_array);
     if ( rc != 0 )
     {
         DOMPRINTF("Could not allocate special pages.");
         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),
+                               X86_HVM_NR_SPECIAL_PAGES) )
             goto error_out;
 
     xc_hvm_param_set(xch, domid, HVM_PARAM_STORE_PFN,
tools/libxl/libxl.c +31 -13

75 lines not on this page · raw message

tools/libxl/libxl_create.c +15 -1
index 5128160..00fe462 100644
@@ -119,6 +119,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;
             }
 
@@ -132,6 +134,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();
         }
 
@@ -236,6 +240,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) {
@@ -923,7 +930,8 @@ static void initiate_domain_create(libxl__egc *egc,
          * called libxl_device_nic_add when domcreate_launch_dm gets called,
          * but qemu needs the nic information to be complete.
          */
-        ret = libxl__device_nic_setdefault(gc, &d_config->nics[i], domid);
+        ret = libxl__device_nic_setdefault(gc, &d_config->nics[i], domid,
+                                           &d_config->b_info);
         if (ret) {
             LOG(ERROR, "Unable to set nic defaults for nic %d", i);
             goto error_out;
@@ -1260,6 +1268,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_dm.c +2 -1
index 16ad47a..7ae10d3 100644
@@ -1501,7 +1501,8 @@ static void spawn_stub_launch_dm(libxl__egc *egc,
          * called libxl_device_nic_add at this point, but qemu needs
          * the nic information to be complete.
          */
-        ret = libxl__device_nic_setdefault(gc, &dm_config->nics[i], dm_domid);
+        ret = libxl__device_nic_setdefault(gc, &dm_config->nics[i], dm_domid,
+                                           &dm_config->b_info);
         if (ret)
             goto out;
     }
tools/libxl/libxl_dom.c +51 -23

141 lines not on this page · raw message

tools/libxl/libxl_internal.h +8 -1
index 294d442..e155987 100644
@@ -112,6 +112,12 @@
 #define TAP_DEVICE_SUFFIX "-emu"
 #define DOMID_XS_PATH "domid"
 
+/* Size macros. */
+#define __AC(X,Y)   (X##Y)
+#define _AC(X,Y)    __AC(X,Y)
+#define MB(_mb)     (_AC(_mb, ULL) << 20)
+#define GB(_gb)     (_AC(_gb, ULL) << 30)
+
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 
 #define ROUNDUP(_val, _order)                                           \
@@ -1173,7 +1179,8 @@ _hidden int libxl__domain_build_info_setdefault(libxl__gc *gc,
 _hidden int libxl__device_disk_setdefault(libxl__gc *gc,
                                           libxl_device_disk *disk);
 _hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic,
-                                         uint32_t domid);
+                                         uint32_t domid,
+                                         libxl_domain_build_info *info);
 _hidden int libxl__device_vtpm_setdefault(libxl__gc *gc, libxl_device_vtpm *vtpm);
 _hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb);
 _hidden int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb);
tools/libxl/libxl_types.idl +1 -0
index ef346e7..b6e99c4 100644
@@ -98,6 +98,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 +6 -3
index 9ecd85d..cf68541 100644
@@ -7,7 +7,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 = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
                                       XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
                                       XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
@@ -488,6 +490,7 @@ int libxl__arch_domain_construct_memmap(libxl__gc *gc,
     struct e820entry *e820 = NULL;
     uint64_t highmem_size =
                     dom->highmem_end ? dom->highmem_end - (1ull << 32) : 0;
+    uint32_t lowmem_start = dom->device_model ? GUEST_LOW_MEM_START_DEFAULT : 0;
 
     /* Add all rdm entries. */
     for (i = 0; i < d_config->num_rdms; i++)
@@ -508,8 +511,8 @@ int libxl__arch_domain_construct_memmap(libxl__gc *gc,
     e820 = libxl__malloc(gc, sizeof(struct e820entry) * e820_entries);
 
     /* Low memory */
-    e820[nr].addr = GUEST_LOW_MEM_START_DEFAULT;
-    e820[nr].size = dom->lowmem_end - GUEST_LOW_MEM_START_DEFAULT;
+    e820[nr].addr = lowmem_start;
+    e820[nr].size = dom->lowmem_end - lowmem_start;
     e820[nr].type = E820_RAM;
     nr++;
 
tools/libxl/xl_cmdimpl.c +2 -0
index ebbb9a5..4464aa5 100644
@@ -2172,6 +2172,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
#95 lore raw

PATCH v6 29/29 libxl: add support for migrating HVM guests without a device model

In reply to Roger Pau Monne

Only some minor libxl changes are needed in order to be able to migrate HVM guests without a device model, no hypervisor changes are needed.

This change adds support for LIBXL_DEVICE_MODEL_VERSION_NONE into the migration code.

Cc Ian Jackson <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxl/libxl_dom.c              | 3 +++
 tools/libxl/libxl_dom_suspend.c      | 4 ++++
 tools/libxl/libxl_sr_stream_format.h | 1 +
 tools/libxl/libxl_stream_write.c     | 9 ++++++++-
 4 files changed, 16 insertions(+), 1 deletion(-)
tools/libxl/libxl_dom.c +3 -0
index b82b938..1566456 100644
@@ -1308,6 +1308,9 @@ void libxl__domain_suspend_common_switch_qemu_logdirty
     case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
         domain_suspend_switch_qemu_xen_logdirty(domid, enable, shs);
         break;
+    case LIBXL_DEVICE_MODEL_VERSION_NONE:
+        libxl__xc_domain_saverestore_async_callback_done(egc, shs, 0);
+        break;
     default:
         LOG(ERROR,"logdirty switch failed"
             ", no valid device model version found, abandoning suspend");
tools/libxl/libxl_dom_suspend.c +4 -0
index 4cc01ad..7205e60 100644
@@ -43,6 +43,8 @@ int libxl__domain_suspend_device_model(libxl__gc *gc,
         if (ret)
             unlink(filename);
         break;
+    case LIBXL_DEVICE_MODEL_VERSION_NONE:
+        break;
     default:
         return ERROR_INVAL;
     }
@@ -394,6 +396,8 @@ int libxl__domain_resume_device_model(libxl__gc *gc, uint32_t domid)
         if (libxl__qmp_resume(gc, domid))
             return ERROR_FAIL;
         break;
+    case LIBXL_DEVICE_MODEL_VERSION_NONE:
+        break;
     default:
         return ERROR_INVAL;
     }
tools/libxl/libxl_sr_stream_format.h +1 -0
index 54da360..960211c 100644
@@ -46,6 +46,7 @@ typedef struct libxl__sr_emulator_hdr
 #define EMULATOR_UNKNOWN             0x00000000U
 #define EMULATOR_QEMU_TRADITIONAL    0x00000001U
 #define EMULATOR_QEMU_UPSTREAM       0x00000002U
+#define EMULATOR_NONE                0x00000003U
 
 #endif /* LIBXL__SR_STREAM_FORMAT_H */
 
tools/libxl/libxl_stream_write.c +8 -1
index 52a60d7..aa0a5e5 100644
@@ -232,6 +232,10 @@ void libxl__stream_write_start(libxl__egc *egc,
             stream->emu_sub_hdr.id = EMULATOR_QEMU_UPSTREAM;
             break;
 
+        case LIBXL_DEVICE_MODEL_VERSION_NONE:
+            stream->emu_sub_hdr.id = EMULATOR_NONE;
+            break;
+
         default:
             rc = ERROR_FAIL;
             LOG(ERROR, "Unknown emulator for HVM domain");
@@ -387,8 +391,11 @@ static void emulator_xenstore_record_done(libxl__egc *egc,
                                           libxl__stream_write_state *stream)
 {
     libxl__domain_suspend_state *dss = stream->dss;
+    STATE_AO_GC(stream->ao);
 
-    if (dss->type == LIBXL_DOMAIN_TYPE_HVM)
+    if (dss->type == LIBXL_DOMAIN_TYPE_HVM &&
+        libxl__device_model_version_running(gc, dss->domid) !=
+        LIBXL_DEVICE_MODEL_VERSION_NONE)
         write_emulator_context_record(egc, stream);
     else {
         if (stream->in_checkpoint)
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

Re: [PATCH v6 29/29] libxl: add support for migrating HVM guests without a device model

Quoted 11 lines · Roger Pau Monne

Only some minor libxl changes are needed in order to be able to migrate HVM guests without a device model, no hypervisor changes are needed.

This change adds support for LIBXL_DEVICE_MODEL_VERSION_NONE into the migration code.

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

---

[...]

tools/libxl/libxl_sr_stream_format.h typedef struct libxl__sr_emulator_hdr · line 50

Quoted 10 lines
tools/libxl/libxl_sr_stream_format.h +1 -0
index 54da360..960211c 100644
@@ -46,6 +46,7 @@ typedef struct libxl__sr_emulator_hdr
 #define EMULATOR_UNKNOWN             0x00000000U
 #define EMULATOR_QEMU_TRADITIONAL    0x00000001U
 #define EMULATOR_QEMU_UPSTREAM       0x00000002U
+#define EMULATOR_NONE                0x00000003U
 

You also need to patch migration stream spec under docs.

Wei.

#97 lore raw

Re: [PATCH v6 29/29] libxl: add support for migrating HVM guests without a device model

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

Only some minor libxl changes are needed in order to be able to migrate HVM guests without a device model, no hypervisor changes are needed.

This change adds support for LIBXL_DEVICE_MODEL_VERSION_NONE into the migration code.

IMO, this is conceptually wrong.

No device model should be signified by not sending an emulator record. Sending an emulator record saying "No emulator" is pointless in a single emulator setup, and wrong for a multi-emulator setup.

Furthermore, for situations like vGPU with no-dm guests, there will actually be an emulator record sent for demu (The component XenServer currently uses to make vGPU function).

On the save side, if the domain has no emulator, no EMULATOR_* records should be sent.

On the receive side the domain configuration has already been sent so the domain is known to not have an emulator. The arrival of an EMULATOR_* record should be a fatal error for restore.

Support for migration of no-dm guests does not require any extension to the migration ABI. Having said this, the libxl spec does not have a "LAYOUT" section like the libxc spec, and might benefit from having one.

~Andrew

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

#98 lore raw
In reply to Roger Pau Monne
Quoted 6 lines · Roger Pau Monne

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. This batch of patches can go in regardless of the status of the rest of the series IMHO, and in fact would help me quite a lot with the rebasing.

In principal I agree, however they are a pretty major refactoring which would potentially make cherry-picking of subsequent patches for 4.6 more difficult, so I'd like to hold off for a few weeks until we are getting towards the final 4.6 release candidates.

Sorry.

Ian.