x86/hyperlaunch: move remaining pvh dom0 construction
RFC v2 20/38 x86/hyperlaunch: move remaining pvh dom0 construction
Move pvh_load_kernel() and its helper functions to the domain builder. With this move, it is now possible to move the remaining logic of dom0_construct_pvh() to the domain builder. With all the logic moved, the function can be dropped.
--- xen/arch/x86/hvm/dom0_build.c | 364 -------------------------- xen/arch/x86/hvm/dom_build.c | 361 ++++++++++++++++++++++++- xen/arch/x86/include/asm/dom0_build.h | 1 - 3 files changed, 360 insertions(+), 366 deletions(-)
xen/arch/x86/hvm/dom0_build.c +0 -364
@@ -479,334 +479,6 @@ int __init dom0_pvh_populate_p2m(struct domain *d)#undef MB1_PAGES } -static paddr_t __init find_memory ( -const struct domain *d,const struct elf_binary *elf,size_t size) -{ -paddr_t kernel_start = (paddr_t )elf->dest_base &PAGE_MASK ; -paddr_t kernel_end =ROUNDUP ((paddr_t )elf->dest_base + elf->dest_size, -PAGE_SIZE ); -unsigned int i; - -/* -* The memory map is sorted and all RAM regions starts and sizes are -* aligned to page boundaries. -*/ -for ( i =0 ; i < d->arch.nr_e820; i++ ) - { -paddr_t start, end = d->arch.e820[i].addr + d->arch.e820[i].size; - -/* Don't use memory below 1MB, as it could overwrite BDA/EBDA/IBFT. */ -if ( end <=MB (1 ) || d->arch.e820[i].type !=E820_RAM ) -continue ; - - start =MAX (ROUNDUP (d->arch.e820[i].addr,PAGE_SIZE ),MB (1 )); - -ASSERT (IS_ALIGNED (start,PAGE_SIZE ) &&IS_ALIGNED (end,PAGE_SIZE )); - -/* -* NB: Even better would be to use rangesets to determine a suitable -* range, in particular in case a kernel requests multiple heavily -* discontiguous regions (which right now we fold all into one big -* region). -*/ -if ( end <= kernel_start || start >= kernel_end ) - { -/* No overlap, just check whether the region is large enough. */ -if ( end - start >= size ) -return start; - } -/* Deal with the kernel already being loaded in the region. */ -else if ( kernel_start > start && kernel_start - start >= size ) -return start; -else if ( kernel_end < end && end - kernel_end >= size ) -return kernel_end; - } - -return INVALID_PADDR ; -} - -static bool __init check_load_address ( -const struct domain *d,const struct elf_binary *elf) -{ -paddr_t kernel_start = (uintptr_t )elf->dest_base; -paddr_t kernel_end = kernel_start + elf->dest_size; -unsigned int i; - -/* Relies on a sorted memory map with adjacent entries merged. */ -for ( i =0 ; i < d->arch.nr_e820; i++ ) - { -paddr_t start = d->arch.e820[i].addr; -paddr_t end = start + d->arch.e820[i].size; - -if ( start >= kernel_end ) -return false; - -if ( d->arch.e820[i].type ==E820_RAM && - start <= kernel_start && - end >= kernel_end ) -return true; - } - -return false; -} - -/* Find an e820 RAM region that fits the kernel at a suitable alignment. */ -static paddr_t __init find_kernel_memory ( -const struct domain *d,struct elf_binary *elf, -const struct elf_dom_parms *parms) -{ -paddr_t kernel_size = elf->dest_size; -unsigned int align; -unsigned int i; - -if ( parms->phys_align !=UNSET_ADDR32 ) - align = parms->phys_align; -else if ( elf->palign >=PAGE_SIZE ) - align = elf->palign; -else - align =MB (2 ); - -/* Search backwards to find the highest address. */ -for ( i = d->arch.nr_e820; i--; ) - { -paddr_t start = d->arch.e820[i].addr; -paddr_t end = start + d->arch.e820[i].size; -paddr_t kstart, kend; - -if ( d->arch.e820[i].type !=E820_RAM || - d->arch.e820[i].size < kernel_size ) -continue ; - -if ( start > parms->phys_max ) -continue ; - -if ( end -1 > parms->phys_max ) - end = parms->phys_max +1 ; - - kstart = (end - kernel_size) & ~(align -1 ); - kend = kstart + kernel_size; - -if ( kstart < parms->phys_min ) -return 0 ; - -if ( kstart >= start && kend <= end ) -return kstart; - } - -return 0 ; -} - -/* Check the kernel load address, and adjust if necessary and possible. */ -static bool __init check_and_adjust_load_address ( -const struct domain *d,struct elf_binary *elf,struct elf_dom_parms *parms) -{ -paddr_t reloc_base; - -if (check_load_address (d, elf) ) -return true; - -if ( !parms->phys_reloc ) - { -printk ("%pd kernel: Address conflict and not relocatable\n" , d); -return false; - } - - reloc_base =find_kernel_memory (d, elf, parms); -if ( !reloc_base ) - { -printk ("%pd kernel: Failed find a load address\n" , d); -return false; - } - -if ( opt_dom0_verbose ) -printk ("%pd kernel: Moving [%p, %p] -> [%" PRIpaddr", %" PRIpaddr"]\n" , d, - elf->dest_base, elf->dest_base + elf->dest_size -1 , - reloc_base, reloc_base + elf->dest_size -1 ); - - parms->phys_entry = - reloc_base + (parms->phys_entry - (uintptr_t )elf->dest_base); - elf->dest_base = (char *)reloc_base; - -return true; -} - -static int __init pvh_load_kernel ( -const struct boot_domain *bd,paddr_t *entry,paddr_t *start_info_addr) -{ -struct domain *d = bd->d; -struct boot_module *image = bd->kernel; -struct boot_module *initrd = bd->ramdisk; -void *image_base =bootstrap_map_bm (image); -void *image_start = image_base + image->headroom; -unsigned long image_len = image->size; -unsigned long initrd_len = initrd ? initrd->size :0 ; -size_t cmdline_len = bd->cmdline ?strlen (bd->cmdline) +1 :0 ; -const char *initrd_cmdline =NULL ; -struct elf_binary elf; -struct elf_dom_parms parms; -size_t extra_space; -paddr_t last_addr; -struct hvm_start_info start_info = {0 }; -struct hvm_modlist_entry mod = {0 }; -struct vcpu *v = d->vcpu[0 ]; -int rc; - -if ( (rc =bzimage_parse (image_base, &image_start, &image_len)) !=0 ) - { -printk ("Error trying to detect bz compressed kernel\n" ); -return rc; - } - -if ( (rc =elf_init (&elf, image_start, image_len)) !=0 ) - { -printk ("Unable to init ELF\n" ); -return rc; - } -if ( opt_dom0_verbose ) -elf_set_verbose (&elf); -elf_parse_binary (&elf); -if ( (rc =elf_xen_parse (&elf, &parms, true)) !=0 ) - { -printk ("Unable to parse kernel for ELFNOTES\n" ); -if (elf_check_broken (&elf) ) -printk ("%pd kernel: broken ELF: %s\n" , d,elf_check_broken (&elf)); -return rc; - } - -if ( parms.phys_entry ==UNSET_ADDR32 ) - { -printk ("Unable to find XEN_ELFNOTE_PHYS32_ENTRY address\n" ); -return -EINVAL ; - } - -/* Copy the OS image and free temporary buffer. */ - elf.dest_base = (void *)(parms.virt_kstart - parms.virt_base); - elf.dest_size = parms.virt_kend - parms.virt_kstart; - -if ( !check_and_adjust_load_address (d, &elf, &parms) ) -return -ENOSPC ; - -elf_set_vcpu (&elf, v); - rc =elf_load_binary (&elf); -if ( rc <0 ) - { -printk ("Failed to load kernel: %d\n" , rc); -if (elf_check_broken (&elf) ) -printk ("%pd kernel: broken ELF: %s\n" , d,elf_check_broken (&elf)); -return rc; - } - -/* -* Find a RAM region big enough (and that doesn't overlap with the loaded -* kernel) in order to load the initrd and the metadata. Note it could be -* split into smaller allocations, done as a single region in order to -* simplify it. -*/ - extra_space =sizeof (start_info); - -if ( initrd ) - { -size_t initrd_space =elf_round_up (&elf, initrd_len); - -if ( initrd->cmdline_pa ) - { - initrd_cmdline =__va (initrd->cmdline_pa); -if ( !*initrd_cmdline ) - initrd_cmdline =NULL ; - } -if ( initrd_cmdline ) - initrd_space +=strlen (initrd_cmdline) +1 ; - -if ( initrd_space ) - extra_space +=ROUNDUP (initrd_space,PAGE_SIZE ) +sizeof (mod); -else - initrd =NULL ; - } - - extra_space +=elf_round_up (&elf, cmdline_len); - - last_addr =find_memory (d, &elf, extra_space); -if ( last_addr ==INVALID_PADDR ) - { -printk ("Unable to find a memory region to load initrd and metadata\n" ); -return -ENOMEM ; - } - -if ( initrd !=NULL ) - { - rc =hvm_copy_to_guest_phys (last_addr,__va (initrd->start), - initrd_len, v); -if ( rc ) - { -printk ("Unable to copy initrd to guest\n" ); -return rc; - } - - mod.paddr = last_addr; - mod.size = initrd_len; - last_addr +=elf_round_up (&elf, initrd_len); -if ( initrd_cmdline ) - { -size_t len =strlen (initrd_cmdline) +1 ; - - rc =hvm_copy_to_guest_phys (last_addr, initrd_cmdline, len, v); -if ( rc ) - { -printk ("Unable to copy module command line\n" ); -return rc; - } - mod.cmdline_paddr = last_addr; - last_addr += len; - } - last_addr =ROUNDUP (last_addr,PAGE_SIZE ); - } - -/* Free temporary buffers. */ -free_boot_modules (); - - rc =hvm_copy_to_guest_phys (last_addr, bd->cmdline, cmdline_len, v); -if ( rc ) - { -printk ("Unable to copy guest command line\n" ); -return rc; - } - - start_info.cmdline_paddr = cmdline_len ? last_addr :0 ; - -/* -* Round up to 32/64 bits (depending on the guest kernel bitness) so -* the modlist/start_info is aligned. -*/ - last_addr +=elf_round_up (&elf, cmdline_len); - -if ( initrd !=NULL ) - { - rc =hvm_copy_to_guest_phys (last_addr, &mod,sizeof (mod), v); -if ( rc ) - { -printk ("Unable to copy guest modules\n" ); -return rc; - } - start_info.modlist_paddr = last_addr; - start_info.nr_modules =1 ; - last_addr +=sizeof (mod); - } - - start_info.magic =XEN_HVM_START_MAGIC_VALUE ; - start_info.flags =SIF_PRIVILEGED |SIF_INITDOMAIN ; - rc =hvm_copy_to_guest_phys (last_addr, &start_info,sizeof (start_info), v); -if ( rc ) - { -printk ("Unable to copy start info to guest\n" ); -return rc; - } - - *entry = parms.phys_entry; - *start_info_addr = last_addr; - -return 0 ; -} - static int __init cf_check acpi_count_intr_ovr(struct acpi_subtable_header *header,const unsigned long end) {
@@ -1255,42 +927,6 @@ int __init dom0_pvh_setup_acpi(struct domain *d, paddr_t start_info)return 0 ; } -int __init dom0_construct_pvh (struct boot_domain *bd) -{ -paddr_t entry, start_info; -struct domain *d = bd->d; -int rc; - - rc =pvh_load_kernel (bd, &entry, &start_info); -if ( rc ) - { -printk ("Failed to load Dom0 kernel\n" ); -return rc; - } - - rc =hvm_setup_cpus (bd->d, entry, start_info); -if ( rc ) - { -printk ("Failed to setup Dom0 CPUs: %d\n" , rc); -return rc; - } - - rc =dom0_pvh_setup_acpi (bd->d, start_info); -if ( rc ) - { -printk ("Failed to setup Dom0 ACPI tables: %d\n" , rc); -return rc; - } - -if ( opt_dom0_verbose ) - { -printk ("Dom%u memory map:\n" , d->domain_id); -print_e820_memory_map (d->arch.e820, d->arch.nr_e820); - } - -return 0 ; -} -/* * Local variables: * mode: C
xen/arch/x86/hvm/dom_build.c +360 -1
385 lines not on this page · raw message
xen/arch/x86/include/asm/dom0_build.h +0 -1
@@ -24,7 +24,6 @@ int dom0_pvh_setup_acpi(struct domain *d, paddr_t start_info);int dom0_pvh_populate_p2m (struct domain *d);int dom0_construct_pv (struct boot_domain *bd); -int dom0_construct_pvh (struct boot_domain *bd);void dom0_update_physmap (bool compat,unsigned long pfn,unsigned long mfn,unsigned long vphysmap_s);
Signature · 1 line
2.30.2
RFC v2 21/38 x86/hyperlaunch: relocate pvh_steal_ram to domain builder
The function pvh_steal_ram() is not pvh specific and can be used on any HVM domain. Move to the domain builder and rename to hvm_steal_ram.
--- xen/arch/x86/hvm/dom0_build.c | 106 +++------------------- xen/arch/x86/hvm/dom_build.c | 84 +++++++++++++++++ xen/arch/x86/include/asm/domain-builder.h | 7 ++ 3 files changed, 102 insertions(+), 95 deletions(-)
xen/arch/x86/hvm/dom0_build.c +11 -95
@@ -183,90 +183,6 @@ int __init pvh_populate_memory_range(return 0 ; } -/* Steal RAM from the end of a memory region. */ -static int __init pvh_steal_ram (struct domain *d,unsigned long size, -unsigned long align,paddr_t limit, -paddr_t *addr) -{ -unsigned int i = d->arch.nr_e820; - -/* -* Alignment 0 should be set to 1, so it doesn't wrap around in the -* calculations below. -*/ - align = align ? :1 ; -while ( i-- ) - { -struct e820entry *entry = &d->arch.e820[i]; - -if ( entry->type !=E820_RAM || entry->addr + entry->size > limit ) -continue ; - - *addr = (entry->addr + entry->size - size) & ~(align -1 ); -if ( *addr < entry->addr || -/* Don't steal from the low 1MB due to the copying done there. */ - *addr <MB (1 ) ) -continue ; - - entry->size = *addr - entry->addr; -return 0 ; - } - -return -ENOMEM ; -} - -/* NB: memory map must be sorted at all times for this to work correctly. */ -static int __init pvh_add_mem_range (struct domain *d,uint64_t s,uint64_t e, -unsigned int type) -{ -struct e820entry *map; -unsigned int i; - -for ( i =0 ; i < d->arch.nr_e820; i++ ) - { -uint64_t rs = d->arch.e820[i].addr; -uint64_t re = rs + d->arch.e820[i].size; - -if ( rs == e && d->arch.e820[i].type == type ) - { - d->arch.e820[i].addr = s; -return 0 ; - } - -if ( re == s && d->arch.e820[i].type == type && - (i +1 == d->arch.nr_e820 || d->arch.e820[i +1 ].addr >= e) ) - { - d->arch.e820[i].size += e - s; -return 0 ; - } - -if ( rs >= e ) -break ; - -if ( re > s ) -return -EEXIST ; - } - - map = xzalloc_array(struct e820entry, d->arch.nr_e820 + 1); -if ( !map ) - { -printk (XENLOG_WARNING "E820: out of memory to add region\n" ); -return -ENOMEM ; - } - -memcpy (map, d->arch.e820, i *sizeof (*d->arch.e820)); -memcpy (map + i +1 , d->arch.e820 + i, - (d->arch.nr_e820 - i) *sizeof (*d->arch.e820)); - map[i].addr = s; - map[i].size = e - s; - map[i].type = type; -xfree (d->arch.e820); - d->arch.e820 = map; - d->arch.nr_e820++; - -return 0 ; -} -static int __init pvh_setup_vmx_realmode_helpers (struct domain *d) {uint32_t rc, *ident_pt;
@@ -280,14 +196,14 @@ static int __init pvh_setup_vmx_realmode_helpers(struct domain *d)* TSS structure (which accounts for the first 104b) doesn't cross * a page boundary. */ -if ( !pvh_steal_ram (d,HVM_VM86_TSS_SIZE ,128 ,GB (4 ), &gaddr) ) +if ( !hvm_steal_ram (d,HVM_VM86_TSS_SIZE ,128 ,GB (4 ), &gaddr) ) {if (hvm_copy_to_guest_phys (gaddr,NULL ,HVM_VM86_TSS_SIZE , v) != HVMTRANS_okay )printk ("Unable to zero VM86 TSS area\n" ); d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ] =VM86_TSS_UPDATED | ((uint64_t )HVM_VM86_TSS_SIZE <<32 ) | gaddr; -if (pvh_add_mem_range (d, gaddr, gaddr +HVM_VM86_TSS_SIZE , +if (hvm_add_mem_range (d, gaddr, gaddr +HVM_VM86_TSS_SIZE ,E820_RESERVED ) )printk ("Unable to set VM86 TSS as reserved in the memory map\n" ); }
@@ -295,7 +211,7 @@ static int __init pvh_setup_vmx_realmode_helpers(struct domain *d)printk ("Unable to allocate VM86 TSS area\n" );/* Steal some more RAM for the identity page tables. */ -if (pvh_steal_ram (d,PAGE_SIZE ,PAGE_SIZE ,GB (4 ), &gaddr) ) +if (hvm_steal_ram (d,PAGE_SIZE ,PAGE_SIZE ,GB (4 ), &gaddr) ) {printk ("Unable to find memory to stash the identity page tables\n" );return -ENOMEM ;
@@ -317,7 +233,7 @@ static int __init pvh_setup_vmx_realmode_helpers(struct domain *d)unmap_domain_page (ident_pt);put_page (mfn_to_page (mfn)); d->arch.hvm.params[HVM_PARAM_IDENT_PT ] = gaddr; -if (pvh_add_mem_range (d, gaddr, gaddr +PAGE_SIZE ,E820_RESERVED ) ) +if (hvm_add_mem_range (d, gaddr, gaddr +PAGE_SIZE ,E820_RESERVED ) )printk ("Unable to set identity page tables as reserved in the memory map\n" );return 0 ;
@@ -582,7 +498,7 @@ static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr) madt->header.checksum -=acpi_tb_checksum (ACPI_CAST_PTR (u8, madt), size);/* Place the new MADT in guest memory space. */ -if (pvh_steal_ram (d, size,0 ,GB (4 ), addr) ) +if (hvm_steal_ram (d, size,0 ,GB (4 ), addr) ) {printk ("Unable to steal guest RAM for MADT\n" ); rc = -ENOMEM ;
@@ -590,7 +506,7 @@ static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr) }/* Mark this region as E820_ACPI. */ -if (pvh_add_mem_range (d, *addr, *addr + size,E820_ACPI ) ) +if (hvm_add_mem_range (d, *addr, *addr + size,E820_ACPI ) )printk ("Unable to add MADT region to memory map\n" ); rc =hvm_copy_to_guest_phys (*addr, madt, size, d->vcpu[0 ]);
@@ -770,7 +686,7 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr, xsdt->header.checksum -=acpi_tb_checksum (ACPI_CAST_PTR (u8, xsdt), size);/* Place the new XSDT in guest memory space. */ -if (pvh_steal_ram (d, size,0 ,GB (4 ), addr) ) +if (hvm_steal_ram (d, size,0 ,GB (4 ), addr) ) {printk ("Unable to find guest RAM for XSDT\n" ); rc = -ENOMEM ;
@@ -778,7 +694,7 @@ static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr, }/* Mark this region as E820_ACPI. */ -if (pvh_add_mem_range (d, *addr, *addr + size,E820_ACPI ) ) +if (hvm_add_mem_range (d, *addr, *addr + size,E820_ACPI ) )printk ("Unable to add XSDT region to memory map\n" ); rc =hvm_copy_to_guest_phys (*addr, xsdt, size, d->vcpu[0 ]);
@@ -824,7 +740,7 @@ int __init dom0_pvh_setup_acpi(struct domain *d, paddr_t start_info)if (strncmp (sig,ACPI_SIG_MADT ,ACPI_NAME_SIZE ) ?pvh_acpi_table_allowed (sig, addr, size) : !acpi_memory_banned (addr, size) ) -pvh_add_mem_range (d, addr, addr + size,E820_ACPI ); +hvm_add_mem_range (d, addr, addr + size,E820_ACPI ); }/* Identity map ACPI e820 regions. */
@@ -893,14 +809,14 @@ int __init dom0_pvh_setup_acpi(struct domain *d, paddr_t start_info)* the native RSDT, and should not be used for the Dom0 kernel's boot * purposes (we keep it visible for post boot access). */ -if (pvh_steal_ram (d,sizeof (rsdp),0 ,GB (4 ), &rsdp_paddr) ) +if (hvm_steal_ram (d,sizeof (rsdp),0 ,GB (4 ), &rsdp_paddr) ) {printk ("Unable to allocate guest RAM for RSDP\n" );return -ENOMEM ; }/* Mark this region as E820_ACPI. */ -if (pvh_add_mem_range (d, rsdp_paddr, rsdp_paddr +sizeof (rsdp), +if (hvm_add_mem_range (d, rsdp_paddr, rsdp_paddr +sizeof (rsdp),E820_ACPI ) )printk ("Unable to add RSDP region to memory map\n" );
xen/arch/x86/hvm/dom_build.c +84 -0
96 lines not on this page · raw message
xen/arch/x86/include/asm/domain-builder.h +7 -0
@@ -4,10 +4,17 @@struct boot_domain ;struct elf_dom_parms ; +int hvm_add_mem_range ( +struct domain *d,uint64_t s,uint64_t e,unsigned int type); +int hvm_setup_cpus (struct domain *d,paddr_t entry,paddr_t start_info);int pvh_populate_memory_range (struct domain *d,unsigned long start,unsigned long nr_pages); +int hvm_steal_ram ( +struct domain *d,unsigned long size,unsigned long align,paddr_t limit, +paddr_t *addr); +unsigned long dom_paging_pages (const struct boot_domain *d,unsigned long nr_pages);
Signature · 1 line
2.30.2
RFC v2 22/38 x86/hyperlaunch: add domu acpi construction
In reply to Daniel P. SmithIntroduce hvm_setup_acpi() that will construct an APCI table for a general HVM domU guest.
--- xen/arch/x86/hvm/dom_build.c | 213 ++++++++++++++++++++++++++++++++++- 1 file changed, 212 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/dom_build.c +212 -1
@@ -409,6 +409,214 @@ int __init hvm_add_mem_range(return 0 ; } +static int __init hvm_setup_acpi_madt ( +struct domain *d,struct acpi_table_madt *madt) +{ +struct acpi_table_header *table; +struct acpi_madt_local_apic *lapic; +acpi_status status; +unsigned long size =hvm_size_acpi_madt (d); +int i; + +/* Copy the native MADT table header. */ + status =acpi_get_table (ACPI_SIG_MADT ,0 , &table); +if ( !ACPI_SUCCESS (status) ) + { +printk ("Failed to get MADT ACPI table, aborting.\n" ); +return -EINVAL ; + } + madt->header = *table; + madt->address =APIC_DEFAULT_PHYS_BASE ; +/* +* NB: this is currently set to 4, which is the revision in the ACPI +* spec 6.1. Sadly ACPICA doesn't provide revision numbers for the +* tables described in the headers. +*/ + madt->header.revision = min_t(unsigned char, table->revision, 4); + + lapic = (void *)(madt +1 ); + +for ( i =0 ; i < d->max_vcpus; i++ ) + { + lapic->header.type =ACPI_MADT_TYPE_LOCAL_APIC ; + lapic->header.length =sizeof (*lapic); + lapic->id = i *2 ; + lapic->processor_id = i; + lapic->lapic_flags =ACPI_MADT_ENABLED ; + + lapic++; + } + + madt->header.length = size; +/* +* Calling acpi_tb_checksum here is a layering violation, but +* introducing a wrapper for such simple usage seems overkill. +*/ + madt->header.checksum -=acpi_tb_checksum (ACPI_CAST_PTR (u8, madt), size); + +return 0 ; +} + +static int __init hvm_setup_acpi_xsdt ( +struct domain *d,struct acpi_table_xsdt *xsdt,paddr_t madt_addr) +{ +struct acpi_table_header *table; +struct acpi_table_rsdp *rsdp; +unsigned long size =hvm_size_acpi_xsdt (d); +paddr_t xsdt_paddr; + +/* +* Restore original DMAR table signature, we are going to filter it from +* the new XSDT that is presented to the guest, so it is no longer +* necessary to have it's signature zapped. +*/ +acpi_dmar_reinstate (); + +/* Copy the native XSDT table header. */ + rsdp =acpi_os_map_memory (acpi_os_get_root_pointer (),sizeof (*rsdp)); +if ( !rsdp ) + { +printk ("Unable to map RSDP\n" ); +return -EINVAL ; + } + xsdt_paddr = rsdp->xsdt_physical_address; +acpi_os_unmap_memory (rsdp,sizeof (*rsdp)); + table =acpi_os_map_memory (xsdt_paddr,sizeof (*table)); +if ( !table ) + { +printk ("Unable to map XSDT\n" ); +return -EINVAL ; + } + xsdt->header = *table; +acpi_os_unmap_memory (table,sizeof (*table)); + +/* Add the custom MADT. */ + xsdt->table_offset_entry[0 ] = madt_addr; + + xsdt->header.revision =1 ; + xsdt->header.length = size; +/* +* Calling acpi_tb_checksum here is a layering violation, but +* introducing a wrapper for such simple usage seems overkill. +*/ + xsdt->header.checksum -=acpi_tb_checksum (ACPI_CAST_PTR (u8, xsdt), size); + +return 0 ; +} + +static int __init hvm_alloc_acpi_region ( +struct domain *d,void **region,unsigned long size,paddr_t *addr) +{ +int i; + + *addr =0 ; + +for ( i =0 ; i < d->arch.nr_e820; i++ ) + { +if ( d->arch.e820[i].type ==E820_ACPI ) + { +if ( d->arch.e820[i].size < size ) +break ; + + *addr = d->arch.e820[i].addr; +break ; + } + } + +/* The e820 setup did not allocate ACPI region, steal one instead. */ +if ( *addr ==0 ) + { +if (hvm_steal_ram (d, size,0 ,GB (4 ), addr) ) + { +printk ("Unable to allocate guest RAM for RSDP\n" ); +return -ENOMEM ; + } +if (hvm_add_mem_range (d, *addr, *addr + size,E820_ACPI ) ) + { +printk ("Unable to add RSDP region to memory map\n" ); +return -EFAULT ; + } + } + + *region =xzalloc_bytes (size); +if ( !region ) +return -ENOMEM ; + +return 0 ; +} + +static int __init hvm_setup_acpi (struct domain *d,paddr_t start_info) +{ +paddr_t rsdp_paddr, xsdt_paddr, madt_paddr; +struct acpi_table_rsdp *rsdp; +unsigned long size =hvm_size_acpi_region (d); +void *table; +int rc; + + rc =hvm_alloc_acpi_region (d, &table, size, &rsdp_paddr); +if ( rc <0 ) +return rc; + +/* RSDP */ + rsdp = table; + xsdt_paddr = rsdp_paddr +sizeof (struct acpi_table_rsdp ); + + *rsdp = (struct acpi_table_rsdp ){ + .signature =ACPI_SIG_RSDP , + .revision =2 , + .length =sizeof (struct acpi_table_rsdp ), + .oem_id ="XenHL\0" ,/* Xen Hyperlaunch */ + .xsdt_physical_address = xsdt_paddr, + }; + + rsdp->checksum -=acpi_tb_checksum (ACPI_CAST_PTR (u8, rsdp), +ACPI_RSDP_REV0_SIZE ); + rsdp->extended_checksum -=acpi_tb_checksum (ACPI_CAST_PTR (u8, rsdp), +sizeof (*rsdp)); + +/* XSDT */ + table +=sizeof (struct acpi_table_rsdp ); + madt_paddr = xsdt_paddr +hvm_size_acpi_xsdt (d); + + rc =hvm_setup_acpi_xsdt (d, table, madt_paddr); +if ( rc ) + { +printk ("Unable to construct XSDT\n" ); + goto out; + } + + +/* MADT */ + table +=hvm_size_acpi_xsdt (d); + rc =hvm_setup_acpi_madt (d, table); +if ( rc ) + { +printk ("Unable to construct MADT\n" ); + goto out; + } + +/* Copy ACPI region into guest memory. */ + rc =hvm_copy_to_guest_phys (rsdp_paddr, rsdp, size, d->vcpu[0 ]); +if ( rc ) + { +printk ("Unable to copy RSDP into guest memory\n" ); + goto out; + } + +/* Copy RSDP address to start_info. */ + rc =hvm_copy_to_guest_phys ( + start_info + offsetof(struct hvm_start_info , rsdp_paddr), &rsdp_paddr, +sizeof (((struct hvm_start_info *)0 )->rsdp_paddr), d->vcpu[0 ]); +if ( rc ) +printk ("Unable to copy RSDP address to start info\n" ); + + out: +if ( rsdp ) +xfree (rsdp); + +return rc; +} +static bool __init check_load_address (const struct domain *d,const struct elf_binary *elf) {
@@ -757,7 +965,10 @@ int __init dom_construct_pvh(struct boot_domain *bd)return rc; } - rc =dom0_pvh_setup_acpi (bd->d, start_info); +if (is_control_domain (bd->d) ||is_hardware_domain (bd->d) ) + rc =dom0_pvh_setup_acpi (bd->d, start_info); +else + rc =hvm_setup_acpi (bd->d, start_info);if ( rc ) {printk ("Failed to setup Dom0 ACPI tables: %d\n" , rc);
Signature · 1 line
2.30.2
RFC v2 23/38 x86/boot: export command line processing
In reply to Daniel P. SmithExport the function cmdline_cook() so that it can be called outside of setup.c.
--- xen/arch/x86/include/asm/setup.h | 2 ++ xen/arch/x86/setup.c | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/include/asm/setup.h +2 -0
@@ -29,6 +29,8 @@ void init_IRQ(void);struct boot_domain ;int construct_dom0 (struct boot_domain *bd); +const char *cmdline_cook (const char *p,const char *loader_name); +void setup_io_bitmap (struct domain *d);extern struct boot_info xen_boot_info;
xen/arch/x86/setup.c +1 -3
@@ -293,8 +293,6 @@ static int __init cf_check parse_acpi_param(const char *s) }custom_param ("acpi" , parse_acpi_param); -static const char *cmdline_cook (const char *p,const char *loader_name); -struct boot_info __initdata xen_boot_info = { .loader ="unknown" , .cmdline ="" ,
@@ -952,7 +950,7 @@ static bool __init loader_is_grub2(const char *loader_name)* * Always returns a pointer within @p. */ -static const char *__init cmdline_cook (const char *p,const char *loader_name) +const char *__init cmdline_cook (const char *p,const char *loader_name) {/* Strip leading whitespace. */ while ( *p ==' ' )
Signature · 1 line
2.30.2
RFC v2 24/38 x86/hyperlaunch: convert create_dom0 to arch_create_dom
In reply to Daniel P. SmithThe only consumer of the function domain_cmdline_size() and the acpi_param parameter is create_dom(). It is therefore reasonable to move domain_cmdline_size() and the acpi_param parameter along with its parsing code at the same time as create_dom0() is moved under the domain builder. While moving create_dom0(), rename it to arch_create_dom() as the function is now generalized.
--- xen/arch/x86/domain-builder/Makefile | 2 +- xen/arch/x86/domain-builder/domain.c | 180 +++++++++++++++++++++++++++ xen/arch/x86/setup.c | 174 +------------------------- xen/include/xen/domain-builder.h | 3 + 4 files changed, 185 insertions(+), 174 deletions(-)
xen/arch/x86/domain-builder/Makefile +1 -1
@@ -1 +1 @@ -obj-y += domain.init.o +obj-y += domain.o
xen/arch/x86/domain-builder/domain.c +180 -0
209 lines not on this page · raw message
xen/arch/x86/setup.c +1 -173
192 lines not on this page · raw message
xen/include/xen/domain-builder.h +3 -0
@@ -40,4 +40,7 @@ unsigned int dom_max_vcpus(struct boot_domain *bd);struct vcpu *domain_vcpu0_create (struct boot_domain *bd);void domain_vcpus_create (struct domain *d); +struct domain *arch_create_dom ( +struct boot_info *bi,struct boot_domain *bd); +#endif /* __XEN_DOMAIN_BUILDER_H__ */
Signature · 1 line
2.30.2
RFC v2 25/38 x86/hyperlaunch: remove dom0-isms from arch_create_dom
In reply to Daniel P. SmithRemoves the dom0 naming from variables and isolates control/hardware domain specific logic behind capabilities check.
--- xen/arch/x86/domain-builder/domain.c | 47 +++++++++++++++------------- 1 file changed, 26 insertions(+), 21 deletions(-)
xen/arch/x86/domain-builder/domain.c +26 -21
@@ -228,7 +228,7 @@ struct domain *__init arch_create_dom( {char *cmdline =NULL ;size_t cmdline_size; -struct xen_domctl_createdomain dom0_cfg = { +struct xen_domctl_createdomain dom_cfg = { .flags =IS_ENABLED (CONFIG_TBOOT ) ? XEN_DOMCTL_CDF_s3_integrity :0 , .max_evtchn_port =-1 , .max_grant_frames =-1 ,
@@ -244,21 +244,21 @@ struct domain *__init arch_create_dom(if ( opt_dom0_pvh || (bi->hyperlaunch_enabled && !(bd->mode &BUILD_MODE_PARAVIRT )) ) { - dom0_cfg.flags |= (XEN_DOMCTL_CDF_hvm | + dom_cfg.flags |= (XEN_DOMCTL_CDF_hvm | ((hvm_hap_supported () && !opt_dom0_shadow) ? XEN_DOMCTL_CDF_hap :0 )); - dom0_cfg.arch.emulation_flags |= + dom_cfg.arch.emulation_flags |=XEN_X86_EMU_LAPIC |XEN_X86_EMU_IOAPIC |XEN_X86_EMU_VPCI ; }if ( iommu_enabled && (bd->capabilities &DOMAIN_CAPS_HARDWARE ) ) - dom0_cfg.flags |= XEN_DOMCTL_CDF_iommu; + dom_cfg.flags |= XEN_DOMCTL_CDF_iommu;if ( bd->domid ==DOMID_INVALID )/* Create initial domain. Not d0 for pvshim. */ bd->domid =get_initial_domain_id (); - d =domain_create (bd->domid, &dom0_cfg, + d =domain_create (bd->domid, &dom_cfg, ((bd->capabilities &DOMAIN_CAPS_CONTROL ) ? CDF_privileged :0 ) | ((bd->capabilities &DOMAIN_CAPS_HARDWARE ) ? CDF_hardware :0 ));if (IS_ERR (d) )
@@ -289,25 +289,30 @@ struct domain *__init arch_create_dom(cmdline_cook (__va (bd->kernel->cmdline_pa), bi->loader), cmdline_size); -if ( bi->kextra ) -/* kextra always includes exactly one leading space. */ -strlcat (cmdline, bi->kextra, cmdline_size); - -/* Append any extra parameters. */ -if ( skip_ioapic_setup && !strstr (cmdline,"noapic" ) ) -strlcat (cmdline," noapic" , cmdline_size); - -if ( (strlen (acpi_param) ==0 ) && acpi_disabled ) +/* Params from Xen cmd line apply only to classic dom0 */ +if (has_dom0_caps (bd) ) { -printk ("ACPI is disabled, notifying Domain 0 (acpi=off)\n" ); -safe_strcpy (acpi_param,"off" ); +if ( bi->kextra ) +/* kextra always includes exactly one leading space. */ +strlcat (cmdline, bi->kextra, cmdline_size); + +/* Append any extra parameters. */ +if ( skip_ioapic_setup && !strstr (cmdline,"noapic" ) ) +strlcat (cmdline," noapic" , cmdline_size); + +if ( (strlen (acpi_param) ==0 ) && acpi_disabled ) + { +printk ("ACPI is disabled, notifying Domain 0 (acpi=off)\n" ); +safe_strcpy (acpi_param,"off" ); + } + +if ( (strlen (acpi_param) !=0 ) && !strstr (cmdline,"acpi=" ) ) + { +strlcat (cmdline," acpi=" , cmdline_size); +strlcat (cmdline, acpi_param, cmdline_size); + } } -if ( (strlen (acpi_param) !=0 ) && !strstr (cmdline,"acpi=" ) ) - { -strlcat (cmdline," acpi=" , cmdline_size); -strlcat (cmdline, acpi_param, cmdline_size); - } bd->kernel->cmdline_pa =0 ; bd->cmdline = cmdline; }
Signature · 1 line
2.30.2
RFC v2 26/38 x86/hyperlaunch: introduce domain builder general dom creation
In reply to Daniel P. SmithIntroduce the builder_create_domains() function that provides the general domain construction abstraction that selects between classic dom0 construction and the hyperlaunch domain builder.
--- xen/arch/x86/domain-builder/Makefile | 1 + xen/arch/x86/domain-builder/core.c | 36 ++++++++++++++++++++++++++++ xen/arch/x86/include/asm/bootinfo.h | 26 ++++++++++++++++++++ xen/arch/x86/setup.c | 23 +++++++++++++++--- xen/include/xen/domain-builder.h | 2 ++ 5 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 xen/arch/x86/domain-builder/core.c
xen/arch/x86/domain-builder/Makefile +1 -0
@@ -1 +1,2 @@ +obj-y += core.o obj-y += domain.o
xen/arch/x86/domain-builder/core.c new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2025, Apertus Solutions, LLC +*/ + +#include <xen/domain-builder.h> +#include <xen/init.h> +#include <xen/lib.h> + +#include <asm/bootinfo.h> + +unsigned int __init builder_create_domains (struct boot_info *bi) +{ +unsigned int build_count =0 ; +struct boot_domain *bd = &bi->domains[0 ]; + +if ( bd->capabilities &DOMAIN_CAPS_HARDWARE && bd->kernel ==NULL ) +panic ("%s: hardware domain missing kernel\n" , __func__); + + +arch_create_dom (bi, bd); +if ( bd->d ) + build_count++; + +return build_count; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/x86/include/asm/bootinfo.h +26 -0
@@ -132,6 +132,32 @@ static inline unsigned int __init next_boot_module_index( (i) <= (b)->nr_modules; \ (i) = next_boot_module_index(b, t, i + 1) ) +/* +* next_boot_domain_index: +* Finds the next boot domain with capability cap, starting at array index +* start. +* +* Returns: +* Success - index in boot_domains array +* Failure - a value greater than MAX_NR_BOOTDOMS +*/ +static inline unsigned int __init next_boot_domain_index ( +const struct boot_info *bi,uint32_t cap,unsigned int start) +{ +int i; + +for ( i = start; i < bi->nr_domains; i++ ) + { +if ( bi->domains[i].capabilities & cap ) +return i; + } + +return MAX_NR_BOOTDOMS +1 ; +} + +#define first_boot_domain_index (bi, cap) \ + next_boot_domain_index(bi, cap, 0) +#endif /* X86_BOOTINFO_H */ /*
xen/arch/x86/setup.c +20 -3
@@ -2026,9 +2026,26 @@ void asmlinkage __init noreturn __start_xen(void)* We're going to setup domain0 using the module(s) that we stashed safely * above our heap. The second module, if present, is an initrd ramdisk. */ - dom0 =arch_create_dom (bi, &bi->domains[0 ]); -if ( !dom0 ) -panic ("Could not set up DOM0 guest OS\n" ); + ret =builder_create_domains (bi); +if ( ret <=0 ) +panic ("Could not set up boot-time domains\n" ); +else +printk (XENLOG_INFO "Constructed %d boot-time domains\n" , ret); + +/* Selection order: hardware domain, control domain, first domain */ + i =first_boot_domain_index (bi,DOMAIN_CAPS_HARDWARE ); +if ( i >=MAX_NR_BOOTDOMS ) + { + i =first_boot_domain_index (bi,DOMAIN_CAPS_CONTROL ); +if ( i >=MAX_NR_BOOTDOMS ) + { +printk (XENLOG_WARNING +"A hwdom/ctrldom not detected, using 0th domain\n" ); + i =0 ; + } + } + + dom0 = bi->domains[i].d;heap_init_late ();
xen/include/xen/domain-builder.h +2 -0
@@ -43,4 +43,6 @@ void domain_vcpus_create(struct domain *d);struct domain *arch_create_dom (struct boot_info *bi,struct boot_domain *bd); +unsigned int builder_create_domains (struct boot_info *bi); +#endif /* __XEN_DOMAIN_BUILDER_H__ */
Signature · 1 line
2.30.2
RFC v2 27/38 x86/hyperlaunch: introduce arch builder finalize
In reply to Daniel P. SmithThis commit introduces a per arch builder finalize method where all post-construction finalization and cleanup can be handled. The call to discard boot modules relocated from inside the two x86 domain construction paths to the x86 domain builder finalize method. This will ensure modules are not discarded until after all domains have been constructed.
---
Changes since RFC v1:
- reworked the commit to introduce builder finalize
- renamed the commit to refelect builder finalize
--- xen/arch/x86/domain-builder/core.c | 2 ++ xen/arch/x86/domain-builder/domain.c | 8 ++++++++ xen/arch/x86/hvm/dom_build.c | 3 --- xen/arch/x86/pv/dom0_build.c | 3 --- xen/include/xen/domain-builder.h | 2 ++ 5 files changed, 12 insertions(+), 6 deletions(-)
xen/arch/x86/domain-builder/core.c +2 -0
@@ -22,6 +22,8 @@ unsigned int __init builder_create_domains(struct boot_info *bi)if ( bd->d ) build_count++; +arch_builder_finalize (bi); +return build_count; }
xen/arch/x86/domain-builder/domain.c +8 -0
@@ -326,6 +326,14 @@ struct domain *__init arch_create_dom(return d; } +int __init arch_builder_finalize (struct boot_info *bi) +{ +/* Free temporary buffers. */ +free_boot_modules (); + +return 0 ; +} +/* * Local variables: * mode: C
xen/arch/x86/hvm/dom_build.c +0 -3
@@ -853,9 +853,6 @@ static int __init pvh_load_kernel( last_addr =ROUNDUP (last_addr,PAGE_SIZE ); } -/* Free temporary buffers. */ -free_boot_modules (); - rc =hvm_copy_to_guest_phys (last_addr, bd->cmdline, cmdline_len, v);if ( rc ) {
xen/arch/x86/pv/dom0_build.c +0 -3
@@ -866,9 +866,6 @@ static int __init dom0_construct(struct boot_domain *bd)init_hypercall_page (d,_p (parms.virt_hypercall)); } -/* Free temporary buffers. */ -free_boot_modules (); -/* Set up start info area. */ si = (start_info_t *)vstartinfo_start;clear_page (si);
xen/include/xen/domain-builder.h +2 -0
@@ -43,6 +43,8 @@ void domain_vcpus_create(struct domain *d);struct domain *arch_create_dom (struct boot_info *bi,struct boot_domain *bd); +int arch_builder_finalize (struct boot_info *bi); +unsigned int builder_create_domains (struct boot_info *bi);#endif /* __XEN_DOMAIN_BUILDER_H__ */
Signature · 1 line
2.30.2
RFC v2 28/38 x86/hyperlaunch: allocate xenstore for domu
In reply to Daniel P. SmithDuring domU construction, a page of memory and an event channel must be setup for xenstore connection. In this commit, a page from the special page region of domU is setup as the xenstore page along with an event channel. The page address and event channel are published in the HVM parameters, so the domain can be announced to Xenstore.
---
Changes for RFCv2:
- rewrote to setup event chan after construction has finished
- merged the setting of xenstore boot capabilities flag commit
--- xen/arch/x86/domain-builder/domain.c | 56 +++++++++++++++++++++++ xen/arch/x86/hvm/dom_build.c | 26 +++++++++++ xen/arch/x86/include/asm/boot-domain.h | 3 ++ xen/arch/x86/include/asm/domain-builder.h | 2 + 4 files changed, 87 insertions(+)
xen/arch/x86/domain-builder/domain.c +56 -0
@@ -7,6 +7,7 @@#include <xen/domain.h> #include <xen/domain-builder.h> #include <xen/err.h> +#include <xen/event.h> #include <xen/grant_table.h> #include <xen/init.h> #include <xen/lib.h> /* get types.h for libefl.h */
@@ -16,6 +17,7 @@#include <xen/sched.h> #include <public/bootfdt.h> +#include <public/hvm/params.h> #include <asm/bootinfo.h> #include <asm/cpu-policy.h>
@@ -191,6 +193,28 @@ unsigned long __init dom_compute_nr_pages(return bd->mem_pages; } +static int __init alloc_dom_evtchn ( +const struct boot_domain *d,const struct boot_domain *r, +evtchn_port_t *port) +{ +int rc; +evtchn_alloc_unbound_t ec = { + .dom = d->domid, + .remote_dom = r->domid, + }; + + rc =evtchn_alloc_unbound (&ec,0 ); +if ( rc ) + { +printk (XENLOG_WARNING "Failed allocating event channel for %pd\n" , + d->d); +return rc; + } + + *port = ec.port; +return 0 ; +} +static size_t __init domain_cmdline_size (const struct boot_info *bi,const struct boot_domain *bd) {
@@ -258,6 +282,8 @@ struct domain *__init arch_create_dom(if ( bd->domid ==DOMID_INVALID )/* Create initial domain. Not d0 for pvshim. */ bd->domid =get_initial_domain_id (); +if ( bd->capabilities &DOMAIN_CAPS_XENSTORE ) + dom_cfg.flags |= XEN_DOMCTL_CDF_xs_domain; d =domain_create (bd->domid, &dom_cfg, ((bd->capabilities &DOMAIN_CAPS_CONTROL ) ? CDF_privileged :0 ) | ((bd->capabilities &DOMAIN_CAPS_HARDWARE ) ? CDF_hardware :0 ));
@@ -328,6 +354,36 @@ struct domain *__init arch_create_dom(int __init arch_builder_finalize (struct boot_info *bi) { +unsigned int i; +struct boot_domain *xs_bd =NULL ; + + i =first_boot_domain_index (bi,DOMAIN_CAPS_XENSTORE ); +if ( i >MAX_NR_BOOTDOMS ) +printk (XENLOG_WARNING "No xenstore domain configured\n" ); +else + xs_bd = &bi->domains[i]; + +for ( i =0 ; i < bi->nr_domains; i++ ) + { +struct boot_domain *bd = &bi->domains[i]; + +if ( xs_bd && xs_bd->d && (bd != xs_bd) && bd->xs_page ) + { +evtchn_port_t xs_evtchn =0 ; + +if (alloc_dom_evtchn (bd, xs_bd, &xs_evtchn) <0 ) +continue ; + +/* Is HVM/PVH */ +if ( !(bd->mode &BUILD_MODE_PARAVIRT ) ) + { +uint64_t *params = bd->d->arch.hvm.params; + params[HVM_PARAM_STORE_PFN ] = bd->xs_page; + params[HVM_PARAM_STORE_EVTCHN ] = xs_evtchn; + } + } + } +/* Free temporary buffers. */ free_boot_modules ();
xen/arch/x86/hvm/dom_build.c +26 -0
@@ -10,6 +10,7 @@#include <xen/acpi.h> #include <xen/domain-builder.h> +#include <xen/event.h> #include <xen/iommu.h> #include <xen/init.h> #include <xen/softirq.h>
@@ -20,6 +21,7 @@#include <public/arch-x86/hvm/start_info.h> #include <public/hvm/e820.h> #include <public/hvm/hvm_vcpu.h> +#include <public/hvm/params.h> #include <asm/bootinfo.h> #include <asm/bzimage.h>
@@ -896,6 +898,27 @@ static int __init pvh_load_kernel(return 0 ; } +static int __init alloc_xenstore_page (struct boot_domain *bd) +{ +paddr_t xs_addr =special_pfn (SPECIALPAGE_XENSTORE ) <<PAGE_SHIFT ; +uint32_t fields[7 ] = {0 ,0 ,0 ,0 ,0 ,1 ,0 }; + +/* +* Set connection field to XENSTORE_RECONNECT, the +* xenstore_domain_interface fields are located after the two 1024 buffers. +*/ +if (hvm_copy_to_guest_phys (xs_addr +2048 , fields,sizeof (fields), + bd->d->vcpu[0 ]) ) + { +printk ("Unable to set xenstore connection state\n" ); +return -EFAULT ; + } + + bd->xs_page =gfn_x (gaddr_to_gfn (xs_addr)); + +return 0 ; +} +int __init dom_construct_pvh (struct boot_domain *bd) {paddr_t entry, start_info;
@@ -972,6 +995,9 @@ int __init dom_construct_pvh(struct boot_domain *bd)return rc; } +if ( !is_xenstore_domain (bd->d) ) +alloc_xenstore_page (bd); +if ( opt_dom0_verbose ) {printk ("Dom%u memory map:\n" , bd->domid);
xen/arch/x86/include/asm/boot-domain.h +3 -0
@@ -10,6 +10,7 @@#include <public/xen.h> #include <public/bootfdt.h> +#include <public/event_channel.h> struct boot_domain {domid_t domid;
@@ -33,6 +34,8 @@ struct boot_domain {const char *cmdline;struct domain *d; + +xen_pfn_t xs_page; };static inline bool __init has_dom0_caps (const struct boot_domain *bd)
xen/arch/x86/include/asm/domain-builder.h +2 -0
@@ -15,6 +15,8 @@ int hvm_steal_ram( struct domain *d, unsigned long size, unsigned long align, paddr_t limit, paddr_t *addr); +int hvm_alloc_xenstore_page (struct boot_domain *bd,xen_pfn_t *xs_gfn); +unsigned long dom_paging_pages (const struct boot_domain *d,unsigned long nr_pages);
Signature · 1 line
2.30.2
RFC v2 29/38 x86/hyperlaunch: allocate console for domu
In reply to Daniel P. SmithDuring domU construction, a page of memory and an event channel must be setup for the console connection. In this commit, a page from the special page region of domU is setup as the console page along with an event channel. The page address and event channel are published in the HVM parameters, so they may be published in Xenstore once it is online.
---
Changes in RFCv2:
- rewrote inline with xenstore changes for event chan
--- xen/arch/x86/domain-builder/domain.c | 24 +++++++++++++++++++++++- xen/arch/x86/hvm/dom_build.c | 24 ++++++++++++++++++++++++ xen/arch/x86/include/asm/boot-domain.h | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-)
xen/arch/x86/domain-builder/domain.c +23 -1
@@ -355,7 +355,7 @@ struct domain *__init arch_create_dom(int __init arch_builder_finalize (struct boot_info *bi) {unsigned int i; -struct boot_domain *xs_bd =NULL ; +struct boot_domain *xs_bd =NULL , *hw_bd =NULL ; i =first_boot_domain_index (bi,DOMAIN_CAPS_XENSTORE );if ( i >MAX_NR_BOOTDOMS )
@@ -363,6 +363,12 @@ int __init arch_builder_finalize(struct boot_info *bi)else xs_bd = &bi->domains[i]; + i =first_boot_domain_index (bi,DOMAIN_CAPS_HARDWARE ); +if ( i >MAX_NR_BOOTDOMS ) +printk (XENLOG_WARNING "No xenstore domain configured\n" ); +else + hw_bd = &bi->domains[i]; +for ( i =0 ; i < bi->nr_domains; i++ ) {struct boot_domain *bd = &bi->domains[i];
@@ -382,6 +388,22 @@ int __init arch_builder_finalize(struct boot_info *bi) params[HVM_PARAM_STORE_EVTCHN ] = xs_evtchn; } } + +if ( hw_bd && hw_bd->d && (bd != hw_bd) && bd->cons_page ) + { +evtchn_port_t ec =0 ; + +if (alloc_dom_evtchn (bd, hw_bd, &ec) <0 ) +continue ; + +/* Is HVM/PVH */ +if ( !(bd->mode &BUILD_MODE_PARAVIRT ) ) + { +uint64_t *params = bd->d->arch.hvm.params; + params[HVM_PARAM_CONSOLE_PFN ] = bd->cons_page; + params[HVM_PARAM_CONSOLE_EVTCHN ] = ec; + } + } }/* Free temporary buffers. */
xen/arch/x86/hvm/dom_build.c +24 -0
@@ -919,6 +919,27 @@ static int __init alloc_xenstore_page(struct boot_domain *bd)return 0 ; } +static int __init alloc_console_page (struct boot_domain *bd) +{ +paddr_t con_addr =special_pfn (SPECIALPAGE_CONSOLE ) <<PAGE_SHIFT ; +uint32_t fields[4 ] = {0 }; + +/* +* Clear the xencons_interface fields that are located after a 1024 rx and +* a 2048 tx buffer, 3072 bytes. +*/ +if (hvm_copy_to_guest_phys (con_addr +3072 , fields,sizeof (fields), + bd->d->vcpu[0 ]) ) + { +printk ("Unable to set xenstore connection state\n" ); +return -EFAULT ; + } + + bd->cons_page =PFN_DOWN (con_addr); + +return 0 ; +} +int __init dom_construct_pvh (struct boot_domain *bd) {paddr_t entry, start_info;
@@ -998,6 +1019,9 @@ int __init dom_construct_pvh(struct boot_domain *bd)if ( !is_xenstore_domain (bd->d) )alloc_xenstore_page (bd); +if ( !is_hardware_domain (bd->d) ) +alloc_console_page (bd); +if ( opt_dom0_verbose ) {printk ("Dom%u memory map:\n" , bd->domid);
xen/arch/x86/include/asm/boot-domain.h +1 -1
@@ -35,7 +35,7 @@ struct boot_domain {struct domain *d; -xen_pfn_t xs_page; +xen_pfn_t xs_page, cons_page; };static inline bool __init has_dom0_caps (const struct boot_domain *bd)
Signature · 1 line
2.30.2