x86/PVHv2: Add memory map pointer to hvm_start_info struct
v5 cover x86/PVHv2: Add memory map pointer to hvm_start_info struct
Here is the patch series for updating the canonical definition of the hvm_start_info struct corresponding to the discussion happening on the linux-kernel and kvm mailing lists regarding Qemu/KVM use of the PVH entry point:
KVM: x86: Allow Qemu/KVM to use PVH entry point
https://lkml.org/lkml/2018/2/28/1121
Patch 1 contains all the changes to the hvm_start_info struct and patches 2-4 modify Xen to use the new memory map fields of the structure.
Changes since v4:
* Patch 1:
- Addressed a couple of nits in the comments
* Patches 2-4:
- Rebase to upstream
- Simplify interfaces
- Avoid unnecessary dom->e80 allocation
- Fix start_page size calculation (and make it applicable to both HVM and PVH)
Changes since v3:
* Cleaned up hard tabs in start_info.h (patch 1)
* Removed comment about "For PV guests only 0 allowed, for PVH 0 or 1 allowed" from start_info.h (patch 1)
* Make the map available to both HVM and PVH guests (patches 2-4)
* Re-organize libxl changes (patches 2-4)
Changes since v2:
* Better definition of the memory map types including addition of new symbols and tightening up the comments as suggested.
* Added a couple of BUILD_BUG_ON() statements to the c code in patch #4 to document and verify the relationship between these memory types and e820 types.
Changes since v1:
* Made updates to code comments as suggested by Jan and Roger, including better definition of the memory map type field.
* Boris provided additional patches to populate the new fields in the hvm_start_info struct as Jan (and later Roger also) had requested.
Boris Ostrovsky (3):
libxl/x86: Build e820 map earlier for HVM/PVH guests
libxl: Store e820 map in xc_dom_image
libxc: Pass e820 map to HVM/PVH guests via hvm_start_info
Maran Wilson (1):
x86/PVHv2: Add memory map pointer to hvm_start_info struct
tools/libxc/include/xc_dom.h | 7 +++- tools/libxc/xc_dom_x86.c | 29 +++++++++++++ tools/libxl/libxl_arch.h | 10 +---- tools/libxl/libxl_arm.c | 11 +---- tools/libxl/libxl_create.c | 2 +- tools/libxl/libxl_dom.c | 18 ++++---- tools/libxl/libxl_internal.h | 2 +- tools/libxl/libxl_x86.c | 52 ++++++++++++++--------- xen/include/public/arch-x86/hvm/start_info.h | 63 +++++++++++++++++++++++++++- 9 files changed, 143 insertions(+), 51 deletions(-)
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 1/4 x86/PVHv2: Add memory map pointer to hvm_start_info struct
The start info structure that is defined as part of the x86/HVM direct boot ABI and used for starting Xen PVH guests would be more versatile if it also included a way to pass information about the memory map to the guest. This would allow KVM guests to share the same entry point.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: Roger Pau Monné <[email protected]>
--- xen/include/public/arch-x86/hvm/start_info.h | 63 +++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-)
xen/include/public/arch-x86/hvm/start_info.h +62 -1
@@ -33,7 +33,7 @@* | magic | Contains the magic value XEN_HVM_START_MAGIC_VALUE * | | ("xEn3" with the 0x80 bit of the "E" set). * 4 +----------------+ -* | version | Version of this structure. Current version is 0. New +* | version | Version of this structure. Current version is 1. New * | | versions are guaranteed to be backwards-compatible. * 8 +----------------+ * | flags | SIF_xxx flags.
@@ -48,6 +48,15 @@* 32 +----------------+ * | rsdp_paddr | Physical address of the RSDP ACPI data structure. * 40 +----------------+ +* | memmap_paddr | Physical address of the (optional) memory map. Only +* | | present in version 1 and newer of the structure. +* 48 +----------------+ +* | memmap_entries | Number of entries in the memory map table. Zero +* | | if there is no memory map being provided. Only +* | | present in version 1 and newer of the structure. +* 52 +----------------+ +* | reserved | Version 1 and newer only. +* 56 +----------------+ * * The layout of each entry in the module structure is the following: *
@@ -62,14 +71,52 @@* | reserved | * 32 +----------------+ * +* The layout of each entry in the memory map table is as follows: +* +* 0 +----------------+ +* | addr | Base address +* 8 +----------------+ +* | size | Size of mapping in bytes +* 16 +----------------+ +* | type | Type of mapping as defined between the hypervisor +* | | and guest. See XEN_HVM_MEMMAP_TYPE_* values below. +* 20 +----------------| +* | reserved | +* 24 +----------------+ +* * The address and sizes are always a 64bit little endian unsigned integer. * * NB: Xen on x86 will always try to place all the data below the 4GiB * boundary. +* +* Version numbers of the hvm_start_info structure have evolved like this: +* +* Version 0: Initial implementation. +* +* Version 1: Added the memmap_paddr/memmap_entries fields (plus 4 bytes of +* padding) to the end of the hvm_start_info struct. These new +* fields can be used to pass a memory map to the guest. The +* memory map is optional and so guests that understand version 1 +* of the structure must check that memmap_entries is non-zero +* before trying to read the memory map. */ #define XEN_HVM_START_MAGIC_VALUE 0x336ec578/* +* The values used in the type field of the memory map table entries are +* defined below and match the Address Range Types as defined in the "System +* Address Map Interfaces" section of the ACPI Specification. Please refer to +* section 15 in version 6.2 of the ACPI spec: http://uefi.org/specifications +*/ +#define XEN_HVM_MEMMAP_TYPE_RAM 1 +#define XEN_HVM_MEMMAP_TYPE_RESERVED 2 +#define XEN_HVM_MEMMAP_TYPE_ACPI 3 +#define XEN_HVM_MEMMAP_TYPE_NVS 4 +#define XEN_HVM_MEMMAP_TYPE_UNUSABLE 5 +#define XEN_HVM_MEMMAP_TYPE_DISABLED 6 +#define XEN_HVM_MEMMAP_TYPE_PMEM 7 + +/* * C representation of the x86/HVM start info layout. * * The canonical definition of this layout is above, this is just a way to
@@ -86,6 +133,13 @@ struct hvm_start_info {uint64_t cmdline_paddr;/* Physical address of the command line. */ uint64_t rsdp_paddr;/* Physical address of the RSDP ACPI data */ /* structure. */ +/* All following fields only present in version 1 and newer */ +uint64_t memmap_paddr;/* Physical address of an array of */ +/* hvm_memmap_table_entry. */ +uint32_t memmap_entries;/* Number of entries in the memmap table. */ +/* Value will be zero if there is no memory */ +/* map being provided. */ +uint32_t reserved;/* Must be zero. */ };struct hvm_modlist_entry {
@@ -95,4 +149,11 @@ struct hvm_modlist_entry { uint64_t reserved; }; +struct hvm_memmap_table_entry { +uint64_t addr;/* Base address of the memory region */ +uint64_t size;/* Size of the memory region in bytes */ +uint32_t type;/* Mapping type */ +uint32_t reserved;/* Must be zero for Version 1. */ +}; +#endif /* __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__ */
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 2/4 libxl/x86: Build e820 map earlier for HVM/PVH guests
In reply to Maran WilsonFrom: Boris Ostrovsky <[email protected]>
Since hvm_start_info has now been expanded to include memory map (i.e. e820) we need to know size of this map by the time we create dom->start_info_seg in alloc_magic_pages_hvm().
To do so we have to call libxl__arch_domain_construct_memmap() earlier, before xc_dom_build_image(). And since libxl__arch_domain_construct_memmap() is only used by for x86 we can make this call from x86's libxl__arch_domain_finalise_hw_description(), at the same time removing its NOP definition from ARM code and renaming and making it static in libxl_x86.c
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Roger Pau Monné <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: Maran Wilson <[email protected]>
---
Changes in v5:
* Adjusted call interfaces to take into account the fact that libxl_domain_build_info is pointed to from libxl_domain_config.
--- tools/libxl/libxl_arch.h | 10 ++------- tools/libxl/libxl_arm.c | 11 ++-------- tools/libxl/libxl_create.c | 2 +- tools/libxl/libxl_dom.c | 18 +++++++--------- tools/libxl/libxl_internal.h | 2 +- tools/libxl/libxl_x86.c | 49 +++++++++++++++++++++++++++----------------- 6 files changed, 43 insertions(+), 49 deletions(-)
tools/libxl/libxl_arch.h +2 -8
@@ -41,7 +41,8 @@ int libxl__arch_domain_init_hw_description(libxl__gc *gc,/* finalize arch specific hardware description. */ _hidden int libxl__arch_domain_finalise_hw_description(libxl__gc *gc, -libxl_domain_build_info *info, +uint32_t domid, +libxl_domain_config *d_config,struct xc_dom_image *dom);/* perform any pending hardware initialization */
@@ -62,13 +63,6 @@ int libxl__arch_vnuma_build_vmemrange(libxl__gc *gc,_hidden int libxl__arch_domain_map_irq(libxl__gc *gc, uint32_t domid, int irq); -/* arch specific to construct memory mapping function */ -_hidden -int libxl__arch_domain_construct_memmap(libxl__gc *gc, -libxl_domain_config *d_config, -uint32_t domid, -struct xc_dom_image *dom); -_hidden void libxl__arch_domain_build_info_acpi_setdefault(libxl_domain_build_info *b_info);
tools/libxl/libxl_arm.c +2 -9
@@ -1039,7 +1039,8 @@ static void finalise_one_node(libxl__gc *gc, void *fdt, const char *uname, }int libxl__arch_domain_finalise_hw_description (libxl__gc *gc, -libxl_domain_build_info *info, +uint32_t domid, +libxl_domain_config *d_config,struct xc_dom_image *dom) {void *fdt = dom->devicetree_blob;
@@ -1133,14 +1134,6 @@ int libxl__arch_domain_map_irq(libxl__gc *gc, uint32_t domid, int irq)return xc_domain_bind_pt_spi_irq (CTX ->xch, domid, irq, irq); } -int libxl__arch_domain_construct_memmap (libxl__gc *gc, -libxl_domain_config *d_config, -uint32_t domid, -struct xc_dom_image *dom) -{ -return 0 ; -} -void libxl__arch_domain_build_info_acpi_setdefault (libxl_domain_build_info *b_info) {
tools/libxl/libxl_create.c +1 -1
@@ -488,7 +488,7 @@ int libxl__domain_build(libxl__gc *gc,break ;case LIBXL_DOMAIN_TYPE_PV : - ret =libxl__build_pv (gc, domid, info, state); + ret =libxl__build_pv (gc, domid, d_config, state);if (ret) goto out;
tools/libxl/libxl_dom.c +7 -11
@@ -698,9 +698,10 @@ static int set_vnuma_info(libxl__gc *gc, uint32_t domid, }static int libxl__build_dom (libxl__gc *gc,uint32_t domid, -libxl_domain_build_info *info,libxl__domain_build_state *state, +libxl_domain_config *d_config,libxl__domain_build_state *state,struct xc_dom_image *dom) { +libxl_domain_build_info *const info = &d_config->b_info;uint64_t mem_kb;int ret;
@@ -733,7 +734,7 @@ static int libxl__build_dom(libxl__gc *gc, uint32_t domid,LOGE (ERROR ,"xc_dom_boot_mem_init failed" ); goto out; } -if ( (ret =libxl__arch_domain_finalise_hw_description (gc, info, dom)) !=0 ) { +if ( (ret =libxl__arch_domain_finalise_hw_description (gc, domid, d_config, dom)) !=0 ) {LOGE (ERROR ,"libxl__arch_domain_finalise_hw_description failed" ); goto out; }
@@ -759,9 +760,10 @@ out: }int libxl__build_pv (libxl__gc *gc,uint32_t domid, -libxl_domain_build_info *info,libxl__domain_build_state *state) +libxl_domain_config *d_config,libxl__domain_build_state *state) {libxl_ctx *ctx =libxl__gc_owner (gc); +libxl_domain_build_info *const info = &d_config->b_info;struct xc_dom_image *dom;int ret;int flags =0 ;
@@ -847,7 +849,7 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid, dom->vnode_to_pnode[i] = info->vnuma_nodes[i].pnode; } - ret =libxl__build_dom (gc, domid, info, state, dom); + ret =libxl__build_dom (gc, domid, d_config, state, dom);if (ret !=0 ) goto out;
@@ -1293,16 +1295,10 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid, dom->vnode_to_pnode[i] = info->vnuma_nodes[i].pnode; } - rc =libxl__build_dom (gc, domid, info, state, dom); + rc =libxl__build_dom (gc, domid, d_config, state, dom);if (rc !=0 ) goto out; - rc =libxl__arch_domain_construct_memmap (gc, d_config, domid, dom); -if (rc !=0 ) { -LOG (ERROR ,"setting domain memory map failed" ); - goto out; - } - rc = hvm_build_set_params(ctx->xch, domid, info, state->store_port, &state->store_mfn, state->console_port, &state->console_mfn, state->store_domid,
tools/libxl/libxl_internal.h +1 -1
@@ -1159,7 +1159,7 @@ _hidden int libxl__build_post(libxl__gc *gc, uint32_t domid, char **vms_ents, char **local_ents); _hidden int libxl__build_pv(libxl__gc *gc, uint32_t domid, -libxl_domain_build_info *info,libxl__domain_build_state *state); +libxl_domain_config *const d_config,libxl__domain_build_state *state); _hidden int libxl__build_hvm(libxl__gc *gc, uint32_t domid,libxl_domain_config *d_config,libxl__domain_build_state *state);
tools/libxl/libxl_x86.c +30 -19
67 lines not on this page · raw message
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v5 2/4] libxl/x86: Build e820 map earlier for HVM/PVH guests
Quoted 6 lines · Maran Wilson
From: Boris Ostrovsky <[email protected]>
Since
hvm_start_infohas now been expanded to include memory map (i.e. e820) we need to know size of this map by the time we createdom->start_info_seginalloc_magic_pages_hvm().
Quoted 8 lines
To do so we have to call
libxl__arch_domain_construct_memmap()earlier, beforexc_dom_build_image(). And sincelibxl__arch_domain_construct_memmap()is only used by for x86 we can make this call from x86'slibxl__arch_domain_finalise_hw_description(), at the same time removing its NOP definition from ARM code and renaming and making it static inlibxl_x86.cSigned-off-by Boris Ostrovsky <[email protected]>
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 3/4 libxl: Store e820 map in xc_dom_image
In reply to Maran WilsonFrom: Boris Ostrovsky <[email protected]>
We will later copy it to hvm_start_info.
(Also remove stale comment claming that xc_dom_image.start_info_seg is only used for HVMlite guests)
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Roger Pau Monné <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: Maran Wilson <[email protected]>
---
Changes in v5
* No need to allocate/copy to dom->e820, we can just point to the already allocated e820.
--- tools/libxc/include/xc_dom.h | 7 ++++++- tools/libxl/libxl_x86.c | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-)
tools/libxc/include/xc_dom.h +6 -1
@@ -99,7 +99,7 @@ struct xc_dom_image {struct xc_dom_seg p2m_seg;struct xc_dom_seg pgtables_seg;struct xc_dom_seg devicetree_seg; -struct xc_dom_seg start_info_seg;/* HVMlite only */ +struct xc_dom_seg start_info_seg;xen_pfn_t start_info_pfn;xen_pfn_t console_pfn;xen_pfn_t xenstore_pfn;
@@ -224,6 +224,11 @@ struct xc_dom_image {/* Extra SMBIOS structures passed to HVMLOADER */ struct xc_hvm_firmware_module smbios_module; +#if defined(__i386__) || defined(__x86_64__) +struct e820entry *e820; +unsigned int e820_entries; +#endif +xen_pfn_t vuart_gfn; };
tools/libxl/libxl_x86.c +3 -0
@@ -578,6 +578,9 @@ static int domain_construct_memmap(libxl__gc *gc, goto out; } + dom->e820 = e820; + dom->e820_entries = e820_entries; + out:return rc; }
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v5 3/4] libxl: Store e820 map in xc_dom_image
Quoted 5 lines · Maran Wilson
From: Boris Ostrovsky <[email protected]>
We will later copy it to
hvm_start_info.(Also remove stale comment claming that xc_dom_image.start_info_seg is
^ claiming
Quoted 3 lines
only used for HVMlite guests)
Signed-off-by Boris Ostrovsky <[email protected]>
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v5 4/4 libxc: Pass e820 map to HVM/PVH guests via hvm_start_info
In reply to Maran WilsonFrom: Boris Ostrovsky <[email protected]>
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Roger Pau Monné <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: Maran Wilson <[email protected]>
---
Changes in v5:
* Fix calculation of start_info_size (and move it from under "if(!dom->device_model)"
* Rebase
--- tools/libxc/xc_dom_x86.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
tools/libxc/xc_dom_x86.c +29 -0
@@ -35,6 +35,8 @@#include <xen/arch-x86/hvm/start_info.h> #include <xen/io/protocols.h> +#include <xen-tools/libs.h> +#include "xg_private.h" #include "xc_dom.h" #include "xenctrl.h"
@@ -633,6 +635,9 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom) start_info_size +=HVMLOADER_MODULE_CMDLINE_SIZE *HVMLOADER_MODULE_MAX_COUNT ; + start_info_size += + dom->e820_entries *sizeof (struct hvm_memmap_table_entry ); +if ( !dom->device_model ) {if ( dom->cmdline )
@@ -1665,7 +1670,9 @@ static int bootlate_hvm(struct xc_dom_image *dom)uint32_t domid = dom->guest_domid;xc_interface *xch = dom->xch;struct hvm_start_info *start_info; +size_t modsize;struct hvm_modlist_entry *modlist; +struct hvm_memmap_table_entry *memmap;unsigned int i; start_info = xc_map_foreign_range(xch, domid, dom->start_info_seg.pages <<
@@ -1720,7 +1727,29 @@ static int bootlate_hvm(struct xc_dom_image *dom) ((uintptr_t )modlist - (uintptr_t )start_info); } +/* +* Check a couple of XEN_HVM_MEMMAP_TYPEs to verify consistency with +* their corresponding e820 numerical values. +*/ +BUILD_BUG_ON (XEN_HVM_MEMMAP_TYPE_RAM !=E820_RAM ); +BUILD_BUG_ON (XEN_HVM_MEMMAP_TYPE_ACPI !=E820_ACPI ); + + modsize =HVMLOADER_MODULE_MAX_COUNT * + (sizeof (*modlist) +HVMLOADER_MODULE_CMDLINE_SIZE ); + memmap = (void *)modlist + modsize; + + start_info->memmap_paddr = (dom->start_info_seg.pfn <<PAGE_SHIFT ) + + ((uintptr_t )modlist - (uintptr_t )start_info) + modsize; + start_info->memmap_entries = dom->e820_entries; +for ( i =0 ; i < dom->e820_entries; i++ ) + { + memmap[i].addr = dom->e820[i].addr; + memmap[i].size = dom->e820[i].size; + memmap[i].type = dom->e820[i].type; + } + start_info->magic =XEN_HVM_START_MAGIC_VALUE ; + start_info->version =1 ;munmap (start_info, dom->start_info_seg.pages <<XC_DOM_PAGE_SHIFT (dom));
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v5 4/4] libxc: Pass e820 map to HVM/PVH guests via hvm_start_info
Quoted 4 lines · Maran Wilson
From: Boris Ostrovsky <[email protected]>
Signed-off-by Boris Ostrovsky <[email protected]>Signed-off-by Maran Wilson <[email protected]>
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 8 lines · Maran Wilson
Boris Ostrovsky (3):
libxl/x86: Build e820 map earlier for HVM/PVH guests
libxl: Store e820 map inxc_dom_image
libxc: Pass e820 map to HVM/PVH guests viahvm_start_infoMaran Wilson (1):
x86/PVHv2: Add memory map pointer tohvm_start_infostruct
Series:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel