kvm : Paravirt-spinlock support for KVM guests
Subsystems (10)
v6 cover kvm : Paravirt-spinlock support for KVM guests
The 5-patch series to follow this email extends KVM-hypervisor and Linux guest running on KVM-hypervisor to support pv-ticket spinlocks, based on Xen's implementation.
One hypercall is introduced in KVM hypervisor,that allows a vcpu to kick another vcpu out of halt state.
The blocking of vcpu is done using halt() in (lock_spinning) slowpath.
Note: 1) patch is based on 3.4-rc3 + ticketlock patches in
https://lkml.org/lkml/2012/4/19/335
[ The patches are targeted for 3.5 window ]
Changes in V6:
- Rebased to 3.4-rc3
- Removed debugfs changes patch which should now be in Xen/linux-next.
(https://lkml.org/lkml/2012/3/30/687)
- Removed PV_UNHALT_MSR since currently we don't need guest communication, and made pv_unhalt folded to GET_MP_STATE (Marcello, Avi[long back])
- Take jumplabel changes from Ingo/Jason into use (static_key_slow_inc usage)
- Added inline to spinlock_init in non PARAVIRT case
- Move arch specific code to arch/x86 and add stubs to other archs (Marcello)
- Added more comments on pv_unhalt usage etc (Marcello)
Changes in V5:
- rebased to 3.3-rc6
- added PV_UNHALT_MSR that would help in live migration (Avi)
- removed PV_LOCK_KICK vcpu request and pv_unhalt flag (re)added.
- Changed hypercall documentaion (Alex).
- mode_t changed to umode_t in debugfs.
- MSR related documentation added.
- rename PV_LOCK_KICK to PV_UNHALT.
- host and guest patches not mixed. (Marcelo, Alex)
- kvm_kick_cpu now takes cpu so it can be used by flush_tlb_ipi_other paravirtualization (Nikunj)
- coding style changes in variable declarion etc (Srikar)
Changes in V4:
- reabsed to 3.2.0 pre.
- use APIC ID for kicking the vcpu and use kvm_apic_match_dest for matching (Avi)
- fold vcpu->kicked flag into vcpu->requests (KVM_REQ_PVLOCK_KICK) and related changes for UNHALT path to make pv ticket spinlock migration friendly(Avi, Marcello)
- Added Documentation for CPUID, Hypercall (KVM_HC_KICK_CPU)
and capabilty (KVM_CAP_PVLOCK_KICK) (Avi)
- Remove unneeded kvm_arch_vcpu_ioctl_set_mpstate call. (Marcello)
- cumulative variable type changed (int ==> u32) in add_stat (Konrad)
- remove unneeded kvm_guest_init for !CONFIG_KVM_GUEST case
Changes in V3:
- rebased to 3.2-rc1
- use halt() instead of wait for kick hypercall.
- modify kick hyper call to do wakeup halted vcpu.
- hook kvm_spinlock_init to smp_prepare_cpus call (moved the call out of head##.c).
- fix the potential race when zero_stat is read.
- export debugfs_create_32 and add documentation to API.
- use static inline and enum instead of ADDSTAT macro.
- add barrier() in after setting kick_vcpu.
- empty static inline function for kvm_spinlock_init.
- combine the patches one and two readuce overhead.
- make KVM_DEBUGFS depends on DEBUGFS.
- include debugfs header unconditionally.
Changes in V2:
- rebased patchesto -rc9
- synchronization related changes based on Jeremy's changes (Jeremy Fitzhardinge <[email protected]>) pointed by Stephan Diestelhorst <[email protected]>
- enabling 32 bit guests
- splitted patches into two more chunks
Results:
results for PLE / non PLE machine were posted for V5 patches in
https://lkml.org/lkml/2012/3/23/50
https://lkml.org/lkml/2012/4/5/73
Current series is giving similar results but more formal results will be posted in next couple of days.
Interestingly with current patchset I do not see CPU stalls observed in vanilla.
TODO: 1) remove CONFIG_PARAVIRT_SPINLOCK ?
2) experiments on further optimization possibilities. (discussed in V6 of ticketlock)
3) possible debugfs cleanups (combining common code of Xen/KVM)
Let me know if you have any sugestion/comments...
---
V5 kernel changes:
https://lkml.org/lkml/2012/3/23/50
Qemu changes for V5:
http://lists.gnu.org/archive/html/qemu-devel/2012-03/msg04455.html
V4 kernel changes:
https://lkml.org/lkml/2012/1/14/66
Qemu changes for V4:
http://www.mail-archive.com/[email protected]/msg66450.html
V3 kernel Changes:
https://lkml.org/lkml/2011/11/30/62
V2 kernel changes :
https://lkml.org/lkml/2011/10/23/207
Previous discussions : (posted by Srivatsa V).
https://lkml.org/lkml/2010/7/26/24
https://lkml.org/lkml/2011/1/19/212
Qemu patch for V3:
http://lists.gnu.org/archive/html/qemu-devel/2011-12/msg00397.html
Srivatsa Vaddagiri (3):
Add a hypercall to KVM hypervisor to support pv-ticketlocks Added configuration support to enable debug information for KVM Guests pv-ticketlock support for linux guests running on KVM hypervisor
Raghavendra K T (2):
Fold pv_unhalt flag into GET_MP_STATE ioctl to aid migration Add documentation on Hypercalls and features used for PV spinlock
Documentation/virtual/kvm/api.txt | 7 + Documentation/virtual/kvm/cpuid.txt | 4 + Documentation/virtual/kvm/hypercalls.txt | 59 +++++++ arch/ia64/include/asm/kvm_host.h | 3 + arch/powerpc/include/asm/kvm_host.h | 4 + arch/s390/include/asm/kvm_host.h | 4 + arch/x86/Kconfig | 9 + arch/x86/include/asm/kvm_host.h | 6 + arch/x86/include/asm/kvm_para.h | 16 ++- arch/x86/kernel/kvm.c | 254 ++++++++++++++++++++++++++++++ arch/x86/kvm/cpuid.c | 3 +- arch/x86/kvm/x86.c | 46 ++++++- include/linux/kvm.h | 1 + include/linux/kvm_para.h | 1 + virt/kvm/kvm_main.c | 8 + 15 files changed, 421 insertions(+), 4 deletions(-)
RFC PATCH v6 1/5 kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
From: Srivatsa Vaddagiri <[email protected]>
KVM_HC_KICK_CPU allows the calling vcpu to kick another vcpu out of halt state.
The presence of these hypercalls is indicated to guest via KVM_FEATURE_PV_UNHALT/KVM_CAP_PV_UNHALT.
---
arch/ia64/include/asm/kvm_host.h +3 -0
@@ -597,6 +597,9 @@ void kvm_sal_emul(struct kvm_vcpu *vcpu);struct kvm *kvm_arch_alloc_vm (void );void kvm_arch_free_vm (struct kvm *kvm); +static inline void kvm_arch_vcpu_reset_pv_unhalted (struct kvm_vcpu *vcpu) +{ +}#endif /* __ASSEMBLY__*/ #endif
arch/powerpc/include/asm/kvm_host.h +4 -0
@@ -498,4 +498,8 @@ struct kvm_vcpu_arch {#define KVM_MMIO_REG_QPR 0x0040#define KVM_MMIO_REG_FQPR 0x0060 +static inline void kvm_arch_vcpu_reset_pv_unhalted (struct kvm_vcpu *vcpu) +{ +} +#endif /* __POWERPC_KVM_HOST_H__ */
arch/s390/include/asm/kvm_host.h +4 -0
@@ -256,4 +256,8 @@ struct kvm_arch{ };extern int sie64a (struct kvm_s390_sie_block *,u64 *); +static inline void kvm_arch_vcpu_reset_pv_unhalted (struct kvm_vcpu *vcpu) +{ +} +#endif
arch/x86/include/asm/kvm_host.h +6 -0
@@ -481,6 +481,10 @@ struct kvm_vcpu_arch {u64 length;u64 status; } osvw; +/* pv related host specific info */ +struct { +int pv_unhalted; + } pv; };struct kvm_lpage_info {
@@ -967,4 +971,6 @@ int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data);void kvm_handle_pmu_event (struct kvm_vcpu *vcpu);void kvm_deliver_pmi (struct kvm_vcpu *vcpu); +void kvm_arch_vcpu_reset_pv_unhalted (struct kvm_vcpu *vcpu); +#endif /* _ASM_X86_KVM_HOST_H */
arch/x86/include/asm/kvm_para.h +2 -0
@@ -16,12 +16,14 @@#define KVM_FEATURE_CLOCKSOURCE 0#define KVM_FEATURE_NOP_IO_DELAY 1#define KVM_FEATURE_MMU_OP 2 +/* This indicates that the new set of kvmclock msrs * are available. The use of 0x11 and 0x12 is deprecated */ #define KVM_FEATURE_CLOCKSOURCE2 3#define KVM_FEATURE_ASYNC_PF 4#define KVM_FEATURE_STEAL_TIME 5 +#define KVM_FEATURE_PV_UNHALT 6/* The last 8 bits are used to indicate how to interpret the flags field * in pvclock structure. If no bits are set, all flags are ignored.
arch/x86/kvm/cpuid.c +2 -1
@@ -408,7 +408,8 @@ static int do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, (1 <<KVM_FEATURE_NOP_IO_DELAY ) | (1 <<KVM_FEATURE_CLOCKSOURCE2 ) | (1 <<KVM_FEATURE_ASYNC_PF ) | - (1 <<KVM_FEATURE_CLOCKSOURCE_STABLE_BIT ); + (1 <<KVM_FEATURE_CLOCKSOURCE_STABLE_BIT ) | + (1 <<KVM_FEATURE_PV_UNHALT );if (sched_info_on ()) entry->eax |= (1 <<KVM_FEATURE_STEAL_TIME );
arch/x86/kvm/x86.c +42 -0
77 lines not on this page · raw message
include/linux/kvm.h +1 -0
@@ -589,6 +589,7 @@ struct kvm_ppc_pvinfo {#define KVM_CAP_S390_UCONTROL 73#define KVM_CAP_SYNC_REGS 74#define KVM_CAP_PCI_2_3 75 +#define KVM_CAP_PV_UNHALT 76#ifdef KVM_CAP_IRQ_ROUTING
include/linux/kvm_para.h +1 -0
@@ -19,6 +19,7 @@#define KVM_HC_MMU_OP 2#define KVM_HC_FEATURES 3#define KVM_HC_PPC_MAP_MAGIC_PAGE 4 +#define KVM_HC_KICK_CPU 5/* * hypercalls use architecture specific
virt/kvm/kvm_main.c +8 -0
@@ -1500,6 +1500,14 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)prepare_to_wait (&vcpu->wq, &wait,TASK_INTERRUPTIBLE );if (kvm_arch_vcpu_runnable (vcpu)) { +/* +* This is the only safe place to reset unhalt flag. +* otherwise it results in loosing the notification +* which eventually can result in vcpu hangs. +*/ +kvm_arch_vcpu_reset_pv_unhalted (vcpu); +/* preventing reordering should be enough here */ +barrier ();kvm_make_request (KVM_REQ_UNHALT , vcpu);break ; }
RFC PATCH v6 2/5 kvm : Fold pv_unhalt flag into GET_MP_STATE ioctl to aid migration
In reply to Raghavendra K TFrom: Raghavendra K T <[email protected]>
---
arch/x86/kvm/x86.c +3 -1
@@ -5691,7 +5691,9 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) { - mp_state->mp_state = vcpu->arch.mp_state; + mp_state->mp_state = (vcpu->arch.mp_state ==KVM_MP_STATE_HALTED && + vcpu->arch.pv.pv_unhalted) ? +KVM_MP_STATE_RUNNABLE : vcpu->arch.mp_state;return 0 ; }
RFC PATCH v6 2/5 kvm : Fold pv_unhalt flag into GET_MP_STATE ioctl to aid migration
In reply to Raghavendra K TFrom: Raghavendra K T <[email protected]>
---
arch/x86/kvm/x86.c +3 -1
@@ -5691,7 +5691,9 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) { - mp_state->mp_state = vcpu->arch.mp_state; + mp_state->mp_state = (vcpu->arch.mp_state ==KVM_MP_STATE_HALTED && + vcpu->arch.pv.pv_unhalted) ? +KVM_MP_STATE_RUNNABLE : vcpu->arch.mp_state;return 0 ; }
RFC PATCH v6 3/5 kvm guest : Add configuration support to enable debug information for KVM Guests
In reply to Raghavendra K TFrom: Srivatsa Vaddagiri <[email protected]>
---
arch/x86/Kconfig +9 -0
@@ -584,6 +584,15 @@ config KVM_GUEST This option enables various optimizations for running under the KVM hypervisor. +config KVM_DEBUG_FS + bool "Enable debug information for KVM Guests in debugfs" + depends on KVM_GUEST && DEBUG_FS + default n + ---help--- + This option enables collection of various statistics for KVM guest. + Statistics are displayed in debugfs filesystem. Enabling this option + may incur significant overhead. + source "arch/x86/lguest/Kconfig" config PARAVIRT
RFC PATCH v6 3/5 kvm guest : Add configuration support to enable debug information for KVM Guests
In reply to Raghavendra K TFrom: Srivatsa Vaddagiri <[email protected]>
---
arch/x86/Kconfig +9 -0
@@ -584,6 +584,15 @@ config KVM_GUEST This option enables various optimizations for running under the KVM hypervisor. +config KVM_DEBUG_FS + bool "Enable debug information for KVM Guests in debugfs" + depends on KVM_GUEST && DEBUG_FS + default n + ---help--- + This option enables collection of various statistics for KVM guest. + Statistics are displayed in debugfs filesystem. Enabling this option + may incur significant overhead. + source "arch/x86/lguest/Kconfig" config PARAVIRT
RFC PATCH v6 4/5 kvm : pv-ticketlocks support for linux guests running on KVM hypervisor
In reply to Raghavendra K TFrom: Srivatsa Vaddagiri <[email protected]>
During smp_boot_cpus paravirtualied KVM guest detects if the hypervisor has required feature (KVM_FEATURE_PV_UNHALT) to support pv-ticketlocks. If so,
support for pv-ticketlocks is registered via pv_lock_ops.
Use KVM_HC_KICK_CPU hypercall to wakeup waiting/halted vcpu.
---
arch/x86/include/asm/kvm_para.h +12 -2
@@ -195,10 +195,20 @@ void kvm_async_pf_task_wait(u32 token);void kvm_async_pf_task_wake (u32 token);u32 kvm_read_and_reset_pf_reason (void );extern void kvm_disable_steal_time (void ); -#else -#define kvm_guest_init () do { } while (0) + +#ifdef CONFIG_PARAVIRT_SPINLOCKS +void __init kvm_spinlock_init (void ); +#else /* !CONFIG_PARAVIRT_SPINLOCKS */ +static inline void kvm_spinlock_init (void ) +{ +} +#endif /* CONFIG_PARAVIRT_SPINLOCKS */ + +#else /* CONFIG_KVM_GUEST */ +#define kvm_guest_init () do {} while (0)#define kvm_async_pf_task_wait (T ) do {} while(0)#define kvm_async_pf_task_wake (T ) do {} while(0) +static inline u32 kvm_read_and_reset_pf_reason (void ) {return 0 ;
arch/x86/kernel/kvm.c +254 -0
269 lines not on this page · raw message
RFC PATCH v6 4/5 kvm : pv-ticketlocks support for linux guests running on KVM hypervisor
In reply to Raghavendra K TFrom: Srivatsa Vaddagiri <[email protected]>
During smp_boot_cpus paravirtualied KVM guest detects if the hypervisor has required feature (KVM_FEATURE_PV_UNHALT) to support pv-ticketlocks. If so,
support for pv-ticketlocks is registered via pv_lock_ops.
Use KVM_HC_KICK_CPU hypercall to wakeup waiting/halted vcpu.
---
arch/x86/include/asm/kvm_para.h +12 -2
@@ -195,10 +195,20 @@ void kvm_async_pf_task_wait(u32 token);void kvm_async_pf_task_wake (u32 token);u32 kvm_read_and_reset_pf_reason (void );extern void kvm_disable_steal_time (void ); -#else -#define kvm_guest_init () do { } while (0) + +#ifdef CONFIG_PARAVIRT_SPINLOCKS +void __init kvm_spinlock_init (void ); +#else /* !CONFIG_PARAVIRT_SPINLOCKS */ +static inline void kvm_spinlock_init (void ) +{ +} +#endif /* CONFIG_PARAVIRT_SPINLOCKS */ + +#else /* CONFIG_KVM_GUEST */ +#define kvm_guest_init () do {} while (0)#define kvm_async_pf_task_wait (T ) do {} while(0)#define kvm_async_pf_task_wake (T ) do {} while(0) +static inline u32 kvm_read_and_reset_pf_reason (void ) {return 0 ;
arch/x86/kernel/kvm.c +254 -0
269 lines not on this page · raw message
RFC PATCH v6 4/5 kvm : pv-ticketlocks support for linux guests running on KVM hypervisor
In reply to Raghavendra K TFrom: Srivatsa Vaddagiri <[email protected]>
During smp_boot_cpus paravirtualied KVM guest detects if the hypervisor has required feature (KVM_FEATURE_PV_UNHALT) to support pv-ticketlocks. If so,
support for pv-ticketlocks is registered via pv_lock_ops.
Use KVM_HC_KICK_CPU hypercall to wakeup waiting/halted vcpu.
---
arch/x86/include/asm/kvm_para.h +12 -2
@@ -195,10 +195,20 @@ void kvm_async_pf_task_wait(u32 token);void kvm_async_pf_task_wake (u32 token);u32 kvm_read_and_reset_pf_reason (void );extern void kvm_disable_steal_time (void ); -#else -#define kvm_guest_init () do { } while (0) + +#ifdef CONFIG_PARAVIRT_SPINLOCKS +void __init kvm_spinlock_init (void ); +#else /* !CONFIG_PARAVIRT_SPINLOCKS */ +static inline void kvm_spinlock_init (void ) +{ +} +#endif /* CONFIG_PARAVIRT_SPINLOCKS */ + +#else /* CONFIG_KVM_GUEST */ +#define kvm_guest_init () do {} while (0)#define kvm_async_pf_task_wait (T ) do {} while(0)#define kvm_async_pf_task_wake (T ) do {} while(0) +static inline u32 kvm_read_and_reset_pf_reason (void ) {return 0 ;
arch/x86/kernel/kvm.c +254 -0
269 lines not on this page · raw message
RFC PATCH v6 5/5 Documentation/kvm : Add documentation on Hypercalls and features used for PV spinlock
In reply to Raghavendra K TFrom: Raghavendra K T <[email protected]>
KVM_HC_KICK_CPU hypercall added to wakeup halted vcpu in paravirtual spinlock enabled guest.
KVM_FEATURE_PV_UNHALT enables guest to check whether pv spinlock can be enabled in guest. support in host is queried via ioctl(KVM_CHECK_EXTENSION, KVM_CAP_PV_UNHALT)
Thanks Alex for KVM_HC_FEATURES inputs and Vatsa for rewriting KVM_HC_KICK_CPU
---
Documentation/virtual/kvm/api.txt +7 -0
@@ -1119,6 +1119,13 @@ support. Instead it is reported via if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the feature in userspace, then you can enable the feature for KVM_SET_CPUID2. +Paravirtualized ticket spinlocks can be enabled in guest by checking whether +support exists in host via, + + ioctl(KVM_CHECK_EXTENSION, KVM_CAP_PV_UNHALT) + +if this call return true, guest can use the feature. + 4.47 KVM_PPC_GET_PVINFO Capability: KVM_CAP_PPC_GET_PVINFO
Documentation/virtual/kvm/cpuid.txt +4 -0
@@ -39,6 +39,10 @@ KVM_FEATURE_CLOCKSOURCE2 || 3 || kvmclock available at msrs KVM_FEATURE_ASYNC_PF || 4 || async pf can be enabled by || || writing to msr 0x4b564d02 ------------------------------------------------------------------------------ +KVM_FEATURE_PV_UNHALT || 6 || guest checks this feature bit + || || before enabling paravirtualized + || || spinlock support. +------------------------------------------------------------------------------ KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side || || per-cpu warps are expected in || || kvmclock.
Documentation/virtual/kvm/hypercalls.txt new file +59 -0
59 lines not on this page · raw message
RFC PATCH v6 5/5 Documentation/kvm : Add documentation on Hypercalls and features used for PV spinlock
In reply to Raghavendra K TFrom: Raghavendra K T <[email protected]>
KVM_HC_KICK_CPU hypercall added to wakeup halted vcpu in paravirtual spinlock enabled guest.
KVM_FEATURE_PV_UNHALT enables guest to check whether pv spinlock can be enabled in guest. support in host is queried via ioctl(KVM_CHECK_EXTENSION, KVM_CAP_PV_UNHALT)
Thanks Alex for KVM_HC_FEATURES inputs and Vatsa for rewriting KVM_HC_KICK_CPU
---
Documentation/virtual/kvm/api.txt +7 -0
@@ -1119,6 +1119,13 @@ support. Instead it is reported via if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the feature in userspace, then you can enable the feature for KVM_SET_CPUID2. +Paravirtualized ticket spinlocks can be enabled in guest by checking whether +support exists in host via, + + ioctl(KVM_CHECK_EXTENSION, KVM_CAP_PV_UNHALT) + +if this call return true, guest can use the feature. + 4.47 KVM_PPC_GET_PVINFO Capability: KVM_CAP_PPC_GET_PVINFO
Documentation/virtual/kvm/cpuid.txt +4 -0
@@ -39,6 +39,10 @@ KVM_FEATURE_CLOCKSOURCE2 || 3 || kvmclock available at msrs KVM_FEATURE_ASYNC_PF || 4 || async pf can be enabled by || || writing to msr 0x4b564d02 ------------------------------------------------------------------------------ +KVM_FEATURE_PV_UNHALT || 6 || guest checks this feature bit + || || before enabling paravirtualized + || || spinlock support. +------------------------------------------------------------------------------ KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side || || per-cpu warps are expected in || || kvmclock.
Documentation/virtual/kvm/hypercalls.txt new file +59 -0
59 lines not on this page · raw message
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Raghavendra K TQuoted 141 lines · Raghavendra K T
From: Srivatsa Vaddagiri <[email protected]>
KVM_HC_KICK_CPUallows the calling vcpu to kick another vcpu out of halt state.The presence of these hypercalls is indicated to guest via KVM_FEATURE_PV_UNHALT/KVM_CAP_PV_UNHALT.
Signed-off-by Srivatsa Vaddagiri <[email protected]>Signed-off-by Suzuki Poulose <[email protected]>Signed-off-by Raghavendra K T <[email protected]>---
arch/ia64/include/asm/kvm_host.h +3
-0@@ -597,6 +597,9 @@ void kvm_sal_emul(struct kvm_vcpu *vcpu);struct kvm *kvm_arch_alloc_vm (void );void kvm_arch_free_vm (struct kvm *kvm); +static inline void kvm_arch_vcpu_reset_pv_unhalted (struct kvm_vcpu *vcpu) +{ +}#endif /* __ASSEMBLY__*/ #endif arch/powerpc/include/asm/kvm_host.h +4
-0@@ -498,4 +498,8 @@ struct kvm_vcpu_arch {#define KVM_MMIO_REG_QPR 0x0040#define KVM_MMIO_REG_FQPR 0x0060 +static inline void kvm_arch_vcpu_reset_pv_unhalted (struct kvm_vcpu *vcpu) +{ +} +#endif /* __POWERPC_KVM_HOST_H__ */ arch/s390/include/asm/kvm_host.h +4
-0@@ -256,4 +256,8 @@ struct kvm_arch{ };extern int sie64a (struct kvm_s390_sie_block *,u64 *); +static inline void kvm_arch_vcpu_reset_pv_unhalted (struct kvm_vcpu *vcpu) +{ +} +#endif arch/x86/include/asm/kvm_host.h +6
-0@@ -481,6 +481,10 @@ struct kvm_vcpu_arch {u64 length;u64 status; } osvw; +/* pv related host specific info */ +struct { +int pv_unhalted; + } pv; };struct kvm_lpage_info {@@ -967,4 +971,6 @@ int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data);void kvm_handle_pmu_event (struct kvm_vcpu *vcpu);void kvm_deliver_pmi (struct kvm_vcpu *vcpu); +void kvm_arch_vcpu_reset_pv_unhalted (struct kvm_vcpu *vcpu); +#endif /* _ASM_X86_KVM_HOST_H */ arch/x86/include/asm/kvm_para.h +2
-0@@ -16,12 +16,14 @@#define KVM_FEATURE_CLOCKSOURCE 0#define KVM_FEATURE_NOP_IO_DELAY 1#define KVM_FEATURE_MMU_OP 2 +/* This indicates that the new set of kvmclock msrs * are available. The use of 0x11 and 0x12 is deprecated */ #define KVM_FEATURE_CLOCKSOURCE2 3#define KVM_FEATURE_ASYNC_PF 4#define KVM_FEATURE_STEAL_TIME 5 +#define KVM_FEATURE_PV_UNHALT 6/* The last 8 bits are used to indicate how to interpret the flags field * in pvclock structure. If no bits are set, all flags are ignored. arch/x86/kvm/cpuid.c +2
-1@@ -408,7 +408,8 @@ static int do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, (1 <<KVM_FEATURE_NOP_IO_DELAY ) | (1 <<KVM_FEATURE_CLOCKSOURCE2 ) | (1 <<KVM_FEATURE_ASYNC_PF ) | - (1 <<KVM_FEATURE_CLOCKSOURCE_STABLE_BIT ); + (1 <<KVM_FEATURE_CLOCKSOURCE_STABLE_BIT ) | + (1 <<KVM_FEATURE_PV_UNHALT );if (sched_info_on ()) entry->eax |= (1 <<KVM_FEATURE_STEAL_TIME );arch/x86/kvm/x86.c +20
-0@@ -2147,6 +2147,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_ASYNC_PF :case KVM_CAP_GET_TSC_KHZ :case KVM_CAP_PCI_2_3 : +case KVM_CAP_PV_UNHALT : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :@@ -4993,6 +4994,36 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)return 1 ; } +/* +* kvm_pv_kick_cpu_op: Kick a vcpu. +* +* @apicid - apicid of vcpu to be kicked. +*/ +static void kvm_pv_kick_cpu_op (struct kvm *kvm,int apicid) +{ +struct kvm_vcpu *vcpu =NULL ; +int i; + +kvm_for_each_vcpu (i, vcpu, kvm) { +if (!kvm_apic_present (vcpu)) +continue ; + +if (kvm_apic_match_dest (vcpu,0 ,0 , apicid,0 )) +break ; + } +if (vcpu) { +/*
arch/x86/kvm/x86.c int kvm_hv_hypercall(struct kvm_vcpu *vcpu) · line 5025
Quoted 10 lines
arch/x86/kvm/x86.c +10
-0+* Setting unhalt flag here can result in spurious runnable +* state when unhalt reset does not happen in vcpu_block. +* But that is harmless since that should soon result in halt. +*/ + vcpu->arch.pv.pv_unhalted =1 ; +/* We need everybody see unhalt before vcpu unblocks */ +smp_mb (); +kvm_vcpu_kick (vcpu); + } +}
This is too similar to kvm_irq_delivery_to_apic(). Why not reuse it. We can use one of reserved delivery modes as PV delivery mode. We will disallow guest to trigger it through apic interface, so this will not be part of ABI and can be changed at will.
Quoted 70 lines
arch/x86/kvm/x86.c +12
-0+int kvm_emulate_hypercall (struct kvm_vcpu *vcpu) {unsigned long nr, a0, a1, a2, a3, ret;@@ -5026,6 +5057,10 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)case KVM_HC_VAPIC_POLL_IRQ : ret =0 ;break ; +case KVM_HC_KICK_CPU : +kvm_pv_kick_cpu_op (vcpu->kvm, a0); + ret =0 ; +break ;default : ret = -KVM_ENOSYS ;break ;@@ -6128,6 +6163,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)BUG_ON (vcpu->kvm ==NULL ); kvm = vcpu->kvm; +kvm_arch_vcpu_reset_pv_unhalted (vcpu); vcpu->arch.emulate_ctxt.ops = &emulate_ops;if (!irqchip_in_kernel (kvm) ||kvm_vcpu_is_bsp (vcpu)) vcpu->arch.mp_state =KVM_MP_STATE_RUNNABLE ;@@ -6398,11 +6434,17 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu) !vcpu->arch.apf.halted) || !list_empty_careful (&vcpu->async_pf.done) || vcpu->arch.mp_state ==KVM_MP_STATE_SIPI_RECEIVED + || vcpu->arch.pv.pv_unhalted ||atomic_read (&vcpu->arch.nmi_queued) || (kvm_arch_interrupt_allowed (vcpu) &&kvm_cpu_has_interrupt (vcpu)); } +void kvm_arch_vcpu_reset_pv_unhalted (struct kvm_vcpu *vcpu) +{ + vcpu->arch.pv.pv_unhalted =0 ; +} +void kvm_vcpu_kick (struct kvm_vcpu *vcpu) {int me;include/linux/kvm.h +1
-0@@ -589,6 +589,7 @@ struct kvm_ppc_pvinfo {#define KVM_CAP_S390_UCONTROL 73#define KVM_CAP_SYNC_REGS 74#define KVM_CAP_PCI_2_3 75 +#define KVM_CAP_PV_UNHALT 76#ifdef KVM_CAP_IRQ_ROUTING include/linux/kvm_para.h +1
-0@@ -19,6 +19,7 @@#define KVM_HC_MMU_OP 2#define KVM_HC_FEATURES 3#define KVM_HC_PPC_MAP_MAGIC_PAGE 4 +#define KVM_HC_KICK_CPU 5/* * hypercalls use architecture specific virt/kvm/kvm_main.c +0
-0
virt/kvm/kvm_main.c void kvm_vcpu_block(struct kvm_vcpu *vcpu) · line 1507
Quoted 8 lines
virt/kvm/kvm_main.c +5
-0@@ -1500,6 +1500,14 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)prepare_to_wait (&vcpu->wq, &wait,TASK_INTERRUPTIBLE );if (kvm_arch_vcpu_runnable (vcpu)) { +/* +* This is the only safe place to reset unhalt flag. +* otherwise it results in loosing the notification +* which eventually can result in vcpu hangs. +*/
Why this is the only safe place? Why clearing it in kvm/x86.c just after call to kvm_vcpu_block() if KVM_REQ_UNHALT is set is not safe enough?
virt/kvm/kvm_main.c void kvm_vcpu_block(struct kvm_vcpu *vcpu) · line 1513
Quoted 6 lines
virt/kvm/kvm_main.c +3
-0+kvm_arch_vcpu_reset_pv_unhalted (vcpu); +/* preventing reordering should be enough here */ +barrier ();kvm_make_request (KVM_REQ_UNHALT , vcpu);break ; }
--
Gleb.
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
Quoted 2 lines · Gleb Natapov
Quoted 1 line · Raghavendra K T
From: Srivatsa Vaddagiri<[email protected]>
[...]
Quoted 7 lines
Quoted 7 lines
virt/kvm/kvm_main.c +0
-0@@ -1500,6 +1500,14 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)prepare_to_wait (&vcpu->wq,&wait,TASK_INTERRUPTIBLE );
Quoted 9 lines
virt/kvm/kvm_main.c void kvm_vcpu_block(struct kvm_vcpu *vcpu) · line 1507
Quoted 6 lines
virt/kvm/kvm_main.c +5
-0if (kvm_arch_vcpu_runnable (vcpu)) { +/* +* This is the only safe place to reset unhalt flag. +* otherwise it results in loosing the notification +* which eventually can result in vcpu hangs. +*/ Why this is the only safe place? Why clearing it in
kvm/x86.cjust after call tokvm_vcpu_block()ifKVM_REQ_UNHALTis set is not safe enough?
Yes, You are Right. The acceptable window to reset the flag can be extended till there. and Good point about that is it removes the need for having the stubs for other archs and simplifies everything a lot. Thanks for that.
[ When I was experimenting with request bit, clearing request bit in the same place was causing vm hang after some 16 iteration of stress test. I had carried the same impression. Now I have done stress testing to ensure that the change works. Basically as you know, my fear was loosing kick(s) leads to vm hang eventually. ]
Re: [PATCH RFC V6 5/5] Documentation/kvm : Add documentation on Hypercalls and features used for PV spinlock
In reply to Raghavendra K TQuoted 1 line · Raghavendra K T
From: Raghavendra K T <[email protected]>
...
Documentation/virtual/kvm/hypercalls.txt line 4
Quoted 7 lines
Documentation/virtual/kvm/hypercalls.txt new file +4
-0@@ -0,0 +1,59 @@ +KVM Hypercalls Documentation +=========================== +Template for documentation is +The documenenation for hypercalls should inlcude
What does the line about templates mean/
documenenation? inlcude?
Documentation/virtual/kvm/hypercalls.txt line 15
Quoted 11 lines
Documentation/virtual/kvm/hypercalls.txt new file +11
-0+1. Hypercall name, value. +2. Architecture(s) +3. status (deprecated, obsolete, active) +4. Purpose + + +1. KVM_HC_VAPIC_POLL_IRQ +------------------------ +value: 1 +Architecture: x86 +Purpose:
Purpose: none.
Rob
Signature · 2 lines
GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code. Either it's "mere aggregation", or a license violation. Pick one.
Re: [PATCH RFC V6 5/5] Documentation/kvm : Add documentation on Hypercalls and features used for PV spinlock
In reply to Raghavendra K TQuoted 1 line · Raghavendra K T
From: Raghavendra K T <[email protected]>
...
Documentation/virtual/kvm/hypercalls.txt line 4
Quoted 7 lines
Documentation/virtual/kvm/hypercalls.txt new file +4
-0@@ -0,0 +1,59 @@ +KVM Hypercalls Documentation +=========================== +Template for documentation is +The documenenation for hypercalls should inlcude
What does the line about templates mean/
documenenation? inlcude?
Documentation/virtual/kvm/hypercalls.txt line 15
Quoted 11 lines
Documentation/virtual/kvm/hypercalls.txt new file +11
-0+1. Hypercall name, value. +2. Architecture(s) +3. status (deprecated, obsolete, active) +4. Purpose + + +1. KVM_HC_VAPIC_POLL_IRQ +------------------------ +value: 1 +Architecture: x86 +Purpose:
Purpose: none.
Rob
Signature · 2 lines
GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code. Either it's "mere aggregation", or a license violation. Pick one.
Re: [PATCH RFC V6 5/5] Documentation/kvm : Add documentation on Hypercalls and features used for PV spinlock
In reply to Rob LandleyQuoted 13 lines · Rob Landley
Quoted 1 line · Raghavendra K T
From: Raghavendra K T<[email protected]>
...
Documentation/virtual/kvm/hypercalls.txt line 4
Quoted 7 lines
Documentation/virtual/kvm/hypercalls.txt new file +4
-0@@ -0,0 +1,59 @@ +KVM Hypercalls Documentation +=========================== +Template for documentation is +The documenenation for hypercalls should inlcudeWhat does the line about templates mean/
Quoted 1 line
documenenation? inlcude?
I think I should correct some redundant statements here. The template is meant for current "structure / layout of hypercall documentation".
Quoted 15 lines
Documentation/virtual/kvm/hypercalls.txt line 15
Quoted 12 lines
Documentation/virtual/kvm/hypercalls.txt new file +11
-0+1. Hypercall name, value. +2. Architecture(s) +3. status (deprecated, obsolete, active) +4. Purpose + + +1. KVM_HC_VAPIC_POLL_IRQ +------------------------ +value: 1 +Architecture: x86 +Purpose:Purpose: none.
Will add this when I respin the patch soon
Quoted 1 line
Rob
Thanks for review.
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Gleb NatapovQuoted 12 lines · Gleb Natapov
Quoted 11 lines · Raghavendra K T
From: Srivatsa Vaddagiri<[email protected]>
KVM_HC_KICK_CPUallows the calling vcpu to kick another vcpu out of halt state.The presence of these hypercalls is indicated to guest via KVM_FEATURE_PV_UNHALT/KVM_CAP_PV_UNHALT.
Signed-off-by Srivatsa Vaddagiri<[email protected]>Signed-off-by Suzuki Poulose<[email protected]>Signed-off-by Raghavendra K T<[email protected]>---
[...]
Quoted 25 lines
Quoted 25 lines
arch/x86/kvm/x86.c +25
-0+/* +* kvm_pv_kick_cpu_op: Kick a vcpu. +* +* @apicid - apicid of vcpu to be kicked. +*/ +static void kvm_pv_kick_cpu_op (struct kvm *kvm,int apicid) +{ +struct kvm_vcpu *vcpu =NULL ; +int i; + +kvm_for_each_vcpu (i, vcpu, kvm) { +if (!kvm_apic_present (vcpu)) +continue ; + +if (kvm_apic_match_dest (vcpu,0 ,0 , apicid,0 )) +break ; + } +if (vcpu) { +/* +* Setting unhalt flag here can result in spurious runnable +* state when unhalt reset does not happen in vcpu_block. +* But that is harmless since that should soon result in halt. +*/ + vcpu->arch.pv.pv_unhalted =1 ; +/* We need everybody see unhalt before vcpu unblocks */
Quoted 9 lines
arch/x86/kvm/x86.c int kvm_hv_hypercall(struct kvm_vcpu *vcpu) · line 5025
Quoted 4 lines
arch/x86/kvm/x86.c +4
-0+smp_mb (); +kvm_vcpu_kick (vcpu); + } +}This is too similar to
kvm_irq_delivery_to_apic(). Why not reuse it. We can use one of reserved delivery modes as PV delivery mode. We will disallow guest to trigger it through apic interface, so this will not be part of ABI and can be changed at will.
I think it is interesting ( Perhaps more reasonable way of doing it). I am not too familiar with lapic source. So, pardon me if my questions are stupid.
Something like below is what I deciphered from your suggestion which is working.
kvm/x86.c
=========kvm_pv_kick_cpu_op()
{
struct kvm_lapic_irq lapic_irq;
lapic_irq.shorthand = 0;
lapic_irq.dest_mode = 0;
lapic_irq.dest_id = apicid;
lapic_irq.delivery_mode = PV_DELIVERY_MODE;
kvm_irq_delivery_to_apic(kvm, 0, &lapic_irq );
}
kvm/lapic.c
==========_apic_accept_irq()
{
...
case APIC_DM_REMRD:
result = 1;
vcpu->pv_unhalted = 1
smp_mb();
kvm_make_request(KVM_REQ_EVENT, vcpu);
kvm_vcpu_kick(vcpu);
break;...
}
here using PV_DELIVERY_MODE = APIC_DM_REMRD, which was unused.
OR
1) Are you asking to remove vcpu->pv_unhalted flag and replace with an irq?
2) are you talking about some reserved fields in struct local_apic instead of APIC_DM_REMRD what I have used above?
[ Honestly, arch/x86/include/asm/apicdef.h had too much of info to digest :( ]
3) I am not sure about: disallow guest to trigger it through apic interface part also.(mean howto?)
4) And one more question, So you think it takes care of migration part
(in case we are removing pv_unhalted flag)?
It would be helpful if you can give little more explanation/ pointer to Documentation.
Ingo is keen to see whole ticketlock/Xen/KVM patch in one go.
and anyhow since this does not cause any ABI change, I hope you don't mind if
I do only the vcpu->pv_unhalted change you suggested now [ having pv_unhalted reset in vcpu_run if you meant something else than code I have above ], so that whole series get fair amount time for testing.
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
Quoted 85 lines · Raghavendra K T
Quoted 12 lines · Gleb Natapov
Quoted 11 lines · Raghavendra K T
From: Srivatsa Vaddagiri<[email protected]>
KVM_HC_KICK_CPUallows the calling vcpu to kick another vcpu out of halt state.The presence of these hypercalls is indicated to guest via KVM_FEATURE_PV_UNHALT/KVM_CAP_PV_UNHALT.
Signed-off-by Srivatsa Vaddagiri<[email protected]>Signed-off-by Suzuki Poulose<[email protected]>Signed-off-by Raghavendra K T<[email protected]>---
[...]
Quoted 25 lines
Quoted 25 lines
arch/x86/kvm/x86.c +25
-0+/* +* kvm_pv_kick_cpu_op: Kick a vcpu. +* +* @apicid - apicid of vcpu to be kicked. +*/ +static void kvm_pv_kick_cpu_op (struct kvm *kvm,int apicid) +{ +struct kvm_vcpu *vcpu =NULL ; +int i; + +kvm_for_each_vcpu (i, vcpu, kvm) { +if (!kvm_apic_present (vcpu)) +continue ; + +if (kvm_apic_match_dest (vcpu,0 ,0 , apicid,0 )) +break ; + } +if (vcpu) { +/* +* Setting unhalt flag here can result in spurious runnable +* state when unhalt reset does not happen in vcpu_block. +* But that is harmless since that should soon result in halt. +*/ + vcpu->arch.pv.pv_unhalted =1 ; +/* We need everybody see unhalt before vcpu unblocks */ Quoted 9 lines
arch/x86/kvm/x86.c int kvm_hv_hypercall(struct kvm_vcpu *vcpu) · line 5025
Quoted 4 lines
arch/x86/kvm/x86.c +4
-0+smp_mb (); +kvm_vcpu_kick (vcpu); + } +}This is too similar to
kvm_irq_delivery_to_apic(). Why not reuse it. We can use one of reserved delivery modes as PV delivery mode. We will disallow guest to trigger it through apic interface, so this will not be part of ABI and can be changed at will.I think it is interesting ( Perhaps more reasonable way of doing it). I am not too familiar with lapic source. So, pardon me if my questions are stupid.
Something like below is what I deciphered from your suggestion which is working.
kvm/x86.c
=========kvm_pv_kick_cpu_op()
{struct
kvm_lapic_irqlapic_irq;lapic_irq.shorthand = 0;
lapic_irq.dest_mode = 0;
lapic_irq.dest_id = apicid;lapic_irq.delivery_mode =
PV_DELIVERY_MODE;
kvm_irq_delivery_to_apic(kvm, 0, &lapic_irq );}
kvm/lapic.c
==========_apic_accept_irq()
{
...
caseAPIC_DM_REMRD:result = 1; vcpu->pv_unhalted = 1 smp_mb(); kvm_make_request(KVM_REQ_EVENT, vcpu); kvm_vcpu_kick(vcpu); break;
Quoted 5 lines
...
}here using
PV_DELIVERY_MODE=APIC_DM_REMRD, which was unused.
Yes, this is what I mean except that PV_DELIVERY_MODE should be number defined as reserved by Intel spec.
Quoted 2 lines
OR
1) Are you asking to removevcpu->pv_unhaltedflag and replace with an irq?
I would like to remove vcpu->pv_unhalted, but do not see how to do that, so I do not asking that :)
Quoted 2 lines
2) are you talking about some reserved fields in struct
local_apicinstead ofAPIC_DM_REMRDwhat I have used above?
Delivery modes 011b and 111b are reserved. We can use one if them.
Quoted 5 lines
[ Honestly,
arch/x86/include/asm/apicdef.hhad too much of info to digest :( ]3) I am not sure about: disallow guest to trigger it through apic interface part also.(mean howto?)
I mean we should disallow guest to set delivery mode to reserved values through apic interface.
Quoted 2 lines
4) And one more question, So you think it takes care of migration part (in case we are removing
pv_unhaltedflag)?
No, since I am not asking for removing pv_unhalted flag. I want to reuse code that we already have to deliver the unhalt event.
Quoted 11 lines
It would be helpful if you can give little more explanation/ pointer to Documentation.
Ingo is keen to see whole ticketlock/Xen/KVM patch in one go. and anyhow since this does not cause any ABI change, I hope you don't mind if
I do only thevcpu->pv_unhaltedchange you suggested now [ havingpv_unhaltedreset invcpu_runif
you meant something else than code I have above ], so that whole series get fair amount time for testing.
--
Gleb.
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Gleb NatapovQuoted 26 lines · Gleb Natapov
Quoted 26 lines
arch/x86/kvm/x86.c +25
-0+/* +* kvm_pv_kick_cpu_op: Kick a vcpu. +* +* @apicid - apicid of vcpu to be kicked. +*/ +static void kvm_pv_kick_cpu_op (struct kvm *kvm,int apicid) +{ +struct kvm_vcpu *vcpu =NULL ; +int i; + +kvm_for_each_vcpu (i, vcpu, kvm) { +if (!kvm_apic_present (vcpu)) +continue ; + +if (kvm_apic_match_dest (vcpu,0 ,0 , apicid,0 )) +break ; + } +if (vcpu) { +/* +* Setting unhalt flag here can result in spurious runnable +* state when unhalt reset does not happen in vcpu_block. +* But that is harmless since that should soon result in halt. +*/ + vcpu->arch.pv.pv_unhalted =1 ; +/* We need everybody see unhalt before vcpu unblocks */
Quoted 9 lines
arch/x86/kvm/x86.c int kvm_hv_hypercall(struct kvm_vcpu *vcpu) · line 5025
Quoted 4 lines
arch/x86/kvm/x86.c +4
-0+smp_mb (); +kvm_vcpu_kick (vcpu); + } +}This is too similar to
kvm_irq_delivery_to_apic(). Why not reuse it. We can use one of reserved delivery modes as PV delivery mode. We will disallow guest to trigger it through apic interface, so this will not be part of ABI and can be changed at will.
I'm not thrilled about this. Those delivery modes will eventually become unreserved. We can have a kvm_lookup_apic_id() that is shared among implementations.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
Quoted 37 lines · Avi Kivity
Quoted 26 lines · Gleb Natapov
Quoted 26 lines
arch/x86/kvm/x86.c +25
-0+/* +* kvm_pv_kick_cpu_op: Kick a vcpu. +* +* @apicid - apicid of vcpu to be kicked. +*/ +static void kvm_pv_kick_cpu_op (struct kvm *kvm,int apicid) +{ +struct kvm_vcpu *vcpu =NULL ; +int i; + +kvm_for_each_vcpu (i, vcpu, kvm) { +if (!kvm_apic_present (vcpu)) +continue ; + +if (kvm_apic_match_dest (vcpu,0 ,0 , apicid,0 )) +break ; + } +if (vcpu) { +/* +* Setting unhalt flag here can result in spurious runnable +* state when unhalt reset does not happen in vcpu_block. +* But that is harmless since that should soon result in halt. +*/ + vcpu->arch.pv.pv_unhalted =1 ; +/* We need everybody see unhalt before vcpu unblocks */ Quoted 9 lines
arch/x86/kvm/x86.c int kvm_hv_hypercall(struct kvm_vcpu *vcpu) · line 5025
Quoted 4 lines
arch/x86/kvm/x86.c +4
-0+smp_mb (); +kvm_vcpu_kick (vcpu); + } +}This is too similar to
kvm_irq_delivery_to_apic(). Why not reuse it. We can use one of reserved delivery modes as PV delivery mode. We will disallow guest to trigger it through apic interface, so this will not be part of ABI and can be changed at will.
Quoted 4 lines
I'm not thrilled about this. Those delivery modes will eventually become unreserved. We can have a
kvm_lookup_apic_id()that is shared among implementations.
This is only internal implementation. If they become unreserved we will use something else.
--
Gleb.
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Raghavendra K TQuoted 13 lines · Raghavendra K T
From: Srivatsa Vaddagiri <[email protected]>
KVM_HC_KICK_CPUallows the calling vcpu to kick another vcpu out of halt state.The presence of these hypercalls is indicated to guest via KVM_FEATURE_PV_UNHALT/KVM_CAP_PV_UNHALT.
#endif
arch/x86/include/asm/kvm_host.h +0
-0
arch/x86/include/asm/kvm_host.h struct kvm_vcpu_arch { · line 488
Quoted 8 lines
arch/x86/include/asm/kvm_host.h +4
-0@@ -481,6 +481,10 @@ struct kvm_vcpu_arch {u64 length;u64 status; } osvw; +/* pv related host specific info */ +struct { +int pv_unhalted; + } pv; };
'bool'. Or maybe push into vcpu->requests.
arch/x86/kvm/x86.c int kvm_dev_ioctl_check_extension(long ext) · line 2153
Quoted 13 lines
arch/x86/kvm/x86.c +1
-0@@ -2147,6 +2147,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_ASYNC_PF :case KVM_CAP_GET_TSC_KHZ :case KVM_CAP_PCI_2_3 : +case KVM_CAP_PV_UNHALT : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :
Redundant, since we can infer this from KVM_GET_SUPPORTED_CPUID. But please indicate this in the documentation.
Quoted 17 lines
arch/x86/kvm/x86.c +16
-0+/* +* kvm_pv_kick_cpu_op: Kick a vcpu. +* +* @apicid - apicid of vcpu to be kicked. +*/ +static void kvm_pv_kick_cpu_op (struct kvm *kvm,int apicid) +{ +struct kvm_vcpu *vcpu =NULL ; +int i; + +kvm_for_each_vcpu (i, vcpu, kvm) { +if (!kvm_apic_present (vcpu)) +continue ; + +if (kvm_apic_match_dest (vcpu,0 ,0 , apicid,0 )) +break ;
arch/x86/kvm/x86.c int kvm_hv_hypercall(struct kvm_vcpu *vcpu) · line 5022
Quoted 10 lines
arch/x86/kvm/x86.c +10
-0+ } +if (vcpu) { +/* +* Setting unhalt flag here can result in spurious runnable +* state when unhalt reset does not happen in vcpu_block. +* But that is harmless since that should soon result in halt. +*/ + vcpu->arch.pv.pv_unhalted =1 ; +/* We need everybody see unhalt before vcpu unblocks */ +smp_mb ();
smp_wmb().
Quoted 17 lines
arch/x86/kvm/x86.c +4
-0+kvm_vcpu_kick (vcpu); + } +} +/* * hypercalls use architecture specific virt/kvm/kvm_main.c +1
-0@@ -1500,6 +1500,14 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)prepare_to_wait (&vcpu->wq, &wait,TASK_INTERRUPTIBLE );if (kvm_arch_vcpu_runnable (vcpu)) { +/*
virt/kvm/kvm_main.c void kvm_vcpu_block(struct kvm_vcpu *vcpu) · line 1513
Quoted 10 lines
virt/kvm/kvm_main.c +7
-0+* This is the only safe place to reset unhalt flag. +* otherwise it results in loosing the notification +* which eventually can result in vcpu hangs. +*/ +kvm_arch_vcpu_reset_pv_unhalted (vcpu); +/* preventing reordering should be enough here */ +barrier ();kvm_make_request (KVM_REQ_UNHALT , vcpu);break ; }
Hm, what about reusing KVM_REQ_UNHALT?
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Gleb NatapovQuoted 6 lines · Gleb Natapov
Quoted 6 lines
Quoted 5 lines
This is too similar to
kvm_irq_delivery_to_apic(). Why not reuse it. We can use one of reserved delivery modes as PV delivery mode. We will disallow guest to trigger it through apic interface, so this will not be part of ABI and can be changed at will.
Quoted 7 lines
Quoted 4 lines
I'm not thrilled about this. Those delivery modes will eventually become unreserved. We can have a
kvm_lookup_apic_id()that is shared among implementations.This is only internal implementation. If they become unreserved we will use something else.
Yeah, I'm thinking of that time. Why do something temporary and fragile?
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH RFC V6 2/5] kvm : Fold pv_unhalt flag into GET_MP_STATE ioctl to aid migration
In reply to Raghavendra K TQuoted 9 lines · Raghavendra K T
From: Raghavendra K T <[email protected]>
Signed-off-by Raghavendra K T <[email protected]>---
arch/x86/kvm/x86.c +0
-0
arch/x86/kvm/x86.c int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, · line 5698
Quoted 9 lines
arch/x86/kvm/x86.c +3
-1@@ -5691,7 +5691,9 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) { - mp_state->mp_state = vcpu->arch.mp_state; + mp_state->mp_state = (vcpu->arch.mp_state ==KVM_MP_STATE_HALTED && + vcpu->arch.pv.pv_unhalted) ? +KVM_MP_STATE_RUNNABLE : vcpu->arch.mp_state;return 0 ; }
Not pretty. Suggest rewriting using an if.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Avi KivityQuoted 11 lines · Avi Kivity
Quoted 10 lines · Gleb Natapov
Quoted 10 lines
Quoted 5 lines
This is too similar to
kvm_irq_delivery_to_apic(). Why not reuse it. We can use one of reserved delivery modes as PV delivery mode. We will disallow guest to trigger it through apic interface, so this will not be part of ABI and can be changed at will.I'm not thrilled about this. Those delivery modes will eventually become unreserved. We can have a
kvm_lookup_apic_id()that is shared among implementations.
Quoted 6 lines
Quoted 3 lines
This is only internal implementation. If they become unreserved we will use something else.
Yeah, I'm thinking of that time. Why do something temporary and fragile?
Why is it fragile? Just by unreserving the value Intel will not break KVM. Only when KVM will implement apic feature that unreserves the value we will have to change internal implementation and use another value, but this will be done by the same patch that does unreserving. The unreserving may even never happen. Meanwhile kvm_irq_delivery_to_apic() will likely be optimized to use hash for unicast delivery and unhalt hypercall will benefit from it immediately.
--
Gleb.
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Avi KivityThanks Avi, for the review.
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Raghavendra K T
From: Srivatsa Vaddagiri<[email protected]>
KVM_HC_KICK_CPUallows the calling vcpu to kick another vcpu out of halt state.The presence of these hypercalls is indicated to guest via KVM_FEATURE_PV_UNHALT/KVM_CAP_PV_UNHALT.
Quoted 16 lines
Quoted 6 lines
#endifarch/x86/include/asm/kvm_host.h +0
-0arch/x86/include/asm/kvm_host.h struct kvm_vcpu_arch { · line 488
Quoted 8 lines
arch/x86/include/asm/kvm_host.h +4
-0@@ -481,6 +481,10 @@ struct kvm_vcpu_arch {u64 length;u64 status; } osvw; +/* pv related host specific info */ +struct { +int pv_unhalted; + } pv; };'bool'. Or maybe push into
vcpu->requests.
Ok. I think you meant
+ struct {
+ bool pv_unhalted;
+ } pv;
and as discussed in old series (V4), cleaner implementation having vcpu request, would still need a flag to prevent vcpu hang, so back to having one flag.
Quoted 18 lines
Quoted 7 lines
arch/x86/kvm/x86.c +0
-0arch/x86/kvm/x86.c int kvm_dev_ioctl_check_extension(long ext) · line 2153
Quoted 7 lines
arch/x86/kvm/x86.c +1
-0@@ -2147,6 +2147,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_ASYNC_PF :case KVM_CAP_GET_TSC_KHZ :case KVM_CAP_PCI_2_3 : +case KVM_CAP_PV_UNHALT : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :Redundant, since we can infer this from
KVM_GET_SUPPORTED_CPUID. But please indicate this in the documentation.
Ok. will mention that in documentation added for KVM_CAP_PV_UNHALT.
Quoted 21 lines
Quoted 21 lines
arch/x86/kvm/x86.c +20
-0+/* +* kvm_pv_kick_cpu_op: Kick a vcpu. +* +* @apicid - apicid of vcpu to be kicked. +*/ +static void kvm_pv_kick_cpu_op (struct kvm *kvm,int apicid) +{ +struct kvm_vcpu *vcpu =NULL ; +int i; + +kvm_for_each_vcpu (i, vcpu, kvm) { +if (!kvm_apic_present (vcpu)) +continue ; + +if (kvm_apic_match_dest (vcpu,0 ,0 , apicid,0 )) +break ; + } +if (vcpu) { +/* +* Setting unhalt flag here can result in spurious runnable
Quoted 9 lines
arch/x86/kvm/x86.c int kvm_hv_hypercall(struct kvm_vcpu *vcpu) · line 5022
Quoted 6 lines
arch/x86/kvm/x86.c +6
-0+* state when unhalt reset does not happen in vcpu_block. +* But that is harmless since that should soon result in halt. +*/ + vcpu->arch.pv.pv_unhalted =1 ; +/* We need everybody see unhalt before vcpu unblocks */ +smp_mb ();
smp_wmb().
Done.
Quoted 14 lines
Quoted 14 lines
arch/x86/kvm/x86.c +4
-0+kvm_vcpu_kick (vcpu); + } +} +/* * hypercalls use architecture specific virt/kvm/kvm_main.c +0
-0@@ -1500,6 +1500,14 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)prepare_to_wait (&vcpu->wq,&wait,TASK_INTERRUPTIBLE );
Quoted 16 lines
virt/kvm/kvm_main.c void kvm_vcpu_block(struct kvm_vcpu *vcpu) · line 1513
Quoted 13 lines
virt/kvm/kvm_main.c +8
-0if (kvm_arch_vcpu_runnable (vcpu)) { +/* +* This is the only safe place to reset unhalt flag. +* otherwise it results in loosing the notification +* which eventually can result in vcpu hangs. +*/ +kvm_arch_vcpu_reset_pv_unhalted (vcpu); +/* preventing reordering should be enough here */ +barrier ();kvm_make_request (KVM_REQ_UNHALT , vcpu);break ; }Hm, what about reusing
KVM_REQ_UNHALT?
Yes, I had experimented this for some time without success. For e.g. havingmake_request(KVM_REQ_UNHALT, vcpu) directly from kick hypercall.
It would still need a flag. (did not get any alternative so far except the workaround posted in V4) :(
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Avi KivityThanks Avi, for the review.
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Raghavendra K T
From: Srivatsa Vaddagiri<[email protected]>
KVM_HC_KICK_CPUallows the calling vcpu to kick another vcpu out of halt state.The presence of these hypercalls is indicated to guest via KVM_FEATURE_PV_UNHALT/KVM_CAP_PV_UNHALT.
Quoted 16 lines
Quoted 6 lines
#endifarch/x86/include/asm/kvm_host.h +0
-0arch/x86/include/asm/kvm_host.h struct kvm_vcpu_arch { · line 488
Quoted 8 lines
arch/x86/include/asm/kvm_host.h +4
-0@@ -481,6 +481,10 @@ struct kvm_vcpu_arch {u64 length;u64 status; } osvw; +/* pv related host specific info */ +struct { +int pv_unhalted; + } pv; };'bool'. Or maybe push into
vcpu->requests.
Ok. I think you meant
+ struct {
+ bool pv_unhalted;
+ } pv;
and as discussed in old series (V4), cleaner implementation having vcpu request, would still need a flag to prevent vcpu hang, so back to having one flag.
Quoted 18 lines
Quoted 7 lines
arch/x86/kvm/x86.c +0
-0arch/x86/kvm/x86.c int kvm_dev_ioctl_check_extension(long ext) · line 2153
Quoted 7 lines
arch/x86/kvm/x86.c +1
-0@@ -2147,6 +2147,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_ASYNC_PF :case KVM_CAP_GET_TSC_KHZ :case KVM_CAP_PCI_2_3 : +case KVM_CAP_PV_UNHALT : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :Redundant, since we can infer this from
KVM_GET_SUPPORTED_CPUID. But please indicate this in the documentation.
Ok. will mention that in documentation added for KVM_CAP_PV_UNHALT.
Quoted 21 lines
Quoted 21 lines
arch/x86/kvm/x86.c +20
-0+/* +* kvm_pv_kick_cpu_op: Kick a vcpu. +* +* @apicid - apicid of vcpu to be kicked. +*/ +static void kvm_pv_kick_cpu_op (struct kvm *kvm,int apicid) +{ +struct kvm_vcpu *vcpu =NULL ; +int i; + +kvm_for_each_vcpu (i, vcpu, kvm) { +if (!kvm_apic_present (vcpu)) +continue ; + +if (kvm_apic_match_dest (vcpu,0 ,0 , apicid,0 )) +break ; + } +if (vcpu) { +/* +* Setting unhalt flag here can result in spurious runnable
Quoted 9 lines
arch/x86/kvm/x86.c int kvm_hv_hypercall(struct kvm_vcpu *vcpu) · line 5022
Quoted 6 lines
arch/x86/kvm/x86.c +6
-0+* state when unhalt reset does not happen in vcpu_block. +* But that is harmless since that should soon result in halt. +*/ + vcpu->arch.pv.pv_unhalted =1 ; +/* We need everybody see unhalt before vcpu unblocks */ +smp_mb ();
smp_wmb().
Done.
Quoted 14 lines
Quoted 14 lines
arch/x86/kvm/x86.c +4
-0+kvm_vcpu_kick (vcpu); + } +} +/* * hypercalls use architecture specific virt/kvm/kvm_main.c +0
-0@@ -1500,6 +1500,14 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)prepare_to_wait (&vcpu->wq,&wait,TASK_INTERRUPTIBLE );
Quoted 16 lines
virt/kvm/kvm_main.c void kvm_vcpu_block(struct kvm_vcpu *vcpu) · line 1513
Quoted 13 lines
virt/kvm/kvm_main.c +8
-0if (kvm_arch_vcpu_runnable (vcpu)) { +/* +* This is the only safe place to reset unhalt flag. +* otherwise it results in loosing the notification +* which eventually can result in vcpu hangs. +*/ +kvm_arch_vcpu_reset_pv_unhalted (vcpu); +/* preventing reordering should be enough here */ +barrier ();kvm_make_request (KVM_REQ_UNHALT , vcpu);break ; }Hm, what about reusing
KVM_REQ_UNHALT?
Yes, I had experimented this for some time without success. For e.g. havingmake_request(KVM_REQ_UNHALT, vcpu) directly from kick hypercall.
It would still need a flag. (did not get any alternative so far except the workaround posted in V4) :(
Re: [PATCH RFC V6 2/5] kvm : Fold pv_unhalt flag into GET_MP_STATE ioctl to aid migration
In reply to Avi KivityQuoted 13 lines · Avi Kivity
Quoted 12 lines · Raghavendra K T
From: Raghavendra K T<[email protected]>
Signed-off-by Raghavendra K T<[email protected]>---
arch/x86/kvm/x86.c +0
-0@@ -5691,7 +5691,9 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) {
Quoted 9 lines
arch/x86/kvm/x86.c int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, · line 5698
Quoted 6 lines
arch/x86/kvm/x86.c +3
-1- mp_state->mp_state = vcpu->arch.mp_state; + mp_state->mp_state = (vcpu->arch.mp_state ==KVM_MP_STATE_HALTED && + vcpu->arch.pv.pv_unhalted) ? +KVM_MP_STATE_RUNNABLE : vcpu->arch.mp_state;return 0 ; }Not pretty. Suggest rewriting using an if.
Ok.. 'll rewrite.
Re: [PATCH RFC V6 2/5] kvm : Fold pv_unhalt flag into GET_MP_STATE ioctl to aid migration
In reply to Avi KivityQuoted 13 lines · Avi Kivity
Quoted 12 lines · Raghavendra K T
From: Raghavendra K T<[email protected]>
Signed-off-by Raghavendra K T<[email protected]>---
arch/x86/kvm/x86.c +0
-0@@ -5691,7 +5691,9 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) {
Quoted 9 lines
arch/x86/kvm/x86.c int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, · line 5698
Quoted 6 lines
arch/x86/kvm/x86.c +3
-1- mp_state->mp_state = vcpu->arch.mp_state; + mp_state->mp_state = (vcpu->arch.mp_state ==KVM_MP_STATE_HALTED && + vcpu->arch.pv.pv_unhalted) ? +KVM_MP_STATE_RUNNABLE : vcpu->arch.mp_state;return 0 ; }Not pretty. Suggest rewriting using an if.
Ok.. 'll rewrite.
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Raghavendra K TQuoted 11 lines · Raghavendra K T
Quoted 2 lines
Hm, what about reusing
KVM_REQ_UNHALT?Yes, I had experimented this for some time without success. For e.g. having
make_request(KVM_REQ_UNHALT, vcpu)directly from kick hypercall.It would still need a flag. (did not get any alternative so far except the workaround posted in V4) :(
Okay.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Gleb NatapovQuoted 16 lines · Gleb Natapov
Quoted 15 lines · Avi Kivity
Quoted 13 lines · Gleb Natapov
Quoted 10 lines
Quoted 5 lines
This is too similar to
kvm_irq_delivery_to_apic(). Why not reuse it. We can use one of reserved delivery modes as PV delivery mode. We will disallow guest to trigger it through apic interface, so this will not be part of ABI and can be changed at will.I'm not thrilled about this. Those delivery modes will eventually become unreserved. We can have a
kvm_lookup_apic_id()that is shared among implementations.This is only internal implementation. If they become unreserved we will use something else.
Quoted 7 lines
Quoted 2 lines
Yeah, I'm thinking of that time. Why do something temporary and fragile?
Why is it fragile? Just by unreserving the value Intel will not break KVM. Only when KVM will implement apic feature that unreserves the value we will have to change internal implementation and use another value, but this will be done by the same patch that does unreserving. The unreserving may even never happen.
Some remains of that may leak somewhere. Why not add an extra parameter? Or do something like
kvm_for_each_apic_dest(vcpu, apic_destination) {
...
}That can be reused in both the apic code and pv kick.
Quoted 3 lines
Meanwhile
kvm_irq_delivery_to_apic()
will likely be optimized to use hash for unicast delivery and unhalt hypercall will benefit from it immediately.
Overloading delivery mode is not the only way to achieve sharing.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Gleb Natapov
Quoted 17 lines · Avi Kivity
Quoted 6 lines · Gleb Natapov
Quoted 6 lines
Quoted 5 lines
This is too similar to
kvm_irq_delivery_to_apic(). Why not reuse it. We can use one of reserved delivery modes as PV delivery mode. We will disallow guest to trigger it through apic interface, so this will not be part of ABI and can be changed at will.Quoted 7 lines
Quoted 4 lines
I'm not thrilled about this. Those delivery modes will eventually become unreserved. We can have a
kvm_lookup_apic_id()that is shared among implementations.This is only internal implementation. If they become unreserved we will use something else.
Yeah, I'm thinking of that time. Why do something temporary and fragile?
Quoted 7 lines
Quoted 5 lines
Why is it fragile? Just by unreserving the value Intel will not break KVM. Only when KVM will implement apic feature that unreserves the value we will have to change internal implementation and use another value, but this will be done by the same patch that does unreserving. The unreserving may even never happen.
Some remains of that may leak somewhere.
I do not see where. APIC code should #GP if a guest attempts to set reserved values through APIC interface, or at least ignore them.
Quoted 2 lines
Why not add an extra
parameter?
Yes, we can add extra parameter to "struct kvm_lapic_irq" and propagate it to __apic_accept_irq(). We can do that now, or when Intel unreserve all reserved values. I prefer the later since I do not believe it will happen in observable feature.
Quoted 8 lines
Or do something like
kvm_for_each_apic_dest(vcpu, apic_destination) { ... }That can be reused in both the apic code and pv kick.
That's exactly what kvm_irq_delivery_to_apic() is.
Quoted 6 lines
Quoted 3 lines
Meanwhile
kvm_irq_delivery_to_apic()
will likely be optimized to use hash for unicast delivery and unhalt hypercall will benefit from it immediately.Overloading delivery mode is not the only way to achieve sharing.
It is simplest and most straightforward with no demonstratable drawbacks :) Adding parameter to "struct kvm_lapic_irq" is next best thing.
--
Gleb.
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Raghavendra K TQuoted 17 lines · Raghavendra K T
Quoted 7 lines
Quoted 7 lines
arch/x86/kvm/x86.c +0
-0@@ -2147,6 +2147,7 @@ int kvm_dev_ioctl_check_extension(long ext)case
KVM_CAP_ASYNC_PF:
caseKVM_CAP_GET_TSC_KHZ:Quoted 9 lines
Quoted 5 lines
case
KVM_CAP_PCI_2_3:
+ caseKVM_CAP_PV_UNHALT:
r = 1;
break;
caseKVM_CAP_COALESCED_MMIO:Redundant, since we can infer this from
KVM_GET_SUPPORTED_CPUID. But please indicate this in the documentation.
Quoted 2 lines
Ok. will mention that in documentation added for
KVM_CAP_PV_UNHALT.
I think it is better to remove KVM_CAP_PV_UNHALT itself and avoid spamming CAP.. will do that in coming version.
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Raghavendra K TQuoted 17 lines · Raghavendra K T
Quoted 7 lines
Quoted 7 lines
arch/x86/kvm/x86.c +0
-0@@ -2147,6 +2147,7 @@ int kvm_dev_ioctl_check_extension(long ext)case
KVM_CAP_ASYNC_PF:
caseKVM_CAP_GET_TSC_KHZ:Quoted 9 lines
Quoted 5 lines
case
KVM_CAP_PCI_2_3:
+ caseKVM_CAP_PV_UNHALT:
r = 1;
break;
caseKVM_CAP_COALESCED_MMIO:Redundant, since we can infer this from
KVM_GET_SUPPORTED_CPUID. But please indicate this in the documentation.
Quoted 2 lines
Ok. will mention that in documentation added for
KVM_CAP_PV_UNHALT.
I think it is better to remove KVM_CAP_PV_UNHALT itself and avoid spamming CAP.. will do that in coming version.
Re: [PATCH RFC V6 1/5] kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks
In reply to Gleb NatapovQuoted 48 lines · Gleb Natapov
Quoted 47 lines · Raghavendra K T
Quoted 12 lines · Gleb Natapov
Quoted 11 lines · Raghavendra K T
From: Srivatsa Vaddagiri<[email protected]>
KVM_HC_KICK_CPUallows the calling vcpu to kick another vcpu out of halt state.The presence of these hypercalls is indicated to guest via KVM_FEATURE_PV_UNHALT/KVM_CAP_PV_UNHALT.
Signed-off-by Srivatsa Vaddagiri<[email protected]>Signed-off-by Suzuki Poulose<[email protected]>Signed-off-by Raghavendra K T<[email protected]>---
[...]
Quoted 33 lines
Quoted 19 lines
arch/x86/kvm/x86.c +19
-0+/* +* kvm_pv_kick_cpu_op: Kick a vcpu. +* +* @apicid - apicid of vcpu to be kicked. +*/ +static void kvm_pv_kick_cpu_op (struct kvm *kvm,int apicid) +{ +struct kvm_vcpu *vcpu =NULL ; +int i; + +kvm_for_each_vcpu (i, vcpu, kvm) { +if (!kvm_apic_present (vcpu)) +continue ; + +if (kvm_apic_match_dest (vcpu,0 ,0 , apicid,0 )) +break ; + } +if (vcpu) { +/* arch/x86/kvm/x86.c int kvm_hv_hypercall(struct kvm_vcpu *vcpu) · line 5025
Quoted 10 lines
arch/x86/kvm/x86.c +10
-0+* Setting unhalt flag here can result in spurious runnable +* state when unhalt reset does not happen in vcpu_block. +* But that is harmless since that should soon result in halt. +*/ + vcpu->arch.pv.pv_unhalted =1 ; +/* We need everybody see unhalt before vcpu unblocks */ +smp_mb (); +kvm_vcpu_kick (vcpu); + } +}This is too similar to
kvm_irq_delivery_to_apic(). Why not reuse it. We can use one of reserved delivery modes as PV delivery mode. We will disallow guest to trigger it through apic interface, so this will not be part of ABI and can be changed at will.
[...]
Quoted 29 lines
Quoted 29 lines
kvm/x86.c
=========kvm_pv_kick_cpu_op()
{struct
kvm_lapic_irqlapic_irq;lapic_irq.shorthand = 0; lapic_irq.dest_mode = 0; lapic_irq.dest_id = apicid; lapic_irq.delivery_mode = PV_DELIVERY_MODE; kvm_irq_delivery_to_apic(kvm, 0,&lapic_irq );}
kvm/lapic.c
==========_apic_accept_irq()
{
...
caseAPIC_DM_REMRD:result = 1; vcpu->pv_unhalted = 1 smp_mb(); kvm_make_request(KVM_REQ_EVENT, vcpu); kvm_vcpu_kick(vcpu); break;
Quoted 8 lines
Quoted 5 lines
...
}here using
PV_DELIVERY_MODE=APIC_DM_REMRD, which was unused.Yes, this is what I mean except that
PV_DELIVERY_MODEshould be number defined as reserved by Intel spec.
Hi Gleb, Avi,
This had been TODO in my V8 patches.
I 'll fold this into V9 (while rebasing to
3.5-rc).
Please let me know if it is OK.