Comet: Run PV in PVH container
PATCH v2 1/62 x86/svm: Offer CPUID Faulting to AMD HVM guests as well
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
CPUID Faulting can be virtulised for HVM guests without hardware support, meaning it can be offered to SVM guests.
--- xen/arch/x86/hvm/svm/svm.c | 6 ++++++ xen/arch/x86/msr.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/svm/svm.c +6 -0
@@ -1786,6 +1786,12 @@ static void svm_vmexit_do_cpuid(struct cpu_user_regs *regs)if ( (inst_len =__get_instruction_length (curr,INSTR_CPUID )) ==0 )return ; +if (hvm_check_cpuid_faulting (curr) ) + { +hvm_inject_hw_exception (TRAP_gp_fault,0 ); +return ; + } +guest_cpuid (curr, regs->eax, regs->ecx, &res);HVMTRACE_5D (CPUID , regs->eax, res.a, res.b, res.c, res.d);
xen/arch/x86/msr.c +2 -1
@@ -39,7 +39,8 @@ static void __init calculate_hvm_max_policy(void)return ;/* 0x000000ce MSR_INTEL_PLATFORM_INFO */ -if ( boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) +if ( boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL || + boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) { dp->plaform_info.available = true; dp->plaform_info.cpuid_faulting = true;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 3/62 tools/libxc: remove extraneous newline in xc_dom_load_acpi
In reply to Wei Liu--- tools/libxc/xc_dom_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxc/xc_dom_core.c +1 -1
@@ -1078,7 +1078,7 @@ static int xc_dom_load_acpi(struct xc_dom_image *dom)while ( (i <MAX_ACPI_MODULES ) && dom->acpi_modules[i].length ) { -DOMPRINTF ("%s: %d bytes at address %" PRIx64"\n" , __FUNCTION__, +DOMPRINTF ("%s: %d bytes at address %" PRIx64, __FUNCTION__, dom->acpi_modules[i].length, dom->acpi_modules[i].guest_addr_out);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 6/62 xen/common: Widen the guest logging buffer slightly
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
This reduces the amount of line wrapping from guests; Xen in particular likes to print lines longer than 80 characters.
--- xen/include/xen/sched.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/xen/sched.h +1 -1
@@ -427,7 +427,7 @@ struct domainxen_domain_handle_t handle;/* hvm_print_line() and guest_console_write() logging. */ -#define DOMAIN_PBUF_SIZE 80 +#define DOMAIN_PBUF_SIZE 200char *pbuf;unsigned pbuf_idx;spinlock_t pbuf_lock;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 5/62 tools/libxc: Multi modules support
In reply to Wei LiuFrom: Jonathan Ludlam <[email protected]>
--- stubdom/grub/kexec.c | 7 +- tools/helpers/init-xenstore-domain.c | 4 +- tools/libxc/include/xc_dom.h | 48 ++++++----- tools/libxc/xc_dom_compat_linux.c | 2 +- tools/libxc/xc_dom_core.c | 152 +++++++++++++++++++++++------------ tools/libxc/xc_dom_x86.c | 65 ++++++++------- tools/libxl/libxl_dom.c | 10 +-- 7 files changed, 175 insertions(+), 113 deletions(-)
stubdom/grub/kexec.c +3 -4
@@ -202,7 +202,7 @@ static void tpm_hash2pcr(struct xc_dom_image *dom, char *cmdline)ASSERT (rv ==0 && resp->status ==0 ); cmd.pcr =bswap_32 (5 );// PCR #5 for initrd -sha1 (dom->ramdisk_blob, dom->ramdisk_size, cmd.hash); +sha1 (dom->modules[0 ].blob, dom->modules[0 ].size, cmd.hash); rv =tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), (void *)&resp, &resplen);ASSERT (rv ==0 && resp->status ==0 );
@@ -231,13 +231,12 @@ void kexec(void *kernel, long kernel_size, void *module, long module_size, char/* We are using guest owned memory, therefore no limits. */ xc_dom_kernel_max_size (dom,0 ); -xc_dom_ramdisk_max_size (dom,0 ); +xc_dom_module_max_size (dom,0 ); dom->kernel_blob = kernel; dom->kernel_size = kernel_size; - dom->ramdisk_blob = module; - dom->ramdisk_size = module_size; +xc_dom_module_mem (dom, module, module_size,NULL ); dom->flags = flags; dom->console_evtchn = start_info.console.domU.evtchn;
tools/helpers/init-xenstore-domain.c +2 -2
@@ -145,10 +145,10 @@ static int build(xc_interface *xch)if ( ramdisk ) { - rv =xc_dom_ramdisk_file (dom, ramdisk); + rv =xc_dom_module_file (dom, ramdisk,NULL );if ( rv ) { -fprintf (stderr,"xc_dom_ramdisk_file failed\n" ); +fprintf (stderr,"xc_dom_module_file failed\n" ); goto err; } }
tools/libxc/include/xc_dom.h +28 -20
97 lines not on this page · raw message
tools/libxc/xc_dom_compat_linux.c +1 -1
@@ -56,7 +56,7 @@ int xc_linux_build(xc_interface *xch, uint32_t domid,if ( (rc =xc_dom_kernel_file (dom, image_name)) !=0 ) goto out;if ( initrd_name &&strlen (initrd_name) && - ((rc =xc_dom_ramdisk_file (dom, initrd_name)) !=0 ) ) + ((rc =xc_dom_module_file (dom, initrd_name,NULL )) !=0 ) ) goto out; dom->flags |= flags;
tools/libxc/xc_dom_core.c +101 -51
239 lines not on this page · raw message
tools/libxc/xc_dom_x86.c +35 -30
143 lines not on this page · raw message
tools/libxl/libxl_dom.c +5 -5
@@ -796,12 +796,12 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid,if ( state->pv_ramdisk.path &&strlen (state->pv_ramdisk.path) ) {if (state->pv_ramdisk.mapped) { -if ( (ret =xc_dom_ramdisk_mem (dom, state->pv_ramdisk.data, state->pv_ramdisk.size)) !=0 ) { +if ( (ret =xc_dom_module_mem (dom, state->pv_ramdisk.data, state->pv_ramdisk.size,NULL )) !=0 ) {LOGE (ERROR ,"xc_dom_ramdisk_mem failed" ); goto out; } }else { -if ( (ret =xc_dom_ramdisk_file (dom, state->pv_ramdisk.path)) !=0 ) { +if ( (ret =xc_dom_module_file (dom, state->pv_ramdisk.path,NULL )) !=0 ) {LOGE (ERROR ,"xc_dom_ramdisk_file failed" ); goto out; }
@@ -1043,14 +1043,14 @@ static int libxl__domain_firmware(libxl__gc *gc,if (state->pv_ramdisk.path &&strlen (state->pv_ramdisk.path)) {if (state->pv_ramdisk.mapped) { - rc =xc_dom_ramdisk_mem (dom, state->pv_ramdisk.data, - state->pv_ramdisk.size); + rc =xc_dom_module_mem (dom, state->pv_ramdisk.data, + state->pv_ramdisk.size,NULL );if (rc) {LOGE (ERROR ,"xc_dom_ramdisk_mem failed" ); goto out; } }else { - rc =xc_dom_ramdisk_file (dom, state->pv_ramdisk.path); + rc =xc_dom_module_file (dom, state->pv_ramdisk.path,NULL );if (rc) {LOGE (ERROR ,"xc_dom_ramdisk_file failed" ); goto out;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 2/62 xen/x86: report domain id on cpuid
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
Use the ECX register of the hypervisor leaf 5. The EAX register on this leaf is a flags field that can be used to notice the presence of the domain id in ECX. Note that this is only available to HVM guests.
---
Changes since v1:
- Use leaf 5 instead.
--- xen/arch/x86/traps.c | 5 +++++ xen/include/public/arch-x86/cpuid.h | 2 ++ 2 files changed, 7 insertions(+)
xen/arch/x86/traps.c +5 -0
@@ -924,6 +924,11 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,/* Indicate presence of vcpu id and set it in ebx */ res->a |=XEN_HVM_CPUID_VCPU_ID_PRESENT ; res->b = v->vcpu_id; + +/* Indicate presence of domain id and set it in ecx */ + res->a |=XEN_HVM_CPUID_DOMID_PRESENT ; + res->c = d->domain_id; +break ;case 5 :/* PV-specific parameters */
xen/include/public/arch-x86/cpuid.h +2 -0
@@ -94,12 +94,14 @@* HVM-specific features * Sub-leaf 0: EAX: Features * Sub-leaf 0: EBX: vcpu id (iff EAX has XEN_HVM_CPUID_VCPU_ID_PRESENT flag) +* Sub-leaf 0: ECX: domain id (iff EAX has XEN_HVM_CPUID_DOMID_PRESENT flag) */ #define XEN_HVM_CPUID_APIC_ACCESS_VIRT (1u << 0)/* Virtualized APIC registers */ #define XEN_HVM_CPUID_X2APIC_VIRT (1u << 1)/* Virtualized x2APIC accesses */ /* Memory mapped from other domains has valid IOMMU entries */ #define XEN_HVM_CPUID_IOMMU_MAPPINGS (1u << 2)#define XEN_HVM_CPUID_VCPU_ID_PRESENT (1u << 3)/* vcpu id is present in EBX */ +#define XEN_HVM_CPUID_DOMID_PRESENT (1u << 4)/* domid is present in ECX */ /* * Leaf 6 (0x40000x05)
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 4/62 tools/libelf: fix elf notes check for PVH guest
In reply to Wei LiuPVH only requires PHYS32_ENTRY to be set. Return immediately if that's the case.
Also remove the printk in pvh_load_kernel.
--- xen/arch/x86/hvm/dom0_build.c | 4 ---- xen/common/libelf/libelf-dominfo.c | 9 ++++++++- 2 files changed, 8 insertions(+), 5 deletions(-)
xen/arch/x86/hvm/dom0_build.c +0 -4
@@ -484,10 +484,6 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image,return -EINVAL ; } -printk ("OS: %s version: %s loader: %s bitness: %s\n" , parms.guest_os, - parms.guest_ver, parms.loader, -elf_64bit (&elf) ?"64-bit" :"32-bit" ); -/* 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;
xen/common/libelf/libelf-dominfo.c +8 -1
@@ -381,6 +381,13 @@ static elf_errorstatus elf_xen_note_check(struct elf_binary *elf,return 0 ; } +/* PVH only requires one ELF note to be set */ +if ( parms->phys_entry !=UNSET_ADDR32 ) + { +elf_msg (elf,"ELF: Found PVH image\n" ); +return 0 ; + } +/* Check the contents of the Xen notes or guest string. */ if ( ((strlen(parms->loader) == 0) || strncmp(parms->loader, "generic", 7)) &&
@@ -389,7 +396,7 @@ static elf_errorstatus elf_xen_note_check(struct elf_binary *elf, {elf_err (elf,"ERROR: Will only load images built for the generic loader or Linux images" -" (Not '%.*s' and '%.*s')\n" , +" (Not '%.*s' and '%.*s') or with PHYS32_ENTRY set\n" , (int )sizeof (parms->loader), parms->loader, (int )sizeof (parms->guest_os), parms->guest_os);return -1 ;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 9/62 ACPICA: Make ACPI Power Management Timer (PM Timer) optional.
In reply to Wei LiuFrom: Bob Moore <[email protected]>
PM Timer is now optional.
This support is already in Windows8 and "SHOULD" come out in ACPI 5.0A (if all goes well).
The change doesn't affect Xen directly, because it does not rely on the presence of the PM timer.
--- xen/drivers/acpi/tables/tbfadt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
xen/drivers/acpi/tables/tbfadt.c +3 -2
@@ -95,7 +95,8 @@ static struct acpi_fadt_info __initdata fadt_info_table[] = { {"PmTimerBlock" ,ACPI_FADT_OFFSET (xpm_timer_block),ACPI_FADT_OFFSET (pm_timer_block), - ACPI_FADT_OFFSET(pm_timer_length), ACPI_FADT_REQUIRED}, +ACPI_FADT_OFFSET (pm_timer_length), + ACPI_FADT_SEPARATE_LENGTH}, /* ACPI 5.0A: Timer is optional */ {"Gpe0Block", ACPI_FADT_OFFSET(xgpe0_block), ACPI_FADT_OFFSET(gpe0_block),
@@ -437,7 +438,7 @@ static void __init acpi_tb_validate_fadt(void)if (fadt_info_table[i].type &ACPI_FADT_REQUIRED ) {/* -* Field is required (Pm1a_event, Pm1a_control, pm_timer). +* Field is required (Pm1a_event, Pm1a_control). * Both the address and length must be non-zero. */ if (!address64->address || !length) {
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
v2 cover Comet: Run PV in PVH container
Hi all
This is a patch series to run PV guest inside a PVH container. It should also support running under HVM mode but we've not extensively tested it. The future plan is for this to merge with the Vixen work Amazon did.
The series can be found at:
https://xenbits.xen.org/git-http/people/liuw/xen.git wip.pvshim-v2.3
The basic idea can be found at page 15 of the slides at [0]. This can be used to mitigate Meltdown as stated in [1].
The difference between Comet and Vixen is discussed somewhere else. Please consult those threads to pick the right short term solution.
This version now has a functional toolstack. A lot of comments in the previous version are addressed, but there are leftovers.
Instructions on using the shim:
1. Git clone the branch and configure as you normally would.
2. A xen-shim binary would be built and installed into Xen's firmware
directory, along side hvmloader and co.
3. Append the following options to guest config file
type = 'pvh'
pvshim = 1
pvshim_cmdline = "xxxx" # if any
pvshim_extra = "xxxx"
Please see xl manpage for more information.
I personally use
pvshim_cmdline="pv-shim console=xen,pv loglvl=all guest_loglvl=all apic_verbosity=debug e820-verbose sched=null"
to get more debugging output.
4. xl create -c guest.cfg
You should be able to see some Xen messages first and then guest kernel messages.
The patch series is split into three parts. Please see the markers.
# Host patches
c2b5d19366 x86/svm: Offer CPUID Faulting to AMD HVM guests as well de1db54d3d xen/x86: report domain id on cpuidfeaddf0628 tools/libxc: remove extraneous newline in xc_dom_load_acpi 2d73544d60 tools/libelf: fix elf notes check for PVH guest 605ecc28ab tools/libxc: Multi modules support8daffd4bba xen/common: Widen the guest logging buffer slightly
# Shim patches
2008783b68 x86/time: Print a more helpful error when a platform timer can't be found aa43415bec x86/link: Introduce and use SECTION_ALIGN53d943eeb8 ACPICA: Make ACPI Power Management Timer (PM Timer) optional. 030f8d0fd6 xen/domctl: Return arch_config via getdomaininfo79fcb598ae tools/ocaml: Expose arch_config in domaininfo990438cd5d tools/ocaml: Extend domain_create() to take arch_domainconfig bd2ccf4c6f x86/fixmap: Modify fix_to_virt() to return a void pointer 8c36939118 x86: Common cpuid faulting supportedcad6ef4b x86/Kconfig: Options for Xen and PVH supporta5446dbf31 x86/link: Relocate program headers80b3a08f9c x86: introduce ELFNOTE macro068933f37a x86: produce a binary that can be booted as PVH3acd23e0a1 x86/entry: Early PVH boot codecdd1de873d x86/boot: Map more than the first 16MB3f6c1c33ec x86/entry: Probe for Xen early during boot855856e857 x86/guest: Hypercall supportf204a73fef x86/shutdown: Support for using SCHEDOP_{shutdown,reboot} 3c9590135d x86/pvh: Retrieve memory map from Xen85cfd2a735 xen/console: Introduce console=xen47ad4ecf25 xen: introduce rangeset_claim_range971b5c8d1f xen/pvshim: keep track of used PFN rangese3039f2df0 x86/guest: map shared_info page
3997881097 xen/guest: fetch vCPU ID from Xend693b10299 x86/guest: map per-cpu vcpu_info area.c582962ac7 x86: xen pv clock time source2e8afc1ead x86: APIC timer calibration when running as a guest b5a6e58ff3 x86: read wallclock from Xen when running in pvh mode bc3e5e866a x86: don't swallow the first command line item in guest mode 09cedc3af3 x86/guest: setup event channel upcall vector8343a651ea x86/guest: add PV console codeec8fb8f7a1 x86/guest: use PV console for Xen/Dom0 I/O1ec222a153 x86/shim: Kconfig and command line options0620686d72 tools/firmware: Build and install xen-shim536339a994 xen/x86: make VGA support selectable21f0a6ed97 xen/pvh: do not mark the low 1MB as IO memdb104c0391 sched/null: skip vCPUs on the waitqueue that are blocked 549dba6a5a xen/pvshim: skip Dom0-only domain builder parts1bba66e4c7 xen: mark xenstore/console pages as RAMb907ed7322 xen/pvshim: modify Dom0 builder in order to build a DomU 867380c40e xen/pvshim: set correct domid valued3682baafb xen/pvshim: forward evtchn ops between L0 Xen and L2 DomU 25f682b751 xen/pvshim: add grant table operationsc538c7f635 x86/pv-shim: shadow PV console's page for L2 DomU 85d142a053 xen/pvshim: add migration support92612a97ef xen/pvshim: add shim_mem cmdline parameter1f64261cca xen/pvshim: set max_pages to the value of tot_pages f9f9265f0e xen/pvshim: support vCPU hotplug7f723b6dff xen/pvshim: memory hotplug5016c05fc9 xen/shim: modify shim_mem parameter behaviour4f4cf3304a xen/pvshim: use default position for the m2p mappings c7bde74df9 xen/shim: crash instead of reboot in shim modef842ed539a xen/shim: allow DomU to have as many vcpus as available
# Toolstack patches
5c43c5721c libxl: pvshim: Provide first-class config settings to enable shim mode 6833537050 libxl: pvshim: Introduce pvshim_extrac128981e73 xl: pvshim: Provide and document xl config4689dc2e29 xl: Default guest mode changed from PV to PVH with PV shim
Wei.
[0] https://www.slideshare.net/xen_com_mgr/xpdds17-keynote-towards-a-configurable-and-slimmer-x86-hypervisor-wei-liu-citrix
[1] https://xenbits.xen.org/xsa/advisory-254.html
.gitignore | 5 + docs/man/xl.cfg.pod.5.in | 35 ++ docs/misc/xen-command-line.markdown | 36 +- stubdom/grub/kexec.c | 7 +- tools/firmware/Makefile | 9 + tools/firmware/xen-dir/Makefile | 59 +++ tools/firmware/xen-dir/shim.config | 85 +++ tools/helpers/init-xenstore-domain.c | 4 +- tools/libxc/include/xc_dom.h | 48 +- tools/libxc/include/xenctrl.h | 1 + tools/libxc/xc_dom_compat_linux.c | 2 +- tools/libxc/xc_dom_core.c | 154 ++++-- tools/libxc/xc_dom_x86.c | 65 +-- tools/libxc/xc_domain.c | 1 + tools/libxl/libxl.h | 8 + tools/libxl/libxl_create.c | 22 +- tools/libxl/libxl_dom.c | 67 ++- tools/libxl/libxl_internal.h | 4 + tools/libxl/libxl_types.idl | 6 +- tools/ocaml/libs/xc/xenctrl.ml | 31 +- tools/ocaml/libs/xc/xenctrl.mli | 30 +- tools/ocaml/libs/xc/xenctrl_stubs.c | 48 +- tools/xl/xl_parse.c | 25 +- xen/Makefile | 16 +- xen/arch/x86/Kconfig | 40 +- xen/arch/x86/Makefile | 9 + xen/arch/x86/acpi/lib.c | 2 +- xen/arch/x86/apic.c | 38 +- xen/arch/x86/boot/build32.mk | 1 + xen/arch/x86/boot/cmdline.c | 5 +- xen/arch/x86/boot/head.S | 47 ++ xen/arch/x86/boot/trampoline.S | 7 + xen/arch/x86/boot/x86_64.S | 5 +- xen/arch/x86/compat.c | 4 +- xen/arch/x86/cpu/amd.c | 16 +- xen/arch/x86/cpu/common.c | 76 ++- xen/arch/x86/cpu/intel.c | 81 +-- xen/arch/x86/dom0_build.c | 48 +- xen/arch/x86/domctl.c | 2 + xen/arch/x86/e820.c | 7 +- xen/arch/x86/efi/efi-boot.h | 4 + xen/arch/x86/guest/Makefile | 4 + xen/arch/x86/guest/hypercall_page.S | 79 +++ xen/arch/x86/guest/pvh-boot.c | 139 +++++ xen/arch/x86/guest/xen.c | 388 ++++++++++++++ xen/arch/x86/hvm/dom0_build.c | 4 - xen/arch/x86/hvm/svm/svm.c | 6 + xen/arch/x86/mm.c | 13 +- xen/arch/x86/mpparse.c | 2 +- xen/arch/x86/msi.c | 3 +- xen/arch/x86/msr.c | 3 +- xen/arch/x86/platform_hypercall.c | 2 + xen/arch/x86/pv/Makefile | 1 + xen/arch/x86/pv/dom0_build.c | 58 ++- xen/arch/x86/pv/hypercall.c | 17 + xen/arch/x86/pv/shim.c | 957 ++++++++++++++++++++++++++++++++++ xen/arch/x86/setup.c | 84 ++- xen/arch/x86/shutdown.c | 39 +- xen/arch/x86/smpboot.c | 4 + xen/arch/x86/tboot.c | 4 +- xen/arch/x86/time.c | 124 ++++- xen/arch/x86/traps.c | 5 + xen/arch/x86/xen.lds.S | 82 ++- xen/common/domain.c | 53 +- xen/common/event_channel.c | 99 ++-- xen/common/libelf/libelf-dominfo.c | 9 +- xen/common/memory.c | 21 + xen/common/page_alloc.c | 15 + xen/common/rangeset.c | 52 ++ xen/common/sched_null.c | 11 +- xen/common/schedule.c | 3 +- xen/drivers/acpi/apei/apei-io.c | 2 +- xen/drivers/acpi/tables/tbfadt.c | 5 +- xen/drivers/char/Makefile | 2 + xen/drivers/char/console.c | 72 +++ xen/drivers/char/consoled.c | 148 ++++++ xen/drivers/char/ehci-dbgp.c | 2 +- xen/drivers/char/ns16550.c | 2 +- xen/drivers/char/xen_pv_console.c | 208 ++++++++ xen/drivers/video/Kconfig | 8 +- xen/include/asm-x86/apicdef.h | 2 +- xen/include/asm-x86/asm_defns.h | 12 + xen/include/asm-x86/cpuid.h | 3 - xen/include/asm-x86/dom0_build.h | 4 + xen/include/asm-x86/e820.h | 1 + xen/include/asm-x86/fixmap.h | 6 +- xen/include/asm-x86/guest.h | 37 ++ xen/include/asm-x86/guest/hypercall.h | 206 ++++++++ xen/include/asm-x86/guest/pvh-boot.h | 57 ++ xen/include/asm-x86/guest/xen.h | 92 ++++ xen/include/asm-x86/hypercall.h | 3 + xen/include/asm-x86/processor.h | 4 +- xen/include/asm-x86/pv/shim.h | 107 ++++ xen/include/asm-x86/setup.h | 6 + xen/include/public/arch-x86/cpuid.h | 2 + xen/include/public/domctl.h | 3 +- xen/include/xen/consoled.h | 27 + xen/include/xen/domain.h | 1 + xen/include/xen/event.h | 15 + xen/include/xen/pv_console.h | 38 ++ xen/include/xen/rangeset.h | 4 +- xen/include/xen/sched.h | 4 +- 102 files changed, 4106 insertions(+), 418 deletions(-) create mode 100644 tools/firmware/xen-dir/Makefile create mode 100644 tools/firmware/xen-dir/shim.config create mode 100644 xen/arch/x86/guest/Makefile create mode 100644 xen/arch/x86/guest/hypercall_page.S create mode 100644 xen/arch/x86/guest/pvh-boot.c create mode 100644 xen/arch/x86/guest/xen.c create mode 100644 xen/arch/x86/pv/shim.c create mode 100644 xen/drivers/char/consoled.c create mode 100644 xen/drivers/char/xen_pv_console.c create mode 100644 xen/include/asm-x86/guest.h create mode 100644 xen/include/asm-x86/guest/hypercall.h create mode 100644 xen/include/asm-x86/guest/pvh-boot.h create mode 100644 xen/include/asm-x86/guest/xen.h create mode 100644 xen/include/asm-x86/pv/shim.h create mode 100644 xen/include/xen/consoled.h create mode 100644 xen/include/xen/pv_console.h
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 8/62 x86/link: Introduce and use SECTION_ALIGN
From: Andrew Cooper <[email protected]>
... to reduce the quantity of #ifdef EFI.
---
CC: Jan Beulich <[email protected]>
--- xen/arch/x86/xen.lds.S | 50 +++++++++++++------------------------------------- 1 file changed, 13 insertions(+), 37 deletions(-)
xen/arch/x86/xen.lds.S +13 -37
@@ -12,12 +12,14 @@ #define FORMAT "pei-x86-64" #undef __XEN_VIRT_START #define __XEN_VIRT_START __image_base__ +#define SECTION_ALIGN MB(2) ENTRY(efi_start) #else /* !EFI */ #define FORMAT "elf64-x86-64" +#define SECTION_ALIGN PAGE_SIZE ENTRY(start)
@@ -67,11 +69,7 @@ SECTIONS _etext = .; /* End of text section */ } :text = 0x9090 -#ifdef EFI - . = ALIGN(MB(2)); -#else - . = ALIGN(PAGE_SIZE); -#endif + . = ALIGN(SECTION_ALIGN); __2M_text_end = .; __2M_rodata_start = .; /* Start of 2M superpages, mapped RO. */
@@ -149,11 +147,7 @@ SECTIONS #endif _erodata = .; -#ifdef EFI - . = ALIGN(MB(2)); -#else - . = ALIGN(PAGE_SIZE); -#endif + . = ALIGN(SECTION_ALIGN); __2M_rodata_end = .; __2M_init_start = .; /* Start of 2M superpages, mapped RWX (boot only). */
@@ -215,11 +209,7 @@ SECTIONS __ctors_end = .; } :text -#ifdef EFI - . = ALIGN(MB(2)); -#else - . = ALIGN(PAGE_SIZE); -#endif + . = ALIGN(SECTION_ALIGN); __init_end = .; __2M_init_end = .;
@@ -257,11 +247,7 @@ SECTIONS } :text _end = . ; -#ifdef EFI - . = ALIGN(MB(2)); -#else - . = ALIGN(PAGE_SIZE); -#endif + . = ALIGN(SECTION_ALIGN); __2M_rwdata_end = .; #ifdef EFI
@@ -310,23 +296,13 @@ ASSERT(__image_base__ > XEN_VIRT_START || ASSERT(kexec_reloc_size - kexec_reloc <= PAGE_SIZE, "kexec_reloc is too large") #endif -#ifdef EFI -ASSERT(IS_ALIGNED(__2M_text_end, MB(2)), "__2M_text_end misaligned") -ASSERT(IS_ALIGNED(__2M_rodata_start, MB(2)), "__2M_rodata_start misaligned") -ASSERT(IS_ALIGNED(__2M_rodata_end, MB(2)), "__2M_rodata_end misaligned") -ASSERT(IS_ALIGNED(__2M_init_start, MB(2)), "__2M_init_start misaligned") -ASSERT(IS_ALIGNED(__2M_init_end, MB(2)), "__2M_init_end misaligned") -ASSERT(IS_ALIGNED(__2M_rwdata_start, MB(2)), "__2M_rwdata_start misaligned") -ASSERT(IS_ALIGNED(__2M_rwdata_end, MB(2)), "__2M_rwdata_end misaligned") -#else -ASSERT(IS_ALIGNED(__2M_text_end, PAGE_SIZE), "__2M_text_end misaligned") -ASSERT(IS_ALIGNED(__2M_rodata_start, PAGE_SIZE), "__2M_rodata_start misaligned") -ASSERT(IS_ALIGNED(__2M_rodata_end, PAGE_SIZE), "__2M_rodata_end misaligned") -ASSERT(IS_ALIGNED(__2M_init_start, PAGE_SIZE), "__2M_init_start misaligned") -ASSERT(IS_ALIGNED(__2M_init_end, PAGE_SIZE), "__2M_init_end misaligned") -ASSERT(IS_ALIGNED(__2M_rwdata_start, PAGE_SIZE), "__2M_rwdata_start misaligned") -ASSERT(IS_ALIGNED(__2M_rwdata_end, PAGE_SIZE), "__2M_rwdata_end misaligned") -#endif +ASSERT(IS_ALIGNED(__2M_text_end, SECTION_ALIGN), "__2M_text_end misaligned") +ASSERT(IS_ALIGNED(__2M_rodata_start, SECTION_ALIGN), "__2M_rodata_start misaligned") +ASSERT(IS_ALIGNED(__2M_rodata_end, SECTION_ALIGN), "__2M_rodata_end misaligned") +ASSERT(IS_ALIGNED(__2M_init_start, SECTION_ALIGN), "__2M_init_start misaligned") +ASSERT(IS_ALIGNED(__2M_init_end, SECTION_ALIGN), "__2M_init_end misaligned") +ASSERT(IS_ALIGNED(__2M_rwdata_start, SECTION_ALIGN), "__2M_rwdata_start misaligned") +ASSERT(IS_ALIGNED(__2M_rwdata_end, SECTION_ALIGN), "__2M_rwdata_end misaligned") ASSERT(IS_ALIGNED(cpu0_stack, STACK_SIZE), "cpu0_stack misaligned")
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 7/62 x86/time: Print a more helpful error when a platform timer can't be found
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
--- xen/arch/x86/time.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/time.c +2 -1
@@ -708,7 +708,8 @@ static u64 __init init_platform_timer(void) } } -BUG_ON (rc <=0 ); +if ( rc <=0 ) +panic ("Unable to find usable platform timer" );printk ("Platform timer is %s %s\n" ,freq_string (pts->frequency), pts->name);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 14/62 x86: Common cpuid faulting support
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
With CPUID Faulting offered to SVM guests, move Xen's faulting code to being common rather than Intel specific.
This is necessary for nested Xen (inc. pv-shim mode) to prevent PV guests from finding the outer HVM Xen leaves via native cpuid.
--- xen/arch/x86/cpu/amd.c | 16 +++++--- xen/arch/x86/cpu/common.c | 76 ++++++++++++++++++++++++++++++++++++-- xen/arch/x86/cpu/intel.c | 81 +++++++---------------------------------- xen/include/asm-x86/cpuid.h | 3 -- xen/include/asm-x86/processor.h | 4 +- 5 files changed, 98 insertions(+), 82 deletions(-)
xen/arch/x86/cpu/amd.c +10 -6
@@ -198,11 +198,12 @@ static void __init noinline probe_masking_msrs(void) }/* -* Context switch levelling state to the next domain. A parameter of NULL is -* used to context switch to the default host state (by the cpu bringup-code, -* crash path, etc). +* Context switch CPUID masking state to the next domain. Only called if +* CPUID Faulting isn't available, but masking MSRs have been detected. A +* parameter of NULL is used to context switch to the default host state (by +* the cpu bringup-code, crash path, etc). */ -static void amd_ctxt_switch_levelling (const struct vcpu *next) +static void amd_ctxt_switch_masking (const struct vcpu *next) {struct cpuidmasks *these_masks = &this_cpu (cpuidmasks);const struct domain *nextd = next ? next->domain :NULL ;
@@ -263,6 +264,9 @@ static void __init noinline amd_init_levelling(void) {const struct cpuidmask *m =NULL ; +if (probe_cpuid_faulting ()) +return ; +probe_masking_msrs ();if (*opt_famrev !='\0' ) {
@@ -352,7 +356,7 @@ static void __init noinline amd_init_levelling(void) }if (levelling_caps) - ctxt_switch_levelling = amd_ctxt_switch_levelling; + ctxt_switch_masking = amd_ctxt_switch_masking; }/*
@@ -518,7 +522,7 @@ static void early_init_amd(struct cpuinfo_x86 *c)if (c == &boot_cpu_data)amd_init_levelling (); -amd_ctxt_switch_levelling (NULL ); +ctxt_switch_levelling (NULL ); }static void init_amd (struct cpuinfo_x86 *c)
xen/arch/x86/cpu/common.c +72 -4
84 lines not on this page · raw message
xen/arch/x86/cpu/intel.c +13 -68
115 lines not on this page · raw message
xen/include/asm-x86/cpuid.h +0 -3
@@ -58,9 +58,6 @@ DECLARE_PER_CPU(struct cpuidmasks, cpuidmasks);/* Default masking MSR values, calculated at boot. */ extern struct cpuidmasks cpuidmask_defaults; -/* Whether or not cpuid faulting is available for the current domain. */ -DECLARE_PER_CPU (bool, cpuid_faulting_enabled); -#define CPUID_GUEST_NR_BASIC (0xdu + 1)#define CPUID_GUEST_NR_FEAT (0u + 1)#define CPUID_GUEST_NR_CACHE (5u + 1)
xen/include/asm-x86/processor.h +3 -1
@@ -151,7 +151,9 @@ extern struct cpuinfo_x86 boot_cpu_data;extern struct cpuinfo_x86 cpu_data[];#define current_cpu_data cpu_data[smp_processor_id()] -extern void (*ctxt_switch_levelling)(const struct vcpu *next); +extern bool probe_cpuid_faulting (void ); +extern void ctxt_switch_levelling (const struct vcpu *next); +extern void (*ctxt_switch_masking)(const struct vcpu *next);extern u64 host_pat;extern bool_t opt_cpu_info;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 24/62 x86/pvh: Retrieve memory map from Xen
In reply to Wei Liu---
v2: fixed clang build, dropped rb tag
--- xen/arch/x86/e820.c | 3 +-- xen/arch/x86/guest/pvh-boot.c | 20 ++++++++++++++++++++ xen/arch/x86/guest/xen.c | 3 +++ xen/arch/x86/setup.c | 7 ++++++- xen/include/asm-x86/e820.h | 1 + xen/include/asm-x86/guest/hypercall.h | 5 +++++ 6 files changed, 36 insertions(+), 3 deletions(-)
xen/arch/x86/e820.c +1 -2
@@ -134,8 +134,7 @@ static struct change_member *change_point[2*E820MAX] __initdata;static struct e820entry *overlap_list[E820MAX ]__initdata ;static struct e820entry new_bios[E820MAX ]__initdata ; -static int __init sanitize_e820_map (struct e820entry *biosmap, -unsigned int *pnr_map) +int __init sanitize_e820_map (struct e820entry *biosmap,unsigned int *pnr_map) {struct change_member *change_tmp;unsigned long current_type, last_type;
xen/arch/x86/guest/pvh-boot.c +20 -0
@@ -22,6 +22,7 @@#include <xen/lib.h> #include <xen/mm.h> +#include <asm/e820.h> #include <asm/guest.h> #include <public/arch-x86/hvm/start_info.h>
@@ -70,10 +71,29 @@ static void __init convert_pvh_info(void) } } +static void __init get_memory_map (void ) +{ +struct xen_memory_map memmap = { + .nr_entries =E820MAX , + }; + +set_xen_guest_handle (memmap.buffer, e820_raw.map); +BUG_ON (xen_hypercall_memory_op (XENMEM_memory_map, &memmap)); + e820_raw.nr_map = memmap.nr_entries; + +/* :( Various toolstacks don't sort the memory map. */ +sanitize_e820_map (e820_raw.map, &e820_raw.nr_map); +} +multiboot_info_t *__init pvh_init (void ) {convert_pvh_info (); +probe_hypervisor (); +ASSERT (xen_guest); + +get_memory_map (); +return &pvh_mbi; }
xen/arch/x86/guest/xen.c +3 -0
@@ -54,6 +54,9 @@ static void __init find_xen_leaves(void)void __init probe_hypervisor (void ) { +if ( xen_guest ) +return ; +/* Too early to use cpu_has_hypervisor */ if ( !(cpuid_ecx (1 ) &cpufeat_mask (X86_FEATURE_HYPERVISOR )) )return ;
xen/arch/x86/setup.c +6 -1
@@ -795,7 +795,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)if ( !(mbi->flags &MBI_MODULES ) || (mbi->mods_count ==0 ) )panic ("dom0 kernel not specified. Check bootloader configuration." ); -if (efi_enabled (EFI_LOADER ) ) +if ( pvh_boot ) + { +/* pvh_init() already filled in e820_raw */ + memmap_type ="PVH-e820" ; + } +else if (efi_enabled (EFI_LOADER ) ) {set_pdx_range (xen_phys_start >>PAGE_SHIFT , (xen_phys_start +BOOTSTRAP_MAP_BASE ) >>PAGE_SHIFT );
xen/include/asm-x86/e820.h +1 -0
@@ -23,6 +23,7 @@ struct e820map {struct e820entry map[E820MAX ]; }; +extern int sanitize_e820_map (struct e820entry *biosmap,unsigned int *pnr_map);extern int e820_all_mapped (u64 start,u64 end,unsigned type);extern int reserve_e820_ram (struct e820map *e820,uint64_t s,uint64_t e); extern int e820_change_range_type(
xen/include/asm-x86/guest/hypercall.h +5 -0
@@ -91,6 +91,11 @@ static inline long xen_hypercall_sched_op(unsigned int cmd, void *arg)return _hypercall64_2 (long, __HYPERVISOR_sched_op, cmd, arg); } +static inline long xen_hypercall_memory_op (unsigned int cmd,void *arg) +{ +return _hypercall64_2 (long, __HYPERVISOR_memory_op, cmd, arg); +} +/* * Higher level hypercall helpers */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 47/62 xen/pvshim: forward evtchn ops between L0 Xen and L2 DomU
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
Note that the unmask and the virq operations are handled by the shim itself, and that FIFO event channels are not exposed to the guest.
---
Changes since v1:
- Use find_first_set_bit instead of ffsl.
- Indent macro one more level.
- Have a single evtchn_close struct in pv_shim_event_channel_op.
- Add blank lines between switch cases.
- Use -EOPNOTSUPP in order to signal lack of FIFO or PIRQ support.
- Switch evtchn_bind_virq parameter to evtchn_port_t and use 0 signal allocation needed.
- Switch evtchn helpers return type to int instead of long.
- Re-write event channel hypercall table handler instead of adding hooks.
- Remove the pv_domain variable and instead use a static variable in shim code.
--- xen/arch/x86/compat.c | 4 +- xen/arch/x86/guest/xen.c | 25 +++- xen/arch/x86/pv/hypercall.c | 17 +++ xen/arch/x86/pv/shim.c | 263 ++++++++++++++++++++++++++++++++++++++ xen/common/event_channel.c | 99 ++++++++------ xen/drivers/char/xen_pv_console.c | 11 +- xen/include/asm-x86/hypercall.h | 3 + xen/include/asm-x86/pv/shim.h | 5 + xen/include/xen/event.h | 15 +++ xen/include/xen/pv_console.h | 6 + 10 files changed, 402 insertions(+), 46 deletions(-)
xen/arch/x86/compat.c +2 -2
@@ -69,8 +69,8 @@ long do_event_channel_op_compat(XEN_GUEST_HANDLE_PARAM(evtchn_op_t) uop)case EVTCHNOP_bind_ipi:case EVTCHNOP_bind_vcpu:case EVTCHNOP_unmask: -return do_event_channel_op (op.cmd, -guest_handle_from_ptr (&uop.p->u, void)); +return pv_get_hypercall_handler (__HYPERVISOR_event_channel_op, false) + (op.cmd, (unsigned long )&uop.p->u,0 ,0 ,0 ,0 );default :return -ENOSYS ;
xen/arch/x86/guest/xen.c +23 -2
@@ -18,6 +18,7 @@* * Copyright (c) 2017 Citrix Systems Ltd. */ +#include <xen/event.h> #include <xen/init.h> #include <xen/mm.h> #include <xen/pfn.h>
@@ -193,11 +194,31 @@ static void __init init_memmap(void)static void xen_evtchn_upcall (struct cpu_user_regs *regs) {struct vcpu_info *vcpu_info =this_cpu (vcpu_info); +unsigned long pending; vcpu_info->evtchn_upcall_pending =0 ; -write_atomic (&vcpu_info->evtchn_pending_sel,0 ); + pending =xchg (&vcpu_info->evtchn_pending_sel,0 ); -pv_console_rx (regs); +while ( pending ) + { +unsigned int l1 =find_first_set_bit (pending); +unsigned long evtchn =xchg (&XEN_shared_info->evtchn_pending[l1],0 ); + +__clear_bit (l1, &pending); + evtchn &= ~XEN_shared_info->evtchn_mask[l1]; +while ( evtchn ) + { +unsigned int port =find_first_set_bit (evtchn); + +__clear_bit (port, &evtchn); + port += l1 *BITS_PER_LONG ; + +if ( pv_console && port ==pv_console_evtchn () ) +pv_console_rx (regs); +else if ( pv_shim ) +pv_shim_inject_evtchn (port); + } + }ack_APIC_irq (); }
xen/arch/x86/pv/hypercall.c +17 -0
@@ -320,6 +320,23 @@ void hypercall_page_initialise_ring1_kernel(void *hypercall_page) *(u16 *)(p+6 ) = (HYPERCALL_VECTOR <<8 ) |0xcd ;/* int $xx */ } +void __init pv_hypercall_table_replace (unsigned int hypercall, +hypercall_fn_t * native, +hypercall_fn_t *compat) +{ +#define HANDLER_POINTER (f) \ + ((unsigned long *)__va(__pa(&pv_hypercall_table[hypercall].f))) +write_atomic (HANDLER_POINTER (native), (unsigned long )native); +write_atomic (HANDLER_POINTER (compat), (unsigned long )compat); +#undef HANDLER_POINTER +} + +hypercall_fn_t *pv_get_hypercall_handler (unsigned int hypercall,bool compat) +{ +return compat ? pv_hypercall_table[hypercall].compat + : pv_hypercall_table[hypercall].native; +} +/* * Local variables: * mode: C
xen/arch/x86/pv/shim.c +263 -0
299 lines not on this page · raw message
xen/common/event_channel.c +63 -36
165 lines not on this page · raw message
xen/drivers/char/xen_pv_console.c +5 -6
@@ -88,6 +88,11 @@ static void notify_daemon(void)xen_hypercall_evtchn_send (cons_evtchn); } +evtchn_port_t pv_console_evtchn (void ) +{ +return cons_evtchn; +} +size_t pv_console_rx (struct cpu_user_regs *regs) {char c;
@@ -97,10 +102,6 @@ size_t pv_console_rx(struct cpu_user_regs *regs)if ( !cons_ring )return 0 ; -/* TODO: move this somewhere */ -if ( !test_bit (cons_evtchn, XEN_shared_info->evtchn_pending) ) -return 0 ; - prod =ACCESS_ONCE (cons_ring->in_prod); cons = cons_ring->in_cons;
@@ -125,8 +126,6 @@ size_t pv_console_rx(struct cpu_user_regs *regs)ACCESS_ONCE (cons_ring->in_cons) = cons;notify_daemon (); -clear_bit (cons_evtchn, XEN_shared_info->evtchn_pending); -return recv; }
xen/include/asm-x86/hypercall.h +3 -0
@@ -28,6 +28,9 @@ extern const hypercall_args_t hypercall_args_table[NR_hypercalls];void pv_hypercall (struct cpu_user_regs *regs);void hypercall_page_initialise_ring3_kernel (void *hypercall_page);void hypercall_page_initialise_ring1_kernel (void *hypercall_page); +void pv_hypercall_table_replace (unsigned int hypercall,hypercall_fn_t * native, +hypercall_fn_t *compat); +hypercall_fn_t *pv_get_hypercall_handler (unsigned int hypercall,bool compat);/* * Both do_mmuext_op() and do_mmu_update():
xen/include/asm-x86/pv/shim.h +5 -0
@@ -36,6 +36,7 @@ void pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, unsigned long console_va, unsigned long vphysmap, start_info_t *si);void pv_shim_shutdown (uint8_t reason); +void pv_shim_inject_evtchn (unsigned int port);domid_t get_initial_domain_id (void );#else
@@ -53,6 +54,10 @@ static inline void pv_shim_shutdown(uint8_t reason) {ASSERT_UNREACHABLE (); } +static inline void pv_shim_inject_evtchn (unsigned int port) +{ +ASSERT_UNREACHABLE (); +}static inline domid_t get_initial_domain_id (void ) {return 0 ;
xen/include/xen/event.h +15 -0
@@ -48,6 +48,21 @@ int evtchn_send(struct domain *d, unsigned int lport);/* Bind a local event-channel port to the specified VCPU. */ long evtchn_bind_vcpu (unsigned int port,unsigned int vcpu_id); +/* Bind a VIRQ. */ +int evtchn_bind_virq (evtchn_bind_virq_t *bind,evtchn_port_t port); + +/* Get the status of an event channel port. */ +int evtchn_status (evtchn_status_t *status); + +/* Close an event channel. */ +int evtchn_close (struct domain *d1,int port1,bool guest); + +/* Free an event channel. */ +void evtchn_free (struct domain *d,struct evtchn *chn); + +/* Allocate a specific event channel port. */ +int evtchn_allocate_port (struct domain *d,unsigned int port); +/* Unmask a local event-channel port. */ int evtchn_unmask (unsigned int port);
xen/include/xen/pv_console.h +6 -0
@@ -10,6 +10,7 @@ void pv_console_set_rx_handler(serial_rx_fn fn);void pv_console_init_postirq (void );void pv_console_puts (const char *buf);size_t pv_console_rx (struct cpu_user_regs *regs); +evtchn_port_t pv_console_evtchn (void );#else
@@ -18,6 +19,11 @@ static inline void pv_console_set_rx_handler(serial_rx_fn fn) { }static inline void pv_console_init_postirq (void ) { }static inline void pv_console_puts (const char *buf) { }static inline size_t pv_console_rx (struct cpu_user_regs *regs) {return 0 ; } +evtchn_port_t pv_console_evtchn (void ) +{ +ASSERT_UNREACHABLE (); +return 0 ; +}#endif /* !CONFIG_XEN_GUEST */ #endif /* __XEN_PV_CONSOLE_H__ */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 28/62 x86/guest: map shared_info page
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
Use an unpopulated PFN in order to map it.
---
Changes since v1:
- Use an unpopulated PFN to map the shared_info page.
- Mask all event channels.
- Report XENMEM_add_to_physmap error code in case of failure.
--- xen/arch/x86/guest/xen.c | 27 +++++++++++++++++++++++++++ xen/include/asm-x86/fixmap.h | 3 +++ xen/include/asm-x86/guest/xen.h | 5 +++++ 3 files changed, 35 insertions(+)
xen/arch/x86/guest/xen.c +27 -0
@@ -77,6 +77,31 @@ void __init probe_hypervisor(void) xen_guest = true; } +static void map_shared_info (void ) +{ +mfn_t mfn; +struct xen_add_to_physmap xatp = { + .domid =DOMID_SELF , + .space = XENMAPSPACE_shared_info, + }; +unsigned int i; +unsigned long rc; + +if (hypervisor_alloc_unused_page (&mfn) ) +panic ("unable to reserve shared info memory page" ); + + xatp.gpfn =mfn_x (mfn); + rc =xen_hypercall_memory_op (XENMEM_add_to_physmap, &xatp); +if ( rc ) +panic ("failed to map shared_info page: %ld" , rc); + +set_fixmap (FIX_XEN_SHARED_INFO ,mfn_x (mfn) <<PAGE_SHIFT ); + +/* Mask all upcalls */ +for ( i =0 ; i <ARRAY_SIZE (XEN_shared_info->evtchn_mask); i++ ) +write_atomic (&XEN_shared_info->evtchn_mask[i], ~0ul ); +} +static void __init init_memmap (void ) {unsigned int i;
@@ -109,6 +134,8 @@ static void __init init_memmap(void)void __init hypervisor_setup (void ) {init_memmap (); + +map_shared_info (); }int hypervisor_alloc_unused_page (mfn_t *mfn)
xen/include/asm-x86/fixmap.h +3 -0
@@ -45,6 +45,9 @@ enum fixed_addresses {FIX_COM_BEGIN ,FIX_COM_END ,FIX_EHCI_DBGP , +#ifdef CONFIG_XEN_GUEST +FIX_XEN_SHARED_INFO , +#endif /* CONFIG_XEN_GUEST *//* Everything else should go further down. */ FIX_APIC_BASE , FIX_IO_APIC_BASE_0,
xen/include/asm-x86/guest/xen.h +5 -0
@@ -21,6 +21,11 @@#include <xen/types.h> +#include <asm/e820.h> +#include <asm/fixmap.h> + +#define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_INFO)) +#ifdef CONFIG_XEN_GUEST extern bool xen_guest;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 51/62 xen/pvshim: add shim_mem cmdline parameter
In reply to Wei LiuFrom: Sergey Dyasli <[email protected]>
--- docs/misc/xen-command-line.markdown | 16 +++++++++++++ xen/arch/x86/dom0_build.c | 18 ++++++++++++++- xen/arch/x86/pv/shim.c | 46 +++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/pv/shim.h | 6 +++++ 4 files changed, 85 insertions(+), 1 deletion(-)
docs/misc/xen-command-line.markdown +16 -0
@@ -686,6 +686,8 @@ any dom0 autoballooning feature present in your toolstack. See the _xl.conf(5)_ man page or [Xen Best Practices](http://wiki.xen.org/wiki/Xen_Best_Practices#Xen_dom0_dedicated_memory_and_preventing_dom0_memory_ballooning). +This option doesn't have effect if pv-shim mode is enabled. + ### dom0\_nodes > `= List of [ <integer> | relaxed | strict ]`
@@ -1456,6 +1458,20 @@ guest compatibly inside an HVM container. In this mode, the kernel and initrd passed as modules to the hypervisor are constructed into a plain unprivileged PV domain. +### shim\_mem (x86) +> `= List of ( min:<size> | max:<size> | <size> )` + +Set the amount of memory that xen-shim reserves for itself. Only has effect +if pv-shim mode is enabled. + +* `min:<size>` specifies the minimum amount of memory. Ignored if greater + than max. Default: 10M. +* `max:<size>` specifies the maximum amount of memory. Default: 128M. +* `<size>` specifies the exact amount of memory. Overrides both min and max. + +By default, 1/16th of total HVM container's memory is reserved for xen-shim +with minimum amount being 10MB and maximum amount 128MB. + ### rcu-idle-timer-period-ms > `= <integer>`
xen/arch/x86/dom0_build.c +17 -1
@@ -51,6 +51,13 @@ static long __init parse_amt(const char *s, const char **ps)static int __init parse_dom0_mem (const char *s) { +/* xen-shim uses shim_mem parameter instead of dom0_mem */ +if ( pv_shim ) + { +printk ("Ignoring dom0_mem param in pv-shim mode\n" ); +return 0 ; + } + do { if ( !strncmp(s, "min:", 4) ) dom0_min_nrpages = parse_amt(s+4, &s);
@@ -284,7 +291,16 @@ unsigned long __init dom0_compute_nr_pages(* maximum of 128MB. */ if ( nr_pages ==0 ) - nr_pages = -min (avail /16 ,128UL << (20 -PAGE_SHIFT )); + { +uint64_t rsvd =min (avail /16 ,128UL << (20 -PAGE_SHIFT )); +if ( pv_shim ) + { + rsvd =pv_shim_mem (avail); +printk ("Reserved %lu pages for xen-shim\n" , rsvd); + + } + nr_pages = -rsvd; + }/* Negative specification means "all memory - specified amount". */ if ( (long )nr_pages <0 ) nr_pages += avail;
xen/arch/x86/pv/shim.c +46 -0
52 lines not on this page · raw message
xen/include/asm-x86/pv/shim.h +6 -0
@@ -38,6 +38,7 @@ void pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start,int pv_shim_shutdown (uint8_t reason);void pv_shim_inject_evtchn (unsigned int port);domid_t get_initial_domain_id (void ); +uint64_t pv_shim_mem (uint64_t avail);#else
@@ -63,6 +64,11 @@ static inline domid_t get_initial_domain_id(void) {return 0 ; } +static inline uint64_t pv_shim_mem (uint64_t avail) +{ +ASSERT_UNREACHABLE (); +return 0 ; +}#endif
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 45/62 xen/pvshim: modify Dom0 builder in order to build a DomU
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
According to the PV ABI the initial virtual memory regions should contain the xenstore and console pages after the start_info. Also set the correct values in the start_info for DomU operation.
---
Changes since v1:
- Modify the position of the __init attribute in dom0_update_physmap.
- Move the addition of sizeof(struct dom0_vga_console_info) to vstartinfo_end with an existing if branch.
- Add a TODO item for fill_console_start_info in the !CONFIG_VIDEO case.
- s/replace_va/replace_va_mapping/.
- Remove call to free_domheap_pages in replace_va_mapping. put_page_and_type should already take care of freeing the page.
- Use PFN_DOWN in SET_AND_MAP_PARAM macro.
- Parenthesize va in SET_AND_MAP_PARAM macro when required.
--- xen/arch/x86/pv/dom0_build.c | 48 +++++++++++++++++++++++------- xen/arch/x86/pv/shim.c | 63 ++++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/dom0_build.h | 4 +++ xen/include/asm-x86/pv/shim.h | 21 ++++++++++++++ 4 files changed, 126 insertions(+), 10 deletions(-)
xen/arch/x86/pv/dom0_build.c +38 -10
@@ -31,9 +31,8 @@#define L3_PROT (BASE_PROT|_PAGE_DIRTY)#define L4_PROT (BASE_PROT|_PAGE_DIRTY) -static __init void dom0_update_physmap (struct domain *d,unsigned long pfn, -unsigned long mfn, -unsigned long vphysmap_s) +void __init dom0_update_physmap (struct domain *d,unsigned long pfn, +unsigned long mfn,unsigned long vphysmap_s) {if ( !is_pv_32bit_domain (d) ) ((unsigned long *)vphysmap_s)[pfn] = mfn;
@@ -315,6 +314,10 @@ int __init dom0_construct_pv(struct domain *d,unsigned long vphysmap_end;unsigned long vstartinfo_start;unsigned long vstartinfo_end; +unsigned long vxenstore_start =0 ; +unsigned long vxenstore_end =0 ; +unsigned long vconsole_start =0 ; +unsigned long vconsole_end =0 ;unsigned long vstack_start;unsigned long vstack_end;unsigned long vpt_start;
@@ -440,11 +443,22 @@ int __init dom0_construct_pv(struct domain *d,if ( parms.p2m_base !=UNSET_ADDR ) vphysmap_end = vphysmap_start; vstartinfo_start =round_pgup (vphysmap_end); - vstartinfo_end = (vstartinfo_start + -sizeof (struct start_info ) + -sizeof (struct dom0_vga_console_info )); + vstartinfo_end = vstartinfo_start +sizeof (struct start_info ); + +if ( pv_shim ) + { + vxenstore_start =round_pgup (vstartinfo_end); + vxenstore_end = vxenstore_start +PAGE_SIZE ; + vconsole_start = vxenstore_end; + vconsole_end = vconsole_start +PAGE_SIZE ; + vpt_start = vconsole_end; + } +else + { + vpt_start =round_pgup (vstartinfo_end); + vstartinfo_end +=sizeof (struct dom0_vga_console_info ); + } - vpt_start =round_pgup (vstartinfo_end);for ( nr_pt_pages =2 ; ; nr_pt_pages++ ) { vpt_end = vpt_start + (nr_pt_pages *PAGE_SIZE );
@@ -537,6 +551,8 @@ int __init dom0_construct_pv(struct domain *d," Init. ramdisk: %p->%p\n" " Phys-Mach map: %p->%p\n" " Start info: %p->%p\n" +" Xenstore ring: %p->%p\n" +" Console ring: %p->%p\n" " Page tables: %p->%p\n" " Boot stack: %p->%p\n" " TOTAL: %p->%p\n",
@@ -544,6 +560,8 @@ int __init dom0_construct_pv(struct domain *d,_p (vinitrd_start),_p (vinitrd_end),_p (vphysmap_start),_p (vphysmap_end),_p (vstartinfo_start),_p (vstartinfo_end), +_p (vxenstore_start),_p (vxenstore_end), +_p (vconsole_start),_p (vconsole_end),_p (vpt_start),_p (vpt_end),_p (vstack_start),_p (vstack_end), _p(v_start), _p(v_end));
@@ -737,7 +755,8 @@ int __init dom0_construct_pv(struct domain *d, si->shared_info =virt_to_maddr (d->shared_info); - si->flags =SIF_PRIVILEGED |SIF_INITDOMAIN ; +if ( !pv_shim ) + si->flags =SIF_PRIVILEGED |SIF_INITDOMAIN ;if ( !vinitrd_start && initrd_len ) si->flags |=SIF_MOD_START_PFN ; si->flags |= (xen_processor_pmbits <<8 ) &SIF_PM_MASK ;
@@ -829,15 +848,24 @@ int __init dom0_construct_pv(struct domain *d,strlcpy ((char *)si->cmd_line, cmdline,sizeof (si->cmd_line));#ifdef CONFIG_VIDEO -if (fill_console_start_info ((void *)(si +1 )) ) +if ( !pv_shim &&fill_console_start_info ((void *)(si +1 )) ) { si->console.dom0.info_off =sizeof (struct start_info ); si->console.dom0.info_size =sizeof (struct dom0_vga_console_info ); }#endif +/* +* TODO: provide an empty stub for fill_console_start_info in the +* !CONFIG_VIDEO case so the logic here can be simplified. +*/ +if ( pv_shim ) +pv_shim_setup_dom (d, l4start, v_start, vxenstore_start, vconsole_start, + vphysmap_start, si); +if (is_pv_32bit_domain (d) ) -xlat_start_info (si, XLAT_start_info_console_dom0); +xlat_start_info (si, pv_shim ? XLAT_start_info_console_domU + : XLAT_start_info_console_dom0);/* Return to idle domain's page tables. */ mapcache_override_current (NULL );
xen/arch/x86/pv/shim.c +63 -0
79 lines not on this page · raw message
xen/include/asm-x86/dom0_build.h +4 -0
@@ -1,6 +1,7 @@#ifndef _DOM0_BUILD_H_#define _DOM0_BUILD_H_ +#include <xen/libelf.h> #include <xen/sched.h> #include <asm/setup.h>
@@ -27,6 +28,9 @@ int dom0_construct_pvh(struct domain *d, const module_t *image,unsigned long dom0_paging_pages (const struct domain *d,unsigned long nr_pages); +void dom0_update_physmap (struct domain *d,unsigned long pfn, +unsigned long mfn,unsigned long vphysmap_s); +#endif /* _DOM0_BUILD_H_ */ /*
xen/include/asm-x86/pv/shim.h +21 -0
@@ -29,6 +29,27 @@ extern bool pv_shim;# define pv_shim 0#endif /* CONFIG_PV_SHIM{,_EXCLUSIVE} */ +#ifdef CONFIG_PV_SHIM + +void pv_shim_setup_dom (struct domain *d,l4_pgentry_t *l4start, +unsigned long va_start,unsigned long store_va, +unsigned long console_va,unsigned long vphysmap, +start_info_t *si); + +#else + +static inline void pv_shim_setup_dom (struct domain *d,l4_pgentry_t *l4start, +unsigned long va_start, +unsigned long store_va, +unsigned long console_va, +unsigned long vphysmap, +start_info_t *si) +{ +ASSERT_UNREACHABLE (); +} + +#endif +#endif /* __X86_PV_SHIM_H__ */ /*
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 38/62 x86/shim: Kconfig and command line options
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
--- docs/misc/xen-command-line.markdown | 11 ++++++++++ xen/arch/x86/Kconfig | 22 +++++++++++++++++++ xen/arch/x86/pv/Makefile | 1 + xen/arch/x86/pv/shim.c | 39 ++++++++++++++++++++++++++++++++++ xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/pv/shim.h | 42 +++++++++++++++++++++++++++++++++++++ 6 files changed, 116 insertions(+) create mode 100644 xen/arch/x86/pv/shim.c create mode 100644 xen/include/asm-x86/pv/shim.h
docs/misc/xen-command-line.markdown +11 -0
@@ -1445,6 +1445,17 @@ do; there may be other custom operating systems which do. If you're certain you don't plan on having PV guests which use this feature, turning it off can reduce the attack surface. +### pv-shim (x86) +> `= <boolean>` + +> Default: `false` + +This option is intended for use by a toolstack, when choosing to run a PV +guest compatibly inside an HVM container. + +In this mode, the kernel and initrd passed as modules to the hypervisor are +constructed into a plain unprivileged PV domain. + ### rcu-idle-timer-period-ms > `= <integer>`
xen/arch/x86/Kconfig +22 -0
@@ -133,6 +133,28 @@ config PVH_GUEST ---help--- Support booting using the PVH ABI. + If unsure, say N. + +config PV_SHIM + def_bool n + prompt "PV Shim" + depends on PV && XEN_GUEST + ---help--- + Build Xen with a mode which acts as a shim to allow PV guest to run + in an HVM/PVH container. This mode can only be enabled with command + line option. + + If unsure, say N. + +config PV_SHIM_EXCLUSIVE + def_bool n + prompt "PV Shim Exclusive" + depends on PV_SHIM + ---help--- + Build Xen in a way which unconditionally assumes PV_SHIM mode. This + option is only intended for use when building a dedicated PV Shim + firmware, and will not function correctly in other scenarios. + If unsure, say N. endmenu
xen/arch/x86/pv/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-y += iret.o obj-y += misc-hypercalls.o obj-y += mm.o obj-y += ro-page-fault.o +obj-$(CONFIG_PV_SHIM) += shim.o obj-y += traps.o obj-bin-y += dom0_build.init.o
xen/arch/x86/pv/shim.c new file +39 -0
@@ -0,0 +1,39 @@ +/****************************************************************************** +* arch/x86/pv/shim.c +* +* Functionaltiy for PV Shim mode +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2017 Citrix Systems Ltd. +*/ +#include <xen/init.h> +#include <xen/types.h> + +#include <asm/apic.h> + +#ifndef CONFIG_PV_SHIM_EXCLUSIVE +bool pv_shim; +boolean_param ("pv-shim" , pv_shim); +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/asm-x86/guest.h +1 -0
@@ -22,6 +22,7 @@#include <asm/guest/hypercall.h> #include <asm/guest/pvh-boot.h> #include <asm/guest/xen.h> +#include <asm/pv/shim.h> #endif /* __X86_GUEST_H__ */
xen/include/asm-x86/pv/shim.h new file +42 -0
42 lines not on this page · raw message
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 52/62 xen/pvshim: set max_pages to the value of tot_pages
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
So that the guest is not able to deplete the memory pool of the shim itself by trying to balloon up.
--- xen/arch/x86/pv/shim.c | 6 ++++++ 1 file changed, 6 insertions(+)
xen/arch/x86/pv/shim.c +6 -0
@@ -204,6 +204,12 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, (hypercall_fn_t *)pv_shim_grant_table_op, (hypercall_fn_t *)pv_shim_grant_table_op); guest = d; + +/* +* Set the max pages to the current number of pages to prevent the +* guest from depleting the shim memory pool. +*/ + d->max_pages = d->tot_pages; }static void write_start_info (struct domain *d)
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 34/62 x86: don't swallow the first command line item in guest mode
In reply to Wei Liu--- xen/arch/x86/setup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/setup.c +2 -2
@@ -632,8 +632,8 @@ static char * __init cmdline_cook(char *p, const char *loader_name)while ( *p ==' ' ) p++; -/* GRUB2 does not include image name as first item on command line. */ -if (loader_is_grub2 (loader_name) ) +/* GRUB2 and PVH don't not include image name as first item on command line. */ +if ( xen_guest ||loader_is_grub2 (loader_name) )return p;/* Strip image name plus whitespace. */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 48/62 xen/pvshim: add grant table operations
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
---
Changes since v1:
- Use __ of copy_to_guest.
- Return EOPNOTSUPP for not implemented grant table hypercalls.
- Forward user provided buffer in GNTTABOP_query_size.
- Rewrite grant table hypercall handler.
--- xen/arch/x86/pv/shim.c | 164 ++++++++++++++++++++++++++++++++++ xen/include/asm-x86/guest/hypercall.h | 6 ++ 2 files changed, 170 insertions(+)
xen/arch/x86/pv/shim.c +164 -0
@@ -22,6 +22,7 @@#include <xen/guest_access.h> #include <xen/hypercall.h> #include <xen/init.h> +#include <xen/iocap.h> #include <xen/shutdown.h> #include <xen/types.h>
@@ -32,6 +33,8 @@#include <public/arch-x86/cpuid.h> +#include <compat/grant_table.h> +#ifndef CONFIG_PV_SHIM_EXCLUSIVE bool pv_shim;boolean_param ("pv-shim" , pv_shim);
@@ -39,7 +42,14 @@ boolean_param("pv-shim", pv_shim);static struct domain *guest; +static unsigned int nr_grant_list; +static unsigned long *grant_frames; +static DEFINE_SPINLOCK (grant_lock); +static long pv_shim_event_channel_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg); +static long pv_shim_grant_table_op (unsigned int cmd, +XEN_GUEST_HANDLE_PARAM (void ) uop, +unsigned int count);#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER| \ _PAGE_GUEST_KERNEL)
@@ -127,6 +137,9 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start,pv_hypercall_table_replace (__HYPERVISOR_event_channel_op, (hypercall_fn_t *)pv_shim_event_channel_op, (hypercall_fn_t *)pv_shim_event_channel_op); +pv_hypercall_table_replace (__HYPERVISOR_grant_table_op, + (hypercall_fn_t *)pv_shim_grant_table_op, + (hypercall_fn_t *)pv_shim_grant_table_op); guest = d; }
@@ -363,6 +376,157 @@ void pv_shim_inject_evtchn(unsigned int port) } } +static long pv_shim_grant_table_op (unsigned int cmd, +XEN_GUEST_HANDLE_PARAM (void ) uop, +unsigned int count) +{ +struct domain *d = current->domain; +long rc =0 ; + +if ( count !=1 ) +return -EINVAL ; + +switch ( cmd ) + { +case GNTTABOP_setup_table: + { +bool compat =is_pv_32bit_domain (d); +struct gnttab_setup_table nat; +struct compat_gnttab_setup_table cmp; +unsigned int i; + +if (unlikely (compat ?copy_from_guest (&cmp, uop,1 ) + :copy_from_guest (&nat, uop,1 )) || +unlikely (compat ? !compat_handle_okay (cmp.frame_list, + cmp.nr_frames) + : !guest_handle_okay (nat.frame_list, + nat.nr_frames)) ) + { + rc = -EFAULT ; +break ; + } + if ( compat ) +#define XLAT_gnttab_setup_table_HNDL_frame_list (d, s) +XLAT_gnttab_setup_table (&nat, &cmp); +#undef XLAT_gnttab_setup_table_HNDL_frame_list + + nat.status = GNTST_okay; + +spin_lock (&grant_lock); +if ( !nr_grant_list ) + { +struct gnttab_query_size query_size = { + .dom =DOMID_SELF , + }; + + rc =xen_hypercall_grant_table_op (GNTTABOP_query_size, + &query_size,1 ); +if ( rc ) + { +spin_unlock (&grant_lock); +break ; + } + +ASSERT (!grant_frames); + grant_frames = xzalloc_array(unsigned long, + query_size.max_nr_frames); +if ( !grant_frames ) + { +spin_unlock (&grant_lock); + rc = -ENOMEM ; +break ; + } + + nr_grant_list = query_size.max_nr_frames; + } + +if ( nat.nr_frames > nr_grant_list ) + { +spin_unlock (&grant_lock); + rc = -EINVAL ; +break ; + } + +for ( i =0 ; i < nat.nr_frames; i++ ) + { +if ( !grant_frames[i] ) + { +struct xen_add_to_physmap xatp = { + .domid =DOMID_SELF , + .idx = i, + .space = XENMAPSPACE_grant_table, + }; +mfn_t mfn; + + rc =hypervisor_alloc_unused_page (&mfn); +if ( rc ) + { +gprintk (XENLOG_ERR , +"unable to get memory for grant table\n" ); +break ; + } + + xatp.gpfn =mfn_x (mfn); + rc =xen_hypercall_memory_op (XENMEM_add_to_physmap, &xatp); +if ( rc ) + { +hypervisor_free_unused_page (mfn); +break ; + } + +BUG_ON (iomem_permit_access (d,mfn_x (mfn),mfn_x (mfn))); + grant_frames[i] =mfn_x (mfn); + } + +ASSERT (grant_frames[i]); +if ( compat ) + { +compat_pfn_t pfn = grant_frames[i]; + +if (__copy_to_compat_offset (cmp.frame_list, i, &pfn,1 ) ) + { + nat.status = GNTST_bad_virt_addr; + rc = -EFAULT ; +break ; + } + } +else if (__copy_to_guest_offset (nat.frame_list, i, + &grant_frames[i],1 ) ) + { + nat.status = GNTST_bad_virt_addr; + rc = -EFAULT ; +break ; + } + } +spin_unlock (&grant_lock); + + if ( compat ) +#define XLAT_gnttab_setup_table_HNDL_frame_list (d, s) +XLAT_gnttab_setup_table (&cmp, &nat); +#undef XLAT_gnttab_setup_table_HNDL_frame_list + +if (unlikely (compat ?__copy_to_guest (uop, &cmp,1 ) + :__copy_to_guest (uop, &nat,1 )) ) + { + rc = -EFAULT ; +break ; + } + +break ; + } + +case GNTTABOP_query_size: + rc =xen_hypercall_grant_table_op (GNTTABOP_query_size, uop.p, count); +break ; + +default : + rc = -EOPNOTSUPP ; +break ; + } + +return rc; +} +domid_t get_initial_domain_id (void ) {uint32_t eax, ebx, ecx, edx;
xen/include/asm-x86/guest/hypercall.h +6 -0
@@ -110,6 +110,12 @@ static inline long xen_hypercall_event_channel_op(unsigned int cmd, void *arg)return _hypercall64_2 (long, __HYPERVISOR_event_channel_op, cmd, arg); } +static inline long xen_hypercall_grant_table_op (unsigned int cmd,void *arg, +unsigned int count) +{ +return _hypercall64_3 (long, __HYPERVISOR_grant_table_op, cmd, arg, count); +} +static inline long xen_hypercall_hvm_op (unsigned int op,void *arg) {return _hypercall64_2 (long, __HYPERVISOR_hvm_op, op, arg);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 19/62 x86/entry: Early PVH boot code
In reply to Wei Liu---
v2:
1. Fix comment.
2. Use cmpb $0.
3. Address comments on pvh-boot.c.
4. Haven't changed the pritnk modifiers to accommodate future changes.
5. Missing a prerequisite patch to relocate pvh_info to make __va work reliably. [BLOCKER].
--- xen/arch/x86/Makefile | 1 + xen/arch/x86/boot/head.S | 40 +++++++++++- xen/arch/x86/boot/x86_64.S | 2 +- xen/arch/x86/guest/Makefile | 1 + xen/arch/x86/guest/pvh-boot.c | 119 +++++++++++++++++++++++++++++++++++ xen/arch/x86/setup.c | 18 +++++- xen/include/asm-x86/guest.h | 34 ++++++++++ xen/include/asm-x86/guest/pvh-boot.h | 57 +++++++++++++++++ 8 files changed, 268 insertions(+), 4 deletions(-) create mode 100644 xen/arch/x86/guest/Makefile create mode 100644 xen/arch/x86/guest/pvh-boot.c create mode 100644 xen/include/asm-x86/guest.h create mode 100644 xen/include/asm-x86/guest/pvh-boot.h
xen/arch/x86/Makefile +1 -0
@@ -1,6 +1,7 @@ subdir-y += acpi subdir-y += cpu subdir-y += genapic +subdir-$(CONFIG_XEN_GUEST) += guest subdir-$(CONFIG_HVM) += hvm subdir-y += mm subdir-$(CONFIG_XENOPROF) += oprofile
xen/arch/x86/boot/head.S +39 -1
@@ -379,7 +379,39 @@ cs32_switch: ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .long sym_offs(__pvh_start)) __pvh_start: - ud2a + cld + cli + + /* + * We need one push/pop to determine load address. Use the same + * absolute stack address as the native path, for lack of a better + * alternative. + */ + mov $0x1000, %esp + + /* Calculate the load base address. */ + call 1f +1: pop %esi + sub $sym_offs(1b), %esi + + /* Set up stack. */ + lea STACK_SIZE + sym_esi(cpu0_stack), %esp + + mov %ebx, sym_esi(pvh_start_info_pa) + + /* Prepare gdt and segments */ + add %esi, sym_esi(gdt_boot_base) + lgdt sym_esi(gdt_boot_descr) + + mov $BOOT_DS, %ecx + mov %ecx, %ds + mov %ecx, %es + mov %ecx, %ss + + /* Skip bootloader setup and bios setup, go straight to trampoline */ + movb $1, sym_esi(pvh_boot) + movb $1, sym_esi(skip_realmode) + jmp trampoline_setup #endif /* CONFIG_PVH_GUEST */
@@ -543,12 +575,18 @@ trampoline_setup: /* Get bottom-most low-memory stack address. */ add $TRAMPOLINE_SPACE,%ecx +#ifdef CONFIG_PVH_GUEST + cmpb $0, sym_fs(pvh_boot) + jne 1f +#endif + /* Save the Multiboot info struct (after relocation) for later use. */ push %ecx /* Bottom-most low-memory stack address. */ push %ebx /* Multiboot information address. */ push %eax /* Multiboot magic. */ call reloc mov %eax,sym_fs(multiboot_ptr) +1: /* * Now trampoline_phys points to the following structure (lowest address
xen/arch/x86/boot/x86_64.S +1 -1
@@ -31,7 +31,7 @@ ENTRY(__high_start) test %ebx,%ebx jnz start_secondary - /* Pass off the Multiboot info structure to C land. */ + /* Pass off the Multiboot info structure to C land (if applicable). */ mov multiboot_ptr(%rip),%edi call __start_xen BUG /* __start_xen() shouldn't return. */
xen/arch/x86/guest/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-bin-$(CONFIG_PVH_GUEST) += pvh-boot.init.o
xen/arch/x86/guest/pvh-boot.c new file +119 -0
119 lines not on this page · raw message
xen/arch/x86/setup.c +16 -2
@@ -51,6 +51,7 @@#include <asm/alternative.h> #include <asm/mc146818rtc.h> #include <asm/cpuid.h> +#include <asm/guest.h> /* opt_nosmp: If true, secondary processors are ignored. */ static bool __initdata opt_nosmp;
@@ -649,8 +650,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)char *memmap_type =NULL ;char *cmdline, *kextra, *loader;unsigned int initrdidx, domcr_flags = DOMCRF_s3_integrity; -multiboot_info_t *mbi =__va (mbi_p); -module_t *mod = (module_t *)__va (mbi->mods_addr); +multiboot_info_t *mbi; +module_t *mod;unsigned long nr_pages, raw_max_page, modules_headroom, *module_map;int i, j, e820_warn =0 , bytes =0 ;bool acpi_boot_table_init_done = false, relocated = false;
@@ -680,6 +681,16 @@ void __init noreturn __start_xen(unsigned long mbi_p)/* Full exception support from here on in. */ +if ( pvh_boot ) + { +ASSERT (mbi_p ==0 ); + mbi =pvh_init (); + } +else + mbi =__va (mbi_p); + + mod =__va (mbi->mods_addr); + loader = (mbi->flags &MBI_LOADERNAME ) ? (char *)__va (mbi->boot_loader_name) :"unknown" ;
@@ -719,6 +730,9 @@ void __init noreturn __start_xen(unsigned long mbi_p)ehci_dbgp_init ();console_init_preirq (); +if ( pvh_boot ) +pvh_print_info (); +printk ("Bootloader: %s\n" , loader);printk ("Command line: %s\n" , cmdline);
xen/include/asm-x86/guest.h new file +34 -0
@@ -0,0 +1,34 @@ +/****************************************************************************** +* asm-x86/guest.h +* +* This program is free software; you can redistribute it and/or +* modify it under the terms and conditions of the GNU General Public +* License, version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2017 Citrix Systems Ltd. +*/ + +#ifndef __X86_GUEST_H__ +#define __X86_GUEST_H__ + +#include <asm/guest/pvh-boot.h> + +#endif /* __X86_GUEST_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/asm-x86/guest/pvh-boot.h new file +57 -0
57 lines not on this page · raw message
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 33/62 x86: read wallclock from Xen when running in pvh mode
In reply to Wei Liu--- xen/arch/x86/time.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-)
xen/arch/x86/time.c +28 -4
@@ -964,6 +964,30 @@ static unsigned long get_cmos_time(void)return mktime (rtc.year, rtc.mon, rtc.day, rtc.hour, rtc.min, rtc.sec); } +static unsigned long get_wallclock_time (void ) +{ +#ifdef CONFIG_XEN_GUEST +if ( xen_guest ) + { +struct shared_info *sh_info = XEN_shared_info; +uint32_t wc_version; +uint64_t wc_sec; + +do { + wc_version = sh_info->wc_version & ~1 ; +smp_rmb (); + + wc_sec = sh_info->wc_sec; +smp_rmb (); + }while ( wc_version != sh_info->wc_version ); + +return wc_sec +read_xen_timer () /1000000000 ; + } +#endif + +return get_cmos_time (); +} +/*************************************************************************** * System Time ***************************************************************************/
@@ -1759,8 +1783,8 @@ int __init init_xen_time(void)open_softirq (TIME_CALIBRATE_SOFTIRQ , local_time_calibration); -/* NB. get_cmos_time() can take over one second to execute. */ -do_settime (get_cmos_time (),0 ,NOW ()); +/* NB. get_wallclock_time() can take over one second to execute. */ +do_settime (get_wallclock_time (),0 ,NOW ());/* Finish platform timer initialization. */ try_platform_timer_tail (false);
@@ -1870,7 +1894,7 @@ int time_suspend(void) {if (smp_processor_id () ==0 ) { - cmos_utc_offset = -get_cmos_time (); + cmos_utc_offset = -get_wallclock_time (); cmos_utc_offset +=get_sec ();kill_timer (&calibration_timer);
@@ -1897,7 +1921,7 @@ int time_resume(void)set_timer (&calibration_timer,NOW () +EPOCH ); -do_settime (get_cmos_time () + cmos_utc_offset,0 ,NOW ()); +do_settime (get_wallclock_time () + cmos_utc_offset,0 ,NOW ());update_vcpu_system_time (current);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 54/62 xen/pvshim: memory hotplug
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
---
Changes since v1:
- Add an order parameter to batch_memory_op.
- Add a TODO item regarding high order memory chunks to pv_shim_online_memory.
- Use page_list_splice.
- Make sure the shim handlers are not called multiple times when the hypercall is preempted.
--- xen/arch/x86/pv/shim.c | 112 ++++++++++++++++++++++++++++++++++++++++++ xen/common/memory.c | 21 ++++++++ xen/include/asm-x86/pv/shim.h | 10 ++++ 3 files changed, 143 insertions(+)
xen/arch/x86/pv/shim.c +112 -0
@@ -48,6 +48,9 @@ static unsigned int nr_grant_list;static unsigned long *grant_frames;static DEFINE_SPINLOCK (grant_lock); +static PAGE_LIST_HEAD (balloon); +static DEFINE_SPINLOCK (balloon_lock); +static long pv_shim_event_channel_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg); static long pv_shim_grant_table_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) uop,
@@ -814,6 +817,115 @@ long pv_shim_cpu_down(void *data)return 0 ; } +static unsigned long batch_memory_op (unsigned int cmd,unsigned int order, +const struct page_list_head *list) +{ +struct xen_memory_reservation xmr = { + .domid =DOMID_SELF , + .extent_order = order, + }; +unsigned long pfns[64 ]; +const struct page_info *pg; +unsigned long done =0 ; + +set_xen_guest_handle (xmr.extent_start, pfns); + page_list_for_each ( pg, list ) + { + pfns[xmr.nr_extents++] =page_to_mfn (pg); +if ( xmr.nr_extents ==ARRAY_SIZE (pfns) || !page_list_next (pg, list) ) + { +long nr =xen_hypercall_memory_op (cmd, &xmr); + + done += nr >0 ? nr :0 ; +if ( nr != xmr.nr_extents ) +break ; + xmr.nr_extents =0 ; + } + } + +return done; +} + +void pv_shim_online_memory (unsigned int nr,unsigned int order) +{ +struct page_info *page, *tmp; +PAGE_LIST_HEAD (list); + +spin_lock (&balloon_lock); + page_list_for_each_safe ( page, tmp, &balloon ) + { +/* TODO: add support for splitting high order memory chunks. */ +if ( page->v.free.order != order ) +continue ; + +page_list_del (page, &balloon); +page_list_add_tail (page, &list); +if ( !--nr ) +break ; + } +spin_unlock (&balloon_lock); + +if ( nr ) +gprintk (XENLOG_WARNING , +"failed to allocate %u extents of order %u for onlining\n" , + nr, order); + + nr =batch_memory_op (XENMEM_populate_physmap, order, &list); +while ( nr-- ) + { +BUG_ON ((page =page_list_remove_head (&list)) ==NULL ); +free_domheap_pages (page, order); + } + +if ( !page_list_empty (&list) ) + { +gprintk (XENLOG_WARNING , +"failed to online some of the memory regions\n" ); +spin_lock (&balloon_lock); +page_list_splice (&list, &balloon); +spin_unlock (&balloon_lock); + } +} + +void pv_shim_offline_memory (unsigned int nr,unsigned int order) +{ +struct page_info *page; +PAGE_LIST_HEAD (list); + +while ( nr-- ) + { + page =alloc_domheap_pages (NULL , order,0 ); +if ( !page ) +break ; + +page_list_add_tail (page, &list); + page->v.free.order = order; + } + +if ( nr +1 ) +gprintk (XENLOG_WARNING , +"failed to reserve %u extents of order %u for offlining\n" , + nr +1 , order); + + + nr =batch_memory_op (XENMEM_decrease_reservation, order, &list); +spin_lock (&balloon_lock); +while ( nr-- ) + { +BUG_ON ((page =page_list_remove_head (&list)) ==NULL ); +page_list_add_tail (page, &balloon); + } +spin_unlock (&balloon_lock); + +if ( !page_list_empty (&list) ) + { +gprintk (XENLOG_WARNING , +"failed to offline some of the memory regions\n" ); +while ( (page =page_list_remove_head (&list)) !=NULL ) +free_domheap_pages (page, order); + } +} +domid_t get_initial_domain_id (void ) {uint32_t eax, ebx, ecx, edx;
xen/common/memory.c +21 -0
@@ -29,6 +29,10 @@#include <public/memory.h> #include <xsm/xsm.h> +#ifdef CONFIG_X86 +#include <asm/guest.h> +#endif +struct memop_args {/* INPUT */ struct domain *domain;/* Domain to be affected. */
@@ -993,6 +997,12 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return start_extent; } +#ifdef CONFIG_X86 +if ( pv_shim && op != XENMEM_decrease_reservation && !args.preempted ) +/* Avoid calling pv_shim_online_memory when preempted. */ +pv_shim_online_memory (args.nr_extents, args.extent_order); +#endif +switch ( op ) {case XENMEM_increase_reservation:
@@ -1015,6 +1025,17 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) __HYPERVISOR_memory_op,"lh" , op | (rc << MEMOP_EXTENT_SHIFT), arg); +#ifdef CONFIG_X86 +if ( pv_shim && op == XENMEM_decrease_reservation ) +/* +* Only call pv_shim_offline_memory when the hypercall has +* finished. Note that nr_done is used to cope in case the +* hypercall has failed and only part of the extents where +* processed. +*/ +pv_shim_offline_memory (args.nr_extents, args.nr_done); +#endif +break ;case XENMEM_exchange:
xen/include/asm-x86/pv/shim.h +10 -0
@@ -39,6 +39,8 @@ int pv_shim_shutdown(uint8_t reason);void pv_shim_inject_evtchn (unsigned int port);long pv_shim_cpu_up (void *data);long pv_shim_cpu_down (void *data); +void pv_shim_online_memory (unsigned int nr,unsigned int order); +void pv_shim_offline_memory (unsigned int nr,unsigned int order);domid_t get_initial_domain_id (void );uint64_t pv_shim_mem (uint64_t avail);
@@ -72,6 +74,14 @@ static inline long pv_shim_cpu_down(void *data)ASSERT_UNREACHABLE ();return 0 ; } +static inline void pv_shim_online_memory (unsigned int nr,unsigned int order) +{ +ASSERT_UNREACHABLE (); +} +static inline void pv_shim_offline_memory (unsigned int nr,unsigned int order) +{ +ASSERT_UNREACHABLE (); +}static inline domid_t get_initial_domain_id (void ) {return 0 ;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 27/62 xen/pvshim: keep track of used PFN ranges
In reply to Wei LiuSimple infrastructure to keep track of PFN space usage, so that we can use unpopulated PFNs to map special pages like shared info and grant table.
As rangeset depends on malloc being ready so hypervisor_setup is introduced for things that can be initialised late in the process.
Note that the PFN is marked as reserved at least up to 4GiB (or more if the guest has more memory). This is not a perfect solution but avoids using the MMIO hole below 4GiB. Ideally the shim (L1) should have a way to ask the underlying Xen (L0) which memory regions are populated, unpopulated, or MMIO space.
--- xen/arch/x86/guest/xen.c | 56 +++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/setup.c | 3 +++ xen/include/asm-x86/guest/xen.h | 7 ++++++ 3 files changed, 66 insertions(+)
xen/arch/x86/guest/xen.c +56 -0
@@ -19,8 +19,12 @@* Copyright (c) 2017 Citrix Systems Ltd. */ #include <xen/init.h> +#include <xen/mm.h> +#include <xen/pfn.h> +#include <xen/rangeset.h> #include <xen/types.h> +#include <asm/e820.h> #include <asm/guest.h> #include <asm/msr.h> #include <asm/processor.h>
@@ -31,6 +35,7 @@ bool __read_mostly xen_guest;static __read_mostly uint32_t xen_cpuid_base;extern char hypercall_page[]; +static struct rangeset *mem;static void __init find_xen_leaves (void ) {
@@ -72,6 +77,57 @@ void __init probe_hypervisor(void) xen_guest = true; } +static void __init init_memmap (void ) +{ +unsigned int i; + + mem =rangeset_new (NULL ,"host memory map" ,0 ); +if ( !mem ) +panic ("failed to allocate PFN usage rangeset" ); + +/* +* Mark up to the last memory page (or 4GiB) as RAM. This is done because +* Xen doesn't know the position of possible MMIO holes, so at least try to +* avoid the know MMIO hole below 4GiB. Note that this is subject to future +* discussion and improvements. +*/ + if ( rangeset_add_range(mem, 0, max_t(unsigned long, max_page - 1, +PFN_DOWN (GB (4 ) -1 ))) ) +panic ("unable to add RAM to in-use PFN rangeset" ); + +for ( i =0 ; i < e820.nr_map; i++ ) + { +struct e820entry *e = &e820.map[i]; + +if (rangeset_add_range (mem,PFN_DOWN (e->addr), +PFN_UP (e->addr + e->size -1 )) ) +panic ("unable to add range [%#lx, %#lx] to in-use PFN rangeset" , +PFN_DOWN (e->addr),PFN_UP (e->addr + e->size -1 )); + } +} + +void __init hypervisor_setup (void ) +{ +init_memmap (); +} + +int hypervisor_alloc_unused_page (mfn_t *mfn) +{ +unsigned long m; +int rc; + + rc =rangeset_claim_range (mem,1 , &m); +if ( !rc ) + *mfn =_mfn (m); + +return rc; +} + +int hypervisor_free_unused_page (mfn_t mfn) +{ +return rangeset_remove_range (mem,mfn_x (mfn),mfn_x (mfn)); +} +/* * Local variables: * mode: C
xen/arch/x86/setup.c +3 -0
@@ -1472,6 +1472,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) max_cpus = nr_cpu_ids; } +if ( xen_guest ) +hypervisor_setup (); +/* Low mappings were only needed for some BIOS table parsing. */ zap_low_mappings ();
xen/include/asm-x86/guest/xen.h +7 -0
@@ -26,12 +26,19 @@extern bool xen_guest;void probe_hypervisor (void ); +void hypervisor_setup (void ); +int hypervisor_alloc_unused_page (mfn_t *mfn); +int hypervisor_free_unused_page (mfn_t mfn);#else #define xen_guest 0static inline void probe_hypervisor (void ) {}; +static inline void hypervisor_setup (void ) +{ +ASSERT_UNREACHABLE (); +}#endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 35/62 x86/guest: setup event channel upcall vector
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
And a dummy event channel upcall handler.
Note that with the current code the underlying Xen (L0) must support HVMOP_set_evtchn_upcall_vector or else event channel setup is going to fail. This limitation can be lifted by implementing more event channel interrupt injection methods as a backup.
Register callback_irq to trick toolstack to think the domain is enlightened.
--- xen/arch/x86/guest/xen.c | 41 +++++++++++++++++++++++++++++++++++ xen/include/asm-x86/guest/hypercall.h | 17 +++++++++++++++ 2 files changed, 58 insertions(+)
xen/arch/x86/guest/xen.c +41 -0
@@ -24,6 +24,7 @@#include <xen/rangeset.h> #include <xen/types.h> +#include <asm/apic.h> #include <asm/e820.h> #include <asm/guest.h> #include <asm/msr.h>
@@ -186,6 +187,43 @@ static void __init init_memmap(void) } } +static void xen_evtchn_upcall (struct cpu_user_regs *regs) +{ +struct vcpu_info *vcpu_info =this_cpu (vcpu_info); + + vcpu_info->evtchn_upcall_pending =0 ; +write_atomic (&vcpu_info->evtchn_pending_sel,0 ); + +ack_APIC_irq (); +} + +static void init_evtchn (void ) +{ +static uint8_t evtchn_upcall_vector; +int rc; + +if ( !evtchn_upcall_vector ) +alloc_direct_apic_vector (&evtchn_upcall_vector, xen_evtchn_upcall); + +ASSERT (evtchn_upcall_vector); + + rc =xen_hypercall_set_evtchn_upcall_vector (this_cpu (vcpu_id), + evtchn_upcall_vector); +if ( rc ) +panic ("Unable to set evtchn upcall vector: %d" , rc); + +/* Trick toolstack to think we are enlightened */ + { +struct xen_hvm_param a = { + .domid =DOMID_SELF , + .index =HVM_PARAM_CALLBACK_IRQ , + .value =1 , + }; + +BUG_ON (xen_hypercall_hvm_op (HVMOP_set_param, &a)); + } +} +void __init hypervisor_setup (void ) {init_memmap ();
@@ -210,12 +248,15 @@ void __init hypervisor_setup(void)"unable to map vCPU info, limiting vCPUs to: %u\n" , XEN_LEGACY_MAX_VCPUS); } + +init_evtchn (); }void hypervisor_ap_setup (void ) {set_vcpu_id ();map_vcpuinfo (); +init_evtchn (); }int hypervisor_alloc_unused_page (mfn_t *mfn)
xen/include/asm-x86/guest/hypercall.h +17 -0
@@ -25,6 +25,7 @@#include <public/xen.h> #include <public/sched.h> +#include <public/hvm/hvm_op.h> #include <public/vcpu.h>
@@ -104,6 +105,11 @@ static inline int xen_hypercall_vcpu_op(unsigned int cmd, unsigned int vcpu,return _hypercall64_3 (long, __HYPERVISOR_vcpu_op, cmd, vcpu, arg); } +static inline long xen_hypercall_hvm_op (unsigned int op,void *arg) +{ +return _hypercall64_2 (long, __HYPERVISOR_hvm_op, op, arg); +} +/* * Higher level hypercall helpers */
@@ -120,6 +126,17 @@ static inline long xen_hypercall_shutdown(unsigned int reason) return xen_hypercall_sched_op(SCHEDOP_shutdown, &s); } +static inline long xen_hypercall_set_evtchn_upcall_vector ( +unsigned int cpu,unsigned int vector) +{ +struct xen_hvm_evtchn_upcall_vector a = { + .vcpu = cpu, + .vector = vector, + }; + +return xen_hypercall_hvm_op (HVMOP_set_evtchn_upcall_vector, &a); +} +#else /* CONFIG_XEN_GUEST */ #include <public/sched.h>
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 12/62 tools/ocaml: Extend domain_create() to take arch_domainconfig
In reply to Wei LiuFrom: Jon Ludlam <[email protected]>
No longer passing NULL into xc_domain_create() allows for the creation of PVH guests.
--- tools/ocaml/libs/xc/xenctrl.ml | 2 +- tools/ocaml/libs/xc/xenctrl.mli | 2 +- tools/ocaml/libs/xc/xenctrl_stubs.c | 22 ++++++++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-)
tools/ocaml/libs/xc/xenctrl.ml +1 -1
@@ -143,7 +143,7 @@ let with_intf f = interface_close xc; r -external _domain_create: handle -> int32 -> domain_create_flag list -> int array -> domid +external _domain_create: handle -> int32 -> domain_create_flag list -> int array -> arch_domainconfig -> domid = "stub_xc_domain_create" let int_array_of_uuid_string s =
tools/ocaml/libs/xc/xenctrl.mli +1 -1
@@ -102,7 +102,7 @@ external sizeof_xen_pfn : unit -> int = "stub_sizeof_xen_pfn" external interface_open : unit -> handle = "stub_xc_interface_open" external interface_close : handle -> unit = "stub_xc_interface_close" val with_intf : (handle -> 'a) -> 'a -val domain_create : handle -> int32 -> domain_create_flag list -> string -> domid +val domain_create : handle -> int32 -> domain_create_flag list -> string -> arch_domainconfig -> domid val domain_sethandle : handle -> domid -> string -> unit external domain_max_vcpus : handle -> domid -> int -> unit = "stub_xc_domain_max_vcpus"
tools/ocaml/libs/xc/xenctrl_stubs.c +20 -2
@@ -144,7 +144,8 @@ static int domain_create_flag_table[] = { }; CAMLprim value stub_xc_domain_create(value xch, value ssidref, -value flags,value handle) +value flags,value handle, +value domconfig) {CAMLparam4 (xch, ssidref, flags, handle);
@@ -155,6 +156,7 @@ CAMLprim value stub_xc_domain_create(value xch, value ssidref,uint32_t c_ssidref =Int32_val (ssidref);unsigned int c_flags =0 ;value l; +xc_domain_configuration_t config = {};if (Wosize_val (handle) !=16 )caml_invalid_argument ("Handle not a 16-integer array" );
@@ -168,8 +170,24 @@ CAMLprim value stub_xc_domain_create(value xch, value ssidref, c_flags |= domain_create_flag_table[v]; } +switch (Tag_val (domconfig)) { +case 0 :/* ARM - nothing to do */ +caml_failwith ("Unhandled: ARM" ); +break ; + +case 1 :/* X86 - emulation flags in the block */ +for (l =Field (Field (domconfig,0 ),0 ); + l != Val_none; + l =Field (l,1 )) + config.emulation_flags |=1u <<Int_val (Field (l,0 )); +break ; + +default : +caml_failwith ("Unhandled domconfig type" ); + } +caml_enter_blocking_section (); - result =xc_domain_create (_H (xch), c_ssidref, h, c_flags, &domid,NULL ); + result =xc_domain_create (_H (xch), c_ssidref, h, c_flags, &domid, &config);caml_leave_blocking_section ();if (result <0 )
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 61/62 xl: pvshim: Provide and document xl config
In reply to Wei LiuFrom: Ian Jackson <[email protected]>
---
v2: pvshim, not pvhshim
works with type "pvh", not type "pv" pvshim_etc. options in config are not erroneously ignored
--- docs/man/xl.cfg.pod.5.in | 35 +++++++++++++++++++++++++++++++++++ tools/xl/xl_parse.c | 14 ++++++++++++++ 2 files changed, 49 insertions(+)
docs/man/xl.cfg.pod.5.in +35 -0
@@ -508,6 +508,41 @@ Load the specified file as firmware for the guest. Currently there's no firmware available for PVH guests, they should be booted using the B<Direct Kernel Boot> method or the B<bootloader> option. +=over 4 + +=item B<pvshim=BOOLEAN> + +Whether to boot this guest as a PV guest within a PVH container. +Ie, the guest will experience a PV environment, +but +processor hardware extensions are used to +separate its address space +to mitigate the Meltdown attack (CVE-2017-5754). + +Default is false. + +=item B<pvshim_path="PATH"> + +The PV shim is a specially-built firmware-like executable +constructed from the hypervisor source tree. +This option specifies to use a non-default shim. +Ignored if pvhsim is false. + +=item B<pvshim_cmdline="STRING"> + +Command line for the shim. +Default is "pv-shim console=xen,pv sched=null". +Ignored if pvhsim is false. + +=item B<pvshim_extra="STRING"> + +Extra command line arguments for the shim. +If supplied, appended to the value for pvshim_cmdline. +Default is empty. +Ignored if pvhsim is false. + +=back + =head3 Other Options =over 4
tools/xl/xl_parse.c +14 -0
@@ -964,6 +964,20 @@ void parse_config_data(const char *config_source,xlu_cfg_replace_string (config,"pool" , &c_info->pool_name,0 );libxl_domain_build_info_init_type (b_info, c_info->type); + +if (b_info->type ==LIBXL_DOMAIN_TYPE_PVH ) { +xlu_cfg_get_defbool (config,"pvshim" , &b_info->u.pvh.pvshim,0 ); +if (!xlu_cfg_get_string (config,"pvshim_path" , &buf,0 )) +xlu_cfg_replace_string (config,"pvshim_path" , + &b_info->u.pvh.pvshim_path,0 ); +if (!xlu_cfg_get_string (config,"pvshim_cmdline" , &buf,0 )) +xlu_cfg_replace_string (config,"pvshim_cmdline" , + &b_info->u.pvh.pvshim_cmdline,0 ); +if (!xlu_cfg_get_string (config,"pvshim_extra" , &buf,0 )) +xlu_cfg_replace_string (config,"pvshim_extra" , + &b_info->u.pvh.pvshim_extra,0 ); + } +if (blkdev_start) b_info->blkdev_start =strdup (blkdev_start);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 46/62 xen/pvshim: set correct domid value
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
If domid is not provided by L0 set domid to 1 by default. Note that L0 not provinding the domid can cause trouble if the guest tries to use it's domid instead of DOMID_SELF when performing hypercalls that are forwarded to the L0 hypervisor.
Since the domain created is no longer the hardware domain add a hook to the domain shutdown path in order to forward shutdown operations to the L0 hypervisor.
---
Changes since v1:
- s/get_dom0_domid/get_initial_domain_id/.
- Add a comment regarding why dom0 needs to be global.
- Fix compilation of xen/common/domain.c on ARM.
--- xen/arch/x86/dom0_build.c | 2 +- xen/arch/x86/guest/xen.c | 5 +++++ xen/arch/x86/pv/shim.c | 21 +++++++++++++++++++++ xen/arch/x86/setup.c | 16 +++++++++++----- xen/common/domain.c | 12 ++++++++++++ xen/include/asm-x86/guest/xen.h | 6 ++++++ xen/include/asm-x86/pv/shim.h | 10 ++++++++++ 7 files changed, 66 insertions(+), 6 deletions(-)
xen/arch/x86/dom0_build.c +1 -1
@@ -472,7 +472,7 @@ int __init construct_dom0(struct domain *d, const module_t *image,int rc;/* Sanity! */ -BUG_ON (d->domain_id !=0 ); +BUG_ON (!pv_shim && d->domain_id !=0 );BUG_ON (d->vcpu[0 ] ==NULL );BUG_ON (d->vcpu[0 ]->is_initialised);
xen/arch/x86/guest/xen.c +5 -0
@@ -322,6 +322,11 @@ const unsigned long *__init hypervisor_reserved_pages(unsigned int *size)return reserved_pages; } +uint32_t hypervisor_cpuid_base (void ) +{ +return xen_cpuid_base; +} +/* * Local variables: * mode: C
xen/arch/x86/pv/shim.c +21 -0
@@ -20,6 +20,7 @@*/ #include <xen/hypercall.h> #include <xen/init.h> +#include <xen/shutdown.h> #include <xen/types.h> #include <asm/apic.h>
@@ -27,6 +28,8 @@#include <asm/guest.h> #include <asm/pv/mm.h> +#include <public/arch-x86/cpuid.h> +#ifndef CONFIG_PV_SHIM_EXCLUSIVE bool pv_shim;boolean_param ("pv-shim" , pv_shim);
@@ -91,6 +94,24 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start,#undef SET_AND_MAP_PARAM } +void pv_shim_shutdown (uint8_t reason) +{ +/* XXX: handle suspend */ +xen_hypercall_shutdown (reason); +} + +domid_t get_initial_domain_id (void ) +{ +uint32_t eax, ebx, ecx, edx; + +if ( !pv_shim ) +return 0 ; + +cpuid (hypervisor_cpuid_base () +4 , &eax, &ebx, &ecx, &edx); + +return (eax &XEN_HVM_CPUID_DOMID_PRESENT ) ? ecx :1 ; +} +/* * Local variables: * mode: C
xen/arch/x86/setup.c +11 -5
@@ -104,6 +104,12 @@ unsigned long __read_mostly mmu_cr4_features = XEN_MINIMAL_CR4;#define SMEP_HVM_ONLY (-1)static s8 __initdata opt_smep =1 ; +/* +* Initial domain place holder. Needs to be global so it can be created in +* __start_xen and unpaused in init_done. +*/ +static struct domain *__initdata dom0; +static int __init parse_smep_param (const char *s) {if ( !*s )
@@ -576,11 +582,11 @@ static void noinline init_done(void) system_state = SYS_STATE_active; +domain_unpause_by_systemcontroller (dom0); +/* MUST be done prior to removing .init data. */ unregister_init_virtual_region (); -domain_unpause_by_systemcontroller (hardware_domain); -/* Zero the .init code and data. */ for ( va = __init_begin; va <_p (__init_end); va +=PAGE_SIZE )clear_page (va);
@@ -659,7 +665,6 @@ void __init noreturn __start_xen(unsigned long mbi_p)unsigned long nr_pages, raw_max_page, modules_headroom, *module_map;int i, j, e820_warn =0 , bytes =0 ;bool acpi_boot_table_init_done = false, relocated = false; -struct domain *dom0;struct ns16550_defaults ns16550 = { .data_bits =8 , .parity ='n' ,
@@ -1617,11 +1622,12 @@ void __init noreturn __start_xen(unsigned long mbi_p) }/* Create initial domain 0. */ - dom0 =domain_create (0 , domcr_flags,0 , &config); + dom0 =domain_create (get_initial_domain_id (), domcr_flags,0 , &config);if (IS_ERR (dom0) || (alloc_dom0_vcpu0 (dom0) ==NULL ) )panic ("Error creating domain 0" ); - dom0->is_privileged =1 ; +if ( !pv_shim ) + dom0->is_privileged =1 ; dom0->target =NULL ;/* Grab the DOM0 command line. */
xen/common/domain.c +12 -0
@@ -43,6 +43,10 @@#include <xen/tmem.h> #include <asm/setup.h> +#ifdef CONFIG_X86 +#include <asm/guest.h> +#endif +/* Linux config option: propageted to domain0 */ /* xen_processor_pmbits: xen control Cx, Px, ... */ unsigned int xen_processor_pmbits =XEN_PROCESSOR_PM_PX ;
@@ -697,6 +701,14 @@ void domain_shutdown(struct domain *d, u8 reason) {struct vcpu *v; +#ifdef CONFIG_X86 +if ( pv_shim ) + { +pv_shim_shutdown (reason); +return ; + } +#endif +spin_lock (&d->shutdown_lock);if ( d->shutdown_code ==SHUTDOWN_CODE_INVALID )
xen/include/asm-x86/guest/xen.h +6 -0
@@ -38,6 +38,7 @@ int hypervisor_alloc_unused_page(mfn_t *mfn);int hypervisor_free_unused_page (mfn_t mfn);void hypervisor_fixup_e820 (struct e820map *e820);const unsigned long *hypervisor_reserved_pages (unsigned int *size); +uint32_t hypervisor_cpuid_base (void ); DECLARE_PER_CPU(unsigned int, vcpu_id); DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
@@ -66,6 +67,11 @@ static inline const unsigned long *hypervisor_reserved_pages(unsigned int *size)ASSERT_UNREACHABLE ();return NULL ; }; +static inline uint32_t hypervisor_cpuid_base (void ) +{ +ASSERT_UNREACHABLE (); +return 0 ; +};#endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */
xen/include/asm-x86/pv/shim.h +10 -0
@@ -35,6 +35,8 @@ void pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, unsigned long va_start, unsigned long store_va, unsigned long console_va, unsigned long vphysmap, start_info_t *si); +void pv_shim_shutdown (uint8_t reason); +domid_t get_initial_domain_id (void );#else
@@ -47,6 +49,14 @@ static inline void pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, {ASSERT_UNREACHABLE (); } +static inline void pv_shim_shutdown (uint8_t reason) +{ +ASSERT_UNREACHABLE (); +} +static inline domid_t get_initial_domain_id (void ) +{ +return 0 ; +}#endif
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 16/62 x86/link: Relocate program headers
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
When the xen binary is loaded by libelf (in the future) we rely on the elf loader to load the binary accordingly. Specify the load address so that the resulting binary can make p_vaddr and p_paddr have different values.
---
v2:
Clarify commit message. Haven't tested grub1 boot.
--- xen/arch/x86/xen.lds.S | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
xen/arch/x86/xen.lds.S +13 -9
@@ -13,6 +13,7 @@ #undef __XEN_VIRT_START #define __XEN_VIRT_START __image_base__ #define SECTION_ALIGN MB(2) +#define DECL_SECTION(x) x : ENTRY(efi_start)
@@ -20,8 +21,9 @@ ENTRY(efi_start) #define FORMAT "elf64-x86-64" #define SECTION_ALIGN PAGE_SIZE +#define DECL_SECTION(x) x : AT(ADDR(x) - __XEN_VIRT_START) -ENTRY(start) +ENTRY(start_pa) #endif /* EFI */
@@ -56,9 +58,11 @@ SECTIONS __2M_text_start = .; /* Start of 2M superpages, mapped RX. */ #endif + start_pa = ABSOLUTE(start - __XEN_VIRT_START); + . = __XEN_VIRT_START + XEN_IMG_OFFSET; _start = .; - .text : { + DECL_SECTION(.text) { _stext = .; /* Text and read-only data */ *(.text) *(.text.cold)
@@ -73,7 +77,7 @@ SECTIONS __2M_text_end = .; __2M_rodata_start = .; /* Start of 2M superpages, mapped RO. */ - .rodata : { + DECL_SECTION(.rodata) { _srodata = .; /* Bug frames table */ __start_bug_frames = .;
@@ -132,13 +136,13 @@ SECTIONS * compiler may want to inject other things in the .note which we don't care * about - hence this unique name. */ - .note.gnu.build-id : { + DECL_SECTION(.note.gnu.build-id) { __note_gnu_build_id_start = .; *(.note.gnu.build-id) __note_gnu_build_id_end = .; } :note :text #elif defined(BUILD_ID_EFI) - .buildid : { + DECL_SECTION(.buildid) { __note_gnu_build_id_start = .; *(.buildid) __note_gnu_build_id_end = .;
@@ -153,7 +157,7 @@ SECTIONS __2M_init_start = .; /* Start of 2M superpages, mapped RWX (boot only). */ . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; - .init : { + DECL_SECTION(.init) { _sinittext = .; *(.init.text) /*
@@ -215,7 +219,7 @@ SECTIONS __2M_rwdata_start = .; /* Start of 2M superpages, mapped RW. */ . = ALIGN(SMP_CACHE_BYTES); - .data.read_mostly : { + DECL_SECTION(.data.read_mostly) { *(.data.read_mostly) . = ALIGN(8); __start_schedulers_array = .;
@@ -223,7 +227,7 @@ SECTIONS __end_schedulers_array = .; } :text - .data : { /* Data */ + DECL_SECTION(.data) { *(.data.page_aligned) *(.data) *(.data.rel)
@@ -231,7 +235,7 @@ SECTIONS CONSTRUCTORS } :text - .bss : { /* BSS */ + DECL_SECTION(.bss) { __bss_start = .; *(.bss.stack_aligned) *(.bss.page_aligned*)
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 53/62 xen/pvshim: support vCPU hotplug
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
---
Changes since v1:
- Fix hotplug so that v->initialized is checked before attempting to bring up the physical CPU.
- Fix ARM compilation.
--- xen/arch/x86/pv/shim.c | 63 +++++++++++++++++++++++++++++++++++++++++++ xen/common/domain.c | 38 +++++++++++++++++--------- xen/include/asm-x86/pv/shim.h | 12 +++++++++ xen/include/xen/domain.h | 1 + 4 files changed, 102 insertions(+), 12 deletions(-)
xen/arch/x86/pv/shim.c +63 -0
@@ -751,6 +751,69 @@ static long pv_shim_grant_table_op(unsigned int cmd,return rc; } +long pv_shim_cpu_up (void *data) +{ +struct vcpu *v = data; +struct domain *d = v->domain; +bool wake; + +BUG_ON (smp_processor_id () !=0 ); + +domain_lock (d); +if ( !v->is_initialised ) + { +domain_unlock (d); +return -EINVAL ; + } + +if ( !cpu_online (v->vcpu_id) ) + { +long rc =cpu_up_helper ((void *)(unsigned long )v->vcpu_id); + +if ( rc ) + { +domain_unlock (d); +gprintk (XENLOG_ERR ,"Failed to bring up CPU#%u: %ld\n" , + v->vcpu_id, rc); +return rc; + } + } + + wake =test_and_clear_bit (_VPF_down, &v->pause_flags); +domain_unlock (d); +if ( wake ) +vcpu_wake (v); + +return 0 ; +} + +long pv_shim_cpu_down (void *data) +{ +struct vcpu *v = data; +long rc; + +BUG_ON (smp_processor_id () !=0 ); + +if ( !test_and_set_bit (_VPF_down, &v->pause_flags) ) +vcpu_sleep_sync (v); + +if (cpu_online (v->vcpu_id) ) + { + rc =cpu_down_helper ((void *)(unsigned long )v->vcpu_id); +if ( rc ) +gprintk (XENLOG_ERR ,"Failed to bring down CPU#%u: %ld\n" , + v->vcpu_id, rc); +/* +* NB: do not propagate errors from cpu_down_helper failing. The shim +* is going to run with extra CPUs, but that's not going to prevent +* normal operation. OTOH most guests are not prepared to handle an +* error on VCPUOP_down failing, and will likely panic. +*/ + } + +return 0 ; +} +domid_t get_initial_domain_id (void ) {uint32_t eax, ebx, ecx, edx;
xen/common/domain.c +26 -12
@@ -1301,22 +1301,36 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)break ; -case VCPUOP_up: { -bool_t wake =0 ; -domain_lock (d); -if ( !v->is_initialised ) - rc = -EINVAL ; +case VCPUOP_up: +#ifdef CONFIG_X86 +if ( pv_shim ) + rc =continue_hypercall_on_cpu (0 , pv_shim_cpu_up, v); else - wake =test_and_clear_bit (_VPF_down, &v->pause_flags); -domain_unlock (d); -if ( wake ) -vcpu_wake (v); +#endif + { +bool wake = false; + +domain_lock (d); +if ( !v->is_initialised ) + rc = -EINVAL ; +else + wake =test_and_clear_bit (_VPF_down, &v->pause_flags); +domain_unlock (d); +if ( wake ) +vcpu_wake (v); + } +break ; - }case VCPUOP_down: -if ( !test_and_set_bit (_VPF_down, &v->pause_flags) ) -vcpu_sleep_nosync (v); +#ifdef CONFIG_X86 +if ( pv_shim ) + rc =continue_hypercall_on_cpu (0 , pv_shim_cpu_down, v); + else +#endif +if ( !test_and_set_bit (_VPF_down, &v->pause_flags) ) +vcpu_sleep_nosync (v); +break ;case VCPUOP_is_up:
xen/include/asm-x86/pv/shim.h +12 -0
@@ -37,6 +37,8 @@ void pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, start_info_t *si);int pv_shim_shutdown (uint8_t reason);void pv_shim_inject_evtchn (unsigned int port); +long pv_shim_cpu_up (void *data); +long pv_shim_cpu_down (void *data);domid_t get_initial_domain_id (void );uint64_t pv_shim_mem (uint64_t avail);
@@ -60,6 +62,16 @@ static inline void pv_shim_inject_evtchn(unsigned int port) {ASSERT_UNREACHABLE (); } +static inline long pv_shim_cpu_up (void *data) +{ +ASSERT_UNREACHABLE (); +return 0 ; +} +static inline long pv_shim_cpu_down (void *data) +{ +ASSERT_UNREACHABLE (); +return 0 ; +}static inline domid_t get_initial_domain_id (void ) {return 0 ;
xen/include/xen/domain.h +1 -0
@@ -17,6 +17,7 @@ struct vcpu *alloc_vcpu( struct domain *d, unsigned int vcpu_id, unsigned int cpu_id);struct vcpu *alloc_dom0_vcpu0 (struct domain *dom0);int vcpu_reset (struct vcpu *); +int vcpu_up (struct vcpu *v);struct xen_domctl_getdomaininfo ;void getdomaininfo (struct domain *d,struct xen_domctl_getdomaininfo *info);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 23/62 x86/shutdown: Support for using SCHEDOP_{shutdown, reboot}
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
---
v2:
1. Use sched_shutdown
2. Move header inclusion
--- docs/misc/xen-command-line.markdown | 3 +++ xen/arch/x86/shutdown.c | 34 ++++++++++++++++++++++++++++++---- xen/include/asm-x86/guest/hypercall.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 4 deletions(-)
docs/misc/xen-command-line.markdown +3 -0
@@ -1478,6 +1478,9 @@ Specify the host reboot method. 'efi' instructs Xen to reboot using the EFI reboot call (in EFI mode by default it will use that method first). +`xen` instructs Xen to reboot using Xen's SCHEDOP hypercall (this is the default +when running nested Xen) + ### rmrr > '= start<-end>=[s1]bdf1[,[s1]bdf2[,...]];start<-end>=[s2]bdf1[,[s2]bdf2[,...]]
xen/arch/x86/shutdown.c +30 -4
@@ -25,6 +25,7 @@#include <asm/mpspec.h> #include <asm/tboot.h> #include <asm/apic.h> +#include <asm/guest.h> enum reboot_type {BOOT_INVALID ,
@@ -34,6 +35,7 @@ enum reboot_type {BOOT_CF9 ='p' ,BOOT_CF9_PWR ='P' ,BOOT_EFI ='e' , + BOOT_XEN = 'x', };static int reboot_mode;
@@ -49,6 +51,7 @@ static int reboot_mode;* pci Use the so-called "PCI reset register", CF9 * Power Like 'pci' but for a full power-cyle reset * efi Use the EFI reboot (if running under EFI) +* xen Use Xen SCHEDOP hypercall (if running under Xen as a guest) */ static enum reboot_type reboot_type =BOOT_INVALID ;
@@ -75,6 +78,7 @@ static int __init set_reboot_type(const char *str)case 'P' :case 'p' :case 't' : +case 'x' : reboot_type = *str;break ;default :
@@ -93,6 +97,13 @@ static int __init set_reboot_type(const char *str) reboot_type =BOOT_INVALID ; } +if ( reboot_type ==BOOT_XEN && !xen_guest ) + { +printk ("Xen reboot selected, but Xen hypervisor not detected\n" +"Falling back to default\n" ); + reboot_type =BOOT_INVALID ; + } +return rc; }custom_param ("reboot" , set_reboot_type);
@@ -109,6 +120,10 @@ static inline void kb_wait(void)static void noreturn__machine_halt (void *unused) {local_irq_disable (); + +if ( reboot_type ==BOOT_XEN ) +xen_hypercall_shutdown (SHUTDOWN_poweroff); +for ( ; ; )halt (); }
@@ -129,10 +144,17 @@ void machine_halt(void)static void default_reboot_type (void ) { -if ( reboot_type ==BOOT_INVALID ) - reboot_type =efi_enabled (EFI_RS ) ?BOOT_EFI - : acpi_disabled ?BOOT_KBD - :BOOT_ACPI ; +if ( reboot_type !=BOOT_INVALID ) +return ; + +if ( xen_guest ) + reboot_type =BOOT_XEN ; +else if (efi_enabled (EFI_RS ) ) + reboot_type =BOOT_EFI ; +else if ( acpi_disabled ) + reboot_type =BOOT_KBD ; +else + reboot_type =BOOT_ACPI ; }static int __init override_reboot (struct dmi_system_id *d)
@@ -618,6 +640,10 @@ void machine_restart(unsigned int delay_millisecs) } reboot_type =BOOT_ACPI ;break ; + +case BOOT_XEN : +xen_hypercall_shutdown (SHUTDOWN_reboot); +break ; } } }
xen/include/asm-x86/guest/hypercall.h +32 -0
@@ -21,6 +21,11 @@#ifdef CONFIG_XEN_GUEST +#include <xen/types.h> + +#include <public/xen.h> +#include <public/sched.h> +/* * Hypercall primatives for 64bit *
@@ -78,6 +83,33 @@ (type )res; \ }) +/* +* Primitive Hypercall wrappers +*/ +static inline long xen_hypercall_sched_op (unsigned int cmd,void *arg) +{ +return _hypercall64_2 (long, __HYPERVISOR_sched_op, cmd, arg); +} + +/* +* Higher level hypercall helpers +*/ +static inline long xen_hypercall_shutdown (unsigned int reason) +{ +struct sched_shutdown s = { .reason = reason }; +return xen_hypercall_sched_op (SCHEDOP_shutdown, &s); +} + +#else /* CONFIG_XEN_GUEST */ + +#include <public/sched.h> + +static inline long xen_hypercall_shutdown (unsigned int reason) +{ +ASSERT_UNREACHABLE (); +return 0 ; +} +#endif /* CONFIG_XEN_GUEST */ #endif /* __X86_XEN_HYPERCALL_H__ */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 10/62 xen/domctl: Return arch_config via getdomaininfo
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
This allows toolstack software to distinguish HVM from PVH guests.
---
v2: bump domctl version number
--- tools/libxc/include/xenctrl.h | 1 + tools/libxc/xc_domain.c | 1 + xen/arch/x86/domctl.c | 2 ++ xen/include/public/domctl.h | 3 ++- 4 files changed, 6 insertions(+), 1 deletion(-)
tools/libxc/include/xenctrl.h +1 -0
@@ -456,6 +456,7 @@ typedef struct xc_dominfo {unsigned int max_vcpu_id;xen_domain_handle_t handle;unsigned int cpupool; +struct xen_arch_domainconfig arch_config; } xc_dominfo_t;typedef xen_domctl_getdomaininfo_t xc_domaininfo_t ;
tools/libxc/xc_domain.c +1 -0
@@ -421,6 +421,7 @@ int xc_domain_getinfo(xc_interface *xch, info->nr_online_vcpus = domctl.u.getdomaininfo.nr_online_vcpus; info->max_vcpu_id = domctl.u.getdomaininfo.max_vcpu_id; info->cpupool = domctl.u.getdomaininfo.cpupool; + info->arch_config = domctl.u.getdomaininfo.arch_config;memcpy (info->handle, domctl.u.getdomaininfo.handle,sizeof (xen_domain_handle_t));
xen/arch/x86/domctl.c +2 -0
@@ -348,6 +348,8 @@ void arch_get_domain_info(const struct domain *d, {if (paging_mode_hap (d) ) info->flags |= XEN_DOMINF_hap; + + info->arch_config.emulation_flags = d->arch.emulation_flags; }#define MAX_IOPORTS 0x10000
xen/include/public/domctl.h +2 -1
@@ -38,7 +38,7 @@#include "hvm/save.h" #include "memory.h" -#define XEN_DOMCTL_INTERFACE_VERSION 0x0000000e +#define XEN_DOMCTL_INTERFACE_VERSION 0x0000000f/* * NB. xen_domctl.domain is an IN/OUT parameter for this operation.
@@ -116,6 +116,7 @@ struct xen_domctl_getdomaininfo {uint32_t ssidref;xen_domain_handle_t handle;uint32_t cpupool; +struct xen_arch_domainconfig arch_config; };typedef struct xen_domctl_getdomaininfo xen_domctl_getdomaininfo_t ;DEFINE_XEN_GUEST_HANDLE (xen_domctl_getdomaininfo_t);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 49/62 x86/pv-shim: shadow PV console's page for L2 DomU
In reply to Wei LiuFrom: Sergey Dyasli <[email protected]>
---
Changes since v1:
- Use pv_shim_inject_evtchn.
--- xen/arch/x86/pv/shim.c | 31 ++++++++-- xen/drivers/char/Makefile | 1 + xen/drivers/char/console.c | 6 ++ xen/drivers/char/consoled.c | 148 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/consoled.h | 27 ++++++++ 5 files changed, 209 insertions(+), 4 deletions(-) create mode 100644 xen/drivers/char/consoled.c create mode 100644 xen/include/xen/consoled.h
xen/arch/x86/pv/shim.c +27 -4
@@ -25,6 +25,8 @@#include <xen/iocap.h> #include <xen/shutdown.h> #include <xen/types.h> +#include <xen/consoled.h> +#include <xen/pv_console.h> #include <asm/apic.h> #include <asm/dom0_build.h>
@@ -127,13 +129,28 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, })SET_AND_MAP_PARAM (HVM_PARAM_STORE_PFN , si->store_mfn, store_va);SET_AND_MAP_PARAM (HVM_PARAM_STORE_EVTCHN , si->store_evtchn,0 ); +SET_AND_MAP_PARAM (HVM_PARAM_CONSOLE_EVTCHN , si->console.domU.evtchn,0 );if ( !pv_console ) - {SET_AND_MAP_PARAM (HVM_PARAM_CONSOLE_PFN , si->console.domU.mfn, console_va); -SET_AND_MAP_PARAM (HVM_PARAM_CONSOLE_EVTCHN , si->console.domU.evtchn,0 ); - }#undef SET_AND_MAP_PARAM + else + { +/* Allocate a new page for DomU's PV console */ +void *page =alloc_xenheap_pages (0 ,MEMF_bits (32 )); +uint64_t console_mfn; + +ASSERT (page); +clear_page (page); + console_mfn =virt_to_mfn (page); + si->console.domU.mfn = console_mfn; +share_xen_page_with_guest (mfn_to_page (console_mfn), d, + XENSHARE_writable); +replace_va_mapping (d, l4start, console_va, console_mfn); +dom0_update_physmap (d, (console_va - va_start) >>PAGE_SHIFT , + console_mfn, vphysmap); +consoled_set_ring_addr (page); + }pv_hypercall_table_replace (__HYPERVISOR_event_channel_op, (hypercall_fn_t *)pv_shim_event_channel_op, (hypercall_fn_t *)pv_shim_event_channel_op);
@@ -341,7 +358,13 @@ static long pv_shim_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_from_guest (&send, arg,1 ) !=0 )return -EFAULT ; - rc =xen_hypercall_event_channel_op (EVTCHNOP_send, &send); +if ( pv_console && send.port ==pv_console_evtchn () ) + { +consoled_guest_rx (); + rc =0 ; + } +else + rc =xen_hypercall_event_channel_op (EVTCHNOP_send, &send);break ; }
xen/drivers/char/Makefile +1 -0
@@ -9,3 +9,4 @@ obj-$(CONFIG_HAS_EHCI) += ehci-dbgp.o obj-$(CONFIG_ARM) += arm-uart.o obj-y += serial.o obj-$(CONFIG_XEN_GUEST) += xen_pv_console.o +obj-$(CONFIG_PV_SHIM) += consoled.o
xen/drivers/char/console.c +6 -0
@@ -32,6 +32,7 @@#include <xen/warning.h> #ifdef CONFIG_X86 +#include <xen/consoled.h> #include <xen/pv_console.h> #include <asm/guest.h> #endif
@@ -415,6 +416,11 @@ static void __serial_rx(char c, struct cpu_user_regs *regs) serial_rx_ring[SERIAL_RX_MASK (serial_rx_prod++)] = c;/* Always notify the guest: prevents receive path from getting stuck. */ send_global_virq (VIRQ_CONSOLE ); + +#ifdef CONFIG_X86 +if ( pv_shim && pv_console ) +consoled_guest_tx (c); +#endif }static void serial_rx (char c,struct cpu_user_regs *regs)
xen/drivers/char/consoled.c new file +148 -0
148 lines not on this page · raw message
xen/include/xen/consoled.h new file +27 -0
@@ -0,0 +1,27 @@ +#ifndef __XEN_CONSOLED_H__ +#define __XEN_CONSOLED_H__ + +#include <public/io/console.h> + +#ifdef CONFIG_PV_SHIM + +void consoled_set_ring_addr (struct xencons_interface *ring); +struct xencons_interface *consoled_get_ring_addr (void ); +size_t consoled_guest_rx (void ); +size_t consoled_guest_tx (char c); + +#else + +size_t consoled_guest_tx (char c) {return 0 ; } + +#endif /* !CONFIG_PV_SHIM */ +#endif /* __XEN_CONSOLED_H__ */ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 57/62 xen/shim: crash instead of reboot in shim mode
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
All guest shutdown operations are forwarded to L0, so the only native calls to machine_restart happen from crash related paths inside the hypervisor, hence switch the reboot code to instead issue a crash shutdown.
---
Changes since v1:
- Use the ternary operator.
--- xen/arch/x86/shutdown.c | 7 ++++++- xen/drivers/char/console.c | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-)
xen/arch/x86/shutdown.c +6 -1
@@ -642,7 +642,12 @@ void machine_restart(unsigned int delay_millisecs)break ;case BOOT_XEN : -xen_hypercall_shutdown (SHUTDOWN_reboot); +/* +* When running in PV shim mode guest shutdown calls are +* forwarded to L0, hence the only way to get here is if a +* shim crash happens. +*/ +xen_hypercall_shutdown (pv_shim ? SHUTDOWN_crash : SHUTDOWN_reboot);break ; } }
xen/drivers/char/console.c +4 -0
@@ -1253,7 +1253,11 @@ void panic(const char *fmt, ...)if ( opt_noreboot )printk ("Manual reset required ('noreboot' specified)\n" ); else +#ifdef CONFIG_X86 +printk ("%s in five seconds...\n" , pv_shim ?"Crash" :"Reboot" ); +#else printk ("Reboot in five seconds...\n" ); +#endif spin_unlock_irqrestore (&lock, flags);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 13/62 x86/fixmap: Modify fix_to_virt() to return a void pointer
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
Almost all users of fix_to_virt() actually want a pointer. Include the cast within the definition, so the callers don't need to.
Two users which need the integer value are switched to using __fix_to_virt() directly. A few users stay fully unchanged, due to GCC's void pointer arithmetic extension causing the same behaviour. Most users however have their explicit casting dropped.
Since __iomem is not used consistently in Xen, we drop it too.
No functional change.
---
v2: update commit message and remove unnecessary parentheses.
--- xen/arch/x86/acpi/lib.c | 2 +- xen/arch/x86/mm.c | 4 ++-- xen/arch/x86/mpparse.c | 2 +- xen/arch/x86/msi.c | 3 +-- xen/arch/x86/tboot.c | 4 ++-- xen/drivers/acpi/apei/apei-io.c | 2 +- xen/drivers/char/ehci-dbgp.c | 2 +- xen/drivers/char/ns16550.c | 2 +- xen/include/asm-x86/apicdef.h | 2 +- xen/include/asm-x86/fixmap.h | 2 +- 10 files changed, 12 insertions(+), 13 deletions(-)
xen/arch/x86/acpi/lib.c +1 -1
@@ -49,7 +49,7 @@ char *__acpi_map_table(paddr_t phys, unsigned long size) offset = phys & (PAGE_SIZE -1 ); mapped_size =PAGE_SIZE - offset;set_fixmap (FIX_ACPI_END , phys); - base =fix_to_virt (FIX_ACPI_END ); + base =__fix_to_virt (FIX_ACPI_END );/* * Most cases can be covered by the below.
xen/arch/x86/mm.c +2 -2
@@ -5227,12 +5227,12 @@ void __set_fixmap( enum fixed_addresses idx, unsigned long mfn, unsigned long flags) { BUG_ON(idx >= __end_of_fixed_addresses); -map_pages_to_xen (fix_to_virt (idx), mfn,1 , flags); +map_pages_to_xen (__fix_to_virt (idx), mfn,1 , flags); }void *__init arch_vmap_virt_end (void ) { -return (void *)fix_to_virt (__end_of_fixed_addresses); +return fix_to_virt (__end_of_fixed_addresses); }void __iomem *ioremap (paddr_t pa,size_t len)
xen/arch/x86/mpparse.c +1 -1
@@ -703,7 +703,7 @@ static void __init efi_check_config(void)return ;__set_fixmap (FIX_EFI_MPF ,PFN_DOWN (efi.mps), __PAGE_HYPERVISOR); - mpf = (void *)fix_to_virt (FIX_EFI_MPF ) + ((long )efi.mps & (PAGE_SIZE -1 )); + mpf =fix_to_virt (FIX_EFI_MPF ) + ((long )efi.mps & (PAGE_SIZE -1 )); if (memcmp(mpf->mpf_signature, "_MP_", 4) == 0 && mpf->mpf_length == 1 &&
xen/arch/x86/msi.c +1 -2
@@ -960,8 +960,7 @@ static int msix_capability_init(struct pci_dev *dev,xfree (entry);return idx; } - base = (void *)(fix_to_virt (idx) + - ((unsigned long )entry_paddr & (PAGE_SIZE -1 ))); + base =fix_to_virt (idx) + (entry_paddr & (PAGE_SIZE -1 ));/* Mask interrupt here */ writel (1 , base +PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET );
xen/arch/x86/tboot.c +2 -2
@@ -82,7 +82,7 @@ static void __init tboot_copy_memory(unsigned char *va, uint32_t size, { map_base =PFN_DOWN (pa + i);set_fixmap (FIX_TBOOT_MAP_ADDRESS , map_base <<PAGE_SHIFT ); - map_addr = (unsigned char *)fix_to_virt (FIX_TBOOT_MAP_ADDRESS ); + map_addr =fix_to_virt (FIX_TBOOT_MAP_ADDRESS ); } va[i] = map_addr[pa + i - (map_base <<PAGE_SHIFT )]; }
@@ -98,7 +98,7 @@ void __init tboot_probe(void)/* Map and check for tboot UUID. */ set_fixmap (FIX_TBOOT_SHARED_BASE , opt_tboot_pa); - tboot_shared = (tboot_shared_t *)fix_to_virt (FIX_TBOOT_SHARED_BASE ); + tboot_shared =fix_to_virt (FIX_TBOOT_SHARED_BASE );if ( tboot_shared ==NULL )return ;if (memcmp (&tboot_shared_uuid, (uuid_t *)tboot_shared,sizeof (uuid_t)) )
xen/drivers/acpi/apei/apei-io.c +1 -1
@@ -92,7 +92,7 @@ static void __iomem *__init apei_range_map(paddr_t paddr, unsigned long size) apei_range_nr++; } -return (void __iomem *)fix_to_virt (FIX_APEI_RANGE_BASE + start_nr); +return fix_to_virt (FIX_APEI_RANGE_BASE + start_nr); }/*
xen/drivers/char/ehci-dbgp.c +1 -1
@@ -1327,7 +1327,7 @@ static void __init ehci_dbgp_init_preirq(struct serial_port *port)* than enough. 1k is the biggest that was seen. */ set_fixmap_nocache (FIX_EHCI_DBGP , dbgp->bar_val); - ehci_bar = (void __iomem *)fix_to_virt (FIX_EHCI_DBGP ); + ehci_bar =fix_to_virt (FIX_EHCI_DBGP ); ehci_bar += dbgp->bar_val & ~PAGE_MASK ;dbgp_printk ("ehci_bar: %p\n" , ehci_bar);
xen/drivers/char/ns16550.c +1 -1
@@ -697,7 +697,7 @@ static void __init ns16550_init_preirq(struct serial_port *port)enum fixed_addresses idx =FIX_COM_BEGIN + (uart - ns16550_com);set_fixmap_nocache (idx, uart->io_base); - uart->remapped_io_base = (void __iomem *)fix_to_virt (idx); + uart->remapped_io_base =fix_to_virt (idx); uart->remapped_io_base += uart->io_base & ~PAGE_MASK ;#else uart->remapped_io_base = (char *)ioremap (uart->io_base, uart->io_size);
xen/include/asm-x86/apicdef.h +1 -1
@@ -119,7 +119,7 @@/* Only available in x2APIC mode */ #define APIC_SELF_IPI 0x3F0 -#define APIC_BASE (fix_to_virt(FIX_APIC_BASE)) +#define APIC_BASE __fix_to_virt(FIX_APIC_BASE)/* It's only used in x2APIC mode of an x2APIC unit. */ #define APIC_MSR_BASE 0x800
xen/include/asm-x86/fixmap.h +1 -1
@@ -79,7 +79,7 @@ extern void __set_fixmap(#define __fix_to_virt (x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))#define __virt_to_fix (x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT) -#define fix_to_virt (x) (__fix_to_virt(x)) +#define fix_to_virt (x) ((void *)__fix_to_virt(x))static inline unsigned long virt_to_fix (const unsigned long vaddr) {
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 42/62 sched/null: skip vCPUs on the waitqueue that are blocked
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
Avoid scheduling vCPUs that are down, there's no point in assigning them to a pCPU because they are not going to run anyway.
Since down vCPUs are not assigned to pCPUs after this change, force a rescheduling when a vCPU is brought up if it's on the waitqueue. Also when scheduling try to pick a vCPU from the runqueue if the pCPU is running idle.
There's no current way to prevent a user from adding more vcpus to a pool than there are pcpus (if nothing else, by creating a new VM in a given pool), or from taking pcpus from a pool in which #vcpus >= #pcpus.
The null scheduler deals with this by having a queue of "unassigned" vcpus that are waiting for a free pcpu. When a pcpu becomes available, it will do the assignment. When a pcpu that has a vcpu is assigned is removed from the pool, that vcpu is assigned to a different pcpu if one is available; if not, it is put on the list.
In the case of shim mode, this also seems to happen whenever curvcpus < maxvcpus: The L1 hypervisor (shim) only sees curvcpus cpus on which to schedule L2 vcpus, but the L2 guest has maxvcpus vcpus to schedule, of which (maxvcpus-curvcpus) are marked down. In this case, it also seems that the null scheduler sometimes schedules a down vcpu when there are up vcpus on the list; meaning that the up vcpus are never scheduled.
---
Cc: George Dunlap <[email protected]>
Cc: Dario Faggioli <[email protected]>
---
Changes since v1:
- Force a rescheduling when a vCPU is brought up.
- Try to pick a vCPU from the runqueue if running the idle vCPU.
- Add George Dunlap description of the problem to the commit log.
--- xen/common/sched_null.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
xen/common/sched_null.c +9 -2
@@ -574,6 +574,8 @@ static void null_vcpu_wake(const struct scheduler *ops, struct vcpu *v) {/* Not exactly "on runq", but close enough for reusing the counter */ SCHED_STAT_CRANK (vcpu_wake_onrunq); +/* Force a rescheduling in case some CPU is idle can pick this vCPU */ +cpumask_raise_softirq (&cpu_online_map,SCHEDULE_SOFTIRQ );return ; }
@@ -761,9 +763,10 @@ static struct task_slice null_schedule(const struct scheduler *ops,/* * We may be new in the cpupool, or just coming back online. In which * case, there may be vCPUs in the waitqueue that we can assign to us -* and run. +* and run. Also check whether this CPU is running idle, in which case try +* to pick a vCPU from the waitqueue. */ -if (unlikely (ret.task ==NULL ) ) +if (unlikely (ret.task ==NULL || ret.task == idle_vcpu[cpu]) ) {spin_lock (&prv->waitq_lock);
@@ -781,6 +784,10 @@ static struct task_slice null_schedule(const struct scheduler *ops, {list_for_each_entry ( wvc, &prv->waitq, waitq_elem ) { +if (test_bit (_VPF_down, &wvc->vcpu->pause_flags) ) +/* Skip vCPUs that are down. */ +continue ; +if ( bs ==BALANCE_SOFT_AFFINITY && !has_soft_affinity (wvc->vcpu, wvc->vcpu->cpu_hard_affinity) )continue ;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 60/62 libxl: pvshim: Introduce pvshim_extra
In reply to Wei LiuFrom: Ian Jackson <[email protected]>
And move the debugging options from the default config into a doc comment in libxl_types.idl.
---
v2: pvshim, not pvhshim
works with type "pvh", not type "pv"
--- tools/libxl/libxl.h | 2 +- tools/libxl/libxl_create.c | 5 ++++- tools/libxl/libxl_internal.h | 2 +- tools/libxl/libxl_types.idl | 1 + 4 files changed, 7 insertions(+), 3 deletions(-)
tools/libxl/libxl.h +1 -1
@@ -1105,7 +1105,7 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src);* LIBXL_HAVE_PV_SHIM * * If this is defined, libxl_domain_build_info's pvh type information -* contains members pvshim, pvshim_path, pvshim_cmdline. +* contains members pvshim, pvshim_path, pvshim_cmdline, pvshim_extra. */ #define LIBXL_HAVE_PV_SHIM 1
tools/libxl/libxl_create.c +4 -1
@@ -508,7 +508,10 @@ int libxl__domain_build(libxl__gc *gc,break ;case LIBXL_DOMAIN_TYPE_PVH : state->shim_path = info->u.pvh.pvshim_path; - state->shim_cmdline = info->u.pvh.pvshim_cmdline; + state->shim_cmdline =GCSPRINTF ("%s%s%s" , + info->u.pvh.pvshim_cmdline, + info->u.pvh.pvshim_extra ?" " :"" , + info->u.pvh.pvshim_extra ? info->u.pvh.pvshim_extra :"" ); ret =libxl__build_hvm (gc, domid, d_config, state);if (ret)
tools/libxl/libxl_internal.h +1 -1
@@ -119,7 +119,7 @@#define DOMID_XS_PATH "domid"#define INVALID_DOMID ~0#define PVSHIM_BASENAME "xen-shim" -#define PVSHIM_CMDLINE "pv-shim console=xen,pv sched=null loglvl=all guest_loglvl=all apic_verbosity=debug e820-verbose" +#define PVSHIM_CMDLINE "pv-shim console=xen,pv sched=null"/* Size macros. */ #define __AC (X ,Y ) (X##Y)
tools/libxl/libxl_types.idl +1 -0
@@ -595,6 +595,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("pvh", Struct(None, [("pvshim", libxl_defbool), ("pvshim_path", string), ("pvshim_cmdline", string), + ("pvshim_extra", string), # eg "loglvl=all guest_loglvl=all apic_verbosity=debug e820-verbose" ])), ("invalid", None), ], keyvar_init_val = "LIBXL_DOMAIN_TYPE_INVALID")),
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 17/62 x86: introduce ELFNOTE macro
In reply to Wei LiuIt is needed later for introducing PVH entry point.
---
v2:
1. Specify section attribute and type.
2. Use p2align.
3. Align instructions.
4. Haven't used .L or turned it into assembly macro.
--- xen/include/asm-x86/asm_defns.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
xen/include/asm-x86/asm_defns.h +12 -0
@@ -336,4 +336,16 @@ static always_inline void stac(void)#define REX64_PREFIX "rex64/"#endif +#define ELFNOTE(name, type, desc) \ + .pushsection .note.name, "a", @note ; \ + .p2align 2 ; \ + .long 2f - 1f /* namesz */ ; \ + .long 4f - 3f /* descsz */ ; \ + .long type /* type */ ; \ +1: .asciz #name /* name */ ; \ +2: .p2align 2 ; \ +3: desc/* desc */ ; \ +4: .p2align 2 ; \ + .popsection +#endif /* __X86_ASM_DEFNS_H__ */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 21/62 x86/entry: Probe for Xen early during boot
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
---
v2: Add __read_mostly.
--- xen/arch/x86/guest/Makefile | 2 ++ xen/arch/x86/guest/xen.c | 75 +++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/setup.c | 2 ++ xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/xen.h | 47 ++++++++++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 xen/arch/x86/guest/xen.c create mode 100644 xen/include/asm-x86/guest/xen.h
xen/arch/x86/guest/Makefile +2 -0
@@ -1 +1,3 @@ +obj-y += xen.o + obj-bin-$(CONFIG_PVH_GUEST) += pvh-boot.init.o
xen/arch/x86/guest/xen.c new file +75 -0
75 lines not on this page · raw message
xen/arch/x86/setup.c +2 -0
@@ -715,6 +715,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)* allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations (); +probe_hypervisor (); +parse_video_info ();rdmsrl (MSR_EFER ,this_cpu (efer));
xen/include/asm-x86/guest.h +1 -0
@@ -20,6 +20,7 @@#define __X86_GUEST_H__#include <asm/guest/pvh-boot.h> +#include <asm/guest/xen.h> #endif /* __X86_GUEST_H__ */
xen/include/asm-x86/guest/xen.h new file +47 -0
47 lines not on this page · raw message
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 32/62 x86: APIC timer calibration when running as a guest
In reply to Wei LiuThe timer calibration currently depends on PIT. Introduce a variant to wait for a tick's worth of time to elapse when running as a PVH guest.
--- xen/arch/x86/apic.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-)
xen/arch/x86/apic.c +30 -8
@@ -36,6 +36,8 @@#include <mach_apic.h> #include <io_ports.h> #include <xen/kexec.h> +#include <asm/guest.h> +#include <asm/time.h> static bool __read_mostly tdt_enabled;static bool __initdata tdt_enable = true;
@@ -1091,6 +1093,20 @@ static void setup_APIC_timer(void)local_irq_restore (flags); } +static void wait_tick_pvh (void ) +{ +u64 lapse_ns =1000000000ULL /HZ ; +s_time_t start, curr_time; + + start =NOW (); + +/* Won't wrap around */ +do { +cpu_relax (); + curr_time =NOW (); + }while ( curr_time - start < lapse_ns ); +} +/* * In this function we calibrate APIC bus clocks to the external * timer. Unfortunately we cannot use jiffies and the timer irq
@@ -1123,12 +1139,15 @@ static int __init calibrate_APIC_clock(void)*/ __setup_APIC_LVTT (1000000000 ); -/* -* The timer chip counts down to zero. Let's wait -* for a wraparound to start exact measurement: -* (the current tick might have been already half done) -*/ -wait_8254_wraparound (); +if ( !xen_guest ) +/* +* The timer chip counts down to zero. Let's wait +* for a wraparound to start exact measurement: +* (the current tick might have been already half done) +*/ +wait_8254_wraparound (); +else +wait_tick_pvh ();/* * We wrapped around just now. Let's start:
@@ -1137,10 +1156,13 @@ static int __init calibrate_APIC_clock(void) tt1 =apic_read (APIC_TMCCT );/* -* Let's wait LOOPS wraprounds: +* Let's wait LOOPS ticks: */ for (i =0 ; i <LOOPS ; i++) -wait_8254_wraparound (); +if ( !xen_guest ) +wait_8254_wraparound (); +else +wait_tick_pvh (); tt2 =apic_read (APIC_TMCCT ); t2 =rdtsc_ordered ();
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 36/62 x86/guest: add PV console code
In reply to Wei LiuFrom: Sergey Dyasli <[email protected]>
--- xen/drivers/char/Makefile | 1 + xen/drivers/char/xen_pv_console.c | 205 ++++++++++++++++++++++++++++++++++ xen/include/asm-x86/fixmap.h | 1 + xen/include/asm-x86/guest/hypercall.h | 33 ++++++ xen/include/xen/pv_console.h | 32 ++++++ 5 files changed, 272 insertions(+) create mode 100644 xen/drivers/char/xen_pv_console.c create mode 100644 xen/include/xen/pv_console.h
xen/drivers/char/Makefile +1 -0
@@ -8,3 +8,4 @@ obj-$(CONFIG_HAS_SCIF) += scif-uart.o obj-$(CONFIG_HAS_EHCI) += ehci-dbgp.o obj-$(CONFIG_ARM) += arm-uart.o obj-y += serial.o +obj-$(CONFIG_XEN_GUEST) += xen_pv_console.o
xen/drivers/char/xen_pv_console.c new file +205 -0
205 lines not on this page · raw message
xen/include/asm-x86/fixmap.h +1 -0
@@ -46,6 +46,7 @@ enum fixed_addresses { FIX_COM_END, FIX_EHCI_DBGP,#ifdef CONFIG_XEN_GUEST + FIX_PV_CONSOLE, FIX_XEN_SHARED_INFO,#endif /* CONFIG_XEN_GUEST */ /* Everything else should go further down. */
xen/include/asm-x86/guest/hypercall.h +33 -0
@@ -105,6 +105,11 @@ static inline int xen_hypercall_vcpu_op(unsigned int cmd, unsigned int vcpu,return _hypercall64_3 (long, __HYPERVISOR_vcpu_op, cmd, vcpu, arg); } +static inline long xen_hypercall_event_channel_op (unsigned int cmd,void *arg) +{ +return _hypercall64_2 (long, __HYPERVISOR_event_channel_op, cmd, arg); +} +static inline long xen_hypercall_hvm_op (unsigned int op,void *arg) {return _hypercall64_2 (long, __HYPERVISOR_hvm_op, op, arg);
@@ -126,6 +131,34 @@ static inline long xen_hypercall_shutdown(unsigned int reason)return xen_hypercall_sched_op (SCHEDOP_shutdown, &s); } +static inline long xen_hypercall_evtchn_send (evtchn_port_t port) +{ +struct evtchn_send send = { .port = port }; + +return xen_hypercall_event_channel_op (EVTCHNOP_send, &send); +} + +static inline long xen_hypercall_evtchn_unmask (evtchn_port_t port) +{ +struct evtchn_unmask unmask = { .port = port }; + +return xen_hypercall_event_channel_op (EVTCHNOP_unmask, &unmask); +} + +static inline long xen_hypercall_hvm_get_param (uint32_t index,uint64_t *value) +{ +struct xen_hvm_param xhv = { + .domid =DOMID_SELF , + .index = index, + }; +long ret =xen_hypercall_hvm_op (HVMOP_get_param, &xhv); + +if ( ret ==0 ) + *value = xhv.value; + +return ret; +} +static inline long xen_hypercall_set_evtchn_upcall_vector (unsigned int cpu,unsigned int vector) {
xen/include/xen/pv_console.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef __XEN_PV_CONSOLE_H__ +#define __XEN_PV_CONSOLE_H__ + +#include <xen/serial.h> + +#ifdef CONFIG_XEN_GUEST + +void pv_console_init (void ); +void pv_console_set_rx_handler (serial_rx_fn fn); +void pv_console_init_postirq (void ); +void pv_console_puts (const char *buf); +size_t pv_console_rx (struct cpu_user_regs *regs); + +#else + +static inline void pv_console_init (void ) {} +static inline void pv_console_set_rx_handler (serial_rx_fn fn) { } +static inline void pv_console_init_postirq (void ) { } +static inline void pv_console_puts (const char *buf) { } +static inline size_t pv_console_rx (struct cpu_user_regs *regs) {return 0 ; } + +#endif /* !CONFIG_XEN_GUEST */ +#endif /* __XEN_PV_CONSOLE_H__ */ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 56/62 xen/pvshim: use default position for the m2p mappings
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
When running a 32bit kernel as Dom0 on a 64bit hypervisor the hypervisor will try to shrink the hypervisor hole to the minimum needed, and thus requires the Dom0 to use XENMEM_machphys_mapping in order to fetch the position of the start of the hypervisor virtual mappings.
Disable this feature when running as a PV shim, since some DomU kernels don't implemented XENMEM_machphys_mapping and break if the m2p doesn't begin at the default address.
NB: support for the XENMEM_machphys_mapping was added in Linux by commit 7e7750.
--- xen/arch/x86/pv/dom0_build.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/pv/dom0_build.c +2 -1
@@ -397,7 +397,8 @@ int __init dom0_construct_pv(struct domain *d,if ( parms.pae ==XEN_PAE_EXTCR3 )set_bit (VMASST_TYPE_pae_extended_cr3, &d->vm_assist); -if ( (parms.virt_hv_start_low !=UNSET_ADDR ) &&elf_32bit (&elf) ) +if ( !pv_shim && (parms.virt_hv_start_low !=UNSET_ADDR ) && +elf_32bit (&elf) ) {unsigned long mask = (1UL <<L2_PAGETABLE_SHIFT ) -1 ; value = (parms.virt_hv_start_low + mask) & ~mask;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 29/62 xen/guest: fetch vCPU ID from Xen
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
If available.
--- xen/arch/x86/guest/xen.c | 23 +++++++++++++++++++++++ xen/arch/x86/smpboot.c | 4 ++++ xen/include/asm-x86/guest/xen.h | 7 +++++++ 3 files changed, 34 insertions(+)
xen/arch/x86/guest/xen.c +23 -0
@@ -37,6 +37,8 @@ static __read_mostly uint32_t xen_cpuid_base;extern char hypercall_page[];static struct rangeset *mem; +DEFINE_PER_CPU(unsigned int, vcpu_id); +static void __init find_xen_leaves (void ) {uint32_t eax, ebx, ecx, edx, base;
@@ -102,6 +104,20 @@ static void map_shared_info(void)write_atomic (&XEN_shared_info->evtchn_mask[i], ~0ul ); } +static void set_vcpu_id (void ) +{ +uint32_t eax, ebx, ecx, edx; + +ASSERT (xen_cpuid_base); + +/* Fetch vcpu id from cpuid. */ +cpuid (xen_cpuid_base +4 , &eax, &ebx, &ecx, &edx); +if ( eax &XEN_HVM_CPUID_VCPU_ID_PRESENT ) +this_cpu (vcpu_id) = ebx; +else +this_cpu (vcpu_id) =smp_processor_id (); +} +static void __init init_memmap (void ) {unsigned int i;
@@ -136,6 +152,13 @@ void __init hypervisor_setup(void)init_memmap ();map_shared_info (); + +set_vcpu_id (); +} + +void hypervisor_ap_setup (void ) +{ +set_vcpu_id (); }int hypervisor_alloc_unused_page (mfn_t *mfn)
xen/arch/x86/smpboot.c +4 -0
@@ -38,6 +38,7 @@#include <asm/desc.h> #include <asm/div64.h> #include <asm/flushtlb.h> +#include <asm/guest.h> #include <asm/msr.h> #include <asm/mtrr.h> #include <asm/time.h>
@@ -372,6 +373,9 @@ void start_secondary(void *unused)cpumask_set_cpu (cpu, &cpu_online_map);unlock_vector_lock (); +if ( xen_guest ) +hypervisor_ap_setup (); +/* We can take interrupts now: we're officially "up". */ local_irq_enable ();mtrr_ap_init ();
xen/include/asm-x86/guest/xen.h +7 -0
@@ -32,9 +32,12 @@ extern bool xen_guest;void probe_hypervisor (void );void hypervisor_setup (void ); +void hypervisor_ap_setup (void );int hypervisor_alloc_unused_page (mfn_t *mfn);int hypervisor_free_unused_page (mfn_t mfn); +DECLARE_PER_CPU(unsigned int, vcpu_id); +#else #define xen_guest 0
@@ -44,6 +47,10 @@ static inline void hypervisor_setup(void) {ASSERT_UNREACHABLE (); } +static inline void hypervisor_ap_setup (void ) +{ +ASSERT_UNREACHABLE (); +}#endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 58/62 xen/shim: allow DomU to have as many vcpus as available
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
Since the shim VCPUOP_{up/down} hypercall is wired to the plug/unplug of CPUs to the shim itself, start the shim DomU with only the BSP online, and let the guest bring up other CPUs as it needs them.
---
Changes since v1:
- Fix single line comment style.
- Print Dom%u d->domain_id.
- Change position of __start_xen comment.
--- xen/arch/x86/dom0_build.c | 30 +++++++++++++++++++++++++++--- xen/arch/x86/pv/dom0_build.c | 2 +- xen/arch/x86/setup.c | 28 ++++++++++++++++++---------- 3 files changed, 46 insertions(+), 14 deletions(-)
xen/arch/x86/dom0_build.c +27 -3
@@ -138,9 +138,18 @@ struct vcpu *__init dom0_setup_vcpu(struct domain *d,if ( v ) { -if ( !d->is_pinned && !dom0_affinity_relaxed ) -cpumask_copy (v->cpu_hard_affinity, &dom0_cpus); -cpumask_copy (v->cpu_soft_affinity, &dom0_cpus); +if ( pv_shim ) + { + +cpumask_setall (v->cpu_hard_affinity); +cpumask_setall (v->cpu_soft_affinity); + } +else + { +if ( !d->is_pinned && !dom0_affinity_relaxed ) +cpumask_copy (v->cpu_hard_affinity, &dom0_cpus); +cpumask_copy (v->cpu_soft_affinity, &dom0_cpus); + } }return v;
@@ -153,6 +162,21 @@ unsigned int __init dom0_max_vcpus(void)unsigned int i, max_vcpus, limit;nodeid_t node; +if ( pv_shim ) + { +nodes_setall (dom0_nodes); + +/* +* When booting in shim mode APs are not started until the guest brings +* other vCPUs up. +*/ +cpumask_set_cpu (0 , &dom0_cpus); + +/* On PV shim mode allow the guest to have as many CPUs as available. */ +return nr_cpu_ids; + } + +for ( i =0 ; i < dom0_nr_pxms; ++i )if ( (node =pxm_to_node (dom0_pxms[i])) !=NUMA_NO_NODE )node_set (node, dom0_nodes);
xen/arch/x86/pv/dom0_build.c +1 -1
@@ -696,7 +696,7 @@ int __init dom0_construct_pv(struct domain *d,for ( i =0 ; i <XEN_LEGACY_MAX_VCPUS ; i++ )shared_info (d, vcpu_info[i].evtchn_upcall_mask) =1 ; -printk ("Dom0 has maximum %u VCPUs\n" , d->max_vcpus); +printk ("Dom%u has maximum %u VCPUs\n" , d->domain_id, d->max_vcpus); cpu = v->processor;for ( i =1 ; i < d->max_vcpus; i++ )
xen/arch/x86/setup.c +18 -10
@@ -1584,18 +1584,26 @@ void __init noreturn __start_xen(unsigned long mbi_p)do_presmp_initcalls (); -for_each_present_cpu ( i ) +/* +* NB: when running as a PV shim VCPUOP_up/down is wired to the shim +* physical cpu_add/remove functions, so launch the guest with only +* the BSP online and let it bring up the other CPUs as required. +*/ +if ( !pv_shim ) { -/* Set up cpu_to_node[]. */ -srat_detect_node (i); -/* Set up node_to_cpumask based on cpu_to_node[]. */ -numa_add_cpu (i); - -if ( (num_online_cpus () < max_cpus) && !cpu_online (i) ) +for_each_present_cpu ( i ) { -int ret =cpu_up (i); -if ( ret !=0 ) -printk ("Failed to bring up CPU %u (error %d)\n" , i, ret); +/* Set up cpu_to_node[]. */ +srat_detect_node (i); +/* Set up node_to_cpumask based on cpu_to_node[]. */ +numa_add_cpu (i); + +if ( (num_online_cpus () < max_cpus) && !cpu_online (i) ) + { +int ret =cpu_up (i); +if ( ret !=0 ) +printk ("Failed to bring up CPU %u (error %d)\n" , i, ret); + } } }
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 41/62 xen/pvh: do not mark the low 1MB as IO mem
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
On PVH there's nothing special on the low 1MB.
This is an optional patch that doesn't affect the functionality of the shim.
--- xen/arch/x86/mm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
xen/arch/x86/mm.c +7 -2
@@ -122,6 +122,7 @@#include <asm/fixmap.h> #include <asm/io_apic.h> #include <asm/pci.h> +#include <asm/guest.h> #include <asm/hvm/grant_table.h> #include <asm/pv/grant_table.h>
@@ -288,8 +289,12 @@ void __init arch_init_memory(void) dom_cow =domain_create (DOMID_COW , DOMCRF_dummy,0 ,NULL );BUG_ON (IS_ERR (dom_cow)); -/* First 1MB of RAM is historically marked as I/O. */ -for ( i =0 ; i <0x100 ; i++ ) +/* +* First 1MB of RAM is historically marked as I/O. If we booted PVH, +* reclaim the space. Irrespective, leave MFN 0 as special for the sake +* of 0 being a very common default value. +*/ +for ( i =0 ; i < (pvh_boot ?1 :0x100 ); i++ )share_xen_page_with_guest (mfn_to_page (_mfn (i)), dom_io, XENSHARE_writable);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 22/62 x86/guest: Hypercall support
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
---
v2: append underscores to tmp.
--- xen/arch/x86/guest/Makefile | 1 + xen/arch/x86/guest/hypercall_page.S | 79 ++++++++++++++++++++++++++++++ xen/arch/x86/guest/xen.c | 5 ++ xen/arch/x86/xen.lds.S | 1 + xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hypercall.h | 92 +++++++++++++++++++++++++++++++++++ 6 files changed, 179 insertions(+) create mode 100644 xen/arch/x86/guest/hypercall_page.S create mode 100644 xen/include/asm-x86/guest/hypercall.h
xen/arch/x86/guest/Makefile +1 -0
@@ -1,3 +1,4 @@ +obj-y += hypercall_page.o obj-y += xen.o obj-bin-$(CONFIG_PVH_GUEST) += pvh-boot.init.o
xen/arch/x86/guest/hypercall_page.S new file +79 -0
79 lines not on this page · raw message
xen/arch/x86/guest/xen.c +5 -0
@@ -22,6 +22,7 @@#include <xen/types.h> #include <asm/guest.h> +#include <asm/msr.h> #include <asm/processor.h> #include <public/arch-x86/cpuid.h>
@@ -29,6 +30,7 @@bool __read_mostly xen_guest;static __read_mostly uint32_t xen_cpuid_base; +extern char hypercall_page[];static void __init find_xen_leaves (void ) {
@@ -61,6 +63,9 @@ void __init probe_hypervisor(void)if ( !xen_cpuid_base )return ; +/* Fill the hypercall page. */ +wrmsrl (cpuid_ebx (xen_cpuid_base +2 ),__pa (hypercall_page)); + xen_guest = true; }
xen/arch/x86/xen.lds.S +1 -0
@@ -65,6 +65,7 @@ SECTIONS DECL_SECTION(.text) { _stext = .; /* Text and read-only data */ *(.text) + *(.text.page_aligned) *(.text.cold) *(.text.unlikely) *(.fixup)
xen/include/asm-x86/guest.h +1 -0
@@ -19,6 +19,7 @@#ifndef __X86_GUEST_H__#define __X86_GUEST_H__ +#include <asm/guest/hypercall.h> #include <asm/guest/pvh-boot.h> #include <asm/guest/xen.h>
xen/include/asm-x86/guest/hypercall.h new file +92 -0
92 lines not on this page · raw message
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 37/62 x86/guest: use PV console for Xen/Dom0 I/O
In reply to Wei LiuFrom: Sergey Dyasli <[email protected]>
--- docs/misc/xen-command-line.markdown | 5 ++++- xen/arch/x86/guest/xen.c | 3 +++ xen/drivers/char/console.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-)
docs/misc/xen-command-line.markdown +4 -1
@@ -365,7 +365,7 @@ The following are examples of correct specifications: Specify the size of the console ring buffer. ### console -> `= List of [ vga | com1[H,L] | com2[H,L] | dbgp | none ]` +> `= List of [ vga | com1[H,L] | com2[H,L] | pv | dbgp | none ]` > Default: `console=com1,vga`
@@ -381,6 +381,9 @@ the converse; transmitted and received characters will have their MSB cleared. This allows a single port to be shared by two subsystems (e.g. console and debugger). +`pv` indicates that Xen should use Xen's PV console. This option is +only available when used together with `pv-in-pvh`. + `dbgp` indicates that Xen should use a USB debug port. `none` indicates that Xen should not use a console. This option only
xen/arch/x86/guest/xen.c +3 -0
@@ -23,6 +23,7 @@#include <xen/pfn.h> #include <xen/rangeset.h> #include <xen/types.h> +#include <xen/pv_console.h> #include <asm/apic.h> #include <asm/e820.h>
@@ -194,6 +195,8 @@ static void xen_evtchn_upcall(struct cpu_user_regs *regs) vcpu_info->evtchn_upcall_pending =0 ;write_atomic (&vcpu_info->evtchn_pending_sel,0 ); +pv_console_rx (regs); +ack_APIC_irq (); }
xen/drivers/char/console.c +16 -0
@@ -32,6 +32,7 @@#include <xen/warning.h> #ifdef CONFIG_X86 +#include <xen/pv_console.h> #include <asm/guest.h> #endif
@@ -344,6 +345,11 @@ static void sercon_puts(const char *s) (*serial_steal_fn)(s); elseserial_puts (sercon_handle ,s ); + +#ifdef CONFIG_X86 +/* Copy all serial output into PV console */ +pv_console_puts (s); +#endif }static void dump_console_ring_key (unsigned char key)
@@ -805,6 +811,8 @@ void __init console_init_preirq(void)if ( !strncmp (p,"vga" ,3 ) )video_init ();#ifdef CONFIG_X86 + else if ( !strncmp(p, "pv", 2) ) +pv_console_init (); else if ( !strncmp(p, "xen", 3) ) opt_console_xen = true;#endif
@@ -828,6 +836,10 @@ void __init console_init_preirq(void)serial_set_rx_handler (sercon_handle, serial_rx); +#ifdef CONFIG_X86 +pv_console_set_rx_handler (serial_rx); +#endif +/* HELLO WORLD --- start-of-day banner text. */ spin_lock (&console_lock);__putstr (xen_banner ());
@@ -880,6 +892,10 @@ void __init console_init_postirq(void) {serial_init_postirq (); +#ifdef CONFIG_X86 +pv_console_init_postirq (); +#endif +if ( conring != _conring )return ;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 50/62 xen/pvshim: add migration support
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
---
Changes since v1:
- Use bitmap_zero instead of memset.
- Don't drop the __init attribute of unshare_xen_page_with_guest, it's not needed for migration.
- Remove BUG_ON to check correct mapping, map_domain_page cannot fail.
- Reduce indentation level of pv_shim_shutdown.
--- xen/arch/x86/guest/xen.c | 29 +++++++ xen/arch/x86/pv/shim.c | 155 +++++++++++++++++++++++++++++++++++++- xen/common/domain.c | 11 ++- xen/common/schedule.c | 3 +- xen/drivers/char/xen_pv_console.c | 2 +- xen/include/asm-x86/guest/xen.h | 5 ++ xen/include/asm-x86/pv/shim.h | 5 +- xen/include/xen/sched.h | 2 +- 8 files changed, 197 insertions(+), 15 deletions(-)
xen/arch/x86/guest/xen.c +29 -0
@@ -348,6 +348,35 @@ uint32_t hypervisor_cpuid_base(void)return xen_cpuid_base; } +static void ap_resume (void *unused) +{ +map_vcpuinfo (); +init_evtchn (); +} + +void hypervisor_resume (void ) +{ +/* Reset shared info page. */ +map_shared_info (); + +/* +* Reset vcpu_info. Just clean the mapped bitmap and try to map the vcpu +* area again. On failure to map (when it was previously mapped) panic +* since it's impossible to safely shut down running guest vCPUs in order +* to meet the new XEN_LEGACY_MAX_VCPUS requirement. +*/ +bitmap_zero (vcpu_info_mapped,NR_CPUS ); +if (map_vcpuinfo () && nr_cpu_ids >XEN_LEGACY_MAX_VCPUS ) +panic ("unable to remap vCPU info and vCPUs > legacy limit" ); + +/* Setup event channel upcall vector. */ +init_evtchn (); +smp_call_function (ap_resume,NULL ,1 ); + +if ( pv_console ) +pv_console_init (); +} +/* * Local variables: * mode: C
xen/arch/x86/pv/shim.c +152 -3
162 lines not on this page · raw message
xen/common/domain.c +5 -6
@@ -697,16 +697,13 @@ void __domain_crash_synchronous(void) } -void domain_shutdown (struct domain *d,u8 reason) +int domain_shutdown (struct domain *d,u8 reason) {struct vcpu *v;#ifdef CONFIG_X86 if ( pv_shim ) - { -pv_shim_shutdown (reason); -return ; - } +return pv_shim_shutdown (reason);#endif spin_lock (&d->shutdown_lock);
@@ -721,7 +718,7 @@ void domain_shutdown(struct domain *d, u8 reason)if ( d->is_shutting_down ) {spin_unlock (&d->shutdown_lock); -return ; +return 0 ; } d->is_shutting_down =1 ;
@@ -743,6 +740,8 @@ void domain_shutdown(struct domain *d, u8 reason)__domain_finalise_shutdown (d);spin_unlock (&d->shutdown_lock); + +return 0 ; }void domain_resume (struct domain *d)
xen/common/schedule.c +1 -2
@@ -1149,11 +1149,10 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_from_guest (&sched_shutdown, arg,1 ) )break ; - ret =0 ;TRACE_3D (TRC_SCHED_SHUTDOWN , current->domain->domain_id, current->vcpu_id, sched_shutdown.reason); -domain_shutdown (current->domain, (u8 )sched_shutdown.reason); + ret =domain_shutdown (current->domain, (u8 )sched_shutdown.reason);break ; }
xen/drivers/char/xen_pv_console.c +1 -1
@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(tx_lock);bool pv_console; -void __init pv_console_init (void ) +void pv_console_init (void ) {long r;uint64_t raw_pfn =0 , raw_evtchn =0 ;
xen/include/asm-x86/guest/xen.h +5 -0
@@ -39,6 +39,7 @@ int hypervisor_free_unused_page(mfn_t mfn);void hypervisor_fixup_e820 (struct e820map *e820);const unsigned long *hypervisor_reserved_pages (unsigned int *size);uint32_t hypervisor_cpuid_base (void ); +void hypervisor_resume (void ); DECLARE_PER_CPU(unsigned int, vcpu_id); DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
@@ -72,6 +73,10 @@ static inline uint32_t hypervisor_cpuid_base(void)ASSERT_UNREACHABLE ();return 0 ; }; +static inline void hypervisor_resume (void ) +{ +ASSERT_UNREACHABLE (); +};#endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */
xen/include/asm-x86/pv/shim.h +3 -2
@@ -35,7 +35,7 @@ void pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, unsigned long va_start, unsigned long store_va, unsigned long console_va, unsigned long vphysmap, start_info_t *si); -void pv_shim_shutdown (uint8_t reason); +int pv_shim_shutdown (uint8_t reason);void pv_shim_inject_evtchn (unsigned int port);domid_t get_initial_domain_id (void );
@@ -50,9 +50,10 @@ static inline void pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start, {ASSERT_UNREACHABLE (); } -static inline void pv_shim_shutdown (uint8_t reason) +static inline int pv_shim_shutdown (uint8_t reason) {ASSERT_UNREACHABLE (); +return 0 ; }static inline void pv_shim_inject_evtchn (unsigned int port) {
xen/include/xen/sched.h +1 -1
@@ -603,7 +603,7 @@ static inline struct domain *rcu_lock_current_domain(void)struct domain *get_domain_by_id (domid_t dom);void domain_destroy (struct domain *d);int domain_kill (struct domain *d); -void domain_shutdown (struct domain *d,u8 reason); +int domain_shutdown (struct domain *d,u8 reason);void domain_resume (struct domain *d);void domain_pause_for_debugger (void );
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 25/62 xen/console: Introduce console=xen
In reply to Wei LiuThis specifies whether to use Xen specific console output. There are two variants: one is the hypervisor console, the other is the magic debug port 0xe9.
--- xen/drivers/char/console.c | 46 +++++++++++++++++++++++++++++++++++ xen/include/asm-x86/guest/hypercall.h | 13 ++++++++++ 2 files changed, 59 insertions(+)
xen/drivers/char/console.c +46 -0
@@ -31,6 +31,10 @@#include <xen/early_printk.h> #include <xen/warning.h> +#ifdef CONFIG_X86 +#include <asm/guest.h> +#endif +/* console: comma-separated list of console outputs. */ static char __initdata opt_console[30 ] =OPT_CONSOLE_STR ;string_param ("console" , opt_console);
@@ -83,6 +87,10 @@ static uint32_t conringc, conringp;static int __read_mostly sercon_handle =-1 ; +#ifdef CONFIG_X86 +static bool __read_mostly opt_console_xen;/* console=xen */ +#endif +static DEFINE_SPINLOCK (console_lock);/*
@@ -432,6 +440,16 @@ static void notify_dom0_con_ring(unsigned long unused) static DECLARE_SOFTIRQ_TASKLET(notify_dom0_con_ring_tasklet, notify_dom0_con_ring, 0); +#ifdef CONFIG_X86 +static inline void xen_console_write_debug_port (const char *buf,size_t len) +{ +unsigned long tmp; + asmvolatile ("rep outsb;" + :"=&S" (tmp),"=&c" (tmp) + :"0" (buf),"1" (len),"d" (0xe9 ) ); +} +#endif +static long guest_console_write (XEN_GUEST_HANDLE_PARAM (char ) buffer,int count) {char kbuf[128 ];
@@ -458,6 +476,18 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer, int count)sercon_puts (kbuf);video_puts (kbuf); +#ifdef CONFIG_X86 +if ( opt_console_xen ) + { +size_t len =strlen (kbuf); + +if ( xen_guest ) +xen_hypercall_console_write (kbuf, len); +else +xen_console_write_debug_port (kbuf, len); + } +#endif +if ( opt_console_to_ring ) {conring_puts (kbuf);
@@ -567,6 +597,18 @@ static void __putstr(const char *str)sercon_puts (str);video_puts (str); +#ifdef CONFIG_X86 +if ( opt_console_xen ) + { +size_t len =strlen (str); + +if ( xen_guest ) +xen_hypercall_console_write (str, len); +else +xen_console_write_debug_port (str, len); + } +#endif +conring_puts (str);if ( !console_locks_busted )
@@ -762,6 +804,10 @@ void __init console_init_preirq(void) p++;if ( !strncmp (p,"vga" ,3 ) )video_init (); +#ifdef CONFIG_X86 + else if ( !strncmp(p, "xen", 3) ) + opt_console_xen = true; +#endif else if ( !strncmp(p, "none", 4) )continue ; else if ( (sh = serial_parse_handle(p)) >= 0 )
xen/include/asm-x86/guest/hypercall.h +13 -0
@@ -99,6 +99,13 @@ static inline long xen_hypercall_memory_op(unsigned int cmd, void *arg)/* * Higher level hypercall helpers */ +static inline void xen_hypercall_console_write ( +const char *buf,unsigned int count) +{ + (void )_hypercall64_3 (long, __HYPERVISOR_console_io, + CONSOLEIO_write, count, buf); +} +static inline long xen_hypercall_shutdown (unsigned int reason) {struct sched_shutdown s = { .reason = reason };
@@ -109,6 +116,12 @@ static inline long xen_hypercall_shutdown(unsigned int reason)#include <public/sched.h> +static inline void xen_hypercall_console_write ( +const char *buf,unsigned int count) +{ +ASSERT_UNREACHABLE (); +} +static inline long xen_hypercall_shutdown (unsigned int reason) {ASSERT_UNREACHABLE ();
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 11/62 tools/ocaml: Expose arch_config in domaininfo
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
--- tools/ocaml/libs/xc/xenctrl.ml | 29 +++++++++++++++++++++++++++++ tools/ocaml/libs/xc/xenctrl.mli | 28 ++++++++++++++++++++++++++++ tools/ocaml/libs/xc/xenctrl_stubs.c | 26 ++++++++++++++++++++++++-- 3 files changed, 81 insertions(+), 2 deletions(-)
tools/ocaml/libs/xc/xenctrl.ml +29 -0
@@ -28,6 +28,34 @@ type vcpuinfo = cpumap: int32; } +type xen_arm_arch_domainconfig = +{ + gic_version: int; + nr_spis: int; + clock_frequency: int32; +} + +type x86_arch_emulation_flags = + | X86_EMU_LAPIC + | X86_EMU_HPET + | X86_EMU_PM + | X86_EMU_RTC + | X86_EMU_IOAPIC + | X86_EMU_PIC + | X86_EMU_VGA + | X86_EMU_IOMMU + | X86_EMU_PIT + | X86_EMU_USE_PIRQ + +type xen_x86_arch_domainconfig = +{ + emulation_flags: x86_arch_emulation_flags list; +} + +type arch_domainconfig = + | ARM of xen_arm_arch_domainconfig + | X86 of xen_x86_arch_domainconfig + type domaininfo = { domid : domid;
@@ -46,6 +74,7 @@ type domaininfo = max_vcpu_id : int; ssidref : int32; handle : int array; + arch_config : arch_domainconfig; } type sched_control =
tools/ocaml/libs/xc/xenctrl.mli +28 -0
@@ -22,6 +22,33 @@ type vcpuinfo = { cputime : int64; cpumap : int32; } + +type xen_arm_arch_domainconfig = { + gic_version: int; + nr_spis: int; + clock_frequency: int32; +} + +type x86_arch_emulation_flags = + | X86_EMU_LAPIC + | X86_EMU_HPET + | X86_EMU_PM + | X86_EMU_RTC + | X86_EMU_IOAPIC + | X86_EMU_PIC + | X86_EMU_VGA + | X86_EMU_IOMMU + | X86_EMU_PIT + | X86_EMU_USE_PIRQ + +type xen_x86_arch_domainconfig = { + emulation_flags: x86_arch_emulation_flags list; +} + +type arch_domainconfig = + | ARM of xen_arm_arch_domainconfig + | X86 of xen_x86_arch_domainconfig + type domaininfo = { domid : domid; dying : bool;
@@ -39,6 +66,7 @@ type domaininfo = { max_vcpu_id : int; ssidref : int32; handle : int array; + arch_config : arch_domainconfig; } type sched_control = { weight : int; cap : int; } type physinfo_cap_flag = CAP_HVM | CAP_DirectIO
tools/ocaml/libs/xc/xenctrl_stubs.c +24 -2
@@ -273,10 +273,10 @@ CAMLprim value stub_xc_domain_shutdown(value xch, value domid, value reason)static value alloc_domaininfo (xc_domaininfo_t * info) {CAMLparam0 (); -CAMLlocal2 (result, tmp); +CAMLlocal5 (result, tmp, arch_config, x86_arch_config, emul_list);int i; - result =caml_alloc_tuple (16 ); + result =caml_alloc_tuple (17 );Store_field (result,0 ,Val_int (info->domain));Store_field (result,1 ,Val_bool (info->flags & XEN_DOMINF_dying));
@@ -302,6 +302,28 @@ static value alloc_domaininfo(xc_domaininfo_t * info)Store_field (result,15 , tmp); +/* emulation_flags: x86_arch_emulation_flags list; */ + tmp = emul_list = Val_emptylist; +for (i =0 ; i <10 ; i++) { +if ((info->arch_config.emulation_flags >> i) &1 ) { + tmp =caml_alloc_small (2 , Tag_cons); +Field (tmp,0 ) =Val_int (i); +Field (tmp,1 ) = emul_list; + emul_list = tmp; + } + } + +/* xen_x86_arch_domainconfig */ + x86_arch_config =caml_alloc_tuple (1 ); +Store_field (x86_arch_config,0 , emul_list); + +/* arch_config: arch_domainconfig */ + arch_config =caml_alloc_small (1 ,1 ); + +Store_field (arch_config,0 , x86_arch_config); + +Store_field (result,16 , arch_config); +CAMLreturn (result); }
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 40/62 xen/x86: make VGA support selectable
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
Through a Kconfig option. Enable it by default, and disable it for the PV-in-PVH shim.
--- tools/firmware/xen-dir/shim.config | 2 -- xen/arch/x86/Kconfig | 1 - xen/arch/x86/boot/build32.mk | 1 + xen/arch/x86/boot/cmdline.c | 5 ++++- xen/arch/x86/boot/trampoline.S | 7 +++++++ xen/arch/x86/efi/efi-boot.h | 4 ++++ xen/arch/x86/platform_hypercall.c | 2 ++ xen/arch/x86/pv/dom0_build.c | 2 ++ xen/arch/x86/setup.c | 6 ++++++ xen/drivers/video/Kconfig | 8 +++++++- xen/include/asm-x86/setup.h | 6 ++++++ 11 files changed, 39 insertions(+), 5 deletions(-)
tools/firmware/xen-dir/shim.config +0 -2
@@ -68,8 +68,6 @@ CONFIG_HAS_EHCI=y CONFIG_HAS_CPUFREQ=y CONFIG_HAS_PASSTHROUGH=y CONFIG_HAS_PCI=y -CONFIG_VIDEO=y -CONFIG_VGA=y CONFIG_DEFCONFIG_LIST="$ARCH_DEFCONFIG" CONFIG_ARCH_SUPPORTS_INT128=y
xen/arch/x86/Kconfig +0 -1
@@ -24,7 +24,6 @@ config X86 select HAS_PDX select HAS_UBSAN select NUMA - select VGA config ARCH_DEFCONFIG string
xen/arch/x86/boot/build32.mk +1 -0
@@ -5,6 +5,7 @@ include $(XEN_ROOT)/Config.mk $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) CFLAGS += -Werror -fno-asynchronous-unwind-tables -fno-builtin -g0 -msoft-float +CFLAGS += -I$(XEN_ROOT)/xen/include CFLAGS := $(filter-out -flto,$(CFLAGS)) # NB. awk invocation is a portable alternative to 'head -n -1'
xen/arch/x86/boot/cmdline.c +4 -1
@@ -30,6 +30,7 @@ asm (" jmp cmdline_parse_early \n" ); +#include <xen/kconfig.h> #include "defs.h" #include "video.h"
@@ -336,5 +337,7 @@ void __stdcall cmdline_parse_early(const char *cmdline, early_boot_opts_t *ebo) ebo->skip_realmode =skip_realmode (cmdline); ebo->opt_edd =edd_parse (cmdline); ebo->opt_edid =edid_parse (cmdline); -vga_parse (cmdline, ebo); + +if (IS_ENABLED (CONFIG_VIDEO ) ) +vga_parse (cmdline, ebo); }
xen/arch/x86/boot/trampoline.S +7 -0
@@ -219,7 +219,9 @@ trampoline_boot_cpu_entry: */ call get_memory_map call get_edd +#ifdef CONFIG_VIDEO call video +#endif mov $0x0200,%ax int $0x16
@@ -267,10 +269,13 @@ opt_edid: .byte 0 /* EDID parsing option (force/no/default). */ /* Padding. */ .byte 0 + +#ifdef CONFIG_VIDEO GLOBAL(boot_vid_mode) .word VIDEO_80x25 /* If we don't run at all, assume basic video mode 3 at 80x25. */ vesa_size: .word 0,0,0 /* width x depth x height */ +#endif GLOBAL(kbd_shift_flags) .byte 0
@@ -279,4 +284,6 @@ rm_idt: .word 256*4-1, 0, 0 #include "mem.S" #include "edd.S" +#ifdef CONFIG_VIDEO #include "video.S" +#endif
xen/arch/x86/efi/efi-boot.h +4 -0
@@ -479,16 +479,19 @@ static void __init efi_arch_edd(void)static void __init efi_arch_console_init (UINTN cols,UINTN rows) { +#ifdef CONFIG_VIDEO vga_console_info.video_type =XEN_VGATYPE_TEXT_MODE_3 ; vga_console_info.u.text_mode_3.columns = cols; vga_console_info.u.text_mode_3.rows = rows; vga_console_info.u.text_mode_3.font_height =16 ; +#endif }static void __init efi_arch_video_init (EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,UINTN info_size,EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info) { +#ifdef CONFIG_VIDEO int bpp =0 ; switch ( mode_info->PixelFormat )
@@ -550,6 +553,7 @@ static void __init efi_arch_video_init(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, vga_console_info.u.vesa_lfb.lfb_size = (gop->Mode->FrameBufferSize + 0xffff) >> 16; } +#endif }static void __init efi_arch_memory_setup (void )
xen/arch/x86/platform_hypercall.c +2 -0
@@ -388,6 +388,7 @@ ret_t do_platform_op(XEN_GUEST_HANDLE_PARAM(xen_platform_op_t) u_xenpf_op) }case XEN_FW_VBEDDC_INFO : ret = -ESRCH ; +#ifdef CONFIG_VIDEO if ( op->u.firmware_info.index !=0 )break ;if ( *(u32 *)bootsym (boot_edid_info) ==0x13131313 )
@@ -406,6 +407,7 @@ ret_t do_platform_op(XEN_GUEST_HANDLE_PARAM(xen_platform_op_t) u_xenpf_op) copy_to_compat(op->u.firmware_info.u.vbeddc_info.edid, bootsym(boot_edid_info), 128) ) ret = -EFAULT ; +#endif break ;case XEN_FW_EFI_INFO : ret = efi_get_info(op->u.firmware_info.index,
xen/arch/x86/pv/dom0_build.c +2 -0
@@ -827,11 +827,13 @@ int __init dom0_construct_pv(struct domain *d,if ( cmdline !=NULL )strlcpy ((char *)si->cmd_line, cmdline,sizeof (si->cmd_line)); +#ifdef CONFIG_VIDEO if (fill_console_start_info ((void *)(si +1 )) ) { si->console.dom0.info_off =sizeof (struct start_info ); si->console.dom0.info_size =sizeof (struct dom0_vga_console_info ); } +#endif if (is_pv_32bit_domain (d) )xlat_start_info (si, XLAT_start_info_console_dom0);
xen/arch/x86/setup.c +6 -0
@@ -456,6 +456,7 @@ static void __init setup_max_pdx(unsigned long top_page)/* A temporary copy of the e820 map that we can mess with during bootstrap. */ static struct e820map __initdata boot_e820; +#ifdef CONFIG_VIDEO struct boot_video_info { u8 orig_x; /* 0x00 */ u8 orig_y; /* 0x01 */
@@ -486,9 +487,11 @@ struct boot_video_info { u16 vesa_attrib; /* 0x28 */ };extern struct boot_video_info boot_vid_info; +#endif static void __init parse_video_info (void ) { +#ifdef CONFIG_VIDEO struct boot_video_info *bvi = &bootsym (boot_vid_info);/* vga_console_info is filled directly on EFI platform. */
@@ -524,6 +527,7 @@ static void __init parse_video_info(void) vga_console_info.u.vesa_lfb.gbl_caps = bvi->capabilities; vga_console_info.u.vesa_lfb.mode_attrs = bvi->vesa_attrib; } +#endif }static void __init kexec_reserve_area (struct e820map *e820)
@@ -741,6 +745,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)printk ("Xen image load base address: %#lx\n" , xen_phys_start); +#ifdef CONFIG_VIDEO printk ("Video information:\n" );/* Print VGA display mode information. */
@@ -784,6 +789,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) printk("of reasons unknown\n"); } } +#endif printk ("Disc information:\n" ); printk(" Found %d MBR signatures\n",
xen/drivers/video/Kconfig +7 -1
@@ -3,8 +3,14 @@ config VIDEO bool config VGA - bool + bool "VGA support" if !PV_SHIM_EXCLUSIVE select VIDEO + depends on X86 + default y if !PV_SHIM_EXCLUSIVE + ---help--- + Enable VGA output for the Xen hypervisor. + + If unsure, say Y. config HAS_ARM_HDLCD bool
xen/include/asm-x86/setup.h +6 -0
@@ -31,8 +31,14 @@ void arch_init_memory(void);void subarch_init_memory (void );void init_IRQ (void ); + +#ifdef CONFIG_VIDEO void vesa_init (void );void vesa_mtrr_init (void ); +#else +static inline void vesa_init (void ) {}; +static inline void vesa_mtrr_init (void ) {}; +#endif int construct_dom0( struct domain *d,
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 15/62 x86/Kconfig: Options for Xen and PVH support
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
Introduce two options. One to detect whether the binary is running on Xen, the other enables PVH ABI support.
The former will be useful to PV in HVM approach. Both will be used by PV in PVH approach.
---
v2:
Write commit message. Didn't change the config option value as it requires a lot of changes in later patches.
--- xen/arch/x86/Kconfig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
xen/arch/x86/Kconfig +17 -0
@@ -117,6 +117,23 @@ config TBOOT Technology (TXT) If unsure, say Y. + +config XEN_GUEST + def_bool n + prompt "Xen Guest" + ---help--- + Support for Xen detecting when it is running under Xen. + + If unsure, say N. + +config PVH_GUEST + def_bool n + prompt "PVH Guest" + depends on XEN_GUEST + ---help--- + Support booting using the PVH ABI. + + If unsure, say N. endmenu source "common/Kconfig"
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 20/62 x86/boot: Map more than the first 16MB
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
TODO: Replace somehow (bootstrap_map() ?)
--- xen/arch/x86/boot/x86_64.S | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/boot/x86_64.S +1 -2
@@ -114,11 +114,10 @@ GLOBAL(__page_tables_start) GLOBAL(l2_identmap) .quad sym_offs(l1_identmap) + __PAGE_HYPERVISOR idx = 1 - .rept 7 + .rept 4 * L2_PAGETABLE_ENTRIES - 1 .quad (idx << L2_PAGETABLE_SHIFT) | PAGE_HYPERVISOR | _PAGE_PSE idx = idx + 1 .endr - .fill 4 * L2_PAGETABLE_ENTRIES - 8, 8, 0 .size l2_identmap, . - l2_identmap /*
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 55/62 xen/shim: modify shim_mem parameter behaviour
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
shim_mem will now account for both the memory used by the hypervisor loaded in memory and the free memory slack given to the shim for runtime usage.
From experimental testing it seems like the total amount of MiB used by the shim (giving it ~1MB of free memory for runtime) is:
memory/113 + 20
--- docs/misc/xen-command-line.markdown | 13 +++++++------ xen/arch/x86/dom0_build.c | 14 +++----------- xen/arch/x86/pv/shim.c | 30 +++++++++++++++++++----------- 3 files changed, 29 insertions(+), 28 deletions(-)
docs/misc/xen-command-line.markdown +7 -6
@@ -1461,16 +1461,17 @@ constructed into a plain unprivileged PV domain. ### shim\_mem (x86) > `= List of ( min:<size> | max:<size> | <size> )` -Set the amount of memory that xen-shim reserves for itself. Only has effect -if pv-shim mode is enabled. +Set the amount of memory that xen-shim uses. Only has effect if pv-shim mode is +enabled. Note that this value accounts for the memory used by the shim itself +plus the free memory slack given to the shim for runtime allocations. * `min:<size>` specifies the minimum amount of memory. Ignored if greater - than max. Default: 10M. -* `max:<size>` specifies the maximum amount of memory. Default: 128M. + than max. +* `max:<size>` specifies the maximum amount of memory. * `<size>` specifies the exact amount of memory. Overrides both min and max. -By default, 1/16th of total HVM container's memory is reserved for xen-shim -with minimum amount being 10MB and maximum amount 128MB. +By default, the amount of free memory slack given to the shim for runtime usage +is 1MB. ### rcu-idle-timer-period-ms > `= <integer>`
xen/arch/x86/dom0_build.c +3 -11
@@ -290,17 +290,9 @@ unsigned long __init dom0_compute_nr_pages(* for things like DMA buffers. This reservation is clamped to a * maximum of 128MB. */ -if ( nr_pages ==0 ) - { -uint64_t rsvd =min (avail /16 ,128UL << (20 -PAGE_SHIFT )); -if ( pv_shim ) - { - rsvd =pv_shim_mem (avail); -printk ("Reserved %lu pages for xen-shim\n" , rsvd); - - } - nr_pages = -rsvd; - } +if ( !nr_pages ) + nr_pages = -(pv_shim ?pv_shim_mem (avail) + :min (avail /16 ,128UL << (20 -PAGE_SHIFT )));/* Negative specification means "all memory - specified amount". */ if ( (long )nr_pages <0 ) nr_pages += avail;
xen/arch/x86/pv/shim.c +19 -11
@@ -57,9 +57,8 @@ static long pv_shim_grant_table_op(unsigned int cmd, unsigned int count);/* -* By default, 1/16th of total HVM container's memory is reserved for xen-shim -* with minimum amount being 10MB and maximum amount 128MB. Some users may wish -* to tune this constants for better memory utilization. This can be achieved +* By default give the shim 1MB of free memory slack. Some users may wish to +* tune this constants for better memory utilization. This can be achieved * using the following xen-shim's command line option: * * shim_mem=[min:<min_amt>,][max:<max_amt>,][<amt>]
@@ -71,8 +70,8 @@ static long pv_shim_grant_table_op(unsigned int cmd,* (overrides both min and max) */ static uint64_t __initdata shim_nrpages; -static uint64_t __initdata shim_min_nrpages =10UL << (20 -PAGE_SHIFT ); -static uint64_t __initdata shim_max_nrpages =128UL << (20 -PAGE_SHIFT ); +static uint64_t __initdata shim_min_nrpages; +static uint64_t __initdata shim_max_nrpages;static int __init parse_shim_mem (const char *s) {
@@ -91,15 +90,24 @@ custom_param("shim_mem", parse_shim_mem);uint64_t pv_shim_mem (uint64_t avail) { -uint64_t rsvd =min (avail /16 , shim_max_nrpages); +if ( !shim_nrpages ) + { + shim_nrpages =max (shim_min_nrpages, + total_pages - avail + (1UL << (20 -PAGE_SHIFT ))); +if ( shim_max_nrpages ) + shim_max_nrpages =min (shim_nrpages, shim_max_nrpages); + } + +if ( total_pages - avail > shim_nrpages ) +panic ("pages used by shim > shim_nrpages (%#lx > %#lx)" , + total_pages - avail, shim_nrpages); -if ( shim_nrpages ) -return shim_nrpages; + shim_nrpages -= total_pages - avail; -if ( shim_min_nrpages <= shim_max_nrpages ) - rsvd =max (rsvd, shim_min_nrpages); +printk ("shim used pages %#lx reserving %#lx free pages\n" , + total_pages - avail, shim_nrpages); -return rsvd; +return shim_nrpages; }#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER| \
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 26/62 xen: introduce rangeset_claim_range
In reply to Wei LiuReserve a hole in a rangeset.
---
Changes since v1:
- Change function name.
- Use a local variable instead of *s.
- Add unlikely to the !prev case.
- Move the function prototype position in the header file.
--- xen/common/rangeset.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/rangeset.h | 4 +++- 2 files changed, 55 insertions(+), 1 deletion(-)
xen/common/rangeset.c +52 -0
@@ -298,6 +298,58 @@ int rangeset_report_ranges(return rc; } +int rangeset_claim_range (struct rangeset *r,unsigned long size, +unsigned long *s) +{ +struct range *prev, *next; +unsigned long start =0 ; + +write_lock (&r->lock); + +for ( prev =NULL , next =first_range (r); + next; + prev = next, next =next_range (r, next) ) + { +if ( (next->s - start) >= size ) + goto insert; + +if ( next->e == ~0UL ) + goto out; + + start = next->e +1 ; + } + +if ( (~0UL - start) +1 >= size ) + goto insert; + + out: +write_unlock (&r->lock); +return -ENOSPC ; + + insert: +if (unlikely (!prev) ) + { + next =alloc_range (r); +if ( !next ) + { +write_unlock (&r->lock); +return -ENOMEM ; + } + + next->s = start; + next->e = start + size -1 ; +insert_range (r, prev, next); + } +else + prev->e += size; + +write_unlock (&r->lock); + + *s = start; + +return 0 ; +} +int rangeset_add_singleton (struct rangeset *r,unsigned long s) {
xen/include/xen/rangeset.h +3 -1
@@ -55,9 +55,11 @@ void rangeset_limit(bool_t __must_check rangeset_is_empty (const struct rangeset *r); -/* Add/remove/query a numeric range. */ +/* Add/claim/remove/query a numeric range. */ int __must_check rangeset_add_range (struct rangeset *r,unsigned long s,unsigned long e); +int __must_check rangeset_claim_range (struct rangeset *r,unsigned long size, +unsigned long *s);int __must_check rangeset_remove_range (struct rangeset *r,unsigned long s,unsigned long e); bool_t __must_check rangeset_contains_range(
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 44/62 xen: mark xenstore/console pages as RAM
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
This si required so that later they can be shared with the guest if Xen is running in shim mode.
Also prevent them from being used by Xen by marking them as bad pages in init_boot_pages.
---
Changes since v1:
- Remove adding the pages to dom_io, there's no need since they are already marked as bad pages.
- Use a static global array to store the memory address of this special pages, so Xen avoids having to call xen_hypercall_hvm_get_param twice.
--- xen/arch/x86/e820.c | 4 ++++ xen/arch/x86/guest/xen.c | 43 +++++++++++++++++++++++++++++++++++++++ xen/common/page_alloc.c | 15 ++++++++++++++ xen/drivers/char/xen_pv_console.c | 4 ++++ xen/include/asm-x86/guest/xen.h | 14 +++++++++++++ 5 files changed, 80 insertions(+)
xen/arch/x86/e820.c +4 -0
@@ -9,6 +9,7 @@#include <asm/processor.h> #include <asm/mtrr.h> #include <asm/msr.h> +#include <asm/guest.h> /* * opt_mem: Limit maximum address of physical RAM.
@@ -699,6 +700,9 @@ unsigned long __init init_e820(const char *str, struct e820map *raw)machine_specific_memory_setup (raw); +if ( xen_guest ) +hypervisor_fixup_e820 (&e820); +printk ("%s RAM map:\n" , str);print_e820_memory_map (e820.map, e820.nr_map);
xen/arch/x86/guest/xen.c +43 -0
61 lines not on this page · raw message
xen/common/page_alloc.c +15 -0
@@ -143,6 +143,7 @@#include <asm/numa.h> #include <asm/flushtlb.h> #ifdef CONFIG_X86 +#include <asm/guest.h> #include <asm/p2m.h> #include <asm/setup.h> /* for highmem_start only */ #else
@@ -303,6 +304,20 @@ void __init init_boot_pages(paddr_t ps, paddr_t pe) badpage++; } } + +if ( xen_guest ) + { + badpage =hypervisor_reserved_pages (&array_size); +if ( badpage ) + { +for ( i =0 ; i < array_size; i++ ) + { +bootmem_region_zap (*badpage >>PAGE_SHIFT , + (*badpage >>PAGE_SHIFT ) +1 ); + badpage++; + } + } + }#endif /* Check new pages against the bad-page list. */
xen/drivers/char/xen_pv_console.c +4 -0
@@ -35,6 +35,8 @@ static evtchn_port_t cons_evtchn;static serial_rx_fn cons_rx_handler;static DEFINE_SPINLOCK (tx_lock); +bool pv_console; +void __init pv_console_init (void ) {long r;
@@ -60,6 +62,8 @@ void __init pv_console_init(void)printk ("Initialised PV console at 0x%p with pfn %#lx and evtchn %#x\n" , cons_ring, raw_pfn, cons_evtchn); + pv_console = true; +return ; error:
xen/include/asm-x86/guest/xen.h +14 -0
@@ -29,12 +29,15 @@#ifdef CONFIG_XEN_GUEST extern bool xen_guest; +extern bool pv_console;void probe_hypervisor (void );void hypervisor_setup (void );void hypervisor_ap_setup (void );int hypervisor_alloc_unused_page (mfn_t *mfn);int hypervisor_free_unused_page (mfn_t mfn); +void hypervisor_fixup_e820 (struct e820map *e820); +const unsigned long *hypervisor_reserved_pages (unsigned int *size); DECLARE_PER_CPU(unsigned int, vcpu_id); DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
@@ -42,6 +45,7 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);#else #define xen_guest 0 +#define pv_console 0static inline void probe_hypervisor (void ) {};static inline void hypervisor_setup (void )
@@ -53,6 +57,16 @@ static inline void hypervisor_ap_setup(void)ASSERT_UNREACHABLE (); } +static inline void hypervisor_fixup_e820 (struct e820map *e820) +{ +ASSERT_UNREACHABLE (); +} +static inline const unsigned long *hypervisor_reserved_pages (unsigned int *size) +{ +ASSERT_UNREACHABLE (); +return NULL ; +}; +#endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 43/62 xen/pvshim: skip Dom0-only domain builder parts
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
Do not allow access to any iomem or ioport by the shim, and also remove the check for Dom0 kernel support.
--- xen/arch/x86/dom0_build.c | 4 ++++ xen/arch/x86/pv/dom0_build.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)
xen/arch/x86/dom0_build.c +4 -0
@@ -13,6 +13,7 @@#include <xen/softirq.h> #include <asm/dom0_build.h> +#include <asm/guest.h> #include <asm/hpet.h> #include <asm/io_apic.h> #include <asm/p2m.h>
@@ -385,6 +386,9 @@ int __init dom0_setup_permissions(struct domain *d)unsigned int i;int rc; +if ( pv_shim ) +return 0 ; +/* The hardware domain is initially permitted full I/O capabilities. */ rc =ioports_permit_access (d,0 ,0xFFFF ); rc |=iomem_permit_access (d,0UL , (1UL << (paddr_bits -PAGE_SHIFT )) -1 );
xen/arch/x86/pv/dom0_build.c +2 -1
@@ -17,6 +17,7 @@#include <asm/bzimage.h> #include <asm/dom0_build.h> +#include <asm/guest.h> #include <asm/page.h> #include <asm/pv/mm.h> #include <asm/setup.h>
@@ -372,7 +373,7 @@ int __init dom0_construct_pv(struct domain *d,if ( parms.elf_notes[XEN_ELFNOTE_SUPPORTED_FEATURES ].type !=XEN_ENT_NONE ) { -if ( !test_bit (XENFEAT_dom0, parms.f_supported) ) +if ( !pv_shim && !test_bit (XENFEAT_dom0, parms.f_supported) ) {printk ("Kernel does not support Dom0 operation\n" ); rc = -EINVAL ;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 18/62 x86: produce a binary that can be booted as PVH
In reply to Wei LiuProduce a binary that can be booted as PVH. It doesn't do much yet.
---
v2:
1. Remove shim-y dependency.
2. Remove extraneous blank line.
3. Fix bugs in xen.lds.S.
4. Haven't split code into pvh.S because that will break later patches.
--- .gitignore | 1 + xen/arch/x86/Makefile | 8 ++++++++ xen/arch/x86/boot/head.S | 9 +++++++++ xen/arch/x86/xen.lds.S | 9 ++++++++- 4 files changed, 26 insertions(+), 1 deletion(-)
.gitignore +1 -0
@@ -323,6 +323,7 @@ xen/xsm/flask/xenpolicy-* tools/flask/policy/policy.conf tools/flask/policy/xenpolicy-* xen/xen +xen/xen-shim xen/xen-syms xen/xen-syms.map xen/xen.*
xen/arch/x86/Makefile +8 -0
@@ -75,6 +75,8 @@ efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ -O $(BASEDIR)/include/xen/compile.h ]; then \ echo '$(TARGET).efi'; fi) +shim-$(CONFIG_PVH_GUEST) := $(TARGET)-shim + ifneq ($(build_id_linker),) notes_phdrs = --notes else
@@ -144,6 +146,11 @@ $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o >$(@D)/$(@F).map rm -f $(@D)/.$(@F).[0-9]* +# Use elf32-x86-64 if toolchain support exists, elf32-i386 otherwise. +$(TARGET)-shim: FORMAT = $(firstword $(filter elf32-x86-64,$(shell $(OBJCOPY) --help)) elf32-i386) +$(TARGET)-shim: $(TARGET)-syms + $(OBJCOPY) -O $(FORMAT) $< $@ + note.o: $(TARGET)-syms $(OBJCOPY) -O binary --only-section=.note.gnu.build-id $(BASEDIR)/xen-syms [email protected] $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 \
@@ -224,5 +231,6 @@ clean:: rm -f asm-offsets.s *.lds boot/*.o boot/*~ boot/core boot/mkelf32 rm -f $(BASEDIR)/.xen-syms.[0-9]* boot/.*.d rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.efi efi/disabled efi/mkreloc + rm -f $(BASEDIR)/xen-shim rm -f boot/cmdline.S boot/reloc.S boot/*.lnk boot/*.bin rm -f note.o
xen/arch/x86/boot/head.S +9 -0
@@ -7,6 +7,7 @@ #include <asm/page.h> #include <asm/msr.h> #include <asm/cpufeature.h> +#include <public/elfnote.h> .text .code32
@@ -374,6 +375,14 @@ cs32_switch: /* Jump to earlier loaded address. */ jmp *%edi +#ifdef CONFIG_PVH_GUEST +ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .long sym_offs(__pvh_start)) + +__pvh_start: + ud2a + +#endif /* CONFIG_PVH_GUEST */ + __start: cld cli
xen/arch/x86/xen.lds.S +8 -1
@@ -34,7 +34,7 @@ OUTPUT_ARCH(i386:x86-64) PHDRS { text PT_LOAD ; -#if defined(BUILD_ID) && !defined(EFI) +#if (defined(BUILD_ID) || defined (CONFIG_PVH_GUEST)) && !defined(EFI) note PT_NOTE ; #endif }
@@ -128,6 +128,12 @@ SECTIONS __param_end = .; } :text +#if defined(CONFIG_PVH_GUEST) && !defined(EFI) + DECL_SECTION(.note.Xen) { + *(.note.Xen) + } :note :text +#endif + #if defined(BUILD_ID) #if !defined(EFI) /*
@@ -279,6 +285,7 @@ SECTIONS #ifdef EFI *(.comment) *(.comment.*) + *(.note.Xen) #endif }
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 59/62 libxl: pvshim: Provide first-class config settings to enable shim mode
In reply to Wei LiuFrom: Ian Jackson <[email protected]>
This is API-compatible because old callers are supposed to call libxl_*_init to initialise the struct; and the updated function clears these members.
It is ABI-compatible because the new fields make this member of the guest type union larger but only within the existing size of that union.
Unfortunately it is not easy to backport because it depends on the PVH domain type. Attempts to avoid use of the PVH domain type involved working with two views of the configuration: the "underlying" domain type and the "visible" type (and corresponding config info). Also there are different sets of config settings for PV and PVH, which callers would have to know to set.
And, unfortunately, it will not be possible, with this approach, to enable the shim by default for all libxl callers. (Although it could perhaps be done in xl.)
For now, our config defaults are:
* if enabled, path is "xen-shim" in the xen firmware directory
* if enabled, cmdline is the one we are currently debugging with
The debugging arguments will be rationalised in a moment.
---
v2: pvshim, not pvhshim
works with type "pvh", not type "pv"
--- tools/libxl/libxl.h | 8 +++++++ tools/libxl/libxl_create.c | 19 +++++++++++---- tools/libxl/libxl_dom.c | 57 +++++++++++++++++++++++++++++++++++--------- tools/libxl/libxl_internal.h | 4 ++++ tools/libxl/libxl_types.idl | 5 +++- 5 files changed, 77 insertions(+), 16 deletions(-)
tools/libxl/libxl.h +8 -0
@@ -1101,6 +1101,14 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src);*/ #define LIBXL_HAVE_SET_PARAMETERS 1 +/* +* LIBXL_HAVE_PV_SHIM +* +* If this is defined, libxl_domain_build_info's pvh type information +* contains members pvshim, pvshim_path, pvshim_cmdline. +*/ +#define LIBXL_HAVE_PV_SHIM 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 -4
@@ -389,6 +389,18 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, }break ;case LIBXL_DOMAIN_TYPE_PVH : +libxl_defbool_setdefault (&b_info->u.pvh.pvshim, false); +if (libxl_defbool_val (b_info->u.pvh.pvshim)) { +if (!b_info->u.pvh.pvshim_path) + b_info->u.pvh.pvshim_path = +libxl__sprintf (NOGC ,"%s/%s" , +libxl__xenfirmwaredir_path (), +PVSHIM_BASENAME ); +if (!b_info->u.pvh.pvshim_cmdline) + b_info->u.pvh.pvshim_cmdline = +libxl__strdup (NOGC ,PVSHIM_CMDLINE ); + } +break ;default : LOG(ERROR, "invalid domain type %s in create info",
@@ -476,10 +488,6 @@ int libxl__domain_build(libxl__gc *gc,break ;case LIBXL_DOMAIN_TYPE_PV : - ret =libxl__build_pv (gc, domid, info, state); -if (ret) - goto out; - vments =libxl__calloc (gc,11 ,sizeof (char *)); i =0 ; vments[i++] ="image/ostype" ;
@@ -499,6 +507,9 @@ int libxl__domain_build(libxl__gc *gc,break ;case LIBXL_DOMAIN_TYPE_PVH : + state->shim_path = info->u.pvh.pvshim_path; + state->shim_cmdline = info->u.pvh.pvshim_cmdline; + ret =libxl__build_hvm (gc, domid, d_config, state);if (ret) goto out;
tools/libxl/libxl_dom.c +46 -11
76 lines not on this page · raw message
tools/libxl/libxl_internal.h +4 -0
@@ -118,6 +118,8 @@#define TAP_DEVICE_SUFFIX "-emu"#define DOMID_XS_PATH "domid"#define INVALID_DOMID ~0 +#define PVSHIM_BASENAME "xen-shim" +#define PVSHIM_CMDLINE "pv-shim console=xen,pv sched=null loglvl=all guest_loglvl=all apic_verbosity=debug e820-verbose"/* Size macros. */ #define __AC (X ,Y ) (X##Y)
@@ -1136,6 +1138,8 @@ typedef struct {libxl__file_reference pv_kernel;libxl__file_reference pv_ramdisk; +const char * shim_path; +const char * shim_cmdline;const char * pv_cmdline;xen_vmemrange_t *vmemranges;
tools/libxl/libxl_types.idl +4 -1
@@ -592,7 +592,10 @@ libxl_domain_build_info = Struct("domain_build_info",[ # Use host's E820 for PCI passthrough. ("e820_host", libxl_defbool), ])), - ("pvh", None), + ("pvh", Struct(None, [("pvshim", libxl_defbool), + ("pvshim_path", string), + ("pvshim_cmdline", string), + ])), ("invalid", None), ], keyvar_init_val = "LIBXL_DOMAIN_TYPE_INVALID")),
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 39/62 tools/firmware: Build and install xen-shim
In reply to Wei LiuFrom: Andrew Cooper <[email protected]>
Link a minimum set of files to build the shim. The linkfarm rune can handle creation and deletion of files. Introduce build-shim and install-shim targets in xen/Makefile.
We can do better by properly generate the dependency from the list of files but that's an improvement for later.
---
v2: Introduce a top-level build-shim target. Split the xen-shim build
with normal build.
--- .gitignore | 4 ++ tools/firmware/Makefile | 9 ++++ tools/firmware/xen-dir/Makefile | 59 ++++++++++++++++++++++++++ tools/firmware/xen-dir/shim.config | 87 ++++++++++++++++++++++++++++++++++++++ xen/Makefile | 16 +++++-- 5 files changed, 172 insertions(+), 3 deletions(-) create mode 100644 tools/firmware/xen-dir/Makefile create mode 100644 tools/firmware/xen-dir/shim.config
.gitignore +4 -0
@@ -155,6 +155,10 @@ tools/firmware/rombios/rombios[^/]*.s tools/firmware/rombios/32bit/32bitbios_flat.h tools/firmware/vgabios/vbetables-gen tools/firmware/vgabios/vbetables.h +tools/firmware/xen-dir/*.old +tools/firmware/xen-dir/linkfarm.stamp* +tools/firmware/xen-dir/xen-root +tools/firmware/xen-dir/xen-shim tools/flask/utils/flask-getenforce tools/flask/utils/flask-get-bool tools/flask/utils/flask-loadpolicy
tools/firmware/Makefile +9 -0
@@ -1,6 +1,8 @@ XEN_ROOT = $(CURDIR)/../.. include $(XEN_ROOT)/tools/Rules.mk +CONFIG_PV_SHIM := y + # hvmloader is a 32-bit protected mode binary. TARGET := hvmloader/hvmloader INST_DIR := $(DESTDIR)$(XENFIRMWAREDIR)
@@ -11,6 +13,7 @@ SUBDIRS-$(CONFIG_SEABIOS) += seabios-dir SUBDIRS-$(CONFIG_ROMBIOS) += rombios SUBDIRS-$(CONFIG_ROMBIOS) += vgabios SUBDIRS-$(CONFIG_ROMBIOS) += etherboot +SUBDIRS-$(CONFIG_PV_SHIM) += xen-dir SUBDIRS-y += hvmloader LD32BIT-$(CONFIG_FreeBSD) := LD32BIT_FLAG=-melf_i386_fbsd
@@ -48,6 +51,9 @@ endif ifeq ($(CONFIG_OVMF),y) $(INSTALL_DATA) ovmf-dir/ovmf.bin $(INST_DIR)/ovmf.bin endif +ifeq ($(CONFIG_PV_SHIM),y) + $(INSTALL_DATA) xen-dir/xen-shim $(INST_DIR)/xen-shim +endif .PHONY: uninstall uninstall:
@@ -58,6 +64,9 @@ endif ifeq ($(CONFIG_OVMF),y) rm -f $(INST_DIR)/ovmf.bin endif +ifeq ($(CONFIG_PV_SHIM),y) + rm -f $(INST_DIR)/xen-shim +endif .PHONY: clean clean: subdirs-clean
tools/firmware/xen-dir/Makefile new file +59 -0
59 lines not on this page · raw message
tools/firmware/xen-dir/shim.config new file +87 -0
87 lines not on this page · raw message
xen/Makefile +13 -3
@@ -37,10 +37,10 @@ default: build .PHONY: dist dist: install -build install:: include/config/auto.conf +build install build-shim:: include/config/auto.conf -.PHONY: build install uninstall clean distclean cscope TAGS tags MAP gtags tests -build install uninstall debug clean distclean cscope TAGS tags MAP gtags tests:: +.PHONY: build install uninstall clean distclean cscope TAGS tags MAP gtags tests install-shim build-shim +build install uninstall debug clean distclean cscope TAGS tags MAP gtags tests install-shim build-shim:: ifneq ($(XEN_TARGET_ARCH),x86_32) $(MAKE) -f Rules.mk _$@ else
@@ -80,6 +80,13 @@ _install: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX) fi; \ fi +.PHONY: _build-shim +_build-shim: $(TARGET)-shim + +.PHONY: _install-shim +_install-shim: build-shim + $(INSTALL_DATA) $(TARGET)-shim $(DESTDIR) + .PHONY: _tests _tests: $(MAKE) -f $(BASEDIR)/Rules.mk -C test tests
@@ -144,6 +151,9 @@ $(TARGET): delete-unfresh-files $(MAKE) -f $(BASEDIR)/Rules.mk include/asm-$(TARGET_ARCH)/asm-offsets.h $(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) $(TARGET) +$(TARGET)-shim: $(TARGET) + $(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) $(TARGET)-shim + # drivers/char/console.o contains static banner/compile info. Blow it away. # Don't refresh these files during e.g., 'sudo make install' .PHONY: delete-unfresh-files
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 30/62 x86/guest: map per-cpu vcpu_info area.
In reply to Wei LiuFrom: Roger Pau Monne <[email protected]>
Mapping the per-vcpu vcpu_info area is required in order to use more than XEN_LEGACY_MAX_VCPUS.
---
Changes since v1:
- Make vcpu_info_mapped static.
- Add a BUG_ON in case VCPUOP_register_vcpu_info fails.
- Remove one indentation level in hypervisor_setup.
- Make xen_hypercall_vcpu_op return int.
--- xen/arch/x86/guest/xen.c | 57 +++++++++++++++++++++++++++++++++++ xen/include/asm-x86/guest/hypercall.h | 8 +++++ xen/include/asm-x86/guest/xen.h | 1 + 3 files changed, 66 insertions(+)
xen/arch/x86/guest/xen.c +57 -0
@@ -39,6 +39,10 @@ static struct rangeset *mem; DEFINE_PER_CPU(unsigned int, vcpu_id); +static struct vcpu_info *vcpu_info; +static unsigned long vcpu_info_mapped[BITS_TO_LONGS (NR_CPUS )]; +DEFINE_PER_CPU(struct vcpu_info *, vcpu_info); +static void __init find_xen_leaves (void ) {uint32_t eax, ebx, ecx, edx, base;
@@ -104,6 +108,41 @@ static void map_shared_info(void)write_atomic (&XEN_shared_info->evtchn_mask[i], ~0ul ); } +static int map_vcpuinfo (void ) +{ +unsigned int vcpu =this_cpu (vcpu_id); +struct vcpu_register_vcpu_info info; +int rc; + +if ( !vcpu_info ) + { +this_cpu (vcpu_info) = &XEN_shared_info->vcpu_info[vcpu]; +return 0 ; + } + +if (test_bit (vcpu, vcpu_info_mapped) ) + { +this_cpu (vcpu_info) = &vcpu_info[vcpu]; +return 0 ; + } + + info.mfn =virt_to_mfn (&vcpu_info[vcpu]); + info.offset = (unsigned long )&vcpu_info[vcpu] & ~PAGE_MASK ; + rc =xen_hypercall_vcpu_op (VCPUOP_register_vcpu_info, vcpu, &info); +if ( rc ) + { +BUG_ON (vcpu >=XEN_LEGACY_MAX_VCPUS ); +this_cpu (vcpu_info) = &XEN_shared_info->vcpu_info[vcpu]; + } +else + { +this_cpu (vcpu_info) = &vcpu_info[vcpu]; +set_bit (vcpu, vcpu_info_mapped); + } + +return rc; +} +static void set_vcpu_id (void ) {uint32_t eax, ebx, ecx, edx;
@@ -154,11 +193,29 @@ void __init hypervisor_setup(void)map_shared_info ();set_vcpu_id (); + vcpu_info = xzalloc_array(struct vcpu_info, nr_cpu_ids); +if (map_vcpuinfo () ) + { +xfree (vcpu_info); + vcpu_info =NULL ; + } +if ( !vcpu_info && nr_cpu_ids >XEN_LEGACY_MAX_VCPUS ) + { +unsigned int i; + +for ( i =XEN_LEGACY_MAX_VCPUS ; i < nr_cpu_ids; i++ ) +__cpumask_clear_cpu (i, &cpu_present_map); + nr_cpu_ids =XEN_LEGACY_MAX_VCPUS ; +printk (XENLOG_WARNING +"unable to map vCPU info, limiting vCPUs to: %u\n" , +XEN_LEGACY_MAX_VCPUS ); + } }void hypervisor_ap_setup (void ) {set_vcpu_id (); +map_vcpuinfo (); }int hypervisor_alloc_unused_page (mfn_t *mfn)
xen/include/asm-x86/guest/hypercall.h +8 -0
@@ -26,6 +26,8 @@#include <public/xen.h> #include <public/sched.h> +#include <public/vcpu.h> +/* * Hypercall primatives for 64bit *
@@ -96,6 +98,12 @@ static inline long xen_hypercall_memory_op(unsigned int cmd, void *arg)return _hypercall64_2 (long, __HYPERVISOR_memory_op, cmd, arg); } +static inline int xen_hypercall_vcpu_op (unsigned int cmd,unsigned int vcpu, +void *arg) +{ +return _hypercall64_3 (long, __HYPERVISOR_vcpu_op, cmd, vcpu, arg); +} +/* * Higher level hypercall helpers */
xen/include/asm-x86/guest/xen.h +1 -0
@@ -37,6 +37,7 @@ int hypervisor_alloc_unused_page(mfn_t *mfn);int hypervisor_free_unused_page (mfn_t mfn); DECLARE_PER_CPU(unsigned int, vcpu_id); +DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);#else
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 62/62 xl: Default guest mode changed from PV to PVH with PV shim
In reply to Wei LiuFrom: Ian Jackson <[email protected]>
If the config file specifies a type (or builder), it overrides this default. But if it doesn't, you now get a PV-in-PVH guest.
---
v2: New patch
--- tools/xl/xl_parse.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
tools/xl/xl_parse.c +10 -3
@@ -939,8 +939,12 @@ void parse_config_data(const char *config_source, c_info->type = builder_type; } -if (c_info->type ==LIBXL_DOMAIN_TYPE_INVALID ) - c_info->type =LIBXL_DOMAIN_TYPE_PV ; +static bool pvshim_default_enable =0 ; + +if (c_info->type ==LIBXL_DOMAIN_TYPE_INVALID ) { + c_info->type =LIBXL_DOMAIN_TYPE_PVH ; + pvshim_default_enable =1 ; + }xlu_cfg_get_defbool (config,"hap" , &c_info->hap,0 );
@@ -966,7 +970,10 @@ void parse_config_data(const char *config_source,libxl_domain_build_info_init_type (b_info, c_info->type);if (b_info->type ==LIBXL_DOMAIN_TYPE_PVH ) { -xlu_cfg_get_defbool (config,"pvshim" , &b_info->u.pvh.pvshim,0 ); +if (xlu_cfg_get_defbool (config,"pvshim" , &b_info->u.pvh.pvshim,0 ) + && pvshim_default_enable) +libxl_defbool_set (&b_info->u.pvh.pvshim,1 ); +if (!xlu_cfg_get_string (config,"pvshim_path" , &buf,0 ))xlu_cfg_replace_string (config,"pvshim_path" , &b_info->u.pvh.pvshim_path,0 );
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 31/62 x86: xen pv clock time source
In reply to Wei LiuIt is a variant of TSC clock source.
---
Changes since v1:
- Use the mapped vcpu_info.
--- xen/arch/x86/time.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+)
xen/arch/x86/time.c +89 -0
@@ -29,6 +29,7 @@#include <asm/mpspec.h> #include <asm/processor.h> #include <asm/fixmap.h> +#include <asm/guest.h> #include <asm/mc146818rtc.h> #include <asm/div64.h> #include <asm/acpi.h>
@@ -525,6 +526,91 @@ static struct platform_timesource __initdata plt_tsc = .init = init_tsc, }; +#ifdef CONFIG_XEN_GUEST +/************************************************************ +* PLATFORM TIMER 5: XEN PV CLOCK SOURCE +* +* Xen clock source is a variant of TSC source. +*/ + +static uint64_t xen_timer_cpu_frequency (void ) +{ +struct vcpu_time_info *info = &this_cpu (vcpu_info)->time; +uint64_t freq; + + freq =1000000000ULL <<32 ; +do_div (freq, info->tsc_to_system_mul); +if ( info->tsc_shift <0 ) + freq <<= -info->tsc_shift; +else + freq >>= info->tsc_shift; + +return freq; +} + +static int64_t __init init_xen_timer (struct platform_timesource *pts) +{ +if ( !xen_guest ) +return 0 ; + + pts->frequency =xen_timer_cpu_frequency (); + +return pts->frequency; +} + +static always_inline uint64_t read_cycle(const struct vcpu_time_info *info, +uint64_t tsc) +{ +uint64_t delta = tsc - info->tsc_timestamp; +struct time_scale ts = { + .shift = info->tsc_shift, + .mul_frac = info->tsc_to_system_mul, + }; +uint64_t offset =scale_delta (delta, &ts); + +return info->system_time + offset; +} + +static uint64_t read_xen_timer (void ) +{ +struct vcpu_time_info *info = &this_cpu (vcpu_info)->time; +uint32_t version; +uint64_t ret; +uint64_t last; +static uint64_t last_value; + +do { + version = info->version & ~1 ; +/* Make sure version is read before the data */ +smp_rmb (); + + ret =read_cycle (info,rdtsc_ordered ()); +/* Ignore fancy flags for now */ + +/* Make sure version is reread after the data */ +smp_rmb (); + }while (unlikely (version != info->version) ); + +/* Maintain a monotonic global value */ +do { + last =read_atomic (&last_value); +if ( ret < last ) +return last; + }while (unlikely (cmpxchg (&last_value, last, ret) != last) ); + +return ret; +} + +static struct platform_timesource __initdata plt_xen_timer = +{ + .id ="xen" , + .name ="XEN PV CLOCK" , + .read_counter = read_xen_timer, + .init = init_xen_timer, + .counter_bits =63 , +}; +#endif +/************************************************************ * GENERIC PLATFORM TIMER INFRASTRUCTURE */
@@ -672,6 +758,9 @@ static s64 __init try_platform_timer(struct platform_timesource *pts)static u64 __init init_platform_timer (void ) {static struct platform_timesource *__initdata plt_timers[] = { +#ifdef CONFIG_XEN_GUEST + &plt_xen_timer, +#endif &plt_hpet, &plt_pmtimer, &plt_pit };
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/1 fixup! libxl: pvshim: Provide first-class config settings to enable shim mode
In reply to Wei LiuEarlier versions of this patch have an erroneous hunk which will stop PV guests from working at all!
--- tools/libxl/libxl_create.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/libxl/libxl_create.c +4 -0
@@ -488,6 +488,10 @@ int libxl__domain_build(libxl__gc *gc,break ;case LIBXL_DOMAIN_TYPE_PV : + ret =libxl__build_pv (gc, domid, info, state); +if (ret) + goto out; + vments =libxl__calloc (gc,11 ,sizeof (char *)); i =0 ; vments[i++] ="image/ostype" ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 31/62] x86: xen pv clock time source
In reply to Wei LiuQuoted 50 lines · Wei Liu
It is a variant of TSC clock source.
Signed-off-by Wei Liu <[email protected]>Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>---
Changes since v1:
- Use the mappedvcpu_info.--- xen/arch/x86/time.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+)xen/arch/x86/time.c +23
-0@@ -29,6 +29,7 @@#include <asm/mpspec.h> #include <asm/processor.h> #include <asm/fixmap.h> +#include <asm/guest.h> #include <asm/mc146818rtc.h> #include <asm/div64.h> #include <asm/acpi.h> @@ -525,6 +526,91 @@ static struct platform_timesource __initdata plt_tsc = .init = init_tsc, }; +#ifdef CONFIG_XEN_GUEST +/************************************************************ +* PLATFORM TIMER 5: XEN PV CLOCK SOURCE +* +* Xen clock source is a variant of TSC source. +*/ + +static uint64_t xen_timer_cpu_frequency (void ) +{ +struct vcpu_time_info *info = &this_cpu (vcpu_info)->time; +uint64_t freq; + + freq =1000000000ULL <<32 ; +do_div (freq, info->tsc_to_system_mul); +if ( info->tsc_shift <0 ) + freq <<= -info->tsc_shift; +else + freq >>= info->tsc_shift; + +return freq; +} +
xen/arch/x86/time.c static struct platform_timesource __initdata plt_tsc = · line 560
Quoted 10 lines
xen/arch/x86/time.c +10
-0+static int64_t __init init_xen_timer (struct platform_timesource *pts) +{ +if ( !xen_guest ) +return 0 ; + + pts->frequency =xen_timer_cpu_frequency (); + +return pts->frequency; +} +
Guests that don't have TSC_RELIABLE set in verify_tsc_reliability() you end up evaluating this condition to true:
if ( boot_cpu_has(X86_FEATURE_CONSTANT_TSC) &&
!boot_cpu_has(X86_FEATURE_TSC_RELIABLE) )
time_calibration_rendezvous_fn = time_calibration_tsc_rendezvous;And that's possibly not necessary to keep sync the TSC in sync with pvclock?
Meaning the default rendezvous function (time_calibration_std_rendezvous) might be enough.
Quoted 19 lines
xen/arch/x86/time.c +19
-0+static always_inline uint64_t read_cycle(const struct vcpu_time_info *info, +uint64_t tsc) +{ +uint64_t delta = tsc - info->tsc_timestamp; +struct time_scale ts = { + .shift = info->tsc_shift, + .mul_frac = info->tsc_to_system_mul, + }; +uint64_t offset =scale_delta (delta, &ts); + +return info->system_time + offset; +} + +static uint64_t read_xen_timer (void ) +{ +struct vcpu_time_info *info = &this_cpu (vcpu_info)->time; +uint32_t version; +uint64_t ret; +uint64_t last;
xen/arch/x86/time.c static struct platform_timesource __initdata plt_tsc = · line 589
Quoted 10 lines
xen/arch/x86/time.c +10
-0+static uint64_t last_value; + + do { + version = info->version & ~1; + /* Make sure version is read before the data */ + smp_rmb(); + + ret = read_cycle(info, rdtsc_ordered()); + /* Ignore fancy flags for now */ +
Heh :)
When the dust settles around the security issues, perhaps this patch could help (I can formally submit it after more proper testing, but should give an expectation on the changes).
-- >8 --
Subject: x86/time: mark pvclock as stable if supported
xen/arch/x86/time.c +19 -4
@@ -65,8 +65,12 @@ struct platform_timesource {s64 (*init)(struct platform_timesource *);void (*resume)(struct platform_timesource *);int counter_bits; +unsigned int flags; }; +/* Clocksource counter monotonically increases across CPUs */ +#define CLOCKSOURCE_F_STABLE (1 << 0) + static DEFINE_PER_CPU(struct cpu_time, cpu_time);/* Calibrate all CPUs to platform timer every EPOCH. */
@@ -533,9 +537,8 @@ static struct platform_timesource __initdata plt_tsc =* Xen clock source is a variant of TSC source. */ -static uint64_t xen_timer_cpu_frequency (void ) +static uint64_t xen_timer_cpu_frequency (struct vcpu_time_info *info) { -struct vcpu_time_info *info = &this_cpu (vcpu_info)->time;uint64_t freq; freq =1000000000ULL <<32 ;
@@ -550,10 +553,20 @@ static uint64_t xen_timer_cpu_frequency(void)static int64_t __init init_xen_timer (struct platform_timesource *pts) { +struct vcpu_time_info *info; +if ( !xen_guest )return 0 ; - pts->frequency =xen_timer_cpu_frequency (); + info = &this_cpu (vcpu_info)->time; + + pts->frequency =xen_timer_cpu_frequency (info); + +/* Xen pvclock monotonically increases across CPUs */ +if ( info->flags &XEN_PVCLOCK_TSC_STABLE_BIT ) { + pts->flags |=CLOCKSOURCE_F_STABLE ; +printk ("PV CLOCK marked as stable.\n" ); + }return pts->frequency; }
@@ -585,12 +598,14 @@ static uint64_t read_xen_timer(void)smp_rmb (); ret =read_cycle (info,rdtsc_ordered ()); -/* Ignore fancy flags for now */ /* Make sure version is reread after the data */ smp_rmb (); }while (unlikely (version != info->version) ); +if ( info->flags &XEN_PVCLOCK_TSC_STABLE_BIT ) +return ret; +/* Maintain a monotonic global value */ do { last = read_atomic(&last_value);
@@ -632,6 +647,8 @@ static u64 plt_stamp64; /* 64-bit platform counter
stamp */
static u64 plt_stamp; /* hardware-width platform counter stamp */
static struct timer plt_overflow_timer;
+static bool clocksource_is_stable(void);
+
static s_time_t __read_platform_stime(u64 platform_time)
{
u64 diff = platform_time - platform_timer_stamp;@@ -1077,7 +1094,7 @@ static void __update_vcpu_system_time(struct vcpu *v, int force)
* pvclock read to check whether they can resort solely on this tuple
* or if it further requires monotonicity checks with other vcpus. */
- if ( clocksource_is_tsc() )
+ if ( clocksource_is_stable() )
_u.flags |= XEN_PVCLOCK_TSC_STABLE_BIT;
if ( is_hvm_domain(d) )@@ -1564,7 +1581,7 @@ static void time_calibration(void *unused)
.semaphore = ATOMIC_INIT(0)
};
- if ( clocksource_is_tsc() )
+ if ( clocksource_is_stable() )
{
local_irq_disable();
r.master_stime = read_platform_stime(&r.master_tsc_stamp);
@@ -1740,6 +1757,9 @@ static int __init verify_tsc_reliability(void)
*/
on_selected_cpus(&cpu_online_map, reset_percpu_time, NULL, 1);+ /* TSC clocksource monotonically increases across CPUs. */
+ plt_tsc.flags |= CLOCKSOURCE_F_STABLE;
+
/*
* We won't do CPU Hotplug and TSC clocksource is being used which
* means we have a reliable TSC, plus we don't sync with any other
@@ -1770,7 +1790,12 @@ static int __init verify_tsc_reliability(void)
*/
if ( boot_cpu_has(X86_FEATURE_CONSTANT_TSC) &&
!boot_cpu_has(X86_FEATURE_TSC_RELIABLE) )- time_calibration_rendezvous_fn = time_calibration_tsc_rendezvous;
+ {
+ if ( clocksource_is_stable() )
+ time_calibration_rendezvous_fn = time_calibration_nop_rendezvous;
+ else if ( plt_src.read_counter != read_xen_timer )
+ time_calibration_rendezvous_fn = time_calibration_tsc_rendezvous;
+ }
return 0;
}
@@ -2057,6 +2082,23 @@ bool clocksource_is_tsc(void)
return plt_src.read_counter == read_tsc;}
+static bool clocksource_is_stable(void)
+{
+ struct vcpu_time_info *info;
+
+ if ( !(plt_src.flags & CLOCKSOURCE_F_STABLE) )
+ return false;
+
+ if ( plt_src.read_counter == read_tsc )
+ return true;
+
+ info = &this_cpu(vcpu_info)->time;
+ if ( !(info->flags & XEN_PVCLOCK_TSC_STABLE_BIT) )
+ return false;
+
+ return true;
+}
+
int host_tsc_is_safe(void)
{
return boot_cpu_has(X86_FEATURE_TSC_RELIABLE);_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 31/62] x86: xen pv clock time source
Quoted 64 lines · Joao Martins
Quoted 50 lines · Wei Liu
It is a variant of TSC clock source.
Signed-off-by Wei Liu <[email protected]>Signed-off-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>---
Changes since v1:
- Use the mappedvcpu_info.--- xen/arch/x86/time.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+)xen/arch/x86/time.c +23
-0@@ -29,6 +29,7 @@#include <asm/mpspec.h> #include <asm/processor.h> #include <asm/fixmap.h> +#include <asm/guest.h> #include <asm/mc146818rtc.h> #include <asm/div64.h> #include <asm/acpi.h> @@ -525,6 +526,91 @@ static struct platform_timesource __initdata plt_tsc = .init = init_tsc, }; +#ifdef CONFIG_XEN_GUEST +/************************************************************ +* PLATFORM TIMER 5: XEN PV CLOCK SOURCE +* +* Xen clock source is a variant of TSC source. +*/ + +static uint64_t xen_timer_cpu_frequency (void ) +{ +struct vcpu_time_info *info = &this_cpu (vcpu_info)->time; +uint64_t freq; + + freq =1000000000ULL <<32 ; +do_div (freq, info->tsc_to_system_mul); +if ( info->tsc_shift <0 ) + freq <<= -info->tsc_shift; +else + freq >>= info->tsc_shift; + +return freq; +} +xen/arch/x86/time.c static struct platform_timesource __initdata plt_tsc = · line 560
Quoted 10 lines
xen/arch/x86/time.c +10
-0+static int64_t __init init_xen_timer (struct platform_timesource *pts) +{ +if ( !xen_guest ) +return 0 ; + + pts->frequency =xen_timer_cpu_frequency (); + +return pts->frequency; +} +Guests that don't have
TSC_RELIABLEset inverify_tsc_reliability()you end up evaluating this condition to true:
Quoted 8 lines
if (
boot_cpu_has(X86_FEATURE_CONSTANT_TSC)&&!boot_cpu_has(X86_FEATURE_TSC_RELIABLE) ) time_calibration_rendezvous_fn = time_calibration_tsc_rendezvous;And that's possibly not necessary to keep sync the TSC in sync with pvclock?
Meaning the default rendezvous function (
time_calibration_std_rendezvous) might be enough.
Yes, it is possible that the default function is enough. But we haven't tested that yet.
Quoted 33 lines
Quoted 20 lines
xen/arch/x86/time.c +19
-0+static always_inline uint64_t read_cycle(const struct vcpu_time_info *info, +uint64_t tsc) +{ +uint64_t delta = tsc - info->tsc_timestamp; +struct time_scale ts = { + .shift = info->tsc_shift, + .mul_frac = info->tsc_to_system_mul, + }; +uint64_t offset =scale_delta (delta, &ts); + +return info->system_time + offset; +} + +static uint64_t read_xen_timer (void ) +{ +struct vcpu_time_info *info = &this_cpu (vcpu_info)->time; +uint32_t version; +uint64_t ret; +uint64_t last;xen/arch/x86/time.c static struct platform_timesource __initdata plt_tsc = · line 589
Quoted 10 lines
xen/arch/x86/time.c +10
-0+static uint64_t last_value; + + do { + version = info->version & ~1; + /* Make sure version is read before the data */ + smp_rmb(); + + ret = read_cycle(info, rdtsc_ordered()); + /* Ignore fancy flags for now */ +Heh :)
Quoted 4 lines
When the dust settles around the security issues, perhaps this patch could help (I can formally submit it after more proper testing, but should give an expectation on the changes).
I skimmed through it. It looks like it is mostly an optimisation for this patch. That is, properly detecting the stable bit and using it where appropriate. We can definitely improve in that regard. But as you said, let's handle the security issues at hand first.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel