Clean up viridian code
cover Clean up viridian code
Wei Liu (4):
x86/viridian: drop duplicate defines from private.h and viridian.c x86/viridian: drop private copy of HV_REFERENCE_TSC_PAGE in time.c
x86: provide and use hv_tsc_scale
x86: move viridian_guest_os_id_msr to hyperv-tlfs.h
xen/arch/x86/hvm/viridian/private.h | 66 ------------------------- xen/arch/x86/hvm/viridian/time.c | 50 +++---------------- xen/arch/x86/hvm/viridian/viridian.c | 31 +++--------- xen/arch/x86/time.c | 7 +-- xen/include/asm-x86/guest/hyperv-tlfs.h | 14 ++++++ xen/include/asm-x86/guest/hyperv.h | 32 +++++++++++- xen/include/asm-x86/hvm/viridian.h | 18 ++----- 7 files changed, 64 insertions(+), 154 deletions(-)
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/4 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.
--- xen/arch/x86/hvm/viridian/private.h | 66 ------------------------- xen/arch/x86/hvm/viridian/viridian.c | 29 +++-------- xen/include/asm-x86/guest/hyperv-tlfs.h | 1 + 3 files changed, 8 insertions(+), 88 deletions(-)
xen/arch/x86/hvm/viridian/private.h +0 -66
@@ -5,72 +5,6 @@#include <asm/hvm/save.h> -/* Viridian MSR numbers. */ -#define HV_X64_MSR_GUEST_OS_ID 0x40000000 -#define HV_X64_MSR_HYPERCALL 0x40000001 -#define HV_X64_MSR_VP_INDEX 0x40000002 -#define HV_X64_MSR_RESET 0x40000003 -#define HV_X64_MSR_VP_RUNTIME 0x40000010 -#define HV_X64_MSR_TIME_REF_COUNT 0x40000020 -#define HV_X64_MSR_REFERENCE_TSC 0x40000021 -#define HV_X64_MSR_TSC_FREQUENCY 0x40000022 -#define HV_X64_MSR_APIC_FREQUENCY 0x40000023 -#define HV_X64_MSR_EOI 0x40000070 -#define HV_X64_MSR_ICR 0x40000071 -#define HV_X64_MSR_TPR 0x40000072 -#define HV_X64_MSR_VP_ASSIST_PAGE 0x40000073 -#define HV_X64_MSR_SCONTROL 0x40000080 -#define HV_X64_MSR_SVERSION 0x40000081 -#define HV_X64_MSR_SIEFP 0x40000082 -#define HV_X64_MSR_SIMP 0x40000083 -#define HV_X64_MSR_EOM 0x40000084 -#define HV_X64_MSR_SINT0 0x40000090 -#define HV_X64_MSR_SINT1 0x40000091 -#define HV_X64_MSR_SINT2 0x40000092 -#define HV_X64_MSR_SINT3 0x40000093 -#define HV_X64_MSR_SINT4 0x40000094 -#define HV_X64_MSR_SINT5 0x40000095 -#define HV_X64_MSR_SINT6 0x40000096 -#define HV_X64_MSR_SINT7 0x40000097 -#define HV_X64_MSR_SINT8 0x40000098 -#define HV_X64_MSR_SINT9 0x40000099 -#define HV_X64_MSR_SINT10 0x4000009A -#define HV_X64_MSR_SINT11 0x4000009B -#define HV_X64_MSR_SINT12 0x4000009C -#define HV_X64_MSR_SINT13 0x4000009D -#define HV_X64_MSR_SINT14 0x4000009E -#define HV_X64_MSR_SINT15 0x4000009F -#define HV_X64_MSR_STIMER0_CONFIG 0x400000B0 -#define HV_X64_MSR_STIMER0_COUNT 0x400000B1 -#define HV_X64_MSR_STIMER1_CONFIG 0x400000B2 -#define HV_X64_MSR_STIMER1_COUNT 0x400000B3 -#define HV_X64_MSR_STIMER2_CONFIG 0x400000B4 -#define HV_X64_MSR_STIMER2_COUNT 0x400000B5 -#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6 -#define HV_X64_MSR_STIMER3_COUNT 0x400000B7 -#define HV_X64_MSR_POWER_STATE_TRIGGER_C1 0x400000C1 -#define HV_X64_MSR_POWER_STATE_TRIGGER_C2 0x400000C2 -#define HV_X64_MSR_POWER_STATE_TRIGGER_C3 0x400000C3 -#define HV_X64_MSR_POWER_STATE_CONFIG_C1 0x400000D1 -#define HV_X64_MSR_POWER_STATE_CONFIG_C2 0x400000D2 -#define HV_X64_MSR_POWER_STATE_CONFIG_C3 0x400000D3 -#define HV_X64_MSR_STATS_PARTITION_RETAIL_PAGE 0x400000E0 -#define HV_X64_MSR_STATS_PARTITION_INTERNAL_PAGE 0x400000E1 -#define HV_X64_MSR_STATS_VP_RETAIL_PAGE 0x400000E2 -#define HV_X64_MSR_STATS_VP_INTERNAL_PAGE 0x400000E3 -#define HV_X64_MSR_GUEST_IDLE 0x400000F0 -#define HV_X64_MSR_SYNTH_DEBUG_CONTROL 0x400000F1 -#define HV_X64_MSR_SYNTH_DEBUG_STATUS 0x400000F2 -#define HV_X64_MSR_SYNTH_DEBUG_SEND_BUFFER 0x400000F3 -#define HV_X64_MSR_SYNTH_DEBUG_RECEIVE_BUFFER 0x400000F4 -#define HV_X64_MSR_SYNTH_DEBUG_PENDING_BUFFER 0x400000F5 -#define HV_X64_MSR_CRASH_P0 0x40000100 -#define HV_X64_MSR_CRASH_P1 0x40000101 -#define HV_X64_MSR_CRASH_P2 0x40000102 -#define HV_X64_MSR_CRASH_P3 0x40000103 -#define HV_X64_MSR_CRASH_P4 0x40000104 -#define HV_X64_MSR_CRASH_CTL 0x40000105 -int viridian_synic_wrmsr (struct vcpu *v,uint32_t idx,uint64_t val);int viridian_synic_rdmsr (const struct vcpu *v,uint32_t idx,uint64_t *val);
xen/arch/x86/hvm/viridian/viridian.c +7 -22
@@ -10,6 +10,7 @@#include <xen/hypercall.h> #include <xen/domain_page.h> #include <asm/guest_access.h> +#include <asm/guest/hyperv-tlfs.h> #include <asm/paging.h> #include <asm/p2m.h> #include <asm/apic.h>
@@ -19,22 +20,6 @@#include "private.h" -/* Viridian Hypercall Status Codes. */ -#define HV_STATUS_SUCCESS 0x0000 -#define HV_STATUS_INVALID_HYPERCALL_CODE 0x0002 -#define HV_STATUS_INVALID_PARAMETER 0x0005 - -/* Viridian Hypercall Codes. */ -#define HvFlushVirtualAddressSpace 0x0002 -#define HvFlushVirtualAddressList 0x0003 -#define HvNotifyLongSpinWait 0x0008 -#define HvSendSyntheticClusterIpi 0x000b -#define HvGetPartitionId 0x0046 -#define HvExtCallQueryCapabilities 0x8001 - -/* Viridian Hypercall Flags. */ -#define HV_FLUSH_ALL_PROCESSORS 1 -/* Viridian Partition Privilege Flags */ typedef struct { /* Access to virtual MSRs */
@@ -214,7 +199,7 @@ void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,/* * This value is the recommended number of attempts to try to * acquire a spinlock before notifying the hypervisor via the -* HvNotifyLongSpinWait hypercall. +* HVCALL_NOTIFY_LONG_SPIN_WAIT hypercall. */ res->b = viridian_spinlock_retry_count;break ;
@@ -583,7 +568,7 @@ int viridian_hypercall(struct cpu_user_regs *regs)switch ( input.call_code ) { -case HvNotifyLongSpinWait: +case HVCALL_NOTIFY_LONG_SPIN_WAIT :/* * See section 14.5.1 of the specification. */
@@ -591,8 +576,8 @@ int viridian_hypercall(struct cpu_user_regs *regs) status =HV_STATUS_SUCCESS ;break ; -case HvFlushVirtualAddressSpace: -case HvFlushVirtualAddressList: +case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE : +case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST : {struct {uint64_t address_space;
@@ -632,7 +617,7 @@ int viridian_hypercall(struct cpu_user_regs *regs)break ; } -case HvSendSyntheticClusterIpi: +case HVCALL_SEND_IPI : {struct vcpu *v;uint32_t vector;
@@ -695,7 +680,7 @@ int viridian_hypercall(struct cpu_user_regs *regs)gprintk (XENLOG_WARNING ,"unimplemented hypercall %04x\n" , input.call_code);/* Fallthrough. */ -case HvExtCallQueryCapabilities: +case HVCALL_EXT_CALL_QUERY_CAPABILITIES :/* * This hypercall seems to be erroneously issued by Windows * despite EnableExtendedHypercalls not being set in CPUID leaf 2.
xen/include/asm-x86/guest/hyperv-tlfs.h +1 -0
@@ -374,6 +374,7 @@ struct hv_tsc_emulation_status {#define HVCALL_SIGNAL_EVENT 0x005d#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0 +#define HVCALL_EXT_CALL_QUERY_CAPABILITIES 0x8001#define HV_X64_MSR_VP_ASSIST_PAGE_ENABLE 0x00000001#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT 12
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/4 x86/viridian: drop private copy of HV_REFERENCE_TSC_PAGE in time.c
In reply to Wei LiuUse the one defined in hyperv-tlfs.h instead. No functional change intended.
--- xen/arch/x86/hvm/viridian/time.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
xen/arch/x86/hvm/viridian/time.c +6 -14
@@ -13,19 +13,11 @@#include <asm/apic.h> #include <asm/event.h> +#include <asm/guest/hyperv-tlfs.h> #include <asm/hvm/support.h> #include "private.h" -typedef struct _HV_REFERENCE_TSC_PAGE -{ -uint32_t TscSequence; -uint32_t Reserved1; -uint64_t TscScale; -int64_t TscOffset; -uint64_t Reserved2[509 ]; -}HV_REFERENCE_TSC_PAGE , *PHV_REFERENCE_TSC_PAGE ; -static void update_reference_tsc (const struct domain *d,bool initialize) {struct viridian_domain *vd = d->arch.hvm.viridian;
@@ -61,7 +53,7 @@ static void update_reference_tsc(const struct domain *d, bool initialize)* violate the spec. and rely on a value of 0 to indicate that this * enlightenment should no longer be used. */ - p->TscSequence =0 ; + p->tsc_sequence =0 ;printk (XENLOG_G_INFO "d%d: VIRIDIAN REFERENCE_TSC: invalidated\n" , d->domain_id);
@@ -79,15 +71,15 @@ static void update_reference_tsc(const struct domain *d, bool initialize)* The offset value is calculated on restore after migration and * ensures that Windows will not see a large jump in ReferenceTime. */ - p->TscScale = ((10000ul <<32 ) / d->arch.tsc_khz) <<32 ; - p->TscOffset = trc->off; + p->tsc_scale = ((10000ul <<32 ) / d->arch.tsc_khz) <<32 ; + p->tsc_offset = trc->off;smp_wmb (); - seq = p->TscSequence +1 ; + seq = p->tsc_sequence +1 ;if ( seq ==0xFFFFFFFF || seq ==0 )/* Avoid both 'invalid' values */ seq =1 ; - p->TscSequence = seq; + p->tsc_sequence = seq; }/*
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/4 x86: provide and use hv_tsc_scale
In reply to Wei LiuThe 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.
--- xen/arch/x86/hvm/viridian/time.c | 30 ++-------------------------- xen/arch/x86/time.c | 7 +------ xen/include/asm-x86/guest/hyperv.h | 32 ++++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 36 deletions(-)
xen/arch/x86/hvm/viridian/time.c +2 -28
@@ -13,6 +13,7 @@#include <asm/apic.h> #include <asm/event.h> +#include <asm/guest/hyperv.h> #include <asm/guest/hyperv-tlfs.h> #include <asm/hvm/support.h>
@@ -82,33 +83,6 @@ static void update_reference_tsc(const struct domain *d, bool initialize) p->tsc_sequence = seq; } -/* -* The specification says: "The partition reference time is computed -* by the following formula: -* -* ReferenceTime = ((VirtualTsc * TscScale) >> 64) + TscOffset -* -* The multiplication is a 64 bit multiplication, which results in a -* 128 bit number which is then shifted 64 times to the right to obtain -* the high 64 bits." -*/ -static uint64_t scale_tsc (uint64_t tsc,uint64_t scale,int64_t offset) -{ -uint64_t result; - -/* -* Quadword MUL takes an implicit operand in RAX, and puts the result -* in RDX:RAX. Because we only want the result of the multiplication -* after shifting right by 64 bits, we therefore only need the content -* of RDX. -*/ - asm ("mulq %[scale]" - :"+a" (tsc),"=d" (result) - : [scale]"rm" (scale) ); - -return result + offset; -} -static uint64_t trc_val (const struct domain *d,int64_t offset) {uint64_t tsc, scale;
@@ -116,7 +90,7 @@ static uint64_t trc_val(const struct domain *d, int64_t offset) tsc =hvm_get_guest_tsc (pt_global_vcpu_target (d)); scale = ((10000ul <<32 ) / d->arch.tsc_khz) <<32 ; -return scale_tsc (tsc, scale, offset); +return hv_scale_tsc (tsc, scale, offset); }static void time_ref_count_freeze (const struct domain *d)
xen/arch/x86/time.c +1 -6
@@ -725,12 +725,7 @@ static inline uint64_t read_hyperv_timer(void) }while ( tsc_page->tsc_sequence != seq ); -/* ret = ((tsc * scale) >> 64) + offset; */ - asm ("mul %[scale]; add %[offset], %[ret]" - :"+a" (tsc), [ret]"=&d" (ret) - : [scale]"rm" (scale), [offset]"rm" (offset) ); - -return ret; +return hv_scale_tsc (tsc, scale, offset); } static struct platform_timesource __initdata plt_hyperv_timer =
xen/include/asm-x86/guest/hyperv.h +30 -2
@@ -19,10 +19,38 @@#ifndef __X86_GUEST_HYPERV_H__#define __X86_GUEST_HYPERV_H__ -#ifdef CONFIG_HYPERV_GUEST -#include <xen/types.h> +/* +* The specification says: "The partition reference time is computed +* by the following formula: +* +* ReferenceTime = ((VirtualTsc * TscScale) >> 64) + TscOffset +* +* The multiplication is a 64 bit multiplication, which results in a +* 128 bit number which is then shifted 64 times to the right to obtain +* the high 64 bits." +*/ +static inline uint64_t hv_scale_tsc (uint64_t tsc,uint64_t scale, +int64_t offset) +{ +uint64_t result; + +/* +* Quadword MUL takes an implicit operand in RAX, and puts the result +* in RDX:RAX. Because we only want the result of the multiplication +* after shifting right by 64 bits, we therefore only need the content +* of RDX. +*/ + asm ("mulq %[scale]" + :"+a" (tsc),"=d" (result) + : [scale]"rm" (scale) ); + +return result + offset; +} + +#ifdef CONFIG_HYPERV_GUEST +#include <asm/guest/hypervisor.h> struct ms_hyperv_info {
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/4 x86: move viridian_guest_os_id_msr to hyperv-tlfs.h
In reply to Wei Liu--- xen/arch/x86/hvm/viridian/viridian.c | 2 +- xen/include/asm-x86/guest/hyperv-tlfs.h | 13 +++++++++++++ xen/include/asm-x86/hvm/viridian.h | 18 +++--------------- 3 files changed, 17 insertions(+), 16 deletions(-)
xen/arch/x86/hvm/viridian/viridian.c +1 -1
@@ -218,7 +218,7 @@ void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,static void dump_guest_os_id (const struct domain *d) { -const union viridian_guest_os_id_msr *goi; +const union hv_guest_os_id *goi; goi = &d->arch.hvm.viridian->guest_os_id;
xen/include/asm-x86/guest/hyperv-tlfs.h +13 -0
@@ -327,6 +327,19 @@ struct ms_hyperv_tsc_page {*/ #define HV_LINUX_VENDOR_ID 0x8100 +union hv_guest_os_id +{ +uint64_t raw; +struct + { +uint64_t build_number:16 ; +uint64_t service_pack:8 ; +uint64_t minor:8 ; +uint64_t major:8 ; +uint64_t os:8 ; +uint64_t vendor:16 ; + }; +};struct hv_reenlightenment_control {__u64 vector:8 ;
xen/include/asm-x86/hvm/viridian.h +3 -15
@@ -9,6 +9,8 @@ #ifndef __ASM_X86_HVM_VIRIDIAN_H__ #define __ASM_X86_HVM_VIRIDIAN_H__ +#include <asm/guest/hyperv-tlfs.h> + union viridian_page_msr { uint64_t raw;
@@ -83,20 +85,6 @@ struct viridian_vcpuuint64_t crash_param[5 ]; }; -union viridian_guest_os_id_msr -{ -uint64_t raw; -struct - { -uint64_t build_number:16 ; -uint64_t service_pack:8 ; -uint64_t minor:8 ; -uint64_t major:8 ; -uint64_t os:8 ; -uint64_t vendor:16 ; - }; -}; -struct viridian_time_ref_count {unsigned long flags;
@@ -112,7 +100,7 @@ struct viridian_time_ref_countstruct viridian_domain { -union viridian_guest_os_id_msr guest_os_id; +union hv_guest_os_id guest_os_id;union viridian_page_msr hypercall_gpa;struct viridian_time_ref_count time_ref_count;struct viridian_page reference_tsc;
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
[Xen-devel] [PATCH 5/4] x86/viridian: drop a wrong invalid value from reference TSC implementation
In reply to Wei LiuThe 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
--- xen/arch/x86/hvm/viridian/time.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
xen/arch/x86/hvm/viridian/time.c +4 -9
@@ -45,14 +45,9 @@ static void update_reference_tsc(const struct domain *d, bool initialize)if ( !host_tsc_is_safe () || d->arch.vtsc ) {/* -* The specification states that valid values of TscSequence range -* from 0 to 0xFFFFFFFE. The value 0xFFFFFFFF is used to indicate -* this mechanism is no longer a reliable source of time and that -* the VM should fall back to a different source. -* -* Server 2012 (6.2 kernel) and 2012 R2 (6.3 kernel) actually -* violate the spec. and rely on a value of 0 to indicate that this -* enlightenment should no longer be used. +* The value 0 is used to indicate this mechanism is no longer a +* reliable source of time and that the VM should fall back to a +* different source. */ p->tsc_sequence =0 ;
@@ -77,7 +72,7 @@ static void update_reference_tsc(const struct domain *d, bool initialize)smp_wmb (); seq = p->tsc_sequence +1 ; -if ( seq ==0xFFFFFFFF || seq ==0 )/* Avoid both 'invalid' values */ +if ( seq ==0 )/* Avoid 'invalid' value */ seq =1 ; p->tsc_sequence = seq;
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 5/4] x86/viridian: drop a wrong invalid value from reference TSC implementation
Quoted 58 lines
-----Original Message-----
From: Wei Liu <[email protected]> On Behalf Of Wei Liu
Sent: 20 December 2019 21:21
To: Xen Development List <[email protected]>
Cc: Durrant, Paul <[email protected]>; Michael Kelley <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [PATCH 5/4] x86/viridian: drop a wrong invalid value from reference TSC implementationThe only invalid value mentioned in Hyper-V TLFS 5.0c is 0. Michael Kelley confirmed that
0xFFFFFFFFwas never used [0].[0] https://lists.xen.org/archives/html/xen-devel/2019-12/msg01564.html
Signed-off-by Wei Liu <[email protected]>--- xen/arch/x86/hvm/viridian/time.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)xen/arch/x86/hvm/viridian/time.c +0
-1@@ -45,14 +45,9 @@ static void update_reference_tsc(const struct domain *d, bool initialize)if ( !host_tsc_is_safe () || d->arch.vtsc ) {/* -* The specification states that valid values of TscSequence range
xen/arch/x86/hvm/viridian/time.c +0
-6-* from 0 to 0xFFFFFFFE. The value 0xFFFFFFFF is used to indicate -* this mechanism is no longer a reliable source of time and that -* the VM should fall back to a different source. -* -* Server 2012 (6.2 kernel) and 2012 R2 (6.3 kernel) actually -* violate the spec. and rely on a value of 0 to indicate that this
xen/arch/x86/hvm/viridian/time.c +4
-2-* enlightenment should no longer be used. +* The value 0 is used to indicate this mechanism is no longer a +* reliable source of time and that the VM should fall back to a +* different source. */ p->tsc_sequence =0 ;@@ -77,7 +72,7 @@ static void update_reference_tsc(const struct domain *d,bool initialize) smp_wmb(); seq = p->tsc_sequence + 1; -if ( seq ==0xFFFFFFFF || seq ==0 )/* Avoid both 'invalid' values */ +if ( seq ==0 )/* Avoid 'invalid' value */ seq =1 ;
Quoted 1 line
p->tsc_sequence = seq;
Now that we're just dealing with 0, I think the code would be neater as:
seq = p->tsc_sequence + 1;p->tsc_sequence = seq ? seq : 1; /* Avoid 'invalid' value 0 */
Paul
Quoted 2 lines
--
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/4] x86/viridian: drop duplicate defines from private.h and viridian.c
In reply to Wei LiuQuoted 12 lines
-----Original Message-----
From: Wei Liu <[email protected]> On Behalf Of Wei Liu
Sent: 20 December 2019 19:52
To: Xen Development List <[email protected]>
Cc: Michael Kelley <[email protected]>; Durrant, Paul <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [PATCH 1/4] x86/viridian: drop duplicate defines fromprivate.handviridian.c
Quoted 6 lines
Also add
HVCALL_EXT_CALL_QUERY_CAPABILITIEStohyperv-tlfs.h. HvGetPartitionID was never used in code so just dropped it.No functional change intended.
Signed-off-by Wei Liu <[email protected]>
Quoted 184 lines
--- xen/arch/x86/hvm/viridian/private.h | 66 ------------------------- xen/arch/x86/hvm/viridian/viridian.c | 29 +++-------- xen/include/asm-x86/guest/hyperv-tlfs.h | 1 + 3 files changed, 8 insertions(+), 88 deletions(-)xen/arch/x86/hvm/viridian/private.h +0
-66@@ -5,72 +5,6 @@#include <asm/hvm/save.h> -/* Viridian MSR numbers. */ -#define HV_X64_MSR_GUEST_OS_ID 0x40000000 -#define HV_X64_MSR_HYPERCALL 0x40000001 -#define HV_X64_MSR_VP_INDEX 0x40000002 -#define HV_X64_MSR_RESET 0x40000003 -#define HV_X64_MSR_VP_RUNTIME 0x40000010 -#define HV_X64_MSR_TIME_REF_COUNT 0x40000020 -#define HV_X64_MSR_REFERENCE_TSC 0x40000021 -#define HV_X64_MSR_TSC_FREQUENCY 0x40000022 -#define HV_X64_MSR_APIC_FREQUENCY 0x40000023 -#define HV_X64_MSR_EOI 0x40000070 -#define HV_X64_MSR_ICR 0x40000071 -#define HV_X64_MSR_TPR 0x40000072 -#define HV_X64_MSR_VP_ASSIST_PAGE 0x40000073 -#define HV_X64_MSR_SCONTROL 0x40000080 -#define HV_X64_MSR_SVERSION 0x40000081 -#define HV_X64_MSR_SIEFP 0x40000082 -#define HV_X64_MSR_SIMP 0x40000083 -#define HV_X64_MSR_EOM 0x40000084 -#define HV_X64_MSR_SINT0 0x40000090 -#define HV_X64_MSR_SINT1 0x40000091 -#define HV_X64_MSR_SINT2 0x40000092 -#define HV_X64_MSR_SINT3 0x40000093 -#define HV_X64_MSR_SINT4 0x40000094 -#define HV_X64_MSR_SINT5 0x40000095 -#define HV_X64_MSR_SINT6 0x40000096 -#define HV_X64_MSR_SINT7 0x40000097 -#define HV_X64_MSR_SINT8 0x40000098 -#define HV_X64_MSR_SINT9 0x40000099 -#define HV_X64_MSR_SINT10 0x4000009A -#define HV_X64_MSR_SINT11 0x4000009B -#define HV_X64_MSR_SINT12 0x4000009C -#define HV_X64_MSR_SINT13 0x4000009D -#define HV_X64_MSR_SINT14 0x4000009E -#define HV_X64_MSR_SINT15 0x4000009F -#define HV_X64_MSR_STIMER0_CONFIG 0x400000B0 -#define HV_X64_MSR_STIMER0_COUNT 0x400000B1 -#define HV_X64_MSR_STIMER1_CONFIG 0x400000B2 -#define HV_X64_MSR_STIMER1_COUNT 0x400000B3 -#define HV_X64_MSR_STIMER2_CONFIG 0x400000B4 -#define HV_X64_MSR_STIMER2_COUNT 0x400000B5 -#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6 -#define HV_X64_MSR_STIMER3_COUNT 0x400000B7 -#define HV_X64_MSR_POWER_STATE_TRIGGER_C1 0x400000C1 -#define HV_X64_MSR_POWER_STATE_TRIGGER_C2 0x400000C2 -#define HV_X64_MSR_POWER_STATE_TRIGGER_C3 0x400000C3 -#define HV_X64_MSR_POWER_STATE_CONFIG_C1 0x400000D1 -#define HV_X64_MSR_POWER_STATE_CONFIG_C2 0x400000D2 -#define HV_X64_MSR_POWER_STATE_CONFIG_C3 0x400000D3 -#define HV_X64_MSR_STATS_PARTITION_RETAIL_PAGE 0x400000E0 -#define HV_X64_MSR_STATS_PARTITION_INTERNAL_PAGE 0x400000E1 -#define HV_X64_MSR_STATS_VP_RETAIL_PAGE 0x400000E2 -#define HV_X64_MSR_STATS_VP_INTERNAL_PAGE 0x400000E3 -#define HV_X64_MSR_GUEST_IDLE 0x400000F0 -#define HV_X64_MSR_SYNTH_DEBUG_CONTROL 0x400000F1 -#define HV_X64_MSR_SYNTH_DEBUG_STATUS 0x400000F2 -#define HV_X64_MSR_SYNTH_DEBUG_SEND_BUFFER 0x400000F3 -#define HV_X64_MSR_SYNTH_DEBUG_RECEIVE_BUFFER 0x400000F4 -#define HV_X64_MSR_SYNTH_DEBUG_PENDING_BUFFER 0x400000F5 -#define HV_X64_MSR_CRASH_P0 0x40000100 -#define HV_X64_MSR_CRASH_P1 0x40000101 -#define HV_X64_MSR_CRASH_P2 0x40000102 -#define HV_X64_MSR_CRASH_P3 0x40000103 -#define HV_X64_MSR_CRASH_P4 0x40000104 -#define HV_X64_MSR_CRASH_CTL 0x40000105 -int viridian_synic_wrmsr (struct vcpu *v,uint32_t idx,uint64_t val);int viridian_synic_rdmsr (const struct vcpu *v,uint32_t idx,uint64_t *val);xen/arch/x86/hvm/viridian/viridian.c +2
-17@@ -10,6 +10,7 @@#include <xen/hypercall.h> #include <xen/domain_page.h> #include <asm/guest_access.h> +#include <asm/guest/hyperv-tlfs.h> #include <asm/paging.h> #include <asm/p2m.h> #include <asm/apic.h> @@ -19,22 +20,6 @@#include "private.h" -/* Viridian Hypercall Status Codes. */ -#define HV_STATUS_SUCCESS 0x0000 -#define HV_STATUS_INVALID_HYPERCALL_CODE 0x0002 -#define HV_STATUS_INVALID_PARAMETER 0x0005 - -/* Viridian Hypercall Codes. */ -#define HvFlushVirtualAddressSpace 0x0002 -#define HvFlushVirtualAddressList 0x0003 -#define HvNotifyLongSpinWait 0x0008 -#define HvSendSyntheticClusterIpi 0x000b -#define HvGetPartitionId 0x0046 -#define HvExtCallQueryCapabilities 0x8001 - -/* Viridian Hypercall Flags. */ -#define HV_FLUSH_ALL_PROCESSORS 1 -/* Viridian Partition Privilege Flags */ typedef struct { /* Access to virtual MSRs */@@ -214,7 +199,7 @@ void cpuid_viridian_leaves(const struct vcpu *v,uint32_t leaf,/* * This value is the recommended number of attempts to try to * acquire a spinlock before notifying the hypervisor via the -* HvNotifyLongSpinWait hypercall. +* HVCALL_NOTIFY_LONG_SPIN_WAIT hypercall. */ res->b = viridian_spinlock_retry_count;break;xen/arch/x86/hvm/viridian/viridian.c +5
-5@@ -583,7 +568,7 @@ int viridian_hypercall(struct cpu_user_regs *regs)switch ( input.call_code ) { -case HvNotifyLongSpinWait: +case HVCALL_NOTIFY_LONG_SPIN_WAIT :/* * See section 14.5.1 of the specification. */ @@ -591,8 +576,8 @@ int viridian_hypercall(struct cpu_user_regs *regs) status =HV_STATUS_SUCCESS ;break ; -case HvFlushVirtualAddressSpace: -case HvFlushVirtualAddressList: +case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE : +case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST : {struct {uint64_t address_space;@@ -632,7 +617,7 @@ int viridian_hypercall(struct cpu_user_regs *regs)break ; } -case HvSendSyntheticClusterIpi: +case HVCALL_SEND_IPI : {struct vcpu *v;uint32_t vector;@@ -695,7 +680,7 @@ int viridian_hypercall(struct cpu_user_regs *regs)gprintk (XENLOG_WARNING ,"unimplemented hypercall %04x\n" , input.call_code);/* Fallthrough. */ -case HvExtCallQueryCapabilities: +case HVCALL_EXT_CALL_QUERY_CAPABILITIES :/* * This hypercall seems to be erroneously issued by Windows * despite EnableExtendedHypercalls not being set in CPUID leaf 2.
xen/include/asm- renamed from xen/include/asm-x86/guest/hyperv-tlfs.h +0
-0
x86/guest/hyperv-tlfs.h
indexccd9850b27..b128807b2c100644xen/include/asm-x86/guest/hyperv-tlfs.h +1
-1@@ -374,6 +374,7 @@ struct hv_tsc_emulation_status {#define HVCALL_SIGNAL_EVENT 0x005d#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0 +#define HVCALL_EXT_CALL_QUERY_CAPABILITIES 0x8001#define HV_X64_MSR_VP_ASSIST_PAGE_ENABLE 0x00000001#define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT 12 --
Quoted 1 line
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/4] x86/viridian: drop private copy of HV_REFERENCE_TSC_PAGE in time.c
In reply to Wei LiuQuoted 12 lines
-----Original Message-----
From: Wei Liu <[email protected]> On Behalf Of Wei Liu
Sent: 20 December 2019 19:52
To: Xen Development List <[email protected]>
Cc: Michael Kelley <[email protected]>; Durrant, Paul <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [PATCH 2/4] x86/viridian: drop private copy ofHV_REFERENCE_TSC_PAGEintime.c
Quoted 4 lines
Use the one defined in
hyperv-tlfs.hinstead. No functional change intended.Signed-off-by Wei Liu <[email protected]>
Quoted 63 lines
--- xen/arch/x86/hvm/viridian/time.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)xen/arch/x86/hvm/viridian/time.c +1
-9@@ -13,19 +13,11 @@#include <asm/apic.h> #include <asm/event.h> +#include <asm/guest/hyperv-tlfs.h> #include <asm/hvm/support.h> #include "private.h" -typedef struct _HV_REFERENCE_TSC_PAGE -{ -uint32_t TscSequence; -uint32_t Reserved1; -uint64_t TscScale; -int64_t TscOffset; -uint64_t Reserved2[509 ]; -}HV_REFERENCE_TSC_PAGE , *PHV_REFERENCE_TSC_PAGE ; -static void update_reference_tsc (const struct domain *d,bool initialize) {struct viridian_domain *vd = d->arch.hvm.viridian;@@ -61,7 +53,7 @@ static void update_reference_tsc(const struct domain *d, bool initialize) * violate the spec. and rely on a value of 0 to indicate thatthis
* enlightenment should no longer be used. */xen/arch/x86/hvm/viridian/time.c +1
-1- p->TscSequence =0 ; + p->tsc_sequence =0 ; printk(XENLOG_G_INFO "d%d: VIRIDIAN REFERENCE_TSC:invalidated\n",
d->domain_id);xen/arch/x86/hvm/viridian/time.c +4
-4@@ -79,15 +71,15 @@ static void update_reference_tsc(const struct domain*d, bool initialize) * The offset value is calculated on restore after migration and * ensures that Windows will not see a large jump in ReferenceTime. */ - p->TscScale = ((10000ul <<32 ) / d->arch.tsc_khz) <<32 ; - p->TscOffset = trc->off; + p->tsc_scale = ((10000ul <<32 ) / d->arch.tsc_khz) <<32 ; + p->tsc_offset = trc->off;smp_wmb (); - seq = p->TscSequence +1 ; + seq = p->tsc_sequence +1 ;if ( seq ==0xFFFFFFFF || seq ==0 )/* Avoid both 'invalid' values */ seq =1 ; - p->TscSequence = seq; + p->tsc_sequence = seq; }
Quoted 3 lines
/*
--
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 3/4] x86: provide and use hv_tsc_scale
In reply to Wei LiuQuoted 14 lines
-----Original Message-----
From: Wei Liu <[email protected]> On Behalf Of Wei Liu
Sent: 20 December 2019 19:52
To: Xen Development List <[email protected]>
Cc: Michael Kelley <[email protected]>; Durrant, Paul <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [PATCH 3/4] x86: provide and usehv_tsc_scaleThe Hyper-V clock source and Xen's own viridian code need the same functionality.
Quoted 6 lines
Move the function in
viridian/time.ctohyperv.hand use it in both places.No functional change.
Signed-off-by Wei Liu <[email protected]>
Quoted 131 lines
--- xen/arch/x86/hvm/viridian/time.c | 30 ++-------------------------- xen/arch/x86/time.c | 7 +------ xen/include/asm-x86/guest/hyperv.h | 32 ++++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 36 deletions(-)xen/arch/x86/hvm/viridian/time.c +1
-18@@ -13,6 +13,7 @@#include <asm/apic.h> #include <asm/event.h> +#include <asm/guest/hyperv.h> #include <asm/guest/hyperv-tlfs.h> #include <asm/hvm/support.h> @@ -82,33 +83,6 @@ static void update_reference_tsc(const struct domain *d, bool initialize) p->tsc_sequence = seq; } -/* -* The specification says: "The partition reference time is computed -* by the following formula: -* -* ReferenceTime = ((VirtualTsc * TscScale) >> 64) + TscOffset -* -* The multiplication is a 64 bit multiplication, which results in a -* 128 bit number which is then shifted 64 times to the right to obtain -* the high 64 bits." -*/ -static uint64_t scale_tsc (uint64_t tsc,uint64_t scale,int64_t offset) -{ -uint64_t result; - -/* -* Quadword MUL takes an implicit operand in RAX, and puts the result -* in RDX:RAX. Because we only want the result of the multiplication -* after shifting right by 64 bits, we therefore only need the content
xen/arch/x86/hvm/viridian/time.c +1
-10-* of RDX. -*/ - asm ("mulq %[scale]" - :"+a" (tsc),"=d" (result) - : [scale]"rm" (scale) ); - -return result + offset; -} -static uint64_t trc_val (const struct domain *d,int64_t offset) {uint64_t tsc, scale;@@ -116,7 +90,7 @@ static uint64_t trc_val(const struct domain *d, int64_t offset) tsc =hvm_get_guest_tsc (pt_global_vcpu_target (d)); scale = ((10000ul <<32 ) / d->arch.tsc_khz) <<32 ; -return scale_tsc (tsc, scale, offset); +return hv_scale_tsc (tsc, scale, offset); }static void
time_ref_count_freeze(const struct domain *d)xen/arch/x86/time.c +1
-6@@ -725,12 +725,7 @@ static inline uint64_t read_hyperv_timer(void) }while ( tsc_page->tsc_sequence != seq ); -/* ret = ((tsc * scale) >> 64) + offset; */ - asm ("mul %[scale]; add %[offset], %[ret]" - :"+a" (tsc), [ret]"=&d" (ret) - : [scale]"rm" (scale), [offset]"rm" (offset) ); - -return ret; +return hv_scale_tsc (tsc, scale, offset); } static struct platform_timesource __initdata plt_hyperv_timer =xen/include/asm- renamed from xen/include/asm-x86/guest/hyperv.h +0
-0
x86/guest/hyperv.h
indexcc21b9abfc..c7a7f32bd5100644xen/include/asm-x86/guest/hyperv.h +19
-2@@ -19,10 +19,38 @@#ifndef __X86_GUEST_HYPERV_H__#define __X86_GUEST_HYPERV_H__ -#ifdef CONFIG_HYPERV_GUEST -#include <xen/types.h> +/* +* The specification says: "The partition reference time is computed +* by the following formula: +* +* ReferenceTime = ((VirtualTsc * TscScale) >> 64) + TscOffset +* +* The multiplication is a 64 bit multiplication, which results in a +* 128 bit number which is then shifted 64 times to the right to obtain +* the high 64 bits." +*/ +static inline uint64_t hv_scale_tsc (uint64_t tsc,uint64_t scale, +int64_t offset) +{ +uint64_t result; + +/* +* Quadword MUL takes an implicit operand in RAX, and puts the result +* in RDX:RAX. Because we only want the result of the multiplication +* after shifting right by 64 bits, we therefore only need the content
xen/include/asm-x86/guest/hyperv.h +11
-1+* of RDX. +*/ + asm ("mulq %[scale]" + :"+a" (tsc),"=d" (result) + : [scale]"rm" (scale) ); + +return result + offset; +} + +#ifdef CONFIG_HYPERV_GUEST +#include <asm/guest/hypervisor.h> struct ms_hyperv_info { --
Quoted 1 line
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 4/4] x86: move viridian_guest_os_id_msr to hyperv-tlfs.h
In reply to Wei LiuQuoted 11 lines
-----Original Message-----
From: Wei Liu <[email protected]> On Behalf Of Wei Liu
Sent: 20 December 2019 19:52
To: Xen Development List <[email protected]>
Cc: Michael Kelley <[email protected]>; Durrant, Paul <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>
Subject: [PATCH 4/4] x86: moveviridian_guest_os_id_msrtohyperv-tlfs.h
Quoted 2 lines
Suggested-by Paul Durrant <[email protected]>Signed-off-by Wei Liu <[email protected]>
Quoted 91 lines
--- xen/arch/x86/hvm/viridian/viridian.c | 2 +- xen/include/asm-x86/guest/hyperv-tlfs.h | 13 +++++++++++++ xen/include/asm-x86/hvm/viridian.h | 18 +++--------------- 3 files changed, 17 insertions(+), 16 deletions(-)xen/arch/x86/hvm/viridian/viridian.c +1
-1@@ -218,7 +218,7 @@ void cpuid_viridian_leaves(const struct vcpu *v,uint32_t leaf, static void dump_guest_os_id(const struct domain *d) { - const union viridian_guest_os_id_msr *goi; + const union hv_guest_os_id *goi; goi = &d->arch.hvm.viridian->guest_os_id;xen/include/asm- renamed from xen/include/asm-x86/guest/hyperv-tlfs.h +0
-0
x86/guest/hyperv-tlfs.h
indexb128807b2c..4402854c80100644xen/include/asm-x86/guest/hyperv-tlfs.h +13
-0@@ -327,6 +327,19 @@ struct ms_hyperv_tsc_page {*/ #define HV_LINUX_VENDOR_ID 0x8100 +union hv_guest_os_id +{ +uint64_t raw; +struct + { +uint64_t build_number:16 ; +uint64_t service_pack:8 ; +uint64_t minor:8 ; +uint64_t major:8 ; +uint64_t os:8 ; +uint64_t vendor:16 ; + }; +};struct hv_reenlightenment_control {__u64 vector:8 ;xen/include/asm- renamed from xen/include/asm-x86/hvm/viridian.h +0
-0
x86/hvm/viridian.h
index010c8b58d4..cfbaede158100644xen/include/asm-x86/hvm/viridian.h +3
-16@@ -9,6 +9,8 @@ #ifndef __ASM_X86_HVM_VIRIDIAN_H__ #define __ASM_X86_HVM_VIRIDIAN_H__ +#include <asm/guest/hyperv-tlfs.h> + union viridian_page_msr { uint64_t raw;@@ -83,20 +85,6 @@ struct viridian_vcpuuint64_t crash_param[5 ]; }; -union viridian_guest_os_id_msr -{ -uint64_t raw; -struct - { -uint64_t build_number:16 ; -uint64_t service_pack:8 ; -uint64_t minor:8 ; -uint64_t major:8 ; -uint64_t os:8 ; -uint64_t vendor:16 ; - }; -}; -struct viridian_time_ref_count {unsigned long flags;@@ -112,7 +100,7 @@ struct viridian_time_ref_countstruct viridian_domain { -union viridian_guest_os_id_msr guest_os_id; +union hv_guest_os_id guest_os_id;union viridian_page_msr hypercall_gpa;struct viridian_time_ref_count time_ref_count;struct viridian_page reference_tsc; --
Quoted 1 line
2.20.1
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel