35 Commits
Author SHA1 Message Date
Wei Liu b58dc6dbfa x86/hyperv: stash and use the configured max VP index
The value returned from CPUID is the maximum number for virtual
processors supported by Hyper-V. It could be larger than the maximum
number of virtual processors configured.

Stash the configured number into a variable and use it in calculations.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
2020-05-06 10:40:42 +01:00
Wei Liu 4e3322ec14 x86/hyperv: setup VP assist page
VP assist page is rather important as we need to toggle some bits in it
for efficient nested virtualisation.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <pdurrant@amazon.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
2020-02-05 16:05:06 +00:00
Wei Liu a37007356c x86/hyperv: retrieve vp_index from Hyper-V
This will be useful when invoking hypercall that targets specific
vcpu(s).

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <paul@xen.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
2020-02-05 16:05:06 +00:00
Wei Liu dbc9b60ba3 x86/hyperv: provide percpu hypercall input page
Hyper-V's input / output argument must be 8 bytes aligned an not cross
page boundary. One way to satisfy those requirements is to use percpu
page.

For the foreseeable future we only need to provide input for TLB
and APIC hypercalls, so skip setting up an output page.

We will also need to provide an ap_setup hook for secondary cpus to
setup its own input page.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <pdurrant@amazon.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
2020-02-05 16:05:06 +00:00
Wei Liu acd326759a x86/hyperv: provide Hyper-V hypercall functions
These functions will be used later to make hypercalls to Hyper-V.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <pdurrant@amazon.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2020-02-05 15:55:34 +00:00
Wei Liu 620fc734f8 x86/hyperv: setup hypercall page
Hyper-V uses a technique called overlay page for its hypercall page. It
will insert a backing page to the guest when the hypercall functionality
is enabled. That means we can use a page that is not backed by real
memory for hypercall page.

To avoid shattering L0 superpages and treading on any MMIO areas
residing in low addresses, use the top-most addressable page for that
purpose. Adjust e820 map accordingly.

We also need to register Xen's guest OS ID to Hyper-V. Use 0x3 as the
vendor ID. Fix the comment in hyperv-tlfs.h while at it.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Paul Durrant <pdurrant@amazon.com>
2020-02-05 15:55:02 +00:00
Wei Liu 39ee69e4d6 x86/hypervisor: provide hypervisor_fixup_e820
And implement the hook for Xen guest.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2020-02-05 15:55:02 +00:00
Wei Liu ac661ada11 x86: provide executable fixmap facility
This allows us to set aside some address space for executable mapping.
This fixed map range starts from XEN_VIRT_END so that it is within reach
of the .text section.

Shift the percpu stub range and shrink livepatch range accordingly.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2020-02-05 15:55:02 +00:00
Wei Liu 0566b53215 x86/smp: don't online cpu if hypervisor_ap_setup fails
Push hypervisor_ap_setup down to smp_callin.

Take the chance to replace xen_guest with cpu_has_hypervisor.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2020-02-05 15:55:02 +00:00
Wei Liu 5eeeddf74b x86/hypervisor: make hypervisor_ap_setup return an error code
We want to be able to handle AP setup error in the upper layer.

For Xen, remove all panic() and BUG_ON() in init_evtchn and
map_vcpuinfo. Only panic/BUG_ON when Xen can't fail gracefully.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2020-02-05 15:55:02 +00:00
Wei Liu d9c4499c18 x86: make paddr_bits available earlier
Move early_cpu_init before init_e820, such that paddr_bits can be used
by e820 code.

This will reduce code repetition and prepare for further adjustment when
L0 hypervisor comes into play.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2020-01-31 16:16:12 +00:00
Wei Liu 6325bf54ce x86/hyperv: drop all __packed from hyperv-tlfs.h
All structures are already naturally aligned. Linux added those
attributes out of paranoia.

In Xen we've had instance we had to drop pointless __packed to placate
gcc 9 (see ca9310b24e "x86/IO-APIC: fix build with gcc9"), it is better
to drop those attributes in hyperv-tlfs.h as well.

Requested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Wei Liu <liuwe@microsoft.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2020-01-08 15:30:52 +00:00
Wei Liu 1ca54e74e8 x86/hyperv: drop usage of GENMASK_ULL from hyperv-tlfs.h
I'm told that GENMASK_ULL shouldn't be used outside of Arm code in its
current form.

Requested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Wei Liu <liuwe@microsoft.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2020-01-08 15:30:51 +00:00
Wei Liu f4cf2529fd x86: rename guest/hypercall.h to guest/xen-hcall.h
We will provide a header file for Hyper-V hypercalls.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <paul@xen.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
2020-01-03 17:47:37 +00:00
Wei Liu 5babcc9a33 x86/hyperv: detect absolutely necessary MSRs
If they are not available, disable Hyper-V related features.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2020-01-03 17:45:47 +00:00
Wei Liu 005f85b7d8 x86: include xen/lib.h in guest/pvh-boot.h
It needs ASSERT_UNREACHABLE.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2020-01-03 17:45:33 +00:00
Wei Liu 25ae71fff0 x86/viridian: drop viridian_stimer_config_msr
Use hv_stimer_config instead. No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <paul@xen.org>
2019-12-23 10:51:29 +00:00
Wei Liu 78f019b068 x86/viridian: drop virdian_sint_msr
Use hv_synic_sint in hyperv-tlfs.h instead.

This requires adding the missing "polling" member to hv_synic_sint.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <paul@xen.org>
2019-12-23 10:51:29 +00:00
Wei Liu c9d9b5f4c9 x86/viridian: drop a wrong invalid value from reference TSC implementation
The only invalid value mentioned in Hyper-V TLFS 5.0c is 0. Michael
Kelley confirmed that 0xFFFFFFFF was never used [0].

[0] https://lists.xen.org/archives/html/xen-devel/2019-12/msg01564.html

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <paul@xen.org>
2019-12-23 10:51:29 +00:00
Wei Liu 9520876662 x86: move viridian_guest_os_id_msr to hyperv-tlfs.h
Suggested-by: Paul Durrant <pdurrant@amazon.com>
Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <paul@xen.org>
2019-12-23 10:51:29 +00:00
Wei Liu bb2aa33c2a x86: provide and use hv_tsc_scale
The Hyper-V clock source and Xen's own viridian code need the same
functionality.

Move the function in viridian/time.c to hyperv.h and use it in both
places.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <paul@xen.org>
2019-12-23 10:51:29 +00:00
Wei Liu f1c6ae95b1 x86/viridian: drop private copy of HV_REFERENCE_TSC_PAGE in time.c
Use the one defined in hyperv-tlfs.h instead. No functional change
intended.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <paul@xen.org>
2019-12-23 10:51:29 +00:00
Wei Liu a846ac633a x86/viridian: drop duplicate defines from private.h and viridian.c
Also add HVCALL_EXT_CALL_QUERY_CAPABILITIES to hyperv-tlfs.h.
HvGetPartitionID was never used in code so just dropped it.

No functional change intended.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <paul@xen.org>
2019-12-23 10:51:29 +00:00
Wei Liu 685d16bd56 x86: implement Hyper-V clock source
Implement a clock source using Hyper-V's reference TSC page.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
2019-12-20 17:58:54 +00:00
Wei Liu 8b11ad3871 x86/hyperv: extract more information from Hyper-V
Provide a structure to store that information. The structure will be
accessed from other places later so make it public.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2019-12-20 17:58:54 +00:00
Wei Liu bbba482664 x86: import hyperv-tlfs.h from Linux
Take a pristine copy from Linux commit b2d8b167e15bb5ec2691d1119c025630a247f649.

Do the following to fix it up for Xen:

1. include xen/types.h and xen/bitops.h
2. fix up invocations of BIT macro

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2019-12-20 17:58:54 +00:00
Wei Liu 80268f6364 x86: add a comment regarding the location of hypervisor_probe
Signed-off-by: Wei Liu <liuwe@microsoft.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2019-12-11 11:36:50 +00:00
Wei Liu 05de315b00 x86: introduce CONFIG_HYPERV and detection code
We use the same code structure as we did for Xen.

As starters, detect Hyper-V in probe routine. More complex
functionalities will be added later.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <pdurrant@amazon.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2019-12-04 10:38:22 +00:00
Wei Liu d815e9272c x86: be more verbose when running on a hypervisor
Also replace reference to xen_guest.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2019-12-04 10:38:22 +00:00
Wei Liu a5d847ed64 x86: switch xen guest implementation to use hypervisor framework
Acked-by: Jan Beulich <jbeulich@suse.com>
2019-12-04 10:38:22 +00:00
Wei Liu 62f946a7bc x86: rename hypervisor_{alloc,free}_unused_page
They are used in Xen code only.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <pdurrant@amazon.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2019-12-04 10:38:22 +00:00
Wei Liu 49bd351aee x86: introduce hypervisor framework
We will soon implement Hyper-V support for Xen. Add a framework for
that.

This requires moving some of the hypervisor_* functions from xen.h to
hypervisor.h.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2019-12-04 10:38:17 +00:00
Wei Liu 1c178ffb29 x86: drop hypervisor_cpuid_base
The only user is Xen specific code in PV shim. We can therefore export
the variable directly.

Move __read_mostly to its standard place while at it.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2019-12-04 10:31:25 +00:00
Wei Liu cd78188af5 x86: add missing headers in hypercall.h
Include asm_defns.h because ASM_CALL_CONSTRAINT is defined there.

Include xen/lib.h because we need ASSERT_UNREACHABLE.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2019-12-04 10:31:25 +00:00
Wei Liu ca363f186d x86: introduce CONFIG_GUEST and move code
Xen is able to run as a guest on Xen. We plan to make it able to run
on Hyper-V as well.

Introduce CONFIG_GUEST which is set to true if either running on Xen
or Hyper-V is desired. Restructure code hierarchy for new code to
come.

No functional change intended.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
2019-12-04 10:31:25 +00:00