Add support for some HYPER-V PV features
Subsystems (4)
v2 cover Add support for some HYPER-V PV features
HYPER-V provides PV capabilities for its guests and most new MS Windows detect and use them automatically. Older Windows guests need additional drivers to uses PV. This patch series implements some PV capabilities defined by HYPER-V spec for KVM. Windows guests running on KVM will be able to take advantage of them.
Changelog:
v1->v2
rename kvm_hyperv.h into hyperv.h and move into separate patch minor style fixes
use clear_user-page(0 to zero userspace page
use APIC register names when calling kvm_hv_vapic_msr_(read|write)()
Gleb Natapov (4):
Add HYPE-V header file.
Implement bare minimum of HYPER-V MSRs.
Add HYPER-V apic access MSRs.
Implement NotifyLongSpinWait HYPER-V hypercall.
arch/x86/include/asm/hyperv.h | 187 ++++++++++++++++++++++++++++++++ arch/x86/include/asm/kvm_host.h | 6 + arch/x86/include/asm/kvm_para.h | 1 + arch/x86/kvm/lapic.c | 31 ++++++ arch/x86/kvm/lapic.h | 8 ++ arch/x86/kvm/trace.h | 32 ++++++ arch/x86/kvm/x86.c | 227 ++++++++++++++++++++++++++++++++++++++- include/linux/kvm.h | 3 + 8 files changed, 494 insertions(+), 1 deletions(-) create mode 100644 arch/x86/include/asm/hyperv.h
PATCH v2 1/4 Add HYPE-V header file.
--- arch/x86/include/asm/hyperv.h | 187 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 187 insertions(+), 0 deletions(-) create mode 100644 arch/x86/include/asm/hyperv.h
arch/x86/include/asm/hyperv.h new file +187 -0
@@ -0,0 +1,187 @@ +#ifndef _ASM_X86_KVM_HYPERV_H +#define _ASM_X86_KVM_HYPERV_H + +#include <linux/types.h> + +/* +* The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent +* is set by CPUID(HvCpuIdFunctionVersionAndFeatures). +*/ +#define HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS 0x40000000 +#define HYPERV_CPUID_INTERFACE 0x40000001 +#define HYPERV_CPUID_VERSION 0x40000002 +#define HYPERV_CPUID_FEATURES 0x40000003 +#define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004 +#define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005 + +/* +* Feature identification. EAX indicates which features are available +* to the partition based upon the current partition privileges. +*/ + +/* VP Runtime (HV_X64_MSR_VP_RUNTIME) available */ +#define HV_X64_MSR_VP_RUNTIME_AVAILABLE (1 << 0) +/* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/ +#define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE (1 << 1) +/* +* Basic SynIC MSRs (HV_X64_MSR_SCONTROL through HV_X64_MSR_EOM +* and HV_X64_MSR_SINT0 through HV_X64_MSR_SINT15) available +*/ +#define HV_X64_MSR_SYNIC_AVAILABLE (1 << 2) +/* +* Synthetic Timer MSRs (HV_X64_MSR_STIMER0_CONFIG through +* HV_X64_MSR_STIMER3_COUNT) available +*/ +#define HV_X64_MSR_SYNTIMER_AVAILABLE (1 << 3) +/* +* APIC access MSRs (HV_X64_MSR_EOI, HV_X64_MSR_ICR and HV_X64_MSR_TPR) +* are available +*/ +#define HV_X64_MSR_APIC_ACCESS_AVAILABLE (1 << 4) +/* Hypercall MSRs (HV_X64_MSR_GUEST_OS_ID and HV_X64_MSR_HYPERCALL) available*/ +#define HV_X64_MSR_HYPERCALL_AVAILABLE (1 << 5) +/* Access virtual processor index MSR (HV_X64_MSR_VP_INDEX) available*/ +#define HV_X64_MSR_VP_INDEX_AVAILABLE (1 << 6) +/* Virtual system reset MSR (HV_X64_MSR_RESET) is available*/ +#define HV_X64_MSR_RESET_AVAILABLE (1 << 7) +/* +* Access statistics pages MSRs (HV_X64_MSR_STATS_PARTITION_RETAIL_PAGE, +* HV_X64_MSR_STATS_PARTITION_INTERNAL_PAGE, HV_X64_MSR_STATS_VP_RETAIL_PAGE, +* HV_X64_MSR_STATS_VP_INTERNAL_PAGE) available +*/ +#define HV_X64_MSR_STAT_PAGES_AVAILABLE (1 << 8) + +/* +* Feature identification: EBX indicates which flags were specified at +* partition creation. The format is the same as the partition creation +* flag structure defined in section Partition Creation Flags. +*/ +#define HV_X64_CREATE_PARTITIONS (1 << 0) +#define HV_X64_ACCESS_PARTITION_ID (1 << 1) +#define HV_X64_ACCESS_MEMORY_POOL (1 << 2) +#define HV_X64_ADJUST_MESSAGE_BUFFERS (1 << 3) +#define HV_X64_POST_MESSAGES (1 << 4) +#define HV_X64_SIGNAL_EVENTS (1 << 5) +#define HV_X64_CREATE_PORT (1 << 6) +#define HV_X64_CONNECT_PORT (1 << 7) +#define HV_X64_ACCESS_STATS (1 << 8) +#define HV_X64_DEBUGGING (1 << 11) +#define HV_X64_CPU_POWER_MANAGEMENT (1 << 12) +#define HV_X64_CONFIGURE_PROFILER (1 << 13) + +/* +* Feature identification. EDX indicates which miscellaneous features +* are available to the partition. +*/ +/* The MWAIT instruction is available (per section MONITOR / MWAIT) */ +#define HV_X64_MWAIT_AVAILABLE (1 << 0) +/* Guest debugging support is available */ +#define HV_X64_GUEST_DEBUGGING_AVAILABLE (1 << 1) +/* Performance Monitor support is available*/ +#define HV_X64_PERF_MONITOR_AVAILABLE (1 << 2) +/* Support for physical CPU dynamic partitioning events is available*/ +#define HV_X64_CPU_DYNAMIC_PARTITIONING_AVAILABLE (1 << 3) +/* +* Support for passing hypercall input parameter block via XMM +* registers is available +*/ +#define HV_X64_HYPERCALL_PARAMS_XMM_AVAILABLE (1 << 4) +/* Support for a virtual guest idle state is available */ +#define HV_X64_GUEST_IDLE_STATE_AVAILABLE (1 << 5) + +/* +* Implementation recommendations. Indicates which behaviors the hypervisor +* recommends the OS implement for optimal performance. +*/ +/* +* Recommend using hypercall for address space switches rather +* than MOV to CR3 instruction +*/ +#define HV_X64_MWAIT_RECOMMENDED (1 << 0) +/* Recommend using hypercall for local TLB flushes rather +* than INVLPG or MOV to CR3 instructions */ +#define HV_X64_LOCAL_TLB_FLUSH_RECOMMENDED (1 << 1) +/* +* Recommend using hypercall for remote TLB flushes rather +* than inter-processor interrupts +*/ +#define HV_X64_REMOTE_TLB_FLUSH_RECOMMENDED (1 << 2) +/* +* Recommend using MSRs for accessing APIC registers +* EOI, ICR and TPR rather than their memory-mapped counterparts +*/ +#define HV_X64_APIC_ACCESS_RECOMMENDED (1 << 3) +/* Recommend using the hypervisor-provided MSR to initiate a system RESET */ +#define HV_X64_SYSTEM_RESET_RECOMMENDED (1 << 4) +/* +* Recommend using relaxed timing for this partition. If used, +* the VM should disable any watchdog timeouts that rely on the +* timely delivery of external interrupts +*/ +#define HV_X64_RELAXED_TIMING_RECOMMENDED (1 << 5) + +/* MSR used to identify the guest OS. */ +#define HV_X64_MSR_GUEST_OS_ID 0x40000000 + +/* MSR used to setup pages used to communicate with the hypervisor. */ +#define HV_X64_MSR_HYPERCALL 0x40000001 + +/* MSR used to provide vcpu index */ +#define HV_X64_MSR_VP_INDEX 0x40000002 + +/* Define the virtual APIC registers */ +#define HV_X64_MSR_EOI 0x40000070 +#define HV_X64_MSR_ICR 0x40000071 +#define HV_X64_MSR_TPR 0x40000072 +#define HV_X64_MSR_APIC_ASSIST_PAGE 0x40000073 + +/* Define synthetic interrupt controller model specific registers. */ +#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_HYPERCALL_ENABLE 0x00000001 +#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12 +#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK \ + (~((1ull << HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT) - 1)) + +/* Declare the various hypercall operations. */ +#define HV_X64_HV_NOTIFY_LONG_SPIN_WAIT 0x0008 + +#define HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE 0x00000001 +#define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT 12 +#define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_MASK \ + (~((1ull << HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT) - 1)) + +#define HV_PROCESSOR_POWER_STATE_C0 0 +#define HV_PROCESSOR_POWER_STATE_C1 1 +#define HV_PROCESSOR_POWER_STATE_C2 2 +#define HV_PROCESSOR_POWER_STATE_C3 3 + +/* hypercall status code */ +#define HV_STATUS_SUCCESS 0 +#define HV_STATUS_INVALID_HYPERCALL_CODE 2 +#define HV_STATUS_INVALID_HYPERCALL_INPUT 3 +#define HV_STATUS_INVALID_ALIGNMENT 4 + +#endif +
Signature · 1 line
1.6.5
PATCH v2 2/4 Implement bare minimum of HYPER-V MSRs.
In reply to Gleb NatapovMinimum HYPER-V implementation should have GUEST_OS_ID, HYPERCALL and VP_INDEX MSRs.
--- arch/x86/include/asm/kvm_host.h | 4 + arch/x86/include/asm/kvm_para.h | 1 + arch/x86/kvm/trace.h | 32 +++++++ arch/x86/kvm/x86.c | 184 ++++++++++++++++++++++++++++++++++++++- include/linux/kvm.h | 1 + 5 files changed, 221 insertions(+), 1 deletions(-)
arch/x86/include/asm/kvm_host.h +4 -0
@@ -413,6 +413,10 @@ struct kvm_arch {s64 kvmclock_offset;struct kvm_xen_hvm_config xen_hvm_config; + +/* fields used by HYPER-V emulation */ +u64 hv_guest_os_id; +u64 hv_hypercall; };struct kvm_vm_stat {
arch/x86/include/asm/kvm_para.h +1 -0
@@ -2,6 +2,7 @@#define _ASM_X86_KVM_PARA_H#include <linux/types.h> +#include <asm/hyperv.h> /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It * should be used to determine that a VM is running under KVM.
arch/x86/kvm/trace.h +32 -0
@@ -56,6 +56,38 @@ TRACE_EVENT(kvm_hypercall, );/* +* Tracepoint for hypercall. +*/ +TRACE_EVENT (kvm_hv_hypercall, + TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx, + __u64 ingpa, __u64 outgpa), +TP_ARGS (code, fast, rep_cnt, rep_idx, ingpa, outgpa), + +TP_STRUCT__entry ( + __field( __u16, code ) + __field( bool, fast ) + __field( __u16, rep_cnt ) + __field( __u16, rep_idx ) + __field( __u64, ingpa ) +__field ( __u64, outgpa ) + ), + +TP_fast_assign ( + __entry->code = code; + __entry->fast = fast; + __entry->rep_cnt = rep_cnt; + __entry->rep_idx = rep_idx; + __entry->ingpa = ingpa; + __entry->outgpa = outgpa; + ), + +TP_printk ("code 0x%x %s cnt 0x%x idx 0x%x in 0x%llx out 0x%llx" , + __entry->code, __entry->fast ?"fast" :"slow" , + __entry->rep_cnt, __entry->rep_idx, __entry->ingpa, + __entry->outgpa) +); + +/* * Tracepoint for PIO. */ TRACE_EVENT(kvm_pio,
arch/x86/kvm/x86.c +183 -1
231 lines not on this page · raw message
include/linux/kvm.h +1 -0
@@ -497,6 +497,7 @@ struct kvm_ioeventfd {#endif #define KVM_CAP_S390_PSW 42#define KVM_CAP_PPC_SEGSTATE 43 +#define KVM_CAP_HYPERV 44#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
1.6.5
Re: [PATCHv2 2/4] Implement bare minimum of HYPER-V MSRs.
Quoted 10 lines · Gleb Natapov
Minimum HYPER-V implementation should have
GUEST_OS_ID, HYPERCALL andVP_INDEXMSRs.TRACE_EVENT(kvm_pio,
arch/x86/kvm/x86.c +0
-0
arch/x86/kvm/x86.c static u32 msrs_to_save[] = { · line 636
Quoted 8 lines
arch/x86/kvm/x86.c +2
-1@@ -630,7 +630,8 @@ static u32 msrs_to_save[] = {#ifdef CONFIG_X86_64 MSR_CSTAR ,MSR_KERNEL_GS_BASE ,MSR_SYSCALL_MASK ,MSR_LSTAR , #endif -MSR_IA32_TSC ,MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA +MSR_IA32_TSC ,MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA , + HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL, };
These will be disabled since the msrs don't exist on the host. See the comment above and KVM_SAVE_MSRS_BEGIN.
Quoted 5 lines
arch/x86/kvm/x86.c +4
-0+case HV_X64_MSR_HYPERCALL : { +u64 gfn; +unsigned long addr; +/* if guest os id is not set hypercall should remain disabled */
arch/x86/kvm/x86.c out: · line 1051
Quoted 10 lines
arch/x86/kvm/x86.c +10
-0+if (!kvm->arch.hv_guest_os_id&& data) +break ; + kvm->arch.hv_hypercall = data; +if (!kvm_hv_hypercall_enabled (kvm)) +break ; + gfn = kvm->arch.hv_hypercall>> +HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT ; + addr =gfn_to_hva (kvm, gfn); +if (kvm_is_error_hva (addr)) +return 1 ;
Should di the error check before assigning, perhaps.
arch/x86/kvm/x86.c out: · line 1053
Quoted 3 lines
arch/x86/kvm/x86.c +2
-0+ kvm_x86_ops->patch_hypercall (vcpu, (unsigned char *)addr); + ((unsigned char *)addr)[3 ] =0xc3 ;/* ret */
kvm_write_guest(), this can fault.
arch/x86/kvm/x86.c static inline gpa_t hc_gpa(struct kvm_vcpu *vcpu, unsigned long a0,
Quoted 13 lines
arch/x86/kvm/x86.c +12
-0+int kvm_hv_hypercall (struct kvm_vcpu *vcpu) +{ +u64 param, ingpa, outgpa, ret; +uint16_t code, rep_idx, rep_cnt, res =HV_STATUS_SUCCESS , rep_done =0 ; +bool fast, longmode; +int cs_db, cs_l; + +/* +* hypercall generates UD from non zero cpl and real mode +* per HYPER-V spec +*/ +if (kvm_x86_ops->get_cpl (vcpu) !=0 || !(vcpu->arch.cr0&X86_CR0_PE )) {
Use kvm_read_cr0_bits() to avoid caching.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCHv2 2/4] Implement bare minimum of HYPER-V MSRs.
Quoted 5 lines · Avi Kivity
Quoted 4 lines · Gleb Natapov
Minimum HYPER-V implementation should have
GUEST_OS_ID, HYPERCALL andVP_INDEXMSRs.
Quoted 17 lines
arch/x86/kvm/x86.c static u32 msrs_to_save[] = { · line 635
Quoted 13 lines
TRACE_EVENT(kvm_pio,
arch/x86/kvm/x86.c +2
-1@@ -630,7 +630,8 @@ static u32 msrs_to_save[] = {#ifdef CONFIG_X86_64 MSR_CSTAR ,MSR_KERNEL_GS_BASE ,MSR_SYSCALL_MASK ,MSR_LSTAR , #endif -MSR_IA32_TSC ,MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA +MSR_IA32_TSC ,MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA , + HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL, };These will be disabled since the msrs don't exist on the host. See the comment above and
KVM_SAVE_MSRS_BEGIN.
I see. Why not have two arrays?
Quoted 8 lines
Quoted 8 lines
arch/x86/kvm/x86.c +8
-0+case HV_X64_MSR_HYPERCALL : { +u64 gfn; +unsigned long addr; +/* if guest os id is not set hypercall should remain disabled */ +if (!kvm->arch.hv_guest_os_id&& data) +break ; + kvm->arch.hv_hypercall = data; +if (!kvm_hv_hypercall_enabled (kvm))
Quoted 9 lines
arch/x86/kvm/x86.c out: · line 1051
Quoted 6 lines
arch/x86/kvm/x86.c +6
-0+break ; + gfn = kvm->arch.hv_hypercall>> +HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT ; + addr =gfn_to_hva (kvm, gfn); +if (kvm_is_error_hva (addr)) +return 1 ;Should di the error check before assigning, perhaps.
Spec doesn't tell. And guest will get #GP and BSOD anyway.
Quoted 5 lines
arch/x86/kvm/x86.c out: · line 1053
Quoted 2 lines
arch/x86/kvm/x86.c +2
-0+ kvm_x86_ops->patch_hypercall (vcpu, (unsigned char *)addr); + ((unsigned char *)addr)[3 ] =0xc3 ;/* ret */
kvm_write_guest(), this can fault.
Quoted 18 lines
arch/x86/kvm/x86.c static inline gpa_t hc_gpa(struct kvm_vcpu *vcpu, unsigned long a0,
Quoted 12 lines
arch/x86/kvm/x86.c +12
-0+int kvm_hv_hypercall (struct kvm_vcpu *vcpu) +{ +u64 param, ingpa, outgpa, ret; +uint16_t code, rep_idx, rep_cnt, res =HV_STATUS_SUCCESS , rep_done =0 ; +bool fast, longmode; +int cs_db, cs_l; + +/* +* hypercall generates UD from non zero cpl and real mode +* per HYPER-V spec +*/ +if (kvm_x86_ops->get_cpl (vcpu) !=0 || !(vcpu->arch.cr0&X86_CR0_PE )) {Use
kvm_read_cr0_bits()to avoid caching.Signature · 1 line
error compiling committee.c: too many arguments to function
--
Gleb.
Re: [PATCHv2 2/4] Implement bare minimum of HYPER-V MSRs.
Quoted 26 lines · Gleb Natapov
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Gleb Natapov
Minimum HYPER-V implementation should have
GUEST_OS_ID, HYPERCALL andVP_INDEXMSRs.Quoted 18 lines
Quoted 6 lines
TRACE_EVENT(kvm_pio,
arch/x86/kvm/x86.c +0
-0arch/x86/kvm/x86.c static u32 msrs_to_save[] = { · line 636
Quoted 8 lines
arch/x86/kvm/x86.c +2
-1@@ -630,7 +630,8 @@ static u32 msrs_to_save[] = {#ifdef CONFIG_X86_64 MSR_CSTAR ,MSR_KERNEL_GS_BASE ,MSR_SYSCALL_MASK ,MSR_LSTAR , #endif -MSR_IA32_TSC ,MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA +MSR_IA32_TSC ,MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA , + HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL, };These will be disabled since the msrs don't exist on the host. See the comment above and
KVM_SAVE_MSRS_BEGIN.
Quoted 2 lines
I see. Why not have two arrays?
Clearly better.
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
arch/x86/kvm/x86.c +8
-0+case HV_X64_MSR_HYPERCALL : { +u64 gfn; +unsigned long addr; +/* if guest os id is not set hypercall should remain disabled */ +if (!kvm->arch.hv_guest_os_id&& data) +break ; + kvm->arch.hv_hypercall = data; +if (!kvm_hv_hypercall_enabled (kvm))Quoted 10 lines
arch/x86/kvm/x86.c out: · line 1051
Quoted 7 lines
arch/x86/kvm/x86.c +6
-0+break ; + gfn = kvm->arch.hv_hypercall>> +HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT ; + addr =gfn_to_hva (kvm, gfn); +if (kvm_is_error_hva (addr)) +return 1 ;Should di the error check before assigning, perhaps.
Quoted 2 lines
Spec doesn't tell. And guest will get #GP and BSOD anyway.
Well, all msrs I know of either #GP, or store the value and do what they're supposed to do, never both.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCHv2 2/4] Implement bare minimum of HYPER-V MSRs.
Quoted 43 lines · Avi Kivity
Quoted 22 lines · Gleb Natapov
Quoted 5 lines · Avi Kivity
Quoted 4 lines · Gleb Natapov
Minimum HYPER-V implementation should have
GUEST_OS_ID, HYPERCALL andVP_INDEXMSRs.Quoted 16 lines
arch/x86/kvm/x86.c static u32 msrs_to_save[] = { · line 635
Quoted 13 lines
TRACE_EVENT(kvm_pio,
arch/x86/kvm/x86.c +2
-1@@ -630,7 +630,8 @@ static u32 msrs_to_save[] = {#ifdef CONFIG_X86_64 MSR_CSTAR ,MSR_KERNEL_GS_BASE ,MSR_SYSCALL_MASK ,MSR_LSTAR , #endif -MSR_IA32_TSC ,MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA +MSR_IA32_TSC ,MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA , + HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL, };These will be disabled since the msrs don't exist on the host. See the comment above and
KVM_SAVE_MSRS_BEGIN.Quoted 1 line
I see. Why not have two arrays?
Clearly better.
Quoted 16 lines
Quoted 16 lines
Quoted 4 lines
arch/x86/kvm/x86.c +4
-0+case HV_X64_MSR_HYPERCALL : { +u64 gfn; +unsigned long addr; +/* if guest os id is not set hypercall should remain disabled */ arch/x86/kvm/x86.c out: · line 1051
Quoted 10 lines
arch/x86/kvm/x86.c +10
-0+if (!kvm->arch.hv_guest_os_id&& data) +break ; + kvm->arch.hv_hypercall = data; +if (!kvm_hv_hypercall_enabled (kvm)) +break ; + gfn = kvm->arch.hv_hypercall>> +HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT ; + addr =gfn_to_hva (kvm, gfn); +if (kvm_is_error_hva (addr)) +return 1 ;Should di the error check before assigning, perhaps.
Quoted 6 lines
Quoted 1 line
Spec doesn't tell. And guest will get #GP and BSOD anyway.
Well, all msrs I know of either #GP, or store the value and do what they're supposed to do, never both.
Make sense. Will fix.
--
Gleb.
PATCH v2 3/4 Add HYPER-V apic access MSRs.
In reply to Gleb Natapov--- arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/lapic.c | 31 +++++++++++++++++++++++++++++ arch/x86/kvm/lapic.h | 8 +++++++ arch/x86/kvm/x86.c | 41 ++++++++++++++++++++++++++++++++++++-- include/linux/kvm.h | 1 + 5 files changed, 80 insertions(+), 3 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -0
@@ -363,6 +363,8 @@ struct kvm_vcpu_arch {/* used for guest single stepping over the given code position */ u16 singlestep_cs;unsigned long singlestep_rip; +/* fields used by HYPER-V emulation */ +u64 hv_vapic; };struct kvm_mem_alias {
arch/x86/kvm/lapic.c +31 -0
@@ -1246,3 +1246,34 @@ int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data)return 0 ; } + +int kvm_hv_vapic_msr_write (struct kvm_vcpu *vcpu,u32 reg,u64 data) +{ +struct kvm_lapic *apic = vcpu->arch.apic; + +if (!irqchip_in_kernel (vcpu->kvm)) +return 1 ; + +/* if this is ICR write vector before command */ +if (reg ==APIC_ICR ) +apic_reg_write (apic,APIC_ICR2 , (u32)(data >>32 )); +return apic_reg_write (apic, reg, (u32 )data); +} + +int kvm_hv_vapic_msr_read (struct kvm_vcpu *vcpu,u32 reg,u64 *data) +{ +struct kvm_lapic *apic = vcpu->arch.apic; +u32 low, high =0 ; + +if (!irqchip_in_kernel (vcpu->kvm)) +return 1 ; + +if (apic_reg_read (apic, reg,4 , &low)) +return 1 ; +if (reg ==APIC_ICR ) +apic_reg_read (apic,APIC_ICR2 ,4 , &high); + + *data = (((u64 )high) <<32 ) | low; + +return 0 ; +}
arch/x86/kvm/lapic.h +8 -0
@@ -48,4 +48,12 @@ void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);int kvm_x2apic_msr_write (struct kvm_vcpu *vcpu,u32 msr,u64 data);int kvm_x2apic_msr_read (struct kvm_vcpu *vcpu,u32 msr,u64 *data); + +int kvm_hv_vapic_msr_write (struct kvm_vcpu *vcpu,u32 msr,u64 data); +int kvm_hv_vapic_msr_read (struct kvm_vcpu *vcpu,u32 msr,u64 *data); + +static inline bool kvm_hv_vapic_enabled (struct kvm_vcpu *vcpu) +{ +return !!(vcpu->arch.hv_vapic &HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE ); +}#endif
arch/x86/kvm/x86.c +38 -3
66 lines not on this page · raw message
include/linux/kvm.h +1 -0
@@ -498,6 +498,7 @@ struct kvm_ioeventfd {#define KVM_CAP_S390_PSW 42#define KVM_CAP_PPC_SEGSTATE 43#define KVM_CAP_HYPERV 44 +#define KVM_CAP_HYPERV_VAPIC 45#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
1.6.5
Re: [PATCHv2 3/4] Add HYPER-V apic access MSRs.
Quoted 3 lines · Gleb Natapov
Signed-off-by Gleb Natapov<[email protected]>Signed-off-by Vadim Rozenfeld<[email protected]>
Changelog entry.
Quoted 32 lines
struct kvm_mem_alias {arch/x86/kvm/lapic.c +21
-0@@ -1246,3 +1246,34 @@ int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data)return 0 ; } + +int kvm_hv_vapic_msr_write (struct kvm_vcpu *vcpu,u32 reg,u64 data) +{ +struct kvm_lapic *apic = vcpu->arch.apic; + +if (!irqchip_in_kernel (vcpu->kvm)) +return 1 ; + +/* if this is ICR write vector before command */ +if (reg ==APIC_ICR ) +apic_reg_write (apic,APIC_ICR2 , (u32)(data>>32 )); +return apic_reg_write (apic, reg, (u32 )data); +} + +int kvm_hv_vapic_msr_read (struct kvm_vcpu *vcpu,u32 reg,u64 *data) +{ +struct kvm_lapic *apic = vcpu->arch.apic; +u32 low, high =0 ; + +if (!irqchip_in_kernel (vcpu->kvm)) +return 1 ;
arch/x86/kvm/lapic.c int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data) · line 1279
Quoted 10 lines
arch/x86/kvm/lapic.c +10
-0+ +if (apic_reg_read (apic, reg,4 ,&low)) +return 1 ; +if (reg ==APIC_ICR ) +apic_reg_read (apic,APIC_ICR2 ,4 ,&high); + + *data = (((u64 )high)<<32 ) | low; + +return 0 ; +}
I prefer putting this in x86.c (maybe later split into hyperv.c).
Quoted 7 lines
arch/x86/kvm/lapic.h +0
-0@@ -48,4 +48,12 @@ void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);int kvm_x2apic_msr_write (struct kvm_vcpu *vcpu,u32 msr,u64 data);
arch/x86/kvm/lapic.h void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu); · line 59
Quoted 10 lines
arch/x86/kvm/lapic.h +8
-0int kvm_x2apic_msr_read (struct kvm_vcpu *vcpu,u32 msr,u64 *data); + +int kvm_hv_vapic_msr_write (struct kvm_vcpu *vcpu,u32 msr,u64 data); +int kvm_hv_vapic_msr_read (struct kvm_vcpu *vcpu,u32 msr,u64 *data); + +static inline bool kvm_hv_vapic_enabled (struct kvm_vcpu *vcpu) +{ +return !!(vcpu->arch.hv_vapic&HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE ); +}
Are you sure that vapic enabled is equivalent to apic assist page enable?
!! not required.
arch/x86/kvm/x86.c static u32 msrs_to_save[] = { · line 638
Quoted 13 lines
#endifarch/x86/kvm/x86.c +1
-0@@ -632,6 +632,7 @@ static u32 msrs_to_save[] = {#endif MSR_IA32_TSC ,MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA ,HV_X64_MSR_GUEST_OS_ID ,HV_X64_MSR_HYPERCALL , + HV_X64_MSR_APIC_ASSIST_PAGE, };
Will be dropped by msr validation.
Quoted 11 lines
static unsigned
num_msrs_to_save;arch/x86/kvm/x86.c +4
-2@@ -1063,10 +1064,37 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)static int set_msr_hyperv (struct kvm_vcpu *vcpu,u32 msr,u64 data) { -pr_unimpl (vcpu,"HYPER-V unimplemented wrmsr: 0x%x data 0x%llx\n" , - msr, data); +switch (msr) { +case HV_X64_MSR_APIC_ASSIST_PAGE : { +unsigned long vaddr; +void *addr;
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1080
Quoted 10 lines
arch/x86/kvm/x86.c +9
-0+struct page *page; + vcpu->arch.hv_vapic = data; +if (!kvm_hv_vapic_enabled (vcpu)) +break ; + vaddr =gfn_to_hva (vcpu->kvm, data>> +HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT ); +if (kvm_is_error_hva (vaddr)) +return 1 ; + page =virt_to_page (vaddr);
virt_to_page() takes a kernel address, not a user address. This is get_user_pages(). But I think the whole thing is done better with put_user().
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1096
Quoted 4 lines
arch/x86/kvm/x86.c +3
-0+ addr =kmap_atomic (page,KM_USER0 ); +clear_user_page (addr, vaddr, page); +kunmap_atomic (addr,KM_USER0 );
Surprising that clear_user_page needs kmap_atomic() (but true).
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCHv2 3/4] Add HYPER-V apic access MSRs.
Quoted 6 lines · Avi Kivity
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1082
Quoted 4 lines
arch/x86/kvm/x86.c +3
-0+ addr =kmap_atomic (page,KM_USER0 ); +clear_user_page (addr, vaddr, page); +kunmap_atomic (addr,KM_USER0 );Surprising that
clear_user_pageneedskmap_atomic()(but true).
There's a clear_user_highpage helper to take care of it for you.
Re: [PATCHv2 3/4] Add HYPER-V apic access MSRs.
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Avi Kivity
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1082
Quoted 4 lines
arch/x86/kvm/x86.c +3
-0+ addr =kmap_atomic (page,KM_USER0 ); +clear_user_page (addr, vaddr, page); +kunmap_atomic (addr,KM_USER0 );Surprising that
clear_user_pageneedskmap_atomic()(but true).There's a
clear_user_highpagehelper to take care of it for you.
I copied code from the instead of using helper faction for some unknown to me reason. Anyway if I can't get struct page from user virtual address I can't use it. Actually I am not sure the page should be zeroed at all. Spec only descries first dword of the page and doesn't require zeroing the reset as far as I see.
--
Gleb.
Re: [PATCHv2 3/4] Add HYPER-V apic access MSRs.
Quoted 5 lines · Gleb Natapov
I copied code from the instead of using helper faction for some unknown to me reason. Anyway if I can't get struct page from user virtual address I can't use it. Actually I am not sure the page should be zeroed at all. Spec only descries first dword of the page and doesn't require zeroing the reset as far as I see.
There's a clear_user() function that just takes a user virtual address and a size.
Re: [PATCHv2 3/4] Add HYPER-V apic access MSRs.
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Gleb Natapov
I copied code from the instead of using helper faction for some unknown to me reason. Anyway if I can't get struct page from user virtual address I can't use it. Actually I am not sure the page should be zeroed at all. Spec only descries first dword of the page and doesn't require zeroing the reset as far as I see.
There's a
clear_user()function that just takes a user virtual address and a size.
Precisely what I need. Thanks!
--
Gleb.
Re: [PATCHv2 3/4] Add HYPER-V apic access MSRs.
Quoted 10 lines · Gleb Natapov
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Gleb Natapov
I copied code from the instead of using helper faction for some unknown to me reason. Anyway if I can't get struct page from user virtual address I can't use it. Actually I am not sure the page should be zeroed at all. Spec only descries first dword of the page and doesn't require zeroing the reset as far as I see.
Quoted 6 lines
Quoted 3 lines
There's a
clear_user()function that just takes a user virtual address and a size.Precisely what I need. Thanks!
But clear_user_page() is confusingly named. I assume it deals with virtually tagged caches on archs that have them?
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCHv2 3/4] Add HYPER-V apic access MSRs.
In reply to Avi KivityQuoted 59 lines · Avi Kivity
Quoted 3 lines · Gleb Natapov
Signed-off-by Gleb Natapov<[email protected]>Signed-off-by Vadim Rozenfeld<[email protected]>Changelog entry.
Quoted 32 lines
struct kvm_mem_alias {arch/x86/kvm/lapic.c +21
-0@@ -1246,3 +1246,34 @@ int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data)return 0 ; } + +int kvm_hv_vapic_msr_write (struct kvm_vcpu *vcpu,u32 reg,u64 data) +{ +struct kvm_lapic *apic = vcpu->arch.apic; + +if (!irqchip_in_kernel (vcpu->kvm)) +return 1 ; + +/* if this is ICR write vector before command */ +if (reg ==APIC_ICR ) +apic_reg_write (apic,APIC_ICR2 , (u32)(data>>32 )); +return apic_reg_write (apic, reg, (u32 )data); +} + +int kvm_hv_vapic_msr_read (struct kvm_vcpu *vcpu,u32 reg,u64 *data) +{ +struct kvm_lapic *apic = vcpu->arch.apic; +u32 low, high =0 ; + +if (!irqchip_in_kernel (vcpu->kvm)) +return 1 ;arch/x86/kvm/lapic.c int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data) · line 1279
Quoted 10 lines
arch/x86/kvm/lapic.c +10
-0+ +if (apic_reg_read (apic, reg,4 ,&low)) +return 1 ; +if (reg ==APIC_ICR ) +apic_reg_read (apic,APIC_ICR2 ,4 ,&high); + + *data = (((u64 )high)<<32 ) | low; + +return 0 ; +}I prefer putting this in
x86.c(maybe later split intohyperv.c).Quoted 6 lines
arch/x86/kvm/lapic.h +0
-0@@ -48,4 +48,12 @@ void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);
Quoted 13 lines
arch/x86/kvm/lapic.h void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);
Quoted 11 lines
arch/x86/kvm/lapic.h +8
-0int kvm_x2apic_msr_write (struct kvm_vcpu *vcpu,u32 msr,u64 data);int kvm_x2apic_msr_read (struct kvm_vcpu *vcpu,u32 msr,u64 *data); + +int kvm_hv_vapic_msr_write (struct kvm_vcpu *vcpu,u32 msr,u64 data); +int kvm_hv_vapic_msr_read (struct kvm_vcpu *vcpu,u32 msr,u64 *data); + +static inline bool kvm_hv_vapic_enabled (struct kvm_vcpu *vcpu) +{ +return !!(vcpu->arch.hv_vapic&HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE ); +}Are you sure that vapic enabled is equivalent to apic assist page enable?
At least, when it is disable, the EOI interception mechanism won't work.
Quoted 52 lines
!! not required.
arch/x86/kvm/x86.c static u32 msrs_to_save[] = { · line 638
Quoted 13 lines
#endifarch/x86/kvm/x86.c +1
-0@@ -632,6 +632,7 @@ static u32 msrs_to_save[] = {#endif MSR_IA32_TSC ,MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA ,HV_X64_MSR_GUEST_OS_ID ,HV_X64_MSR_HYPERCALL , + HV_X64_MSR_APIC_ASSIST_PAGE, };Will be dropped by msr validation.
Quoted 11 lines
static unsigned
num_msrs_to_save;arch/x86/kvm/x86.c +4
-2@@ -1063,10 +1064,37 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)static int set_msr_hyperv (struct kvm_vcpu *vcpu,u32 msr,u64 data) { -pr_unimpl (vcpu,"HYPER-V unimplemented wrmsr: 0x%x data 0x%llx\n" , - msr, data); +switch (msr) { +case HV_X64_MSR_APIC_ASSIST_PAGE : { +unsigned long vaddr; +void *addr;arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1080
Quoted 10 lines
arch/x86/kvm/x86.c +9
-0+struct page *page; + vcpu->arch.hv_vapic = data; +if (!kvm_hv_vapic_enabled (vcpu)) +break ; + vaddr =gfn_to_hva (vcpu->kvm, data>> +HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT ); +if (kvm_is_error_hva (vaddr)) +return 1 ; + page =virt_to_page (vaddr);
virt_to_page()takes a kernel address, not a user address. This isget_user_pages(). But I think the whole thing is done better withput_user().arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1096
Quoted 4 lines
arch/x86/kvm/x86.c +3
-0+ addr =kmap_atomic (page,KM_USER0 ); +clear_user_page (addr, vaddr, page); +kunmap_atomic (addr,KM_USER0 );Surprising that
clear_user_pageneedskmap_atomic()(but true).
Re: [PATCHv2 3/4] Add HYPER-V apic access MSRs.
In reply to Avi KivityQuoted 42 lines · Avi Kivity
Quoted 2 lines · Gleb Natapov
Signed-off-by Gleb Natapov<[email protected]>Signed-off-by Vadim Rozenfeld<[email protected]>Changelog entry.
Quoted 35 lines
struct
kvm_mem_alias{arch/x86/kvm/lapic.c +25
-0@@ -1246,3 +1246,34 @@ int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data)return 0 ; } + +int kvm_hv_vapic_msr_write (struct kvm_vcpu *vcpu,u32 reg,u64 data) +{ +struct kvm_lapic *apic = vcpu->arch.apic; + +if (!irqchip_in_kernel (vcpu->kvm)) +return 1 ; + +/* if this is ICR write vector before command */ +if (reg ==APIC_ICR ) +apic_reg_write (apic,APIC_ICR2 , (u32)(data>>32 )); +return apic_reg_write (apic, reg, (u32 )data); +} + +int kvm_hv_vapic_msr_read (struct kvm_vcpu *vcpu,u32 reg,u64 *data) +{ +struct kvm_lapic *apic = vcpu->arch.apic; +u32 low, high =0 ; + +if (!irqchip_in_kernel (vcpu->kvm)) +return 1 ; + +if (apic_reg_read (apic, reg,4 ,&low)) +return 1 ; +if (reg ==APIC_ICR )
Quoted 9 lines
arch/x86/kvm/lapic.c int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data) · line 1279
Quoted 6 lines
arch/x86/kvm/lapic.c +6
-0+apic_reg_read (apic,APIC_ICR2 ,4 ,&high); + + *data = (((u64 )high)<<32 ) | low; + +return 0 ; +}I prefer putting this in
x86.c(maybe later split intohyperv.c).
This implements part of apic behaviour. It uses internal lapic functions like apic_reg_read()/apic_reg_write(). Why move it from lapic.c?
Quoted 19 lines
Quoted 6 lines
arch/x86/kvm/lapic.h +0
-0@@ -48,4 +48,12 @@ void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu);arch/x86/kvm/lapic.h void kvm_lapic_sync_to_vapic(struct kvm_vcpu *vcpu); · line 58
Quoted 10 lines
arch/x86/kvm/lapic.h +8
-0int kvm_x2apic_msr_write (struct kvm_vcpu *vcpu,u32 msr,u64 data);int kvm_x2apic_msr_read (struct kvm_vcpu *vcpu,u32 msr,u64 *data); + +int kvm_hv_vapic_msr_write (struct kvm_vcpu *vcpu,u32 msr,u64 data); +int kvm_hv_vapic_msr_read (struct kvm_vcpu *vcpu,u32 msr,u64 *data); + +static inline bool kvm_hv_vapic_enabled (struct kvm_vcpu *vcpu) +{ +return !!(vcpu->arch.hv_vapic&HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE ); +}Are you sure that vapic enabled is equivalent to apic assist page enable?
Quoted 2 lines
!! not required.
The function is not used to check if vapic is enabled, so the name should be changed.
Quoted 31 lines
arch/x86/kvm/x86.c static u32 msrs_to_save[] = { · line 637
Quoted 12 lines
arch/x86/kvm/lapic.h +0
-0#endif arch/x86/kvm/x86.c +1
-0@@ -632,6 +632,7 @@ static u32 msrs_to_save[] = {#endif MSR_IA32_TSC ,MSR_IA32_PERF_STATUS ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA ,HV_X64_MSR_GUEST_OS_ID ,HV_X64_MSR_HYPERCALL , + HV_X64_MSR_APIC_ASSIST_PAGE, };Will be dropped by msr validation.
Quoted 16 lines
arch/x86/kvm/x86.c +9
-2static unsigned num_msrs_to_save;@@ -1063,10 +1064,37 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)static int set_msr_hyperv (struct kvm_vcpu *vcpu,u32 msr,u64 data) { -pr_unimpl (vcpu,"HYPER-V unimplemented wrmsr: 0x%x data 0x%llx\n" , - msr, data); +switch (msr) { +case HV_X64_MSR_APIC_ASSIST_PAGE : { +unsigned long vaddr; +void *addr; +struct page *page; + vcpu->arch.hv_vapic = data; +if (!kvm_hv_vapic_enabled (vcpu)) +break ; + vaddr = gfn_to_hva(vcpu->kvm, data>>
Quoted 9 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1079
Quoted 4 lines
arch/x86/kvm/x86.c +4
-0+ HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT); +if (kvm_is_error_hva (vaddr)) +return 1 ; + page =virt_to_page (vaddr);
virt_to_page()takes a kernel address, not a user address. This isget_user_pages(). But I think the whole thing is done better withput_user().
So there is no function to get struct page from user virtual address?
Quoted 8 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1082
Quoted 3 lines
arch/x86/kvm/x86.c +3
-0+ addr =kmap_atomic (page,KM_USER0 ); +clear_user_page (addr, vaddr, page); +kunmap_atomic (addr,KM_USER0 );Surprising that
clear_user_pageneedskmap_atomic()(but true).Signature · 1 line
error compiling committee.c: too many arguments to function
--
Gleb.
Re: [PATCHv2 3/4] Add HYPER-V apic access MSRs.
Quoted 22 lines · Gleb Natapov
+
Quoted 11 lines
Quoted 11 lines
arch/x86/kvm/lapic.c +11
-0+int kvm_hv_vapic_msr_read (struct kvm_vcpu *vcpu,u32 reg,u64 *data) +{ +struct kvm_lapic *apic = vcpu->arch.apic; +u32 low, high =0 ; + +if (!irqchip_in_kernel (vcpu->kvm)) +return 1 ; + +if (apic_reg_read (apic, reg,4 ,&low)) +return 1 ; +if (reg ==APIC_ICR )Quoted 10 lines
arch/x86/kvm/lapic.c int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data) · line 1279
Quoted 7 lines
arch/x86/kvm/lapic.c +6
-0+apic_reg_read (apic,APIC_ICR2 ,4 ,&high); + + *data = (((u64 )high)<<32 ) | low; + +return 0 ; +}I prefer putting this in
x86.c(maybe later split intohyperv.c).
Quoted 3 lines
This implements part of apic behaviour. It uses internal lapic functions like apic_reg_read()/apic_reg_write(). Why move it from
lapic.c?
The new functions implement hyper-v behaviour. Why scatter them all around?
Maybe apic_reg_{read,write} need to be exported.
Quoted 23 lines
Quoted 13 lines
Quoted 13 lines
static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data) {arch/x86/kvm/x86.c +9
-2-pr_unimpl (vcpu,"HYPER-V unimplemented wrmsr: 0x%x data 0x%llx\n" , - msr, data); +switch (msr) { +case HV_X64_MSR_APIC_ASSIST_PAGE : { +unsigned long vaddr; +void *addr; +struct page *page; + vcpu->arch.hv_vapic = data; +if (!kvm_hv_vapic_enabled (vcpu)) +break ; + vaddr = gfn_to_hva(vcpu->kvm, data>>Quoted 10 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1079
Quoted 5 lines
arch/x86/kvm/x86.c +4
-0+ HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT); +if (kvm_is_error_hva (vaddr)) +return 1 ; + page =virt_to_page (vaddr);
virt_to_page()takes a kernel address, not a user address. This isget_user_pages(). But I think the whole thing is done better withput_user().
Quoted 2 lines
So there is no function to get struct page from user virtual address?
get_user_pages_fast().
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCHv2 3/4] Add HYPER-V apic access MSRs.
Quoted 21 lines · Avi Kivity
Quoted 20 lines · Gleb Natapov
+
Quoted 19 lines
Quoted 7 lines
arch/x86/kvm/lapic.c +7
-0+int kvm_hv_vapic_msr_read (struct kvm_vcpu *vcpu,u32 reg,u64 *data) +{ +struct kvm_lapic *apic = vcpu->arch.apic; +u32 low, high =0 ; + +if (!irqchip_in_kernel (vcpu->kvm)) +return 1 ;arch/x86/kvm/lapic.c int kvm_x2apic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data) · line 1279
Quoted 10 lines
arch/x86/kvm/lapic.c +10
-0+ +if (apic_reg_read (apic, reg,4 ,&low)) +return 1 ; +if (reg ==APIC_ICR ) +apic_reg_read (apic,APIC_ICR2 ,4 ,&high); + + *data = (((u64 )high)<<32 ) | low; + +return 0 ; +}I prefer putting this in
x86.c(maybe later split intohyperv.c).
Quoted 5 lines
Quoted 2 lines
This implements part of apic behaviour. It uses internal lapic functions like apic_reg_read()/apic_reg_write(). Why move it from
lapic.c?The new functions implement hyper-v behaviour. Why scatter them all around?
Each hyper-v extension is pretty much independent one from another, so why not group things by functionality instead. All apic related code in lapic.c.
Quoted 2 lines
Maybe apic_reg_{read,write} need to be exported.
This is really internal API. It doesn't even check if apic is created.
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 7 lines
static int
set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data){arch/x86/kvm/x86.c +3
-2-pr_unimpl (vcpu,"HYPER-V unimplemented wrmsr: 0x%x data 0x%llx\n" , - msr, data); +switch (msr) { +case HV_X64_MSR_APIC_ASSIST_PAGE : { +unsigned long vaddr;arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1079
Quoted 10 lines
arch/x86/kvm/x86.c +10
-0+void *addr; +struct page *page; + vcpu->arch.hv_vapic = data; +if (!kvm_hv_vapic_enabled (vcpu)) +break ; + vaddr =gfn_to_hva (vcpu->kvm, data>> +HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT ); +if (kvm_is_error_hva (vaddr)) +return 1 ; + page =virt_to_page (vaddr);
virt_to_page()takes a kernel address, not a user address. This isget_user_pages(). But I think the whole thing is done better withput_user().
Quoted 4 lines
Quoted 1 line
So there is no function to get struct page from user virtual address?
get_user_pages_fast().
Doh.
--
Gleb.
Re: [PATCHv2 3/4] Add HYPER-V apic access MSRs.
Quoted 14 lines · Gleb Natapov
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
I prefer putting this in
x86.c(maybe later split intohyperv.c).This implements part of apic behaviour. It uses internal lapic functions like apic_reg_read()/apic_reg_write(). Why move it from
lapic.c?The new functions implement hyper-v behaviour. Why scatter them all around?
Each hyper-v extension is pretty much independent one from another, so why not group things by functionality instead. All apic related code in
lapic.c.
Quoted 5 lines
Quoted 3 lines
Maybe apic_reg_{read,write} need to be exported.
This is really internal API. It doesn't even check if apic is created.
Okay. We can rethink it later when the code grows some more.
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH v2 4/4 Implement NotifyLongSpinWait HYPER-V hypercall.
In reply to Gleb Natapov--- arch/x86/kvm/x86.c | 10 +++++++++- include/linux/kvm.h | 1 + 2 files changed, 10 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +9 -1
@@ -1561,6 +1561,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_VCPU_EVENTS :case KVM_CAP_HYPERV :case KVM_CAP_HYPERV_VAPIC : +case KVM_CAP_HYPERV_SPIN : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :
@@ -3820,7 +3821,14 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)trace_kvm_hv_hypercall (code, fast, rep_cnt, rep_idx, ingpa, outgpa); - res =HV_STATUS_INVALID_HYPERCALL_CODE ; +switch (code) { +case HV_X64_HV_NOTIFY_LONG_SPIN_WAIT : +kvm_vcpu_on_spin (vcpu); +break ; +default : + res =HV_STATUS_INVALID_HYPERCALL_CODE ; +break ; + } ret = res | (((u64 )rep_done &0xfff ) <<32 );if (longmode) {
include/linux/kvm.h +1 -0
@@ -499,6 +499,7 @@ struct kvm_ioeventfd {#define KVM_CAP_PPC_SEGSTATE 43#define KVM_CAP_HYPERV 44#define KVM_CAP_HYPERV_VAPIC 45 +#define KVM_CAP_HYPERV_SPIN 46#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
1.6.5
Re: [PATCHv2 4/4] Implement NotifyLongSpinWait HYPER-V hypercall.
Quoted 3 lines · Gleb Natapov
Signed-off-by Gleb Natapov<[email protected]>Signed-off-by Vadim Rozenfeld<[email protected]>
Changelog entry.
Signature · 1 line
error compiling committee.c: too many arguments to function