Skip to contentSkip to conversation

HVMlite: minor fixes and Dom0 preparatory patches

PATCH In review Roger Pau Monne 5 participants 26 messages Jan 15, 2016 – Jan 20, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover HVMlite: minor fixes and Dom0 preparatory patches

Hello,

This series contains some bug fixes for HVMlite DomU and a preparatory patch for HVMlite Dom0 support (2/4).

Thanks, Roger.

#1 lore raw

PATCH v2 1/4 xen/elfnotes: check phys_entry against UNSET_ADDR32

And introduce UNSET_ADDR32.

---
Cc: Ian Jackson <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Fix commit title.

---
 tools/libxc/xc_dom_elfloader.c     | 2 +-
 xen/common/libelf/libelf-dominfo.c | 1 +
 xen/include/xen/libelf.h           | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)
tools/libxc/xc_dom_elfloader.c +1 -1
index 2ae575e..5039f3f 100644
@@ -57,7 +57,7 @@ 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 )
+         dom->parms.phys_entry != UNSET_ADDR32 )
         return "hvm-3.0-x86_32";
 
     switch ( machine )
xen/common/libelf/libelf-dominfo.c +1 -0
index 02d6cfb..ec69449 100644
@@ -503,6 +503,7 @@ elf_errorstatus elf_xen_parse(struct elf_binary *elf,
     parms->virt_hv_start_low = UNSET_ADDR;
     parms->p2m_base = UNSET_ADDR;
     parms->elf_paddr_offset = UNSET_ADDR;
+    parms->phys_entry = UNSET_ADDR32;
 
     /* Find and parse elf notes. */
     count = elf_phdr_count(elf);
xen/include/xen/libelf.h +1 -0
index 6da4cc0..95b5370 100644
@@ -386,6 +386,7 @@ elf_errorstatus elf_reloc(struct elf_binary *elf);
 /* xc_libelf_dominfo.c                                                      */
 
 #define UNSET_ADDR          ((uint64_t)-1)
+#define UNSET_ADDR32        ((uint32_t)-1)
 
 enum xen_elfnote_type {
     XEN_ENT_NONE = 0,
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 v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] xen/elfnotes: check phys_entry against UNSET_ADDR32

Quoted 22 lines · Roger Pau Monne

And introduce UNSET_ADDR32.

---
Cc: Ian Jackson <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
---
Changes since v1:
- Fix commit title.

---
 tools/libxc/xc_dom_elfloader.c     | 2 +-
 xen/common/libelf/libelf-dominfo.c | 1 +
 xen/include/xen/libelf.h           | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)
tools/libxc/xc_dom_elfloader.c +0 -0
index 2ae575e..5039f3f 100644

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

Quoted 7 lines
tools/libxc/xc_dom_elfloader.c +1 -1
@@ -57,7 +57,7 @@ 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 )
+         dom->parms.phys_entry != UNSET_ADDR32 )
         return "hvm-3.0-x86_32";
 
#3 lore raw

PATCH v2 2/4 libelf: rewrite symtab/strtab loading for Dom0

In reply to Roger Pau Monne

Current implementation of elf_load_bsdsyms is broken when loading inside of a HVM guest, because it assumes elf_memcpy_safe is able to write into guest memory space, which it is not.

Take the oportunity to do some cleanup and properly document how elf_{parse/load}_bsdsyms works. The new implementation uses elf_load_image when dealing with data that needs to be copied to the guest memory space. Also reduce the number of section headers copied to the minimum necessary.

---
Cc: Ian Campbell <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>

---
 xen/common/libelf/libelf-loader.c | 213 ++++++++++++++++++++++++++++----------
 1 file changed, 158 insertions(+), 55 deletions(-)
xen/common/libelf/libelf-loader.c +158 -55
index 6f42bea..9552d4c 100644
@@ -153,7 +153,7 @@ void elf_parse_bsdsyms(struct elf_binary *elf, uint64_t pstart)
 {
     uint64_t sz;
     ELF_HANDLE_DECL(elf_shdr) shdr;
-    unsigned i, type;
+    unsigned int i;
 
     if ( !ELF_HANDLE_VALID(elf->sym_tab) )
         return;
@@ -164,20 +164,33 @@ void elf_parse_bsdsyms(struct elf_binary *elf, uint64_t pstart)
     sz = sizeof(uint32_t);
 
     /* Space for the elf and elf section headers */
-    sz += (elf_uval(elf, elf->ehdr, e_ehsize) +
-           elf_shdr_count(elf) * elf_uval(elf, elf->ehdr, e_shentsize));
+    sz += elf_uval(elf, elf->ehdr, e_ehsize) +
+          3 * elf_uval(elf, elf->ehdr, e_shentsize);
     sz = elf_round_up(elf, sz);
 
-    /* Space for the symbol and string tables. */
+    /* Space for the symbol and string table. */
     for ( i = 0; i < elf_shdr_count(elf); i++ )
     {
         shdr = elf_shdr_by_index(elf, i);
         if ( !elf_access_ok(elf, ELF_HANDLE_PTRVAL(shdr), 1) )
             /* input has an insane section header count field */
             break;
-        type = elf_uval(elf, shdr, sh_type);
-        if ( (type == SHT_STRTAB) || (type == SHT_SYMTAB) )
-            sz = elf_round_up(elf, sz + elf_uval(elf, shdr, sh_size));
+
+        if ( elf_uval(elf, shdr, sh_type) != SHT_SYMTAB )
+            continue;
+
+        sz = elf_round_up(elf, sz + elf_uval(elf, shdr, sh_size));
+        shdr = elf_shdr_by_index(elf, elf_uval(elf, shdr, sh_link));
+
+        if ( !elf_access_ok(elf, ELF_HANDLE_PTRVAL(shdr), 1) )
+            /* input has an insane section header count field */
+            break;
+
+        if ( elf_uval(elf, shdr, sh_type) != SHT_STRTAB )
+            /* Invalid symtab -> strtab link */
+            break;
+
+        sz = elf_round_up(elf, sz + elf_uval(elf, shdr, sh_size));
     }
 
     elf->bsd_symtab_pstart = pstart;
@@ -186,13 +199,31 @@ void elf_parse_bsdsyms(struct elf_binary *elf, uint64_t pstart)
 
 static void elf_load_bsdsyms(struct elf_binary *elf)
 {
-    ELF_HANDLE_DECL(elf_ehdr) sym_ehdr;
-    unsigned long sz;
-    elf_ptrval maxva;
-    elf_ptrval symbase;
-    elf_ptrval symtab_addr;
-    ELF_HANDLE_DECL(elf_shdr) shdr;
-    unsigned i, type;
+    /*
+     * Header that is placed at the end of the kernel and allows
+     * the OS to find where the symtab and strtab have been loaded.
+     * It mimics a valid ELF file header, although it only contains
+     * a symtab and a strtab section.
+     *
+     * NB: according to the ELF spec there's only ONE symtab per ELF
+     * file, and accordingly we will only load the corresponding
+     * strtab, so we only need three section headers in our fake ELF
+     * header (first section header is always a dummy).
+     */
+    struct __packed {
+        elf_ehdr header;
+        elf_shdr section[3];
+    } symbol_header;
+
+    ELF_HANDLE_DECL(elf_ehdr) header_handle;
+    unsigned long shdr_size;
+    uint32_t symsize;
+    ELF_HANDLE_DECL(elf_shdr) section_handle;
+    ELF_HANDLE_DECL(elf_shdr) image_handle;
+    unsigned int i, link;
+    elf_ptrval header_base;
+    elf_ptrval symtab_base;
+    elf_ptrval strtab_base;
 
     if ( !elf->bsd_symtab_pstart )
         return;
@@ -200,64 +231,136 @@ static void elf_load_bsdsyms(struct elf_binary *elf)
 #define elf_hdr_elm(_elf, _hdr, _elm, _val)     \
 do {                                            \
     if ( elf_64bit(_elf) )                      \
-        elf_store_field(_elf, _hdr, e64._elm, _val);  \
+        (_hdr).e64._elm = _val;                 \
     else                                        \
-        elf_store_field(_elf, _hdr, e32._elm, _val);  \
+        (_hdr).e32._elm = _val;                 \
 } while ( 0 )
 
-    symbase = elf_get_ptr(elf, elf->bsd_symtab_pstart);
-    symtab_addr = maxva = symbase + sizeof(uint32_t);
+#define SYMTAB_INDEX    1
+#define STRTAB_INDEX    2
 
-    /* Set up Elf header. */
-    sym_ehdr = ELF_MAKE_HANDLE(elf_ehdr, symtab_addr);
-    sz = elf_uval(elf, elf->ehdr, e_ehsize);
-    elf_memcpy_safe(elf, ELF_HANDLE_PTRVAL(sym_ehdr), ELF_HANDLE_PTRVAL(elf->ehdr), sz);
-    maxva += sz; /* no round up */
+    /* Allow elf_memcpy_safe to write to symbol_header. */
+    elf->caller_xdest_base = &symbol_header;
+    elf->caller_xdest_size = sizeof(symbol_header);
 
-    elf_hdr_elm(elf, sym_ehdr, e_phoff, 0);
-    elf_hdr_elm(elf, sym_ehdr, e_shoff, elf_uval(elf, elf->ehdr, e_ehsize));
-    elf_hdr_elm(elf, sym_ehdr, e_phentsize, 0);
-    elf_hdr_elm(elf, sym_ehdr, e_phnum, 0);
-
-    /* Copy Elf section headers. */
-    shdr = ELF_MAKE_HANDLE(elf_shdr, maxva);
-    sz = elf_shdr_count(elf) * elf_uval(elf, elf->ehdr, e_shentsize);
-    elf_memcpy_safe(elf, ELF_HANDLE_PTRVAL(shdr),
-                    ELF_IMAGE_BASE(elf) + elf_uval(elf, elf->ehdr, e_shoff),
-                    sz);
-    maxva = elf_round_up(elf, (unsigned long)maxva + sz);
+    /*
+     * Calculate the position of the various elements in GUEST MEMORY SPACE.
+     * This addresses MUST only be used with elf_load_image.
+     *
+     * NB: strtab_base cannot be calculated at this point because we don't
+     * know the size of the symtab yet, and the strtab will be placed after it.
+     */
+    header_base = elf_get_ptr(elf, elf->bsd_symtab_pstart) + sizeof(uint32_t);
+    symtab_base = elf_round_up(elf, header_base + sizeof(symbol_header));
+
+    /* Fill the ELF header, copied from the original ELF header. */
+    header_handle = ELF_MAKE_HANDLE(elf_ehdr,
+                                    ELF_REALPTR2PTRVAL(&symbol_header.header));
+    elf_memcpy_safe(elf, ELF_HANDLE_PTRVAL(header_handle),
+                    ELF_HANDLE_PTRVAL(elf->ehdr),
+                    elf_uval(elf, elf->ehdr, e_ehsize));
+
+    /* Set the offset to the shdr array. */
+    elf_hdr_elm(elf, symbol_header.header, e_shoff,
+                offsetof(typeof(symbol_header), section));
+
+    /* Set the right number of section headers. */
+    elf_hdr_elm(elf, symbol_header.header, e_shnum, 3);
+
+    /* Clear a couple of fields we don't use. */
+    elf_hdr_elm(elf, symbol_header.header, e_phoff, 0);
+    elf_hdr_elm(elf, symbol_header.header, e_phentsize, 0);
+    elf_hdr_elm(elf, symbol_header.header, e_phnum, 0);
+
+    /* Zero the dummy section. */
+    section_handle = ELF_MAKE_HANDLE(elf_shdr,
+                     ELF_REALPTR2PTRVAL(&symbol_header.section[SHN_UNDEF]));
+    shdr_size = elf_uval(elf, elf->ehdr, e_shentsize);
+    elf_memset_safe(elf, ELF_HANDLE_PTRVAL(section_handle), 0, shdr_size);
 
+    /*
+     * Find the actual symtab and strtab in the ELF.
+     *
+     * The symtab section header is going to reside in section[SYMTAB_INDEX],
+     * while the corresponding strtab is going to be placed in
+     * section[STRTAB_INDEX]. sh_offset is mangled so it points to the offset
+     * where the sections are actually loaded (relative to the ELF header
+     * location).
+     */
+    section_handle = ELF_MAKE_HANDLE(elf_shdr,
+                     ELF_REALPTR2PTRVAL(&symbol_header.section[SYMTAB_INDEX]));
     for ( i = 0; i < elf_shdr_count(elf); i++ )
     {
-        elf_ptrval old_shdr_p;
-        elf_ptrval new_shdr_p;
 
-        type = elf_uval(elf, shdr, sh_type);
-        if ( (type == SHT_STRTAB) || (type == SHT_SYMTAB) )
+        image_handle = elf_shdr_by_index(elf, i);
+        if ( elf_uval(elf, image_handle, sh_type) != SHT_SYMTAB )
+            continue;
+
+        elf_memcpy_safe(elf, ELF_HANDLE_PTRVAL(section_handle),
+                        ELF_HANDLE_PTRVAL(image_handle),
+                        shdr_size);
+
+        link = elf_uval(elf, section_handle, sh_link);
+        if ( link == SHN_UNDEF )
         {
-             elf_msg(elf, "%s: shdr %i at 0x%"ELF_PRPTRVAL" -> 0x%"ELF_PRPTRVAL"\n", __func__, i,
-                     elf_section_start(elf, shdr), maxva);
-             sz = elf_uval(elf, shdr, sh_size);
-             elf_memcpy_safe(elf, maxva, elf_section_start(elf, shdr), sz);
-             /* Mangled to be based on ELF header location. */
-             elf_hdr_elm(elf, shdr, sh_offset, maxva - symtab_addr);
-             maxva = elf_round_up(elf, (unsigned long)maxva + sz);
+            elf_mark_broken(elf, "bad link in symtab");
+            break;
         }
-        old_shdr_p = ELF_HANDLE_PTRVAL(shdr);
-        new_shdr_p = old_shdr_p + elf_uval(elf, elf->ehdr, e_shentsize);
-        if ( new_shdr_p <= old_shdr_p ) /* wrapped or stuck */
+
+        /* Load symtab into guest memory. */
+        elf_load_image(elf, symtab_base, elf_section_start(elf, section_handle),
+                       elf_uval(elf, section_handle, sh_size),
+                       elf_uval(elf, section_handle, sh_size));
+        elf_hdr_elm(elf, symbol_header.section[SYMTAB_INDEX], sh_offset,
+                    symtab_base - header_base);
+        elf_hdr_elm(elf, symbol_header.section[SYMTAB_INDEX], sh_link,
+                    STRTAB_INDEX);
+
+        /* Calculate the guest address where strtab is loaded. */
+        strtab_base = elf_round_up(elf, symtab_base +
+                                   elf_uval(elf, section_handle, sh_size));
+
+        /* Load strtab section header. */
+        section_handle = ELF_MAKE_HANDLE(elf_shdr,
+                    ELF_REALPTR2PTRVAL(&symbol_header.section[STRTAB_INDEX]));
+        elf_memcpy_safe(elf, ELF_HANDLE_PTRVAL(section_handle),
+                        ELF_HANDLE_PTRVAL(elf_shdr_by_index(elf, link)),
+                        shdr_size);
+
+        if ( elf_uval(elf, section_handle, sh_type) != SHT_STRTAB )
         {
-            elf_mark_broken(elf, "bad section header length");
+            elf_mark_broken(elf, "strtab not found");
             break;
         }
-        if ( !elf_access_ok(elf, new_shdr_p, 1) ) /* outside image */
-            break;
-        shdr = ELF_MAKE_HANDLE(elf_shdr, new_shdr_p);
+
+        /* Load strtab into guest memory. */
+        elf_load_image(elf, strtab_base, elf_section_start(elf, section_handle),
+                       elf_uval(elf, section_handle, sh_size),
+                       elf_uval(elf, section_handle, sh_size));
+        elf_hdr_elm(elf, symbol_header.section[STRTAB_INDEX], sh_offset,
+                    strtab_base - header_base);
+
+        /* Store the whole size (including headers and loaded sections). */
+        symsize = strtab_base + elf_uval(elf, section_handle, sh_size) -
+                  header_base;
+        break;
     }
 
-    /* Write down the actual sym size. */
-    elf_store_val(elf, uint32_t, symbase, maxva - symtab_addr);
+    /* Load the total size at symtab_pstart. */
+    elf_load_image(elf, elf_get_ptr(elf, elf->bsd_symtab_pstart),
+                   ELF_REALPTR2PTRVAL(&symsize), sizeof(symsize),
+                   sizeof(symsize));
+
+    /* Load the headers. */
+    elf_load_image(elf, header_base, ELF_REALPTR2PTRVAL(&symbol_header),
+                   sizeof(symbol_header), sizeof(symbol_header));
+
+    /* Remove permissions from elf_memcpy_safe. */
+    elf->caller_xdest_base = NULL;
+    elf->caller_xdest_size = 0;
 
+#undef SYMTAB_INDEX
+#undef STRTAB_INDEX
 #undef elf_ehdr_elm
 }
 
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 v2 3/4 x86/hvm: don't set the BSP as initialised in hvm_vcpu_initialise

In reply to Roger Pau Monne

The BSP will be marked as initialised after hvm_load_cpu_ctxt has loaded the initial state, which is called from the toolstack during domain creation.

Previous to my HVMlite series HVM guests were started without setting any explicit CPU state (in fact we placed that horrible jmp at 0x0, because the IP was by default set to 0x0). This is no longer true, and now HVM guests require that a proper CPU context is loaded before starting. This change helps enforce this policy.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
Changes since v1:
- Expand commit description.

---
 xen/arch/x86/hvm/hvm.c | 4 ----
 1 file changed, 4 deletions(-)
xen/arch/x86/hvm/hvm.c +0 -4
index 787b7de..05c3ca1 100644
@@ -2474,10 +2474,6 @@ int hvm_vcpu_initialise(struct vcpu *v)
  
         /* Init guest TSC to start from zero. */
         hvm_set_guest_tsc(v, 0);
-
-        /* Can start up without SIPI-SIPI or setvcpucontext domctl. */
-        v->is_initialised = 1;
-        clear_bit(_VPF_down, &v->pause_flags);
     }
 
     return 0;
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 v2 4/4 x86/PV: enable the emulated PIT

In reply to Roger Pau Monne

The HVMlite series removed the initialization of the emulated PIT for PV guests, this patch re-enables it.

---
Cc: Ian Jackson <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
NB: Since it's not clear why an emulated PIT is needed, it won't be enabled by default for HVMlite guests until we can figure out if/why it's needed.
---
Changes since v1:
- New in this version.

---
 tools/libxl/libxl_x86.c | 8 +++++++-
 xen/arch/x86/domain.c   | 5 +++--
 xen/arch/x86/setup.c    | 4 +++-
 3 files changed, 13 insertions(+), 4 deletions(-)
tools/libxl/libxl_x86.c +7 -1
index 46cfafb..7f47cc5 100644
@@ -13,8 +13,14 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
         LIBXL_DEVICE_MODEL_VERSION_NONE) {
         /* HVM domains with a device model. */
         xc_config->emulation_flags = XEN_X86_EMU_ALL;
+    } else if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_PV) {
+        /* PV domains. */
+        xc_config->emulation_flags = XEN_X86_EMU_PIT;
     } else {
-        /* PV or HVM domains without a device model. */
+        assert(d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM);
+        assert(d_config->b_info.device_model_version ==
+               LIBXL_DEVICE_MODEL_VERSION_NONE);
+        /* HVMlite domains. */
         xc_config->emulation_flags = 0;
     }
 
xen/arch/x86/domain.c +3 -2
index 159d960..8ee5d76 100644
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) )
+        if ( (is_hvm_domain(d) && config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) ||
+             (!is_hvm_domain(d) && config->emulation_flags != XEN_X86_EMU_PIT) )
         {
             printk(XENLOG_G_ERR "d%d: Xen does not allow %s domain creation "
                    "with the current selection of emulators: %#x\n",
xen/arch/x86/setup.c +3 -1
index 76c7b0f..08bd3fb 100644
@@ -582,7 +582,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         .parity    = 'n',
         .stop_bits = 1
     };
-    struct xen_arch_domainconfig config = { .emulation_flags = 0 };
+    struct xen_arch_domainconfig config = {
+        .emulation_flags = XEN_X86_EMU_PIT,
+    };
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
 
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 v2 4/4
#6 lore raw

Re: [PATCH v2 4/4] x86/PV: enable the emulated PIT

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

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 15:59, <[email protected]> wrote:
xen/arch/x86/domain.c +3 -2
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) )
+        if ( (is_hvm_domain(d) && config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) ||
+             (!is_hvm_domain(d) && config->emulation_flags != XEN_X86_EMU_PIT) )

IMO it would be more readable when transforming

    if ( (a && b) || (!a && c) )

into

if ( a ? b : c )

With that change

Jan

#7 lore raw

PATCH v3 4/4 x86/PV: enable the emulated PIT

The HVMlite series removed the initialization of the emulated PIT for PV guests, this patch re-enables it.

---
Cc: Ian Jackson <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
NB: Since it's not clear why an emulated PIT is needed, it won't be enabled by default for HVMlite guests until we can figure out if/why it's needed.
---
Changes since v2:
- Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c )'.

Changes since v1:
- New in this version.

---
 tools/libxl/libxl_x86.c | 8 +++++++-
 xen/arch/x86/domain.c   | 5 +++--
 xen/arch/x86/setup.c    | 4 +++-
 3 files changed, 13 insertions(+), 4 deletions(-)
tools/libxl/libxl_x86.c +7 -1
index 46cfafb..7f47cc5 100644
@@ -13,8 +13,14 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
         LIBXL_DEVICE_MODEL_VERSION_NONE) {
         /* HVM domains with a device model. */
         xc_config->emulation_flags = XEN_X86_EMU_ALL;
+    } else if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_PV) {
+        /* PV domains. */
+        xc_config->emulation_flags = XEN_X86_EMU_PIT;
     } else {
-        /* PV or HVM domains without a device model. */
+        assert(d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM);
+        assert(d_config->b_info.device_model_version ==
+               LIBXL_DEVICE_MODEL_VERSION_NONE);
+        /* HVMlite domains. */
         xc_config->emulation_flags = 0;
     }
 
xen/arch/x86/domain.c +3 -2
index 159d960..ae85e45 100644
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) )
+        if ( is_hvm_domain(d) ? (config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) )
         {
             printk(XENLOG_G_ERR "d%d: Xen does not allow %s domain creation "
                    "with the current selection of emulators: %#x\n",
xen/arch/x86/setup.c +3 -1
index 76c7b0f..08bd3fb 100644
@@ -582,7 +582,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         .parity    = 'n',
         .stop_bits = 1
     };
-    struct xen_arch_domainconfig config = { .emulation_flags = 0 };
+    struct xen_arch_domainconfig config = {
+        .emulation_flags = XEN_X86_EMU_PIT,
+    };
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
 
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

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
- Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c )'.

Thanks, but after some more thinking about it I'm afraid there are a few more aspects to consider here:

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

Quoted 12 lines
xen/arch/x86/domain.c +3 -2
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) )
+        if ( is_hvm_domain(d) ? (config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) )
         {

For one I think it would be a good idea to allow zero for PV domains, and perhaps even default new DomU-s to have the PIT flag clear. (Also - indentation.)

Which gets us to the second, broader issue: These flags shouldn't be forced to a particular value during migration, but instead they should be part of the state getting migrated. Incoming domains then would - if the field is missing due to coming from an older hypervisor - have the flag default to 1.

And then - is all this working as intended for the hwdom != Dom0 case?

Jan

#9 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 22 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
- Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c )'.

Thanks, but after some more thinking about it I'm afraid there are a few more aspects to consider here:

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

Quoted 12 lines
xen/arch/x86/domain.c +3 -2
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) )
+        if ( is_hvm_domain(d) ? (config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) )
         {

For one I think it would be a good idea to allow zero for PV domains, and perhaps even default new DomU-s to have the PIT flag clear. (Also - indentation.)

Quoted 5 lines

Which gets us to the second, broader issue: These flags shouldn't be forced to a particular value during migration, but instead they should be part of the state getting migrated. Incoming domains then would - if the field is missing due to coming from an older hypervisor - have the flag default to 1.

There is sadly another ratsnest here.

These values are needed for domain creation, which means that putting them anywhere in the migration stream is already too late, as the domain has been created before the stream header is read.

In principle, the best which could occur is that a value gets stashed in the stream and used as a sanity check. That will at least catch the case when they are different.

I was planning to do exactly the same for the vcpu count etc. as part of my further cpuid work. However, there is a substantial quantity of development work required to make this function in a rational way.

For now, I wouldn't worry too much. It is just one of a very large number of things which should be moved on migrate, but isn't. (Most notably, the cpuid policy.)

~Andrew

#10 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 10:29, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
- Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c )'.

Thanks, but after some more thinking about it I'm afraid there are a few more aspects to consider here:

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

Quoted 3 lines
xen/arch/x86/domain.c +0 -0
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d, unsigned int 

domcr_flags,

Quoted 5 lines

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

Quoted 5 lines
xen/arch/x86/domain.c +0 -2
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) 

)

Quoted 8 lines

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

Quoted 4 lines
xen/arch/x86/domain.c +3 -0
+        if ( is_hvm_domain(d) ? (config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) )
         {

For one I think it would be a good idea to allow zero for PV domains, and perhaps even default new DomU-s to have the PIT flag clear. (Also - indentation.)

Quoted 7 lines
Quoted 5 lines

Which gets us to the second, broader issue: These flags shouldn't be forced to a particular value during migration, but instead they should be part of the state getting migrated. Incoming domains then would - if the field is missing due to coming from an older hypervisor - have the flag default to 1.

There is sadly another ratsnest here.

I've been afraid of that.

Quoted 3 lines

These values are needed for domain creation, which means that putting them anywhere in the migration stream is already too late, as the domain has been created before the stream header is read.

Is that an inherent requirement, or just a result of current code structure? I ask because migrating the emulation flags is going to be a requirement for relaxing the current (almost) all-or-nothing policy on those flags.

Quoted 3 lines

In principle, the best which could occur is that a value gets stashed in the stream and used as a sanity check. That will at least catch the case when they are different.

That'd be a minimal first step.

Jan

#11 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 31 lines · Jan Beulich
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 10:29, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
- Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c )'.

Thanks, but after some more thinking about it I'm afraid there are a few more aspects to consider here:

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

Quoted 3 lines
xen/arch/x86/domain.c +0 -0
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d, unsigned int 

domcr_flags,

Quoted 5 lines

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

Quoted 5 lines
xen/arch/x86/domain.c +0 -2
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) 

)

Quoted 13 lines

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

Quoted 4 lines
xen/arch/x86/domain.c +3 -0
+        if ( is_hvm_domain(d) ? (config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) )
         {

For one I think it would be a good idea to allow zero for PV domains, and perhaps even default new DomU-s to have the PIT flag clear. (Also - indentation.)

Which gets us to the second, broader issue: These flags shouldn't be forced to a particular value during migration, but instead they should be part of the state getting migrated. Incoming domains then would - if the field is missing due to coming from an older hypervisor - have the flag default to 1.

Quoted 8 lines
Quoted 1 line

There is sadly another ratsnest here.

I've been afraid of that.

Quoted 3 lines

These values are needed for domain creation, which means that putting them anywhere in the migration stream is already too late, as the domain has been created before the stream header is read.

Is that an inherent requirement, or just a result of current code structure?

Depends. As far as libxc/libxl migration levels go, current code structure.

Whatever (eventually) gets used to set these values will however be present in the xl configuration, which is at the very start of the stream, and is what is used to create the new domain.

We really don't want the libxc migrate code to be making the DOMCTL_createdomain hypercall itself; it opens up a whole new attack surface via cunningly-crafted save image. The best we can do is have a sanity check later on.

Quoted 8 lines

I ask because migrating the emulation flags is going to
be a requirement for relaxing the current (almost) all-or-nothing policy on those flags.

Quoted 3 lines

In principle, the best which could occur is that a value gets stashed in the stream and used as a sanity check. That will at least catch the case when they are different.

That'd be a minimal first step.

This is a substantial quantity of work to do properly. As the emulation flags are just one in a very long list of fields handed like this, I don't think this issue should block the series.

~Andrew

#12 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 37 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 11:41, <[email protected]> wrote:
Quoted 35 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 10:29, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
- Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c )'.

Thanks, but after some more thinking about it I'm afraid there are a few more aspects to consider here:

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

Quoted 3 lines
xen/arch/x86/domain.c +0 -0
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d, unsigned int 

domcr_flags,

Quoted 5 lines

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

Quoted 5 lines
xen/arch/x86/domain.c +0 -2
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) 

)

Quoted 8 lines

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

Quoted 4 lines
xen/arch/x86/domain.c +3 -0
+        if ( is_hvm_domain(d) ? (config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) )
         {

For one I think it would be a good idea to allow zero for PV domains, and perhaps even default new DomU-s to have the PIT flag clear. (Also - indentation.)

Quoted 6 lines
Quoted 5 lines

Which gets us to the second, broader issue: These flags shouldn't be forced to a particular value during migration, but instead they should be part of the state getting migrated. Incoming domains then would - if the field is missing due to coming from an older hypervisor - have the flag default to 1.

There is sadly another ratsnest here.

I've been afraid of that.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

These values are needed for domain creation, which means that putting them anywhere in the migration stream is already too late, as the domain has been created before the stream header is read.

Is that an inherent requirement, or just a result of current code structure?

Depends. As far as libxc/libxl migration levels go, current code structure.

I.e. fixable.

Quoted 3 lines

Whatever (eventually) gets used to set these values will however be present in the xl configuration, which is at the very start of the stream, and is what is used to create the new domain.

Which makes me repeat the question: Is this an inherent property or just "that's the way it is right now"? And then of course the question arises whether setting those flags at domain creation time is the right model. I.e. ...

Quoted 4 lines

We really don't want the libxc migrate code to be making the DOMCTL_createdomain hypercall itself; it opens up a whole new attack surface via cunningly-crafted save image. The best we can do is have a sanity check later on.

... what about deriving the emulation flags from the various pieces of state getting loaded, at least when there are matching pairs (which namely is the case for PIT)?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

In principle, the best which could occur is that a value gets stashed in the stream and used as a sanity check. That will at least catch the case when they are different.

That'd be a minimal first step.

This is a substantial quantity of work to do properly. As the emulation flags are just one in a very long list of fields handed like this, I don't think this issue should block the series.

Ugly, but the way things seem to stand it may indeed be unavoidable to ignore the issue for now.

Jan

#13 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 24 lines · Jan Beulich
Quoted 6 lines

Which gets us to the second, broader issue: These flags shouldn't be forced to a particular value during migration, but instead they should be part of the state getting migrated. Incoming domains then would - if the field is missing due to coming from an older hypervisor - have the flag default to 1.

Quoted 1 line
Quoted 1 line

There is sadly another ratsnest here.

Quoted 8 lines
Quoted 7 lines

I've been afraid of that.

Quoted 3 lines

These values are needed for domain creation, which means that putting them anywhere in the migration stream is already too late, as the domain has been created before the stream header is read.

Is that an inherent requirement, or just a result of current code structure?

Depends. As far as libxc/libxl migration levels go, current code structure.

I.e. fixable.

Quoted 3 lines

Whatever (eventually) gets used to set these values will however be present in the xl configuration, which is at the very start of the stream, and is what is used to create the new domain.

Which makes me repeat the question: Is this an inherent property or just "that's the way it is right now"? And then of course the question arises whether setting those flags at domain creation time is the right model. I.e. ...

Quoted 7 lines
Quoted 4 lines

We really don't want the libxc migrate code to be making the DOMCTL_createdomain hypercall itself; it opens up a whole new attack surface via cunningly-crafted save image. The best we can do is have a sanity check later on.

... what about deriving the emulation flags from the various pieces of state getting loaded, at least when there are matching pairs (which namely is the case for PIT)?

How would you suggest setting theses flags up in the plain domain build case then?

~Andrew

#14 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 17:10, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 3 lines

Whatever (eventually) gets used to set these values will however be present in the xl configuration, which is at the very start of the stream, and is what is used to create the new domain.

Which makes me repeat the question: Is this an inherent property or just "that's the way it is right now"? And then of course the question arises whether setting those flags at domain creation time is the right model. I.e. ...

Quoted 4 lines

We really don't want the libxc migrate code to be making the DOMCTL_createdomain hypercall itself; it opens up a whole new attack surface via cunningly-crafted save image. The best we can do is have a sanity check later on.

Quoted 6 lines
Quoted 3 lines

... what about deriving the emulation flags from the various pieces of state getting loaded, at least when there are matching pairs (which namely is the case for PIT)?

How would you suggest setting theses flags up in the plain domain build case then?

Via a specific (new) hypercall, along the lines of what XEN_DOMCTL_arm_configure_domain was?

Jan

#15 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 17:10, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 3 lines

Whatever (eventually) gets used to set these values will however be present in the xl configuration, which is at the very start of the stream, and is what is used to create the new domain.

Which makes me repeat the question: Is this an inherent property or just "that's the way it is right now"? And then of course the question arises whether setting those flags at domain creation time is the right model. I.e. ...

Quoted 4 lines

We really don't want the libxc migrate code to be making the DOMCTL_createdomain hypercall itself; it opens up a whole new attack surface via cunningly-crafted save image. The best we can do is have a sanity check later on.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

... what about deriving the emulation flags from the various pieces of state getting loaded, at least when there are matching pairs (which namely is the case for PIT)?

How would you suggest setting theses flags up in the plain domain build case then?

Via a specific (new) hypercall, along the lines of what XEN_DOMCTL_arm_configure_domain was?

This adds the existing problems we have between the createdomain and max_cpus hypercalls.

We need to either specify all information in a single hypercall, or have a dedicated construction phase, during which most hypercalls are invalid to use.

(IMO - All domain construction is a rats nest in need of redesigning from scratch.)

~Andrew

#16 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 17:33, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 17:10, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 3 lines

Whatever (eventually) gets used to set these values will however be present in the xl configuration, which is at the very start of the stream, and is what is used to create the new domain.

Which makes me repeat the question: Is this an inherent property or just "that's the way it is right now"? And then of course the question arises whether setting those flags at domain creation time is the right model. I.e. ...

Quoted 4 lines

We really don't want the libxc migrate code to be making the DOMCTL_createdomain hypercall itself; it opens up a whole new attack surface via cunningly-crafted save image. The best we can do is have a sanity check later on.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

... what about deriving the emulation flags from the various pieces of state getting loaded, at least when there are matching pairs (which namely is the case for PIT)?

How would you suggest setting theses flags up in the plain domain build case then?

Via a specific (new) hypercall, along the lines of what XEN_DOMCTL_arm_configure_domain was?

Quoted 6 lines

This adds the existing problems we have between the createdomain and max_cpus hypercalls.

We need to either specify all information in a single hypercall, or have a dedicated construction phase, during which most hypercalls are invalid to use.

Which is a reasonable requirement to enforce imo.

Jan

#17 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

In reply to Andrew Cooper

El 18/01/16 a les 11.41, Andrew Cooper ha escrit:

Quoted 56 lines · Jan Beulich
Quoted 31 lines
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 10:29, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
- Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c )'.

Thanks, but after some more thinking about it I'm afraid there are a few more aspects to consider here:

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

Quoted 3 lines
xen/arch/x86/domain.c +0 -0
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d, unsigned int 

domcr_flags,

Quoted 5 lines

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

Quoted 5 lines
xen/arch/x86/domain.c +0 -2
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) 

)

Quoted 13 lines

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

Quoted 4 lines
xen/arch/x86/domain.c +3 -0
+        if ( is_hvm_domain(d) ? (config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) )
         {

For one I think it would be a good idea to allow zero for PV domains, and perhaps even default new DomU-s to have the PIT flag clear. (Also - indentation.)

Which gets us to the second, broader issue: These flags shouldn't be forced to a particular value during migration, but instead they should be part of the state getting migrated. Incoming domains then would - if the field is missing due to coming from an older hypervisor - have the flag default to 1.

Quoted 8 lines
Quoted 1 line

There is sadly another ratsnest here.

I've been afraid of that.

Quoted 3 lines

These values are needed for domain creation, which means that putting them anywhere in the migration stream is already too late, as the domain has been created before the stream header is read.

Is that an inherent requirement, or just a result of current code structure?

Depends. As far as libxc/libxl migration levels go, current code structure.

Whatever (eventually) gets used to set these values will however be present in the xl configuration, which is at the very start of the stream, and is what is used to create the new domain.

We really don't want the libxc migrate code to be making the DOMCTL_createdomain hypercall itself; it opens up a whole new attack surface via cunningly-crafted save image. The best we can do is have a sanity check later on.

Quoted 4 lines

I ask because migrating the emulation flags is going to
be a requirement for relaxing the current (almost) all-or-nothing policy on those flags.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

In principle, the best which could occur is that a value gets stashed in the stream and used as a sanity check. That will at least catch the case when they are different.

That'd be a minimal first step.

This is a substantial quantity of work to do properly. As the emulation flags are just one in a very long list of fields handed like this, I don't think this issue should block the series.

You certainly are more familiar with the migration code than me, but wouldn't it be enough to add a new field to libxl_domain_build_info (uint32_t emulation_flags), and teach libxl_domain_build_info_gen_json/libxl__domain_build_info_parse_json
how to properly parse it?

This however raises the question about how to signal that the field is not initialised, because 0 is a valid value (maybe ~0)?

Roger.

#18 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 60 lines · Roger Pau Monné

El 18/01/16 a les 11.41, Andrew Cooper ha escrit:

Quoted 59 lines · Jan Beulich
Quoted 31 lines
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 10:29, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
- Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c )'.

Thanks, but after some more thinking about it I'm afraid there are a few more aspects to consider here:

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

Quoted 3 lines
xen/arch/x86/domain.c +0 -0
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d, unsigned int 

domcr_flags,

Quoted 5 lines

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

Quoted 5 lines
xen/arch/x86/domain.c +0 -2
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) 

)

Quoted 13 lines

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

Quoted 4 lines
xen/arch/x86/domain.c +3 -0
+        if ( is_hvm_domain(d) ? (config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) )
         {

For one I think it would be a good idea to allow zero for PV domains, and perhaps even default new DomU-s to have the PIT flag clear. (Also - indentation.)

Which gets us to the second, broader issue: These flags shouldn't be forced to a particular value during migration, but instead they should be part of the state getting migrated. Incoming domains then would - if the field is missing due to coming from an older hypervisor - have the flag default to 1.

Quoted 8 lines
Quoted 1 line

There is sadly another ratsnest here.

I've been afraid of that.

Quoted 3 lines

These values are needed for domain creation, which means that putting them anywhere in the migration stream is already too late, as the domain has been created before the stream header is read.

Is that an inherent requirement, or just a result of current code structure?

Depends. As far as libxc/libxl migration levels go, current code structure.

Whatever (eventually) gets used to set these values will however be present in the xl configuration, which is at the very start of the stream, and is what is used to create the new domain.

We really don't want the libxc migrate code to be making the DOMCTL_createdomain hypercall itself; it opens up a whole new attack surface via cunningly-crafted save image. The best we can do is have a sanity check later on.

Quoted 8 lines

I ask because migrating the emulation flags is going to
be a requirement for relaxing the current (almost) all-or-nothing policy on those flags.

Quoted 3 lines

In principle, the best which could occur is that a value gets stashed in the stream and used as a sanity check. That will at least catch the case when they are different.

That'd be a minimal first step.

Quoted 8 lines
Quoted 3 lines

This is a substantial quantity of work to do properly. As the emulation flags are just one in a very long list of fields handed like this, I don't think this issue should block the series.

You certainly are more familiar with the migration code than me, but wouldn't it be enough to add a new field to libxl_domain_build_info (uint32_t emulation_flags), and teach libxl_domain_build_info_gen_json/libxl__domain_build_info_parse_json
how to properly parse it?

That would let it be configured from an xl.cfg file, and would normally be moved in the migration stream. However, there is a specific option in xl to restore but using a brand new configuration file.

What it doesn't do it check that the settings for the domain in the stream match the settings of the domid being restored into.

~Andrew

Quoted 6 lines

This however raises the question about how to signal that the field is not initialised, because 0 is a valid value (maybe ~0)?

Roger.

#19 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 86 lines · Andrew Cooper
Quoted 79 lines · Roger Pau Monné

El 18/01/16 a les 11.41, Andrew Cooper ha escrit:

Quoted 73 lines · Jan Beulich
Quoted 43 lines
Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 10:29, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
 - Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c )'.

Quoted 8 lines

Thanks, but after some more thinking about it I'm afraid there are
a few more aspects to consider here:

Quoted 4 lines
xen/arch/x86/domain.c +0 -0
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d,

unsigned int

domcr_flags,

Quoted 6 lines
Quoted 6 lines

                    d->domain_id, config->emulation_flags); return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL)

)

Quoted 10 lines
Quoted 5 lines

+        if ( is_hvm_domain(d) ? (config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) ) {

For one I think it would be a good idea to allow zero for PV domains,
and perhaps even default new DomU-s to have the PIT flag clear. (Also - indentation.)

Quoted 8 lines

Which gets us to the second, broader issue: These flags shouldn't
be forced to a particular value during migration, but instead they
should be part of the state getting migrated. Incoming domains then would - if the field is missing due to coming from an older
hypervisor - have the flag default to 1.

Quoted 1 line

There is sadly another ratsnest here.

I've been afraid of that.

Quoted 7 lines
Quoted 5 lines

These values are needed for domain creation, which means that putting
them anywhere in the migration stream is already too late, as the domain
has been created before the stream header is read.

Is that an inherent requirement, or just a result of current code structure?

Depends.  As far as libxc/libxl migration levels go, current code structure.

Whatever (eventually) gets used to set these values will however be present in the xl configuration, which is at the very start of the stream, and is what is used to create the new domain.

We really don't want the libxc migrate code to be making the DOMCTL_createdomain hypercall itself; it opens up a whole new attack surface via cunningly-crafted save image.  The best we can do is have a
sanity check later on.

Quoted 9 lines

 I ask because migrating the emulation flags is going to be a requirement for relaxing the current (almost) all-or-nothing policy on those flags.

Quoted 5 lines

In principle, the best which could occur is that a value gets stashed in
the stream and used as a sanity check.  That will at least catch the
case when they are different.

Quoted 5 lines
Quoted 1 line

That'd be a minimal first step.

This is a substantial quantity of work to do properly.  As the emulation
flags are just one in a very long list of fields handed like this, I don't think this issue should block the series.

Quoted 5 lines

You certainly are more familiar with the migration code than me, but wouldn't it be enough to add a new field to libxl_domain_build_info (uint32_t emulation_flags), and teach libxl_domain_build_info_gen_json/libxl__domain_build_info_parse_json how to properly parse it?

Quoted 6 lines

That would let it be configured from an xl.cfg file, and would normally be moved in the migration stream.  However, there is a specific option in xl to restore but using a brand new configuration file.

What it doesn't do it check that the settings for the domain in the stream match the settings of the domid being restored into.

That would be the responsibility of the user who has chosen to override the configuration in this way.

Ian.

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

#20 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 86 lines · Ian Campbell
Quoted 85 lines · Andrew Cooper
Quoted 84 lines · Roger Pau Monné

El 18/01/16 a les 11.41, Andrew Cooper ha escrit:

Quoted 73 lines · Jan Beulich
Quoted 43 lines
Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 10:29, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
- Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c
)'.

Quoted 8 lines

Thanks, but after some more thinking about it I'm afraid there are
a few more aspects to consider here:

Quoted 4 lines
xen/arch/x86/domain.c +0 -0
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d,

unsigned int

domcr_flags,

Quoted 6 lines
Quoted 6 lines
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
xen/arch/x86/domain.c +0 -2
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags

!= XEN_X86_EMU_ALL)

)

Quoted 10 lines

xen/arch/x86/domain.c

Quoted 5 lines

+ if ( is_hvm_domain(d) ? (config->emulation_flags !=
XEN_X86_EMU_ALL &&

xen/arch/x86/domain.c +2 -0
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) )
         {

For one I think it would be a good idea to allow zero for PV domains,
and perhaps even default new DomU-s to have the PIT flag clear. (Also - indentation.)

Quoted 8 lines

Which gets us to the second, broader issue: These flags shouldn't
be forced to a particular value during migration, but instead they
should be part of the state getting migrated. Incoming domains then would - if the field is missing due to coming from an older
hypervisor - have the flag default to 1.

Quoted 1 line

There is sadly another ratsnest here.

I've been afraid of that.

Quoted 7 lines
Quoted 5 lines

These values are needed for domain creation, which means that putting
them anywhere in the migration stream is already too late, as the domain
has been created before the stream header is read.

Is that an inherent requirement, or just a result of current code structure?

Depends. As far as libxc/libxl migration levels go, current code structure.

Whatever (eventually) gets used to set these values will however be present in the xl configuration, which is at the very start of the stream, and is what is used to create the new domain.

We really don't want the libxc migrate code to be making the DOMCTL_createdomain hypercall itself; it opens up a whole new attack surface via cunningly-crafted save image. The best we can do is have a
sanity check later on.

Quoted 9 lines

I ask because migrating the emulation flags is going to
be a requirement for relaxing the current (almost) all-or-nothing policy on those flags.

Quoted 5 lines

In principle, the best which could occur is that a value gets stashed in
the stream and used as a sanity check. That will at least catch the
case when they are different.

Quoted 5 lines
Quoted 1 line

That'd be a minimal first step.

This is a substantial quantity of work to do properly. As the emulation
flags are just one in a very long list of fields handed like this, I don't think this issue should block the series.

You certainly are more familiar with the migration code than me, but wouldn't it be enough to add a new field to libxl_domain_build_info (uint32_t emulation_flags), and teach libxl_domain_build_info_gen_json/libxl__domain_build_info_parse_json
how to properly parse it?

Quoted 8 lines
Quoted 6 lines

That would let it be configured from an xl.cfg file, and would normally be moved in the migration stream. However, there is a specific option in xl to restore but using a brand new configuration file.

What it doesn't do it check that the settings for the domain in the stream match the settings of the domid being restored into.

That would be the responsibility of the user who has chosen to override the configuration in this way.

It is the responsibility of Xen to ensure there are no exploitable holes due to partial or misconfiguration.

In particular, this PIT emulation patch fixes an accidental NULL pointer dereference in Xen, due to the accidental disabling of the PIT in PV guests.

~Andrew

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

#21 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 115 lines · Andrew Cooper
Quoted 114 lines · Ian Campbell
Quoted 113 lines · Andrew Cooper
Quoted 99 lines · Roger Pau Monné

El 18/01/16 a les 11.41, Andrew Cooper ha escrit:

Quoted 92 lines · Jan Beulich
Quoted 60 lines
Quoted 51 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 10:29, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
 - Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c
)'.

Thanks, but after some more thinking about it I'm afraid there
are
a few more aspects to consider here:

Quoted 5 lines
Quoted 5 lines
xen/arch/x86/domain.c +0 -0
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain
 *d,

unsigned int

domcr_flags,

Quoted 8 lines
Quoted 8 lines

                    d->domain_id, config-

Quoted 1 line

emulation_flags);

             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config-

Quoted 1 line

emulation_flags

!= XEN_X86_EMU_ALL)

)

Quoted 14 lines
Quoted 7 lines

+        if ( is_hvm_domain(d) ? (config->emulation_flags !=
XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) )
         {

For one I think it would be a good idea to allow zero for PV
domains,
and perhaps even default new DomU-s to have the PIT flag clear.
(Also - indentation.)

Quoted 10 lines

Which gets us to the second, broader issue: These flags shouldn't
be forced to a particular value during migration, but instead
they
should be part of the state getting migrated. Incoming domains
then would - if the field is missing due to coming from an older
hypervisor - have the flag default to 1.

Quoted 1 line

There is sadly another ratsnest here.

I've been afraid of that.

Quoted 6 lines

These values are needed for domain creation, which means that putting
them anywhere in the migration stream is already too late, as the
domain
has been created before the stream header is read.

Quoted 3 lines

Is that an inherent requirement, or just a result of current code
structure?

Depends.  As far as libxc/libxl migration levels go, current code structure.

Whatever (eventually) gets used to set these values will however be
present in the xl configuration, which is at the very start of the
stream, and is what is used to create the new domain.

We really don't want the libxc migrate code to be making the DOMCTL_createdomain hypercall itself; it opens up a whole new attack
surface via cunningly-crafted save image.  The best we can do is have
a
sanity check later on.

Quoted 11 lines

 I ask because migrating the emulation flags is going to be a requirement for relaxing the current (almost) all-or- nothing
policy on those flags.

Quoted 6 lines

In principle, the best which could occur is that a value gets stashed in
the stream and used as a sanity check.  That will at least catch
the
case when they are different.

Quoted 6 lines
Quoted 1 line

That'd be a minimal first step.

This is a substantial quantity of work to do properly.  As the emulation
flags are just one in a very long list of fields handed like this, I
don't think this issue should block the series.

Quoted 7 lines

You certainly are more familiar with the migration code than me, but
wouldn't it be enough to add a new field to libxl_domain_build_info (uint32_t emulation_flags), and teach libxl_domain_build_info_gen_json/libxl__domain_build_info_parse_jso n
 how to properly parse it?

That would let it be configured from an xl.cfg file, and would normally
be moved in the migration stream.  However, there is a specific option
in xl to restore but using a brand new configuration file.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

What it doesn't do it check that the settings for the domain in the stream match the settings of the domid being restored into.

That would be the responsibility of the user who has chosen to override the
configuration in this way.

It is the responsibility of Xen to ensure there are no exploitable holes due to partial or misconfiguration.

Indeed, but it only needs to check things and fail, not work in the face of a bogus save file + cfg file configuration. Perhaps I misunderstood what was being contended here.

Ian.

Quoted 5 lines

In particular, this PIT emulation patch fixes an accidental NULL pointer dereference in Xen, due to the accidental disabling of the PIT in PV guests.

~Andrew

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

#22 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 118 lines · Ian Campbell
Quoted 117 lines · Andrew Cooper
Quoted 116 lines · Ian Campbell
Quoted 115 lines · Andrew Cooper
Quoted 99 lines · Roger Pau Monné

El 18/01/16 a les 11.41, Andrew Cooper ha escrit:

Quoted 92 lines · Jan Beulich
Quoted 60 lines
Quoted 51 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 10:29, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
- Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b
: c
)'.

Thanks, but after some more thinking about it I'm afraid there
are
a few more aspects to consider here:

Quoted 5 lines
Quoted 5 lines
xen/arch/x86/domain.c +0 -0
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain
 *d,

unsigned int

domcr_flags,

Quoted 8 lines
Quoted 8 lines
                    d->domain_id, config-
Quoted 1 line

emulation_flags);

             return -EINVAL;
         }
xen/arch/x86/domain.c +0 -2
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config-
Quoted 1 line

emulation_flags

!= XEN_X86_EMU_ALL)

)

Quoted 14 lines
Quoted 7 lines

+ if ( is_hvm_domain(d) ? (config->emulation_flags
!=
XEN_X86_EMU_ALL &&

xen/arch/x86/domain.c +2 -0
+             config->emulation_flags != 0) :
+             (config->emulation_flags !=

XEN_X86_EMU_PIT) )

         {

For one I think it would be a good idea to allow zero for PV
domains,
and perhaps even default new DomU-s to have the PIT flag clear.
(Also - indentation.)

Quoted 10 lines

Which gets us to the second, broader issue: These flags shouldn't
be forced to a particular value during migration, but instead
they
should be part of the state getting migrated. Incoming domains
then would - if the field is missing due to coming from an older
hypervisor - have the flag default to 1.

Quoted 1 line

There is sadly another ratsnest here.

I've been afraid of that.

Quoted 6 lines

These values are needed for domain creation, which means that putting
them anywhere in the migration stream is already too late, as the
domain
has been created before the stream header is read.

Quoted 3 lines

Is that an inherent requirement, or just a result of current code
structure?

Depends. As far as libxc/libxl migration levels go, current code structure.

Whatever (eventually) gets used to set these values will however be
present in the xl configuration, which is at the very start of the
stream, and is what is used to create the new domain.

We really don't want the libxc migrate code to be making the DOMCTL_createdomain hypercall itself; it opens up a whole new attack
surface via cunningly-crafted save image. The best we can do is have
a
sanity check later on.

Quoted 11 lines

I ask because migrating the emulation flags is going to
be a requirement for relaxing the current (almost) all-or- nothing
policy on those flags.

Quoted 6 lines

In principle, the best which could occur is that a value gets stashed in
the stream and used as a sanity check. That will at least catch
the
case when they are different.

Quoted 6 lines
Quoted 1 line

That'd be a minimal first step.

This is a substantial quantity of work to do properly. As the emulation
flags are just one in a very long list of fields handed like this, I
don't think this issue should block the series.

Quoted 7 lines

You certainly are more familiar with the migration code than me, but
wouldn't it be enough to add a new field to libxl_domain_build_info (uint32_t emulation_flags), and teach libxl_domain_build_info_gen_json/libxl__domain_build_info_parse_jso n
how to properly parse it?

That would let it be configured from an xl.cfg file, and would normally
be moved in the migration stream. However, there is a specific option
in xl to restore but using a brand new configuration file.

What it doesn't do it check that the settings for the domain in the stream match the settings of the domid being restored into.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

That would be the responsibility of the user who has chosen to override the
configuration in this way.

It is the responsibility of Xen to ensure there are no exploitable holes due to partial or misconfiguration.

Indeed, but it only needs to check things and fail, not work in the face of a bogus save file + cfg file configuration. Perhaps I misunderstood what was being contended here.

It would appear that the choices are:

1) Rearchitect all domain building/restore from scratch
2) Implement a check & fail properly (Still a large quantity of work, but less than 1)
3) Hack up a check & fail quickly

There are a very large number of areas which should be checked on migrate which currently are not. I already have plans to address 2) for the cpuid work.

~Andrew

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

#23 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

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

You certainly are more familiar with the migration code than me, but wouldn't it be enough to add a new field to libxl_domain_build_info (uint32_t emulation_flags), and teach libxl_domain_build_info_gen_json/libxl__domain_build_info_parse_json how to properly parse it?

Is libxl not already aware whether a domain is to be dmlite vs pv or hvm based on the domain config?

As such can't it figure out the hardcoded set to use already without actually needing to expose this in libxl API (until we actually have a desire to expose such nobs to users)? Can't this work on resume just like it does on create?

Quoted 2 lines

This however raises the question about how to signal that the field is not initialised, because 0 is a valid value (maybe ~0)?

In libxl's API we tend to try and avoid opaque hex numbers, so the natural result would be a struct full of libxl_defbool options, which IIRC already get properly propagated and have handling for defaulting already in place.

Ian.

Quoted 1 line

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

#24 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

In reply to Jan Beulich

El 18/01/16 a les 8.43, Jan Beulich ha escrit:

Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
- Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c )'.

Thanks, but after some more thinking about it I'm afraid there are a few more aspects to consider here:

Quoted 16 lines

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

Quoted 12 lines
xen/arch/x86/domain.c +3 -2
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) )
+        if ( is_hvm_domain(d) ? (config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) )
         {

For one I think it would be a good idea to allow zero for PV domains, and perhaps even default new DomU-s to have the PIT flag clear. (Also - indentation.)

This sounds fine to me, but IMHO, it should be done in a separate patch. This patch just restores previous behaviour for PV guests, then we can move on from there.

Quoted 2 lines

And then - is all this working as intended for the hwdom != Dom0 case?

I have to admit I have not tried it, but AFAICT in the hwdom != Dom0 case the set of enabled emulated devices should be the same as a normal guest, the hardware domain doesn't get any more or less emulated devices than any other guest ATM.

Roger.

#25 lore raw

Re: [PATCH v3 4/4] x86/PV: enable the emulated PIT

Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 18.01.16 at 10:50, <[email protected]> wrote:

El 18/01/16 a les 8.43, Jan Beulich ha escrit:

Quoted 10 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 15.01.16 at 18:45, <[email protected]> wrote:

Changes since v2:
- Change 'if ( (a && b) || (!a && c) )' into 'if ( a ? b : c )'.

Thanks, but after some more thinking about it I'm afraid there are a few more aspects to consider here:

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

Quoted 3 lines
xen/arch/x86/domain.c +0 -0
@@ -542,8 +542,9 @@ int arch_domain_create(struct domain *d, unsigned int 

domcr_flags,

Quoted 5 lines

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

Quoted 5 lines
xen/arch/x86/domain.c +0 -2
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( config->emulation_flags != 0 &&
-             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) 

)

Quoted 5 lines
Quoted 4 lines
xen/arch/x86/domain.c +3 -0
+        if ( is_hvm_domain(d) ? (config->emulation_flags != XEN_X86_EMU_ALL &&
+             config->emulation_flags != 0) :
+             (config->emulation_flags != XEN_X86_EMU_PIT) )
         {
Quoted 7 lines
Quoted 3 lines

For one I think it would be a good idea to allow zero for PV domains, and perhaps even default new DomU-s to have the PIT flag clear. (Also - indentation.)

This sounds fine to me, but IMHO, it should be done in a separate patch. This patch just restores previous behaviour for PV guests, then we can move on from there.

Well, maybe. To me it would seem cleaner if both options got permitted by the code right away.

Quoted 7 lines
Quoted 2 lines

And then - is all this working as intended for the hwdom != Dom0 case?

I have to admit I have not tried it, but AFAICT in the hwdom != Dom0 case the set of enabled emulated devices should be the same as a normal guest, the hardware domain doesn't get any more or less emulated devices than any other guest ATM.

No - see the use of is_hardware_domain() in pv_pit_handler(). IMO the flag should be forced on by the hypervisor for the hardware domain, i.e. things be made independent of whatever tooling gets used to create that domain.

Jan