VT-d posted-interrupts follow ups
v4 cover VT-d posted-interrupts follow ups
This series contains 4 patches:
[1/4]: Change back to remapped mode when posted mode is not used. [2/4]: Add vector-hashing support to deliver lowest-priority
interrupts for non VT-d PI case.
[3/4]: Add vector-hashing support to deliver lowest-priority
interrupts for VT-d PI case.
[4/4]: Add some enhancement to the trace message for vt-d PI.
Detailed changelog is in each patch.
Feng Wu (4):
KVM: Recover IRTE to remapped mode if the interrupt is not
single-destination
KVM: x86: Use vector-hashing to deliver lowest-priority interrupts
KVM: x86: Add lowest-priority support for vt-d posted-interrupts KVM/VMX: Add host irq information in trace event when updating IRTE
for posted interrupts
arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/irq_comm.c | 25 ++++++++-- arch/x86/kvm/lapic.c | 106 ++++++++++++++++++++++++++++++++++++---- arch/x86/kvm/lapic.h | 2 + arch/x86/kvm/trace.h | 12 +++-- arch/x86/kvm/vmx.c | 17 ++++++- arch/x86/kvm/x86.c | 9 ++++ arch/x86/kvm/x86.h | 1 + 8 files changed, 154 insertions(+), 20 deletions(-)
Signature · 1 line
2.1.0
PATCH v4 1/4 KVM: Recover IRTE to remapped mode if the interrupt is not single-destination
When the interrupt is not single destination any more, we need to change back IRTE to remapped mode explicitly.
---
v4:
- Don't need to Set SN before changing back to remapped mode
arch/x86/kvm/vmx.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx.c +14 -1
@@ -10764,8 +10764,21 @@ static int vmx_update_pi_irte(struct kvm *kvm, unsigned int host_irq,*/ kvm_set_msi_irq (e, &irq); -if (!kvm_intr_is_single_vcpu (kvm, &irq, &vcpu)) +if (!kvm_intr_is_single_vcpu (kvm, &irq, &vcpu)) { +/* +* Make sure the IRTE is in remapped mode if +* we don't handle it in posted mode. +*/ + ret =irq_set_vcpu_affinity (host_irq,NULL ); +if (ret <0 ) { +printk (KERN_INFO +"failed to back to remapped mode, irq: %u\n" , + host_irq); + goto out; + } +continue ; + } vcpu_info.pi_desc_addr =__pa (vcpu_to_pi_desc (vcpu)); vcpu_info.vector = irq.vector;
Signature · 1 line
2.1.0
PATCH v4 2/4 KVM: x86: Use vector-hashing to deliver lowest-priority interrupts
In reply to Feng WuUse vector-hashing to deliver lowest-priority interrupts, As an example, modern Intel CPUs in server platform use this method to handle lowest-priority interrupts.
---
v4:
- Stylistic changes
v3:
- Fix a bug for sparse topologies, in that case, vcpu_id is not equal to the return value got by kvm_get_vcpu().
- Remove unnecessary check in fast irq delivery patch.
- print a error message only once for each guest when we find hardware disabled LAPIC during interrupt injection.
arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/irq_comm.c | 25 +++++++++++++++++---- arch/x86/kvm/lapic.c | 50 ++++++++++++++++++++++++++++++++++++++--- arch/x86/kvm/lapic.h | 2 ++ arch/x86/kvm/x86.c | 9 ++++++++ arch/x86/kvm/x86.h | 1 + 6 files changed, 82 insertions(+), 7 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -0
@@ -754,6 +754,8 @@ struct kvm_arch {bool irqchip_split;u8 nr_reserved_ioapic_pins; + +bool disabled_lapic_found; };struct kvm_vm_stat {
arch/x86/kvm/irq_comm.c +21 -4
@@ -34,6 +34,7 @@#include "lapic.h" #include "hyperv.h" +#include "x86.h" static int kvm_set_pic_irq(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm, int irq_source_id, int level,
@@ -57,6 +58,8 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, {int i, r =-1 ;struct kvm_vcpu *vcpu, *lowest =NULL ; +unsigned long dest_vcpu_bitmap[BITS_TO_LONGS (KVM_MAX_VCPUS )]; +unsigned int dest_vcpus =0 ;if (irq->dest_mode ==0 && irq->dest_id ==0xff &&kvm_lowest_prio_delivery (irq)) {
@@ -67,6 +70,8 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,if (kvm_irq_delivery_to_apic_fast (kvm, src, irq, &r, dest_map))return r; +memset (dest_vcpu_bitmap,0 ,sizeof (dest_vcpu_bitmap)); +kvm_for_each_vcpu (i, vcpu, kvm) {if (!kvm_apic_present (vcpu))continue ;
@@ -80,13 +85,25 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, r =0 ; r +=kvm_apic_set_irq (vcpu, irq, dest_map); }else if (kvm_lapic_enabled (vcpu)) { -if (!lowest) - lowest = vcpu; -else if (kvm_apic_compare_prio (vcpu, lowest) <0 ) - lowest = vcpu; +if (!kvm_vector_hashing_enabled ()) { +if (!lowest) + lowest = vcpu; +else if (kvm_apic_compare_prio (vcpu, lowest) <0 ) + lowest = vcpu; + }else { +__set_bit (i, dest_vcpu_bitmap); + dest_vcpus++; + } } } +if (dest_vcpus !=0 ) { +int idx =kvm_vector_to_index (irq->vector, dest_vcpus, + dest_vcpu_bitmap,KVM_MAX_VCPUS ); + + lowest =kvm_get_vcpu (kvm, idx); + } +if (lowest) r =kvm_apic_set_irq (lowest, irq, dest_map);
arch/x86/kvm/lapic.c +47 -3
74 lines not on this page · raw message
arch/x86/kvm/lapic.h +2 -0
@@ -175,4 +175,6 @@ void wait_lapic_expire(struct kvm_vcpu *vcpu);bool kvm_intr_is_single_vcpu_fast (struct kvm *kvm,struct kvm_lapic_irq *irq,struct kvm_vcpu **dest_vcpu); +int kvm_vector_to_index (u32 vector,u32 dest_vcpus, +const unsigned long *bitmap,u32 bitmap_size);#endif
arch/x86/kvm/x86.c +9 -0
@@ -123,6 +123,9 @@ module_param(tsc_tolerance_ppm, uint, S_IRUGO | S_IWUSR);unsigned int __read_mostly lapic_timer_advance_ns =0 ;module_param (lapic_timer_advance_ns, uint,S_IRUGO |S_IWUSR ); +bool __read_mostly vector_hashing = true; +module_param (vector_hashing, bool,S_IRUGO ); +static bool __read_mostly backwards_tsc_observed = false;#define KVM_NR_SHARED_MSRS 16
@@ -8370,6 +8373,12 @@ int kvm_arch_update_irqfd_routing(struct kvm *kvm, unsigned int host_irq,return kvm_x86_ops->update_pi_irte (kvm, host_irq, guest_irq, set); } +bool kvm_vector_hashing_enabled (void ) +{ +return vector_hashing; +} +EXPORT_SYMBOL_GPL (kvm_vector_hashing_enabled); +EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_exit);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_fast_mmio);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_inj_virq);
arch/x86/kvm/x86.h +1 -0
@@ -179,6 +179,7 @@ int kvm_mtrr_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data);int kvm_mtrr_get_msr (struct kvm_vcpu *vcpu,u32 msr,u64 *pdata);bool kvm_mtrr_check_gfn_range_consistency (struct kvm_vcpu *vcpu,gfn_t gfn,int page_num); +bool kvm_vector_hashing_enabled (void );#define KVM_SUPPORTED_XCR0 (XFEATURE_MASK_FP | XFEATURE_MASK_SSE \ | XFEATURE_MASK_YMM | XFEATURE_MASK_BNDREGS \
Signature · 1 line
2.1.0
PATCH v4 3/4 KVM: x86: Add lowest-priority support for vt-d posted-interrupts
In reply to Feng WuUse vector-hashing to deliver lowest-priority interrupts for VT-d posted-interrupts. This patch extends kvm_intr_is_single_vcpu() to support lowest-priority handling.
---
v4:
- Recover the function name to 'kvm_intr_is_single_vcpu'
- Stylistic changes
v3:
- Remove unnecessary check in fast irq delivery patch
- print a error message only once for each guest when we find hardware disabled LAPIC during interrupt injection.
arch/x86/kvm/lapic.c | 56 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-)
arch/x86/kvm/lapic.c +49 -7
@@ -798,6 +798,20 @@ out:return ret; } +/* +* This routine tries to handler interrupts in posted mode, here is how +* it deals with different cases: +* - For single-destination interrupts, handle it in posted mode +* - Else if vector hashing is enabled and it is a lowest-priority +* interrupt, handle it in posted mode and use the following mechanism +* to find the destinaiton vCPU. +* 1. For lowest-priority interrupts, store all the possible +* destination vCPUs in an array. +* 2. Use "guest vector % max number of destination vCPUs" to find +* the right destination vCPU in the array for the lowest-priority +* interrupt. +* - Otherwise, use remapped mode to inject the interrupt. +*/ bool kvm_intr_is_single_vcpu_fast (struct kvm *kvm,struct kvm_lapic_irq *irq,struct kvm_vcpu **dest_vcpu) {
@@ -839,16 +853,44 @@ bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq,if (cid >=ARRAY_SIZE (map->logical_map)) goto out; -for_each_set_bit (i, &bitmap,16 ) { - dst = map->logical_map[cid][i]; -if (++r ==2 ) +if (kvm_vector_hashing_enabled () && +kvm_lowest_prio_delivery (irq)) { +int idx; +unsigned int dest_vcpus; + + dest_vcpus =hweight16 (bitmap); +if (dest_vcpus ==0 ) goto out; - } -if (dst &&kvm_apic_present (dst->vcpu)) + idx =kvm_vector_to_index (irq->vector, dest_vcpus, + &bitmap,16 ); + +/* +* We may find a hardware disabled LAPIC here, if that +* is the case, print out a error message once for each +* guest and return +*/ + dst = map->logical_map[cid][idx]; +if (!dst && !kvm->arch.disabled_lapic_found) { + kvm->arch.disabled_lapic_found = true; +printk (KERN_INFO +"Disabled LAPIC found during irq injection\n" ); + goto out; + } + *dest_vcpu = dst->vcpu; -else - goto out; + }else { +for_each_set_bit (i, &bitmap,16 ) { + dst = map->logical_map[cid][i]; +if (++r ==2 ) + goto out; + } + +if (dst &&kvm_apic_present (dst->vcpu)) + *dest_vcpu = dst->vcpu; +else + goto out; + } } ret = true;
Signature · 1 line
2.1.0
PATCH v4 4/4 KVM/VMX: Add host irq information in trace event when updating IRTE for posted interrupts
In reply to Feng WuAdd host irq information in trace event, so we can better understand which irq is in posted mode.
--- arch/x86/kvm/trace.h | 12 ++++++++---- arch/x86/kvm/vmx.c | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-)
arch/x86/kvm/trace.h +8 -4
@@ -996,11 +996,13 @@ TRACE_EVENT(kvm_enter_smm,* Tracepoint for VT-d posted-interrupts. */ TRACE_EVENT(kvm_pi_irte_update, - TP_PROTO(unsigned int vcpu_id, unsigned int gsi, - unsigned int gvec, u64 pi_desc_addr, bool set), - TP_ARGS(vcpu_id, gsi, gvec, pi_desc_addr, set), + TP_PROTO(unsigned int host_irq, unsigned int vcpu_id, + unsigned int gsi, unsigned int gvec, + u64 pi_desc_addr, bool set), + TP_ARGS(host_irq, vcpu_id, gsi, gvec, pi_desc_addr, set), TP_STRUCT__entry( + __field( unsigned int, host_irq ) __field( unsigned int, vcpu_id ) __field( unsigned int, gsi ) __field( unsigned int, gvec )
@@ -1009,6 +1011,7 @@ TRACE_EVENT(kvm_pi_irte_update, ), TP_fast_assign( + __entry->host_irq = host_irq; __entry->vcpu_id = vcpu_id; __entry->gsi = gsi; __entry->gvec = gvec;
@@ -1016,9 +1019,10 @@ TRACE_EVENT(kvm_pi_irte_update, __entry->set = set; ), - TP_printk("VT-d PI is %s for this irq, vcpu %u, gsi: 0x%x, " + TP_printk("VT-d PI is %s for irq %u, vcpu %u, gsi: 0x%x, " "gvec: 0x%x, pi_desc_addr: 0x%llx", __entry->set ? "enabled and being updated" : "disabled", + __entry->host_irq, __entry->vcpu_id, __entry->gsi, __entry->gvec,
arch/x86/kvm/vmx.c +1 -1
@@ -10783,7 +10783,7 @@ static int vmx_update_pi_irte(struct kvm *kvm, unsigned int host_irq, vcpu_info.pi_desc_addr =__pa (vcpu_to_pi_desc (vcpu)); vcpu_info.vector = irq.vector; -trace_kvm_pi_irte_update (vcpu->vcpu_id, e->gsi, +trace_kvm_pi_irte_update (vcpu->vcpu_id, host_irq, e->gsi, vcpu_info.vector, vcpu_info.pi_desc_addr, set);if (set)
Signature · 1 line
2.1.0
Re: [PATCH v4 1/4] KVM: Recover IRTE to remapped mode if the interrupt is not single-destination
In reply to Feng Wu2016-01-25 16:53+0800, Feng Wu:
Quoted 5 lines
When the interrupt is not single destination any more, we need to change back IRTE to remapped mode explicitly.
Signed-off-by Feng Wu <[email protected]>---
Re: [PATCH v4 2/4] KVM: x86: Use vector-hashing to deliver lowest-priority interrupts
In reply to Feng Wu2016-01-25 16:53+0800, Feng Wu:
Quoted 6 lines
Use vector-hashing to deliver lowest-priority interrupts, As an example, modern Intel CPUs in server platform use this method to handle lowest-priority interrupts.
Signed-off-by Feng Wu <[email protected]>---
With any proposed resolution of BUG_ON in kvm_vector_to_index,
arch/x86/kvm/x86.c module_param(tsc_tolerance_ppm, uint, S_IRUGO | S_IWUSR); · line 123
Quoted 3 lines
arch/x86/kvm/x86.c +1
-0@@ -123,6 +123,9 @@ module_param(tsc_tolerance_ppm, uint, S_IRUGO | S_IWUSR); +bool __read_mostly vector_hashing = true;
(Module param can be static.)
Quoted 1 line
arch/x86/kvm/x86.c +1
-0+module_param (vector_hashing, bool,S_IRUGO );
Re: [PATCH v4 3/4] KVM: x86: Add lowest-priority support for vt-d posted-interrupts
In reply to Feng Wu2016-01-25 16:53+0800, Feng Wu:
Quoted 6 lines
Use vector-hashing to deliver lowest-priority interrupts for VT-d posted-interrupts. This patch extends
kvm_intr_is_single_vcpu()to support lowest-priority handling.Signed-off-by Feng Wu <[email protected]>---
RE: [PATCH v4 2/4] KVM: x86: Use vector-hashing to deliver lowest-priority interrupts
In reply to Radim KrčmářQuoted 20 lines
-----Original Message-----
From: Radim Krčmář [mailto:[email protected]]
Sent: Wednesday, January 27, 2016 2:59 AM
To: Wu, Feng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 2/4] KVM: x86: Use vector-hashing to deliver lowest- priority interrupts2016-01-25 16:53+0800, Feng Wu:
Quoted 6 lines
Use vector-hashing to deliver lowest-priority interrupts, As an example, modern Intel CPUs in server platform use this method to handle lowest-priority interrupts.
Signed-off-by Feng Wu <[email protected]>---
With any proposed resolution of
BUG_ONinkvm_vector_to_index,
Quoted 10 lines
Reviewed-by Radim Krčmář <[email protected]>arch/x86/kvm/x86.c module_param(tsc_tolerance_ppm, uint, S_IRUGO |
Quoted 2 lines
arch/x86/kvm/x86.c +0
-0@@ -123,6 +123,9 @@ module_param(tsc_tolerance_ppm, uint, S_IRUGO |
S_IWUSR);arch/x86/kvm/x86.c module_param(tsc_tolerance_ppm, uint, S_IRUGO | S_IWUSR); · line 126
Quoted 1 line
arch/x86/kvm/x86.c +1
-0+bool __read_mostly vector_hashing = true;(Module param can be static.)
Quoted 1 line
arch/x86/kvm/x86.c +1
-0+module_param (vector_hashing, bool,S_IRUGO );
Thanks a lot for your comments, Radim & Paolo!
Paolo, given that the only two comments above, do I need to send v5? Or you can handle it while merging them? I am fine with both methods.
Thanks,
Feng
Paolo Bonzini
maintainerRe: [PATCH v4 2/4] KVM: x86: Use vector-hashing to deliver lowest-priority interrupts
Quoted 27 lines · Feng
Quoted 27 lines
-----Original Message-----
From: Radim Krčmář [mailto:[email protected]]
Sent: Wednesday, January 27, 2016 2:59 AM
To: Wu, Feng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 2/4] KVM: x86: Use vector-hashing to deliver lowest- priority interrupts2016-01-25 16:53+0800, Feng Wu:
Quoted 6 lines
Use vector-hashing to deliver lowest-priority interrupts, As an example, modern Intel CPUs in server platform use this method to handle lowest-priority interrupts.
Signed-off-by Feng Wu <[email protected]>---
With any proposed resolution of
BUG_ONinkvm_vector_to_index,Reviewed-by Radim Krčmář <[email protected]>arch/x86/kvm/x86.c module_param(tsc_tolerance_ppm, uint, S_IRUGO |
Quoted 2 lines
arch/x86/kvm/x86.c +0
-0@@ -123,6 +123,9 @@ module_param(tsc_tolerance_ppm, uint, S_IRUGO |
S_IWUSR);Quoted 1 line
arch/x86/kvm/x86.c +1
-0+bool __read_mostly vector_hashing = true;
Quoted 8 lines
Quoted 3 lines
(Module param can be static.)
Quoted 1 line
arch/x86/kvm/x86.c +1
-0+module_param (vector_hashing, bool,S_IRUGO );Thanks a lot for your comments, Radim & Paolo!
Paolo, given that the only two comments above, do I need to send v5? Or you can handle it while merging them? I am fine with both methods.
It's fine, I'm merging it.
Paolo
RE: [PATCH v4 2/4] KVM: x86: Use vector-hashing to deliver lowest-priority interrupts
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:linux-kernel- [email protected]] On Behalf Of Paolo Bonzini
Sent: Friday, January 29, 2016 4:18 PM
To: Wu, Feng <[email protected]>; Radim Krcmár <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v4 2/4] KVM: x86: Use vector-hashing to deliver lowest- priority interrupts
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
+module_param(vector_hashing, bool,
S_IRUGO);Thanks a lot for your comments, Radim & Paolo!
Paolo, given that the only two comments above, do I need to send v5? Or you can handle it while merging them? I am fine with both methods.
It's fine, I'm merging it.
Thanks a lot, Paolo.
Thanks,
Feng
Quoted 2 lines
Paolo