[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <feb1443c-bd56-1be7-e588-f0be4f1716a3@redhat.com>
Date: Tue, 19 Dec 2017 11:41:12 +0100
From: Paolo Bonzini <pbonzini@...hat.com>
To: Lan Tianyu <tianyu.lan@...el.com>,
David Hildenbrand <david@...hat.com>
Cc: rkrcmar@...hat.com, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, dvyukov@...gle.com,
kernellwp@...il.com
Subject: Re: [PATCH] KVM/Eventfd: Avoid crash when assign and deassign same
eventfd in parallel.
On 19/12/2017 07:35, Lan Tianyu wrote:
> On 2017年12月18日 16:50, Paolo Bonzini wrote:
>> On 18/12/2017 09:30, David Hildenbrand wrote:
>>> The ugly thing in kvm_irqfd_assign() is that we access irqfd without
>>> holding a lock. I think that should rather be fixed than working around
>>> that issue. (e.g. lock() -> lookup again -> verify still in list ->
>>> unlock())
>>
>> I wonder if it's even simpler:
>>
>> diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
>> index f2ac53ab8243..17ed298bd66f 100644
>> --- a/virt/kvm/eventfd.c
>> +++ b/virt/kvm/eventfd.c
>> @@ -387,7 +387,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
>>
>> idx = srcu_read_lock(&kvm->irq_srcu);
>> irqfd_update(kvm, irqfd);
>> - srcu_read_unlock(&kvm->irq_srcu, idx);
>>
>> list_add_tail(&irqfd->list, &kvm->irqfds.items);
>>
>> @@ -420,10 +419,12 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
>> irqfd->consumer.token, ret);
>> }
>> #endif
>> + srcu_read_unlock(&kvm->irq_srcu, idx);
>>
>> return 0;
>>
>> fail:
>> + /* irq_srcu is *not* held here. */
>> if (irqfd->resampler)
>> irqfd_resampler_shutdown(irqfd);
>>
>>
>
> Hi Paolo:
> This patch still can't prevent from freeing struct irqfd in
> irq_shutdown() during assign irqfd. Once irqfd is added to
> kvm->irqfds.items list, deassign path can get irqfd and free it.
You're right, that also has to be protected by SRCU. So a new bool is
needed (probably "active" more than "initialized") in order to replace
list_del_init with list_del_rcu.
Paolo
Powered by blists - more mailing lists