Skip to contentSkip to conversation

Introduce HVM without dm and new boot ABI

PATCH Superseded Roger Pau Monne 6 participants 20 messages Nov 27, 2015 – Dec 3, 2015

v9 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v9 cover Introduce HVM without dm and new boot ABI

This are the remaining patches of the HVMlite series. They have been successfully tested on the following hardware:

- Intel Core i3-5010U.
- 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. Migration/save/restore has also been tested with a SMP guest using the FreeBSD kernel provided below.

The series has been compile tested on arm32.

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

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

And for the FreeBSD part:

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

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

As usual, each patch has it's own changelog.

JM xen/x86: set the vPMU interface based on the presence
M xen/x86: make sure the HVM callback vector is
A xen/x86: allow disabling all emulated devices inside
AW libxc: allow creating domains without emulated
M xen/x86: allow HVM guests to use hypercalls to bring
AW M libxc/xen: introduce a start info structure for
AW libxc: switch xc_dom_elfloader to be used with HVMlite
W libxl: allow the creation of HVM domains without a
M libxl: add support for migrating HVM guests without a

A = Acked/Reviewed by Andrew Cooper.
W = Acked/Reviewed by Wei Liu.
J = Acked/Reviewed by Jan Beulich.
M = Modified in this version.

Thanks, Roger.

#1 lore raw

PATCH v9 1/9 xen/x86: set the vPMU interface based on the presence of a lapic

Instead of choosing the interface to expose to guests based on the guest type, do it based on whether the guest has an emulated local apic or not.

---
Changes since v8:
- Don't add the xenpmu hypercalls to the HVM hypercall table (yet).
- Add Jan Beulich Acked-by.

Changes since v7:
- Merge vpmu work from Boris.

Changes since v6:
- Major rework of the approach.
- Drop Andrew Cooper Acked-by.

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

---
 xen/arch/x86/cpu/vpmu.c       | 11 ++++++-----
 xen/arch/x86/cpu/vpmu_amd.c   |  6 +++---
 xen/arch/x86/cpu/vpmu_intel.c |  6 +++---
 xen/arch/x86/hvm/svm/svm.c    |  2 +-
 xen/arch/x86/hvm/vmx/vmx.c    |  2 +-
 5 files changed, 14 insertions(+), 13 deletions(-)
xen/arch/x86/cpu/vpmu.c +6 -5
index d870dcc..4856e98 100644
@@ -94,7 +94,7 @@ void vpmu_lvtpc_update(uint32_t val)
     vpmu->hw_lapic_lvtpc = PMU_APIC_VECTOR | (val & APIC_LVT_MASKED);
 
     /* Postpone APIC updates for PV(H) guests if PMU interrupt is pending */
-    if ( is_hvm_vcpu(curr) || !vpmu->xenpmu_data ||
+    if ( has_vlapic(curr->domain) || !vpmu->xenpmu_data ||
          !vpmu_is_set(vpmu, VPMU_CACHED) )
         apic_write(APIC_LVTPC, vpmu->hw_lapic_lvtpc);
 }
@@ -129,7 +129,7 @@ int vpmu_do_msr(unsigned int msr, uint64_t *msr_content,
      * and since do_wr/rdmsr may load VPMU context we should save
      * (and unload) it again.
      */
-    if ( !is_hvm_vcpu(curr) && vpmu->xenpmu_data &&
+    if ( !has_vlapic(curr->domain) && vpmu->xenpmu_data &&
         vpmu_is_set(vpmu, VPMU_CACHED) )
     {
         vpmu_set(vpmu, VPMU_CONTEXT_SAVE);
@@ -184,7 +184,7 @@ void vpmu_do_interrupt(struct cpu_user_regs *regs)
         return;
 
     /* PV(H) guest */
-    if ( !is_hvm_vcpu(sampling) || (vpmu_mode & XENPMU_MODE_ALL) )
+    if ( !has_vlapic(sampling->domain) || (vpmu_mode & XENPMU_MODE_ALL) )
     {
         const struct cpu_user_regs *cur_regs;
         uint64_t *flags = &vpmu->xenpmu_data->pmu.pmu_flags;
@@ -411,7 +411,8 @@ int vpmu_load(struct vcpu *v, bool_t from_guest)
 
     /* Only when PMU is counting, we load PMU context immediately. */
     if ( !vpmu_is_set(vpmu, VPMU_RUNNING) ||
-         (!is_hvm_vcpu(vpmu_vcpu(vpmu)) && vpmu_is_set(vpmu, VPMU_CACHED)) )
+         (!has_vlapic(vpmu_vcpu(vpmu)->domain) &&
+         vpmu_is_set(vpmu, VPMU_CACHED)) )
         return 0;
 
     if ( vpmu->arch_vpmu_ops && vpmu->arch_vpmu_ops->arch_vpmu_load )
@@ -637,7 +638,7 @@ long do_xenpmu_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg)
     struct xen_pmu_data *xenpmu_data;
     struct vpmu_struct *vpmu;
 
-    if ( !opt_vpmu_enabled )
+    if ( !opt_vpmu_enabled || has_vlapic(current->domain) )
         return -EOPNOTSUPP;
 
     ret = xsm_pmu_op(XSM_OTHER, current->domain, op);
xen/arch/x86/cpu/vpmu_amd.c +3 -3
index 04da81a..990e6f3 100644
@@ -238,7 +238,7 @@ static int amd_vpmu_load(struct vcpu *v, bool_t from_guest)
         bool_t is_running = 0;
         struct xen_pmu_amd_ctxt *guest_ctxt = &vpmu->xenpmu_data->pmu.c.amd;
 
-        ASSERT(!is_hvm_vcpu(v));
+        ASSERT(!has_vlapic(v->domain));
 
         ctxt = vpmu->context;
         ctrl_regs = vpmu_reg_pointer(ctxt, ctrls);
@@ -314,7 +314,7 @@ static int amd_vpmu_save(struct vcpu *v,  bool_t to_guest)
     {
         struct xen_pmu_amd_ctxt *guest_ctxt, *ctxt;
 
-        ASSERT(!is_hvm_vcpu(v));
+        ASSERT(!has_vlapic(v->domain));
         ctxt = vpmu->context;
         guest_ctxt = &vpmu->xenpmu_data->pmu.c.amd;
         memcpy(&guest_ctxt->regs[0], &ctxt->regs[0], regs_sz);
@@ -525,7 +525,7 @@ int svm_vpmu_initialise(struct vcpu *v)
     vpmu->context = ctxt;
     vpmu->priv_context = NULL;
 
-    if ( !is_hvm_vcpu(v) )
+    if ( !has_vlapic(v->domain) )
     {
         /* Copy register offsets to shared area */
         ASSERT(vpmu->xenpmu_data);
xen/arch/x86/cpu/vpmu_intel.c +3 -3
index d5ea7fe..d5fde80 100644
@@ -336,7 +336,7 @@ static int core2_vpmu_save(struct vcpu *v, bool_t to_guest)
 
     if ( to_guest )
     {
-        ASSERT(!is_hvm_vcpu(v));
+        ASSERT(!has_vlapic(v->domain));
         memcpy((void *)(&vpmu->xenpmu_data->pmu.c.intel) + regs_off,
                vpmu->context + regs_off, regs_sz);
     }
@@ -441,7 +441,7 @@ static int core2_vpmu_load(struct vcpu *v, bool_t from_guest)
     {
         int ret;
 
-        ASSERT(!is_hvm_vcpu(v));
+        ASSERT(!has_vlapic(v->domain));
 
         memcpy(vpmu->context + regs_off,
                (void *)&v->arch.vpmu.xenpmu_data->pmu.c.intel + regs_off,
@@ -501,7 +501,7 @@ static int core2_vpmu_alloc_resource(struct vcpu *v)
     vpmu->context = core2_vpmu_cxt;
     vpmu->priv_context = p;
 
-    if ( !is_hvm_vcpu(v) )
+    if ( !has_vlapic(v->domain) )
     {
         /* Copy fixed/arch register offsets to shared area */
         ASSERT(vpmu->xenpmu_data);
xen/arch/x86/hvm/svm/svm.c +1 -1
index 200a5df..eff16bf 100644
@@ -1167,7 +1167,7 @@ static int svm_vcpu_initialise(struct vcpu *v)
     }
 
     /* PVH's VPMU is initialized via hypercall */
-    if ( is_hvm_vcpu(v) )
+    if ( is_hvm_vcpu(v) && has_vlapic(v->domain) )
         vpmu_initialise(v);
 
     svm_guest_osvw_init(v);
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index 2581e97..06c12e1 100644
@@ -148,7 +148,7 @@ static int vmx_vcpu_initialise(struct vcpu *v)
     }
 
     /* PVH's VPMU is initialized via hypercall */
-    if ( is_hvm_vcpu(v) )
+    if ( is_hvm_vcpu(v) && has_vlapic(v->domain) )
         vpmu_initialise(v);
 
     vmx_install_vlapic_mapping(v);
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

Re: [PATCH v9 1/9] xen/x86: set the vPMU interface based on the presence of a lapic

Quoted 11 lines · Roger Pau Monne

Instead of choosing the interface to expose to guests based on the guest type, do it based on whether the guest has an emulated local apic or not.

---
Changes since v8:
- Don't add the xenpmu hypercalls to the HVM hypercall table (yet).

Without having the hypercalls available to HVMlite (?) guests these changes, except possibly those in vmx.c/svm.c, are somewhat pointless since we never reach patched code.

I understand desire not to increase size of hypercall tables which we want to eventually get rid of but is it really worth doing (or rather not doing) at the cost of not including useful functionality?

-boris

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

#3 lore raw

Re: [PATCH v9 1/9] xen/x86: set the vPMU interface based on the presence of a lapic

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 30.11.15 at 21:28, <[email protected]> wrote:
Quoted 11 lines · Roger Pau Monne

Instead of choosing the interface to expose to guests based on the guest type, do it based on whether the guest has an emulated local apic or not.

---
Changes since v8:
- Don't add the xenpmu hypercalls to the HVM hypercall table (yet).

Quoted 7 lines

Without having the hypercalls available to HVMlite (?) guests these changes, except possibly those in vmx.c/svm.c, are somewhat pointless since we never reach patched code.

I understand desire not to increase size of hypercall tables which we want to eventually get rid of but is it really worth doing (or rather not doing) at the cost of not including useful functionality?

Considering that Konrad had designated you as (kind of informal) PVH maintainer, perhaps this is a good reason for you to actually do the folding now (and maybe we should record maintainership in ./MAINTAINERS even if there are no specific files to be listed)? In any event, my ack was made dependent on the HVM hypercall tables being left alone until folded, and I don't think I want to give up on that.

Jan

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

#4 lore raw

PATCH v9 2/9 xen/x86: make sure the HVM callback vector is correctly set

In reply to Roger Pau Monne

If certain devices (like the local or the io apic) are disabled some modes of operation of the HVM event channel callback cannot be used. Make sure Xen doesn't try to setup them.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>

---
Changes since v8:
- Callback injection methods different than HVMIRQ_callback_vector need an emulated PIC.

---
 xen/arch/x86/hvm/irq.c | 4 ++++
 1 file changed, 4 insertions(+)
xen/arch/x86/hvm/irq.c +4 -0
index 990a2ca..0f3ab6c 100644
@@ -330,6 +330,10 @@ void hvm_set_callback_via(struct domain *d, uint64_t via)
          (via_type > HVMIRQ_callback_vector) )
         via_type = HVMIRQ_callback_none;
 
+    if ( via_type != HVMIRQ_callback_vector &&
+         (!has_vlapic(d) || !has_vioapic(d) || !has_vpic(d)) )
+        return;
+
     spin_lock(&d->arch.hvm_domain.irq_lock);
 
     /* Tear down old callback via. */
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 v9 2/9
#5 lore raw

Re: [PATCH v9 2/9] xen/x86: make sure the HVM callback vector is correctly set

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 27.11.15 at 14:42, <[email protected]> wrote:

If certain devices (like the local or the io apic) are disabled some modes of operation of the HVM event channel callback cannot be used. Make sure Xen doesn't try to setup them.

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

#6 lore raw

PATCH v9 3/9 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 v7:
- Rework if condition.

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

---
 xen/arch/x86/domain.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/domain.c +2 -2
index 2a8d5c1..df40dc6 100644
@@ -532,8 +532,8 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                    d->domain_id, config->emulation_flags);
             return -EINVAL;
         }
-        if ( is_hvm_domain(d) ? (config->emulation_flags != XEN_X86_EMU_ALL)
-                              : (config->emulation_flags != 0) )
+        if ( config->emulation_flags != 0 &&
+             (!is_hvm_domain(d) || config->emulation_flags != XEN_X86_EMU_ALL) )
         {
             printk(XENLOG_G_ERR "d%d: Xen does not allow %s domain creation "
                    "with the current selection of emulators: %#x\n",
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 v9 4/9 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 2176216..41e4701 100644
@@ -195,6 +195,10 @@ struct xc_dom_image {
     xen_paddr_t mmio_size;
     xen_paddr_t lowmem_end;
     xen_paddr_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 009ca9c..49d7b90 100644
@@ -997,6 +997,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 58d07cd..2bbd702 100644
@@ -102,6 +102,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
#8 lore raw

PATCH v9 5/9 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 v8:
- Create a generic default_initalize_vcpu function that can be shared with x86 PV guests and ARM guests.
- Pass check_segment register by reference.
- Check that code/data segments always have the 'S' attribute bit set.
- Fix some of the checks done in check_segment.
- Fix indentation of gprintk calls.
- Remove failure messages in case the padding fields are not zero.
- Make hvm_efer_valid and hvm_cr4_guest_reserved_bits global and use them to check the input values provided by the user.
- Only check the attribute field in order to figure out if a segment is null.
- Make sure the TR segment is a system segment.

Changes since v7:
- Improved error messages.
- Set EFER.LMA if EFER.LME is set by the user.
- Fix calculation of CS limit.
- Add more checks to segment registers.
- Add checks to make sure padding fields are 0.
- Remove ugly arch ifdefs from common domain.c.
- Add the implicit padding of vcpu_hvm_x86_32 explicitly in the structure.
- Simplify the compat vcpu code since it's only used on x86.

Changes since v6:
- Add comments to clarify some initializations.
- Introduce a generic default_initialize_vcpu that's used to initialize a ARM vCPU or a x86 PV vCPU.
- Move the undef of the SEG macro.
- Fix the size of the eflags register, it should be 32bits.
- Add a comment regarding the value of the 12-15 bits of the _ar fields.
- Remove the 16bit strucutre, the 32bit one can be used to start the cpu in real mode.
- Add some sanity checks to the values passed in.
- Add paddings to vcpu_hvm_context so the layout on 32/64bits is the same.
- Add support for the compat version of VCPUOP_initialise.

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             |   5 +
 xen/arch/x86/domain.c             | 314 ++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/hvm/hvm.c            |  15 +-
 xen/common/compat/domain.c        |  50 ++++--
 xen/common/domain.c               |  41 +++--
 xen/include/Makefile              |   1 +
 xen/include/asm-x86/domain.h      |   3 +
 xen/include/asm-x86/hvm/hvm.h     |   5 +
 xen/include/public/hvm/hvm_vcpu.h | 144 +++++++++++++++++
 xen/include/public/vcpu.h         |   6 +-
 xen/include/xen/domain.h          |   4 +
 xen/include/xlat.lst              |   3 +
 12 files changed, 554 insertions(+), 37 deletions(-)
 create mode 100644 xen/include/public/hvm/hvm_vcpu.h
xen/arch/arm/domain.c +5 -0
index 860ac7d..423eeaf 100644
@@ -756,6 +756,11 @@ int arch_set_info_guest(
     return 0;
 }
 
+int arch_initialize_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
+{
+    return default_initalize_vcpu(v, arg);
+}
+
 int arch_vcpu_reset(struct vcpu *v)
 {
     vcpu_end_shutdown_deferral(v);
xen/arch/x86/domain.c +314 -0

326 lines not on this page · raw message

xen/arch/x86/hvm/hvm.c +11 -4
index db0aeba..c569f29 100644
@@ -1833,8 +1833,8 @@ static int hvm_save_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
 }
 
 /* Return a string indicating the error, or NULL for valid. */
-static const char * hvm_efer_valid(const struct vcpu *v, uint64_t value,
-                                   signed int cr0_pg)
+const char *hvm_efer_valid(const struct vcpu *v, uint64_t value,
+                           signed int cr0_pg)
 {
     unsigned int ext1_ecx = 0, ext1_edx = 0;
 
@@ -1902,8 +1902,7 @@ static const char * hvm_efer_valid(const struct vcpu *v, uint64_t value,
         X86_CR0_CD | X86_CR0_PG)))
 
 /* These bits in CR4 cannot be set by the guest. */
-static unsigned long hvm_cr4_guest_reserved_bits(const struct vcpu *v,
-                                                 bool_t restore)
+unsigned long hvm_cr4_guest_reserved_bits(const struct vcpu *v,bool_t restore)
 {
     unsigned int leaf1_ecx = 0, leaf1_edx = 0;
     unsigned int leaf7_0_ebx = 0, leaf7_0_ecx = 0;
@@ -5130,6 +5129,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:
@@ -5188,6 +5191,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/compat/domain.c +35 -15

80 lines not on this page · raw message

xen/common/domain.c +25 -16

57 lines not on this page · raw message

xen/include/Makefile +1 -0
index c674f7f..94ba3d8 100644
@@ -26,6 +26,7 @@ headers-$(CONFIG_X86)     += compat/arch-x86/pmu.h
 headers-$(CONFIG_X86)     += compat/arch-x86/xen-mca.h
 headers-$(CONFIG_X86)     += compat/arch-x86/xen.h
 headers-$(CONFIG_X86)     += compat/arch-x86/xen-$(compat-arch-y).h
+headers-$(CONFIG_X86)     += compat/hvm/hvm_vcpu.h
 headers-y                 += compat/arch-$(compat-arch-y).h compat/pmu.h compat/xlat.h
 headers-$(FLASK_ENABLE)   += compat/xsm/flask_op.h
 
xen/include/asm-x86/domain.h +3 -0
index c825975..e8f7037 100644
@@ -600,6 +600,9 @@ static inline void free_vcpu_guest_context(struct vcpu_guest_context *vgc)
     vfree(vgc);
 }
 
+struct vcpu_hvm_context;
+int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx);
+
 #endif /* __ASM_DOMAIN_H__ */
 
 /*
xen/include/asm-x86/hvm/hvm.h +5 -0
index f80e143..b9d893d 100644
@@ -560,6 +560,11 @@ void altp2m_vcpu_update_vmfunc_ve(struct vcpu *v);
 /* emulates #VE */
 bool_t altp2m_vcpu_emulate_ve(struct vcpu *v);
 
+/* Check CR4/EFER values */
+const char *hvm_efer_valid(const struct vcpu *v, uint64_t value,
+                           signed int cr0_pg);
+unsigned long hvm_cr4_guest_reserved_bits(const struct vcpu *v, bool_t restore);
+
 #endif /* __ASM_X86_HVM_HVM_H__ */
 
 /*
xen/include/public/hvm/hvm_vcpu.h new file +144 -0

144 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 +4 -0
index 3dca3f6..269bbe7 100644
@@ -64,6 +64,8 @@ int arch_domain_soft_reset(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);
@@ -103,4 +105,6 @@ struct vnuma_info {
 
 void vnuma_destroy(struct vnuma_info *vnuma);
 
+int default_initalize_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg);
+
 #endif /* __XEN_DOMAIN_H__ */
xen/include/xlat.lst +3 -0
index 3795059..fda1137 100644
@@ -56,6 +56,9 @@
 ?       grant_entry_header              grant_table.h
 ?	grant_entry_v2			grant_table.h
 ?	gnttab_swap_grant_ref		grant_table.h
+?	vcpu_hvm_context		hvm/hvm_vcpu.h
+?	vcpu_hvm_x86_32			hvm/hvm_vcpu.h
+?	vcpu_hvm_x86_64			hvm/hvm_vcpu.h
 ?	kexec_exec			kexec.h
 !	kexec_image			kexec.h
 !	kexec_range			kexec.h
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 v9 5/9] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

Hi Roger,

xen/common/domain.c void unmap_vcpu_info(struct vcpu *v) · line 1211

Quoted 9 lines · Roger Pau Monne
xen/common/domain.c +1 -0
index f56b7ff..3690eec 100644
@@ -1208,11 +1208,34 @@ void unmap_vcpu_info(struct vcpu *v)
     put_page_and_type(mfn_to_page(mfn));
 }
 
+int default_initalize_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)

For here and everywhere this function is called:

s/initalize/initialize/

Regards,

Signature · 1 line
Julien Grall
#10 lore raw

Re: [PATCH v9 5/9] xen/x86: allow HVM guests to use hypercalls to bring up vCPUs

In reply to Roger Pau Monne
Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 27.11.15 at 14:43, <[email protected]> wrote:
xen/arch/x86/domain.c +33 -0
+int arch_set_info_hvm_guest(struct vcpu *v, const vcpu_hvm_context_t *ctx)
+{
+    struct cpu_user_regs *uregs = &v->arch.user_regs;
+    struct segment_register cs, ds, ss, es, tr;
+    const char *errstr;
+    int rc;
+
+    if ( ctx->pad != 0 )
+        return -EINVAL;
+
+    switch ( ctx->mode )
+    {
+    default:
+        return -EINVAL;
+
+    case VCPU_HVM_MODE_32B:
+    {
+        const struct vcpu_hvm_x86_32 *regs = &ctx->cpu_regs.x86_32;
+        uint32_t limit;
+
+        if ( ctx->cpu_regs.x86_32.pad1 != 0 ||
+             ctx->cpu_regs.x86_32.pad2[0] != 0 ||
+             ctx->cpu_regs.x86_32.pad2[1] != 0 ||
+             ctx->cpu_regs.x86_32.pad2[2] != 0 )
+            return -EINVAL;
+
+#define SEG(s, r)                                                       \
+    (struct segment_register){ .sel = 0, .base = (r)->s ## _base,       \
+            .limit = (r)->s ## _limit, .attr.bytes = (r)->s ## _ar }
+        cs = SEG(cs, regs);
+        ds = SEG(ds, regs);
+        ss = SEG(ss, regs);
+        es = SEG(es, regs);

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

Quoted 10 lines
xen/arch/x86/domain.c +10 -0
+        tr = SEG(tr, regs);
+#undef SEG
+
+        rc = check_segment(&cs, x86_seg_cs);
+        rc |= check_segment(&ds, x86_seg_ds);
+        rc |= check_segment(&ss, x86_seg_ss);
+        rc |= check_segment(&es, x86_seg_es);
+        rc |= check_segment(&tr, x86_seg_tr);
+        if ( rc != 0 )
+            return rc;

This could be further simplified: The check_segment() invocation could move into the macro, together with the assignments above. And the .sel initializer is pointless. The former I'd leave to you, but I'd like to see pointless things dropped to help readability.

Quoted 46 lines
xen/arch/x86/domain.c +46 -0
+    case VCPU_HVM_MODE_64B:
+    {
+        const struct vcpu_hvm_x86_64 *regs = &ctx->cpu_regs.x86_64;
+
+        /* Basic sanity checks. */
+        if ( !is_canonical_address(regs->rip) )
+        {
+            gprintk(XENLOG_ERR, "RIP contains a non-canonical address (%#lx)\n",
+                    regs->rip);
+            return -EINVAL;
+        }
+
+        if ( !(regs->cr0 & X86_CR0_PG) )
+        {
+            gprintk(XENLOG_ERR, "CR0 doesn't have paging enabled (%#016lx)\n",
+                    regs->cr0);
+            return -EINVAL;
+        }
+
+        if ( !(regs->cr4 & X86_CR4_PAE) )
+        {
+            gprintk(XENLOG_ERR, "CR4 doesn't have PAE enabled (%#016lx)\n",
+                    regs->cr4);
+            return -EINVAL;
+        }
+
+        if ( !(regs->efer & EFER_LME) )
+        {
+            gprintk(XENLOG_ERR, "EFER doesn't have LME enabled (%#016lx)\n",
+                    regs->efer);
+            return -EINVAL;
+        }
+
+        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;
+
+        v->arch.hvm_vcpu.guest_cr[0] = regs->cr0;
+        v->arch.hvm_vcpu.guest_cr[3] = regs->cr3;

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

Quoted 10 lines
xen/arch/x86/domain.c +10 -0
+        v->arch.hvm_vcpu.guest_cr[4] = regs->cr4;
+        v->arch.hvm_vcpu.guest_efer  = regs->efer;
+
+#define SEG(b, l, a)                                                    \
+    (struct segment_register){ .sel = 0, .base = (b), .limit = (l),     \
+                               .attr.bytes = (a) }
+        cs = SEG(0, ~0u, 0xa9b); /* 64bit code segment. */
+        ds = ss = es = SEG(0, ~0u, 0xc93);
+        tr = SEG(0, 0x67, 0x8b); /* 64bit TSS (busy). */
+#undef SEG

Similarly here: .sel and .base initializers are pointless.

Quoted 8 lines
xen/arch/x86/domain.c +8 -0
+    }
+    break;
+
+    }
+
+    if ( v->arch.hvm_vcpu.guest_efer & EFER_LME )
+        v->arch.hvm_vcpu.guest_efer |= EFER_LMA;
+

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

Quoted 10 lines
xen/arch/x86/domain.c +10 -0
+    if ( v->arch.hvm_vcpu.guest_cr[4] & hvm_cr4_guest_reserved_bits(v, 1) )
+    {
+        gprintk(XENLOG_ERR, "Bad CR4 value: %#016lx\n",
+                v->arch.hvm_vcpu.guest_cr[4]);
+        return -EINVAL;
+    }
+
+    errstr = hvm_efer_valid(v, v->arch.hvm_vcpu.guest_efer,
+                            MASK_EXTR(v->arch.hvm_vcpu.guest_cr[0],
+                                      X86_CR0_PG));

Passing a non-negative value as the third argument here means "use host CPUID", which I don't think is what we want here (and the SCE check would be broken that way too).

Quoted 12 lines
xen/arch/x86/hvm/hvm.c +4 -0
@@ -5130,6 +5129,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:

xen/arch/x86/hvm/hvm.c static long hvm_vcpu_op_compat32( · line 5197

Quoted 7 lines
xen/arch/x86/hvm/hvm.c +4 -0
@@ -5188,6 +5191,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:

I vaguely recall possibly having commented on this before: This leaves just VCPUOP_send_nmi and VCPUOP_get_physid not allowed through, neither of which ought to be a problem to allow. Therefore I'd rather see the wrappers go away than the switch()es to get extended.

Quoted 12 lines
xen/include/xen/domain.h +2 -0
@@ -64,6 +64,8 @@ int arch_domain_soft_reset(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);

xen/include/xen/domain.h struct vnuma_info { · line 108

Quoted 4 lines
xen/include/xen/domain.h +1 -0
@@ -103,4 +105,6 @@ struct vnuma_info {
 
 void vnuma_destroy(struct vnuma_info *vnuma);
 
+int default_initalize_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg);

Any reason the two can't sit next to each other?

Jan

#11 lore raw

PATCH v9 6/9 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 v8:
- Slightly reword comment.

Changes since v7:
- Add a comment to clarify that nothing will be loaded at physical address 0.
- Add Andrew Cooper Reviewed-by.
- Add Wei Liu Ack.

Changes since v6:
- Add a check to make sure the start info data is placed below 4GB.
- Make sure byte addresses are treated as uintptr_t.
- Fix single-line comment.

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 | 23 ++++++++++++++++
 2 files changed, 90 insertions(+), 1 deletion(-)
tools/libxc/xc_dom_x86.c +67 -1
index 341cf6e..dae75a5 100644
@@ -623,7 +623,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) +
+                                ((uintptr_t)cmdline - (uintptr_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) +
+                                ((uintptr_t)modlist - (uintptr_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
@@ -1022,6 +1085,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 +23 -0
index ff5547e..7b629b1 100644
@@ -784,6 +784,29 @@ struct start_info {
 };
 typedef struct start_info start_info_t;
 
+/*
+ * Start of day structure passed to PVH guests in %ebx.
+ *
+ * NOTE: nothing will be loaded at physical address 0, so
+ * a 0 value in any of the address fields should be treated
+ * as not present.
+ */
+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
Acked-by on v9 6/9
#12 lore raw

Re: [PATCH v9 6/9] libxc/xen: introduce a start info structure for HVMlite guests

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

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.

Public interface part

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

#13 lore raw

PATCH v9 7/9 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 36a115e..2ae575e 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
#14 lore raw

PATCH v9 8/9 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 v7:
- Add LIBXL_HAVE_DEVICE_MODEL_VERSION_NONE.

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.h          |  8 +++++
 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      | 15 ++++++---
 tools/libxl/xl_cmdimpl.c     |  2 ++
 12 files changed, 144 insertions(+), 50 deletions(-)
docs/man/xl.cfg.pod.5 +5 -0
index 3b695bd..8899f75 100644
@@ -1789,6 +1789,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 41e4701..aabaac8 100644
@@ -20,6 +20,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 dae75a5..5fd40a6 100644
@@ -58,8 +58,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))
@@ -579,7 +579,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;
 
@@ -594,18 +594,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.h +8 -0
index 6b73848..0dc3be3 100644
@@ -859,6 +859,14 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src);
 */
 #define LIBXL_HAVE_GFX_PASSTHRU_KIND
 
+/*
+ * LIBXL_HAVE_DEVICE_MODEL_VERSION_NONE
+ *
+ * In the case that LIBXL_HAVE_DEVICE_MODEL_VERSION_NONE is set libxl
+ * allows the creation of HVM guests without a device model.
+ */
+#define LIBXL_HAVE_DEVICE_MODEL_VERSION_NONE 1
+
 typedef char **libxl_string_list;
 void libxl_string_list_dispose(libxl_string_list *sl);
 int libxl_string_list_length(const libxl_string_list *sl);
tools/libxl/libxl_create.c +15 -1
index 8770486..8e26fef 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) {
@@ -921,7 +928,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;
@@ -1262,6 +1270,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 a4934df..efcc174 100644
@@ -1606,7 +1606,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 2bbd702..7e8054a 100644
@@ -115,6 +115,12 @@
 #define DOMID_XS_PATH "domid"
 #define INVALID_DOMID ~0
 
+/* 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)                                           \
@@ -1187,7 +1193,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 cf3730f..9658356 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 +11 -4
index 183b6c2..46cfafb 100644
@@ -7,10 +7,16 @@ 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) {
+        /* HVM domains with a device model. */
         xc_config->emulation_flags = XEN_X86_EMU_ALL;
-    else
+    } else {
+        /* PV or HVM domains without a device model. */
         xc_config->emulation_flags = 0;
+    }
 
     return 0;
 }
@@ -485,6 +491,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++)
@@ -505,8 +512,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 2b6371d..f9933cb 100644
@@ -2186,6 +2186,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
#15 lore raw

PATCH v9 9/9 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 prevents sending the emulator context if the device model version is set to none.

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

---
Changes since v8:
- Cache device model version inside of the libxl__stream_write_state structure.
- Add a seatbelt by setting the emulator id to UNKNOWN in the HVMlite case. This can be used to assert we don't reach certain paths.
- Remove stray STATE_AO_GC in emulator_xenstore_record_done.

Changes since v7:
- Prevent sending the emulator context and xenstore record in write_emulator_context_record and write_emulator_xenstore_record.
- Error out if an emulator record is received for a no-dm guest.

---
 tools/libxl/libxl_dom.c          |  3 +++
 tools/libxl/libxl_dom_suspend.c  |  2 ++
 tools/libxl/libxl_internal.h     |  3 +++
 tools/libxl/libxl_stream_read.c  | 16 ++++++++++++++++
 tools/libxl/libxl_stream_write.c | 20 +++++++++++++++++++-
 5 files changed, 43 insertions(+), 1 deletion(-)
tools/libxl/libxl_dom.c +3 -0
index 0f166e9..e730912 100644
@@ -1318,6 +1318,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 +2 -0
index 4cc01ad..3313ad1 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;
     }
tools/libxl/libxl_internal.h +3 -0
index 7e8054a..d6cb63d 100644
@@ -3036,6 +3036,9 @@ struct libxl__stream_write_state {
     libxl__datacopier_state dc;
     sws_record_done_cb record_done_callback;
 
+    /* Cache device model version. */
+    int device_model_version;
+
     /* Only used when constructing EMULATOR records. */
     libxl__datacopier_state emu_dc;
     libxl__carefd *emu_carefd;
tools/libxl/libxl_stream_read.c +16 -0
index 4ec29da..258dec4 100644
@@ -539,6 +539,14 @@ static bool process_record(libxl__egc *egc,
         break;
 
     case REC_TYPE_EMULATOR_XENSTORE_DATA:
+        if (dcs->guest_config->b_info.device_model_version ==
+            LIBXL_DEVICE_MODEL_VERSION_NONE) {
+            rc = ERROR_FAIL;
+            LOG(ERROR,
+                "Received a xenstore emulator record when none was expected");
+            goto err;
+        }
+
         if (rec->hdr.length < sizeof(libxl__sr_emulator_hdr)) {
             rc = ERROR_FAIL;
             LOG(ERROR,
@@ -560,6 +568,14 @@ static bool process_record(libxl__egc *egc,
         break;
 
     case REC_TYPE_EMULATOR_CONTEXT:
+        if (dcs->guest_config->b_info.device_model_version ==
+            LIBXL_DEVICE_MODEL_VERSION_NONE) {
+            rc = ERROR_FAIL;
+            LOG(ERROR,
+                "Received an emulator context record when none was expected");
+            goto err;
+        }
+
         write_emulator_blob(egc, stream, rec);
         break;
 
tools/libxl/libxl_stream_write.c +19 -1
index 52a60d7..c9d1cc8 100644
@@ -167,6 +167,8 @@ static void setup_emulator_write(libxl__egc *egc,
                                  void *body,
                                  sws_record_done_cb cb)
 {
+    assert(stream->emu_sub_hdr.id != EMULATOR_UNKNOWN);
+    assert(stream->device_model_version != LIBXL_DEVICE_MODEL_VERSION_NONE);
     setup_generic_write(egc, stream, what, hdr, emu_hdr, body, cb);
 }
 
@@ -223,7 +225,9 @@ void libxl__stream_write_start(libxl__egc *egc,
     stream->running = true;
 
     if (dss->type == LIBXL_DOMAIN_TYPE_HVM) {
-        switch (libxl__device_model_version_running(gc, dss->domid)) {
+        stream->device_model_version =
+            libxl__device_model_version_running(gc, dss->domid);
+        switch (stream->device_model_version) {
         case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
             stream->emu_sub_hdr.id = EMULATOR_QEMU_TRADITIONAL;
             break;
@@ -232,6 +236,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_UNKNOWN;
+            break;
+
         default:
             rc = ERROR_FAIL;
             LOG(ERROR, "Unknown emulator for HVM domain");
@@ -359,6 +367,11 @@ static void write_emulator_xenstore_record(libxl__egc *egc,
     char *buf = NULL;
     uint32_t len = 0;
 
+    if (stream->device_model_version == LIBXL_DEVICE_MODEL_VERSION_NONE) {
+        emulator_xenstore_record_done(egc, stream);
+        return;
+    }
+
     rc = libxl__save_emulator_xenstore_data(dss, &buf, &len);
     if (rc)
         goto err;
@@ -410,6 +423,11 @@ static void write_emulator_context_record(libxl__egc *egc,
 
     assert(dss->type == LIBXL_DOMAIN_TYPE_HVM);
 
+    if (stream->device_model_version == LIBXL_DEVICE_MODEL_VERSION_NONE) {
+        emulator_context_record_done(egc, stream);
+        return;
+    }
+
     /* Convenience aliases */
     const char *const filename = dss->dm_savefile;
 
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 v9 9/9] libxl: add support for migrating HVM guests without a device model

tools/libxl/libxl_internal.h struct libxl__stream_write_state { · line 3041

Quoted 11 lines · Roger Pau Monne
tools/libxl/libxl_internal.h +3 -0
index 7e8054a..d6cb63d 100644
@@ -3036,6 +3036,9 @@ struct libxl__stream_write_state {
     libxl__datacopier_state dc;
     sws_record_done_cb record_done_callback;
 
+    /* Cache device model version. */
+    int device_model_version;
+

Please put an initialiser in libxl__stream_write_init().

With that done, Reviewed-by: Andrew Cooper <[email protected]>

#17 lore raw

Re: [PATCH v9 9/9] libxl: add support for migrating HVM guests without a device model

El 27/11/15 a les 14.55, Andrew Cooper ha escrit:

Quoted 9 lines · Roger Pau Monne
Quoted 8 lines
tools/libxl/libxl_internal.h +0 -0
index 7e8054a..d6cb63d 100644
@@ -3036,6 +3036,9 @@ struct libxl__stream_write_state {
     libxl__datacopier_state dc;
     sws_record_done_cb record_done_callback;
 
Quoted 5 lines

tools/libxl/libxl_internal.h struct libxl__stream_write_state { · line 3041

Quoted 3 lines
tools/libxl/libxl_internal.h +3 -0
+    /* Cache device model version. */
+    int device_model_version;
+

Please put an initialiser in libxl__stream_write_init().

Right, thanks for noticing. I will hold off sending a new version until I get more comments.

Roger.

Acked-by on v9 9/9
#18 lore raw

Re: [PATCH v9 9/9] libxl: add support for migrating HVM guests without a device model

In reply to Roger Pau Monne

On Fri, Nov 27, 2015 at 02:43:05PM +0100, Roger Pau Monne wrote:
[...]

tools/libxl/libxl_internal.h struct libxl__stream_write_state { · line 3041

Quoted 11 lines
tools/libxl/libxl_internal.h +3 -0
index 7e8054a..d6cb63d 100644
@@ -3036,6 +3036,9 @@ struct libxl__stream_write_state {
     libxl__datacopier_state dc;
     sws_record_done_cb record_done_callback;
 
+    /* Cache device model version. */
+    int device_model_version;
+

Minor nit: use libxl_device_model_version please.

And with Andrew's comment addressed:

#19 lore raw
In reply to Roger Pau Monne
Quoted 11 lines · Roger Pau Monne

This are the remaining patches of the HVMlite series. They have been successfully tested on the following hardware:

- Intel Core i3-5010U.
- 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. Migration/save/restore has also been tested with a SMP guest using the FreeBSD kernel provided below.

Quoted 5 lines

The series has been compile tested on arm32.

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

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

FWIW, I tested my 64- and 32-bit HVMlite Linux SMP and found no problems. I only tested on Intel but I've tried an earlier (v7 or v8) version on AMD and it worked as well.

-boris