On 27/07/16 18:53, Peter Xu wrote:
> On Wed, Jul 27, 2016 at 05:51:46PM +1000, Alexey Kardashevskiy wrote:
>> 3f1fea0fb5bf "kvm-irqchip: do explicit commit when update irq" produces
>> a crash on pseries guest running with VFIO on POWER8 machine as
>> it does not support KVM_CAP_IRQCHIP (KVM_CAP_IRQ_XICS is there instead).
>> At the result, KVMState::irq_routes is NULL when VFIO calls
>> kvm_irqchip_commit_routes.
>>
>> This makes the routing update conditional.
>>
>> Signed-off-by: Alexey Kardashevskiy <a...@ozlabs.ru>
>> ---
>>
>> Or I am too late and there is the fix? Could not find any.
>>
>> This is the backtrace:
>>
>> Thread 4 "qemu-system-ppc" received signal SIGSEGV, Segmentation fault.
>> [Switching to Thread 0x3fffb663ec90 (LWP 11852)]
>> 0x0000000010091fa4 in kvm_irqchip_commit_routes (s=0x10eff3b0) at 
>> /home/aik/p/qemu-ddw/kvm-all.c:1050
>> 1050        s->irq_routes->flags = 0;
>> (gdb) p s
>> $2 = (KVMState *) 0x10eff3b0
>> (gdb) p s->irq_routes
>> $3 = (struct kvm_irq_routing *) 0x0
>> (gdb) bt
>> #0  0x0000000010091fa4 in kvm_irqchip_commit_routes (s=0x10eff3b0) at 
>> /home/aik/p/qemu-ddw/kvm-all.c:1050
>> #1  0x000000001010fcd4 in vfio_update_kvm_msi_virq (vector=0x3fffa8006a10, 
>> msg=..., pdev=0x1101f300) at /h
>> ome/aik/p/qemu-ddw/hw/vfio/pci.c:461
>> #2  0x000000001010fe58 in vfio_msix_vector_do_use (pdev=0x1101f300, nr=0x0, 
>> msg=0x3fffb663dd00, handler=0x
>> 1010f5e8 <vfio_msi_interrupt>) at /home/aik/p/qemu-ddw/hw/vfio/pci.c:496
>> #3  0x000000001011010c in vfio_msix_vector_use (pdev=0x1101f300, nr=0x0, 
>> msg=...) at /home/aik/p/qemu-ddw/
>> hw/vfio/pci.c:557
>> #4  0x00000000103f64c4 in msix_fire_vector_notifier (dev=0x1101f300, 
>> vector=0x0, is_masked=0x0) at /home/a
>> ik/p/qemu-ddw/hw/pci/msix.c:111
>> #5  0x00000000103f6594 in msix_handle_mask_update (dev=0x1101f300, 
>> vector=0x0, was_masked=0x1) at /home/ai
>> k/p/qemu-ddw/hw/pci/msix.c:124
>> #6  0x00000000103f6928 in msix_table_mmio_write (opaque=0x1101f300, 
>> addr=0xc, val=0x0, size=0x4) at /home/
>> aik/p/qemu-ddw/hw/pci/msix.c:186
>> #7  0x0000000010099738 in memory_region_write_accessor (mr=0x1101f838, 
>> addr=0xc, value=0x3fffb663df50, siz
>> e=0x4, shift=0x0, mask=0xffffffff, attrs=...) at 
>> /home/aik/p/qemu-ddw/memory.c:525
>> #8  0x0000000010099a94 in access_with_adjusted_size (addr=0xc, 
>> value=0x3fffb663df50, size=0x4, access_size
>> _min=0x1, access_size_max=0x4, access=0x100995f8 
>> <memory_region_write_accessor>, mr=0x1101f838, attrs=...)
>>  at /home/aik/p/qemu-ddw/memory.c:591
>> #9  0x000000001009cb0c in memory_region_dispatch_write (mr=0x1101f838, 
>> addr=0xc, data=0x0, size=0x4, attrs
>> =...) at /home/aik/p/qemu-ddw/memory.c:1262
>> #10 0x0000000010015300 in address_space_write_continue (as=0x109b3958 
>> <address_space_memory>, addr=0x10120
>> 00200c, attrs=..., buf=0x3fffb5e20028 "", len=0x4, addr1=0xc, l=0x4, 
>> mr=0x1101f838) at /home/aik/p/qemu-dd
>> w/exec.c:2580
>> #11 0x0000000010015558 in address_space_write (as=0x109b3958 
>> <address_space_memory>, addr=0x1012000200c, a
>> ttrs=..., buf=0x3fffb5e20028 "", len=0x4) at /home/aik/p/qemu-ddw/exec.c:2637
>> #12 0x00000000100159e4 in address_space_rw (as=0x109b3958 
>> <address_space_memory>, addr=0x1012000200c, attr
>> s=..., buf=0x3fffb5e20028 "", len=0x4, is_write=0x1) at 
>> /home/aik/p/qemu-ddw/exec.c:2739
>> #13 0x0000000010094cb8 in kvm_cpu_exec (cpu=0x3fffb6e76db0) at 
>> /home/aik/p/qemu-ddw/kvm-all.c:1952
>> #14 0x0000000010072764 in qemu_kvm_cpu_thread_fn (arg=0x3fffb6e76db0) at 
>> /home/aik/p/qemu-ddw/cpus.c:1078
>> #15 0x00003fffb7a184a0 in start_thread (arg=0x3fffb663ec90) at 
>> pthread_create.c:335
>> #16 0x00003fffb7957e74 in clone () at 
>> ../sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S:96
>> (gdb)
>> ---
>>  kvm-all.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/kvm-all.c b/kvm-all.c
>> index 3764ba9..028fdcb 100644
>> --- a/kvm-all.c
>> +++ b/kvm-all.c
>> @@ -1047,6 +1047,10 @@ void kvm_irqchip_commit_routes(KVMState *s)
>>  {
>>      int ret;
>>  
>> +    if (!s->irq_routes) {
>> +        return;
>> +    }
>> +
>>      s->irq_routes->flags = 0;
>>      ret = kvm_vm_ioctl(s, KVM_SET_GSI_ROUTING, s->irq_routes);
>>      assert(ret == 0);
> 
> Sorry for the trouble. How about this one:
> 
> diff --git a/kvm-all.c b/kvm-all.c
> index ef81ca5..4b3e330 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -1047,6 +1047,10 @@ void kvm_irqchip_commit_routes(KVMState *s)
>  {
>      int ret;
> 
> +    if (kvm_gsi_direct_mapping()) {
> +        return 0;
> +    }
> +
>      s->irq_routes->flags = 0;
>      trace_kvm_irqchip_commit_routes();
>      ret = kvm_vm_ioctl(s, KVM_SET_GSI_ROUTING, s->irq_routes);
> 
> I don't know whether irq_routes will be NULL for all GSI direct
> mapping case... at least this can have kvm_irqchip_*() APIs got
> aligned.


This works too.

You may also want to copy if(!kvm_gsi_routing_enabled()) from
kvm_irqchip_add_msi_route() to align API (not needed in my case though). Or
just check the result of these checks by if(!s->irq_routes) :)
Thanks.


-- 
Alexey

Reply via email to