From: Peter Xu <peterx@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: David Hildenbrand <david@redhat.com>,
Lan Tianyu <tianyu.lan@intel.com>,
rkrcmar@redhat.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, dvyukov@google.com,
kernellwp@gmail.com
Subject: Re: [PATCH] KVM/Eventfd: Avoid crash when assign and deassign same eventfd in parallel.
Date: Mon, 25 Dec 2017 16:03:51 +0800 [thread overview]
Message-ID: <20171225080351.GN2443@xz-mi> (raw)
In-Reply-To: <f6337d64-d41a-aba1-d9da-3f646b033a8d@redhat.com>
On Mon, Dec 18, 2017 at 09:50:04AM +0100, 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);
Sorry if I miss anything important, but... should we extend the unlock
of kvm->irqfds.lock instead of kvm->irq_srcu here? AFAIU kvm->irq_srcu
is protecting accesses to kvm->irq_routing, while kvm->irqfds.lock is
the one that really protects kvm->irqfds? Thanks,
--
Peter Xu
next prev parent reply other threads:[~2017-12-25 8:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-17 23:40 [PATCH] KVM/Eventfd: Avoid crash when assign and deassign same eventfd in parallel Lan Tianyu
2017-12-18 8:30 ` David Hildenbrand
2017-12-18 8:50 ` Paolo Bonzini
2017-12-18 9:08 ` David Hildenbrand
2017-12-18 9:24 ` Paolo Bonzini
2017-12-19 6:35 ` Lan Tianyu
2017-12-19 10:41 ` Paolo Bonzini
2017-12-20 8:48 ` Lan Tianyu
2017-12-25 8:03 ` Peter Xu [this message]
2017-12-19 6:21 ` Lan Tianyu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171225080351.GN2443@xz-mi \
--to=peterx@redhat.com \
--cc=david@redhat.com \
--cc=dvyukov@google.com \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=tianyu.lan@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox