KVM: arm/arm64 : add lpi info in vgic-debug
Quoted 55 lines · Peng Hao
Quoted 54 lines
Add lpi debug info to vgic-stat.
the printed info like this:SPI 287 0 000001 0 0 0 160 -1 LPI 8192 2 000100 0 0 0 160 -1Signed-off-by Peng Hao <[email protected]>--- virt/kvm/arm/vgic/vgic-debug.c | 61 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-)virt/kvm/arm/vgic/vgic-debug.c +26
-0@@ -36,9 +36,12 @@struct vgic_state_iter {int nr_cpus;int nr_spis; +int nr_lpis;int dist_id;int vcpu_id;int intid; +int lpi_print_count; +struct vgic_irq **lpi_irqs; };static void iter_next (struct vgic_state_iter *iter)@@ -52,6 +55,40 @@ static void iter_next(struct vgic_state_iter *iter)if (iter->intid ==VGIC_NR_PRIVATE_IRQS && ++iter->vcpu_id < iter->nr_cpus) iter->intid =0 ; + +if (iter->intid >=VGIC_NR_PRIVATE_IRQS + iter->nr_spis) { +if (iter->lpi_print_count < iter->nr_lpis) + iter->intid = iter->lpi_irqs[iter->lpi_print_count]->intid; + iter->lpi_print_count++; + } +} + +static void vgic_debug_get_lpis (struct kvm *kvm,struct vgic_state_iter *iter) +{ +struct vgic_dist *dist = &kvm->arch.vgic; +int i =0 ; +struct vgic_irq *irq =NULL , **lpi_irqs; + +again: + iter->nr_lpis = dist->lpi_list_count; + lpi_irqs =kmalloc_array (iter->nr_lpis,sizeof (irq),GFP_KERNEL ); +if (!lpi_irqs) { + iter->nr_lpis =0 ; +return ; + } +spin_lock (&dist->lpi_list_lock); +if (iter->nr_lpis != dist->lpi_list_count) {
Quoted 8 lines
virt/kvm/arm/vgic/vgic-debug.c static void iter_next(struct vgic_state_iter *iter) · line 84
Quoted 4 lines
virt/kvm/arm/vgic/vgic-debug.c +4
-0+kfree (lpi_irqs); +spin_unlock (&dist->lpi_list_lock); + goto again; + }Why do we need an exact count? It is fine to have a transient count, and the debug code should be able to come with that without performing this terrible loop.
yeah, it is enough to have a rough count for debug code .
Quoted 2 lines
We also already have some code that snapshot the the LPIs (see
vgic_copy_lpi_list), so please consider reusing that instead.
I can't reuse vgic_copy_lpi_list. It snapshots based on LPI's target vcpu.
Quoted 11 lines
virt/kvm/arm/vgic/vgic-debug.c static void iter_next(struct vgic_state_iter *iter) · line 91
Quoted 7 lines
virt/kvm/arm/vgic/vgic-debug.c +7
-0+ +list_for_each_entry (irq, &dist->lpi_list_head, lpi_list) { +vgic_get_irq_kref (irq); + lpi_irqs[i++] = irq; + } +spin_unlock (&dist->lpi_list_lock); + iter->lpi_irqs = lpi_irqs;Messing with the internals of the refcounts is really a bad idea. Please use
vgic_get_irq()in conjunction with the above, and allow it to fail gracefully.
vgic_get_irq require intid as input and vgic_get_lpi that vgic_get_irq calling will traverse the lpi_list with holding lpi_list_lock again, but here I has held lpi_list_lock. So I think calling vgic_get_irq_kref is safe with holding the
lpi_list_lock.
Quoted 43 lines
Quoted 43 lines
virt/kvm/arm/vgic/vgic-debug.c +7
-2} static void iter_init(struct kvm *kvm, struct vgic_state_iter *iter,@@ -64,6 +101,8 @@ static void iter_init(struct kvm *kvm, struct vgic_state_iter *iter, iter->nr_cpus = nr_cpus; iter->nr_spis = kvm->arch.vgic.nr_spis; +if (vgic_supports_direct_msis (kvm) && !pos) +vgic_debug_get_lpis (kvm, iter);/* Fast forward to the right position if needed */ while (pos--)iter_next (iter);@@ -73,7 +112,9 @@ static bool end_of_vgic(struct vgic_state_iter *iter) {return iter->dist_id >0 && iter->vcpu_id == iter->nr_cpus && - (iter->intid -VGIC_NR_PRIVATE_IRQS ) == iter->nr_spis; + (iter->intid -VGIC_NR_PRIVATE_IRQS ) >= iter->nr_spis && + ((iter->nr_lpis ==0 ) || + (iter->lpi_print_count == iter->nr_lpis +1 )); }static void *vgic_debug_start (struct seq_file *s,loff_t *pos)@@ -130,6 +171,7 @@ static void vgic_debug_stop(struct seq_file *s, void *v)mutex_lock (&kvm->lock); iter = kvm->arch.vgic.iter; +kfree (iter->lpi_irqs);kfree (iter); kvm->arch.vgic.iter =NULL ;mutex_unlock (&kvm->lock);@@ -154,7 +196,7 @@ static void print_header(struct seq_file *s, struct vgic_irq *irq, struct kvm_vcpu *vcpu) {int id =0 ; -char *hdr ="SPI " ; +char *hdr ="S/LPI " ;if (vcpu) { hdr ="VCPU" ;@@ -162,7 +204,10 @@ static void print_header(struct seq_file *s, struct vgic_irq *irq, }
Quoted 10 lines
virt/kvm/arm/vgic/vgic-debug.c static void print_header(struct seq_file *s, struct vgic_irq *irq, · line 210
Quoted 6 lines
virt/kvm/arm/vgic/vgic-debug.c +4
-1seq_printf (s,"\n" ); -seq_printf (s,"%s%2d TYP ID TGT_ID PLAEHC HWID TARGET SRC PRI VCPU_ID\n" , hdr, id); +if (vcpu) +seq_printf (s,"%s%2d TYP ID TGT_ID PLAEHC HWID TARGET SRC PRI VCPU_ID\n" , hdr, id); +else +seq_printf (s,"%s TYP ID TGT_ID PLAEHC HWID TARGET SRC PRI VCPU_ID\n" , hdr);This feels like an unnecessary change. But if you really want that kind of detail, change your "S/LPI" to say something more generic, such as "Global".
I modify this just for aligned print output. "Global" is great.
Quoted 27 lines
Quoted 27 lines
virt/kvm/arm/vgic/vgic-debug.c +6
-2seq_printf(s, "---------------------------------------------------------------\n");> }@@ -174,8 +219,10 @@ static void print_irq_state(struct seq_file *s, struct vgic_irq *irq, type ="SGI" ; else if (irq->intid < VGIC_NR_PRIVATE_IRQS) type ="PPI" ; - else + else if (irq->intid < VGIC_MAX_SPI) type ="SPI" ; + else if (irq->intid >= VGIC_MIN_LPI) + type ="LPI" ;if (irq->intid ==0 || irq->intid ==VGIC_NR_PRIVATE_IRQS )print_header (s, irq, vcpu);@@ -220,7 +267,9 @@ static int vgic_debug_show(struct seq_file *s, void *v)if (!kvm->arch.vgic.initialized)return 0 ; -if (iter->vcpu_id < iter->nr_cpus) { +if (iter->intid >=VGIC_MIN_LPI ) + irq = iter->lpi_irqs[iter->lpi_print_count -1 ]; +else if (iter->vcpu_id < iter->nr_cpus) { vcpu =kvm_get_vcpu (kvm, iter->vcpu_id); irq = &vcpu->arch.vgic_cpu.private_irqs[iter->intid]; }else {@@ -230,6 +279,8 @@ static int vgic_debug_show(struct seq_file *s, void *v)spin_lock (&irq->irq_lock);
Quoted 8 lines
virt/kvm/arm/vgic/vgic-debug.c static int vgic_debug_show(struct seq_file *s, void *v) · line 283
Quoted 4 lines
virt/kvm/arm/vgic/vgic-debug.c +2
-0print_irq_state (s, irq, vcpu);spin_unlock (&irq->irq_lock); +if (iter->intid >=VGIC_MIN_LPI ) +vgic_put_irq (kvm, irq);If you adopt the scheme I outlined above, you can have a balanced get/put behaviour, irrespective of the interrupt type, and a much nicer result.
yeah, "if (iter->intid >= VGIC_MIN_LPI)" is unnecessary.
Quoted 7 lines
virt/kvm/arm/vgic/vgic-debug.c static int vgic_debug_show(struct seq_file *s, void *v) · line 286
Quoted 3 lines
virt/kvm/arm/vgic/vgic-debug.c +0
-0return 0 ; }Thanks,
M.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
[fixing Christoffer's email address]
Quoted 63 lines · On 23/03/18 13:33, [email protected] wrote:
Quoted 55 lines · Peng Hao
Quoted 54 lines
Add lpi debug info to vgic-stat.
the printed info like this:SPI 287 0 000001 0 0 0 160 -1 LPI 8192 2 000100 0 0 0 160 -1Signed-off-by Peng Hao <[email protected]>--- virt/kvm/arm/vgic/vgic-debug.c | 61 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-)virt/kvm/arm/vgic/vgic-debug.c +26
-0@@ -36,9 +36,12 @@struct vgic_state_iter {int nr_cpus;int nr_spis; +int nr_lpis;int dist_id;int vcpu_id;int intid; +int lpi_print_count; +struct vgic_irq **lpi_irqs; };static void iter_next (struct vgic_state_iter *iter)@@ -52,6 +55,40 @@ static void iter_next(struct vgic_state_iter *iter)if (iter->intid ==VGIC_NR_PRIVATE_IRQS && ++iter->vcpu_id < iter->nr_cpus) iter->intid =0 ; + +if (iter->intid >=VGIC_NR_PRIVATE_IRQS + iter->nr_spis) { +if (iter->lpi_print_count < iter->nr_lpis) + iter->intid = iter->lpi_irqs[iter->lpi_print_count]->intid; + iter->lpi_print_count++; + } +} + +static void vgic_debug_get_lpis (struct kvm *kvm,struct vgic_state_iter *iter) +{ +struct vgic_dist *dist = &kvm->arch.vgic; +int i =0 ; +struct vgic_irq *irq =NULL , **lpi_irqs; + +again: + iter->nr_lpis = dist->lpi_list_count; + lpi_irqs =kmalloc_array (iter->nr_lpis,sizeof (irq),GFP_KERNEL ); +if (!lpi_irqs) { + iter->nr_lpis =0 ; +return ; + } +spin_lock (&dist->lpi_list_lock); +if (iter->nr_lpis != dist->lpi_list_count) {Quoted 8 lines
virt/kvm/arm/vgic/vgic-debug.c static void iter_next(struct vgic_state_iter *iter) · line 84
Quoted 4 lines
virt/kvm/arm/vgic/vgic-debug.c +4
-0+kfree (lpi_irqs); +spin_unlock (&dist->lpi_list_lock); + goto again; + }Why do we need an exact count? It is fine to have a transient count, and the debug code should be able to come with that without performing this terrible loop.
Quoted 4 lines
yeah, it is enough to have a rough count for debug code .
Quoted 2 lines
We also already have some code that snapshot the the LPIs (see
vgic_copy_lpi_list), so please consider reusing that instead.I can't reuse
vgic_copy_lpi_list. It snapshots based on LPI's target vcpu.
Guess what? You can also change it!
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
virt/kvm/arm/vgic/vgic-debug.c +7
-0+ +list_for_each_entry (irq, &dist->lpi_list_head, lpi_list) { +vgic_get_irq_kref (irq); + lpi_irqs[i++] = irq; + } +spin_unlock (&dist->lpi_list_lock); + iter->lpi_irqs = lpi_irqs;
Quoted 6 lines
Quoted 3 lines
Messing with the internals of the refcounts is really a bad idea. Please use
vgic_get_irq()in conjunction with the above, and allow it to fail gracefully.
vgic_get_irqrequire intid as input andvgic_get_lpithatvgic_get_irqcalling will traverse thelpi_listwith holdinglpi_list_lockagain, but here I has heldlpi_list_lock. So I think callingvgic_get_irq_krefis safe with holding the
lpi_list_lock.
It is safe but terribly ugly. Traversing the LPI list is completely fine, and we have this API for a reason (not reinventing the wheel). I don't think the debug code should sidestep it. If the list proves to be too slow to traverse, then we should adopt a better data structure.
Quoted 9 lines
Quoted 9 lines
virt/kvm/arm/vgic/vgic-debug.c static void iter_init(struct kvm *kvm, struct vgic_state_iter *iter, · line 105
Quoted 9 lines
virt/kvm/arm/vgic/vgic-debug.c +2
-0} static void iter_init(struct kvm *kvm, struct vgic_state_iter *iter,@@ -64,6 +101,8 @@ static void iter_init(struct kvm *kvm, struct vgic_state_iter *iter, iter->nr_cpus = nr_cpus; iter->nr_spis = kvm->arch.vgic.nr_spis; +if (vgic_supports_direct_msis (kvm) && !pos) +vgic_debug_get_lpis (kvm, iter);
BTW, what's the point of this?
Quoted 80 lines
Quoted 34 lines
Quoted 34 lines
virt/kvm/arm/vgic/vgic-debug.c +5
-2/* Fast forward to the right position if needed */ while (pos--)iter_next (iter);@@ -73,7 +112,9 @@ static bool end_of_vgic(struct vgic_state_iter *iter) {return iter->dist_id >0 && iter->vcpu_id == iter->nr_cpus && - (iter->intid -VGIC_NR_PRIVATE_IRQS ) == iter->nr_spis; + (iter->intid -VGIC_NR_PRIVATE_IRQS ) >= iter->nr_spis && + ((iter->nr_lpis ==0 ) || + (iter->lpi_print_count == iter->nr_lpis +1 )); }static void *vgic_debug_start (struct seq_file *s,loff_t *pos)@@ -130,6 +171,7 @@ static void vgic_debug_stop(struct seq_file *s, void *v)mutex_lock (&kvm->lock); iter = kvm->arch.vgic.iter; +kfree (iter->lpi_irqs);kfree (iter); kvm->arch.vgic.iter =NULL ;mutex_unlock (&kvm->lock);@@ -154,7 +196,7 @@ static void print_header(struct seq_file *s, struct vgic_irq *irq, struct kvm_vcpu *vcpu) {int id =0 ; -char *hdr ="SPI " ; +char *hdr ="S/LPI " ;if (vcpu) { hdr ="VCPU" ;@@ -162,7 +204,10 @@ static void print_header(struct seq_file *s, struct vgic_irq *irq, }Quoted 10 lines
virt/kvm/arm/vgic/vgic-debug.c static void print_header(struct seq_file *s, struct vgic_irq *irq, · line 210
Quoted 6 lines
virt/kvm/arm/vgic/vgic-debug.c +4
-1seq_printf (s,"\n" ); -seq_printf (s,"%s%2d TYP ID TGT_ID PLAEHC HWID TARGET SRC PRI VCPU_ID\n" , hdr, id); +if (vcpu) +seq_printf (s,"%s%2d TYP ID TGT_ID PLAEHC HWID TARGET SRC PRI VCPU_ID\n" , hdr, id); +else +seq_printf (s,"%s TYP ID TGT_ID PLAEHC HWID TARGET SRC PRI VCPU_ID\n" , hdr);This feels like an unnecessary change. But if you really want that kind of detail, change your "S/LPI" to say something more generic, such as "Global".
I modify this just for aligned print output. "Global" is great.
Quoted 27 lines
Quoted 27 lines
virt/kvm/arm/vgic/vgic-debug.c +6
-2seq_printf(s, "---------------------------------------------------------------\n");> }@@ -174,8 +219,10 @@ static void print_irq_state(struct seq_file *s, struct vgic_irq *irq, type ="SGI" ; else if (irq->intid < VGIC_NR_PRIVATE_IRQS) type ="PPI" ; - else + else if (irq->intid < VGIC_MAX_SPI) type ="SPI" ; + else if (irq->intid >= VGIC_MIN_LPI) + type ="LPI" ;if (irq->intid ==0 || irq->intid ==VGIC_NR_PRIVATE_IRQS )print_header (s, irq, vcpu);@@ -220,7 +267,9 @@ static int vgic_debug_show(struct seq_file *s, void *v)if (!kvm->arch.vgic.initialized)return 0 ; -if (iter->vcpu_id < iter->nr_cpus) { +if (iter->intid >=VGIC_MIN_LPI ) + irq = iter->lpi_irqs[iter->lpi_print_count -1 ]; +else if (iter->vcpu_id < iter->nr_cpus) { vcpu =kvm_get_vcpu (kvm, iter->vcpu_id); irq = &vcpu->arch.vgic_cpu.private_irqs[iter->intid]; }else {@@ -230,6 +279,8 @@ static int vgic_debug_show(struct seq_file *s, void *v)spin_lock (&irq->irq_lock);Quoted 8 lines
virt/kvm/arm/vgic/vgic-debug.c static int vgic_debug_show(struct seq_file *s, void *v) · line 283
Quoted 4 lines
virt/kvm/arm/vgic/vgic-debug.c +2
-0print_irq_state (s, irq, vcpu);spin_unlock (&irq->irq_lock); +if (iter->intid >=VGIC_MIN_LPI ) +vgic_put_irq (kvm, irq);If you adopt the scheme I outlined above, you can have a balanced get/put behaviour, irrespective of the interrupt type, and a much nicer result.
Quoted 1 line
yeah, "if (
iter->intid>=VGIC_MIN_LPI)" is unnecessary.
I'm still adamant that you should have get/put for every interrupt. It won't cost anything, and the code will look better.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...