[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] vcpu: create vcpu thread with QEMU_THREAD_DETAC
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH] vcpu: create vcpu thread with QEMU_THREAD_DETACHED mode |
Date: |
Tue, 30 Jan 2018 18:02:38 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 |
On 28/01/2018 05:14, CheneyLin wrote:
>> This is dangerous, it risks introducing use-after-free bugs in the vCPU
>> thread. Can you instead add a qemu_thread_join call where the vCPU goes
>> away (e.g. unrealize, I'm not sure)?
>
> 1. If another thread calls qemu_thread_join, it will block until vcpu thread
> exit.
Sure, but that's not a problem. If the code is written correctly, it
will only block for a very short time. In particular, in this case
we'll block anyway in cpu_remove_sync. The fix is just to change that
function from qemu_cond_wait to qemu_thread_join.
> 2. As vcpu exits, its resources should be freed ,which will not be used any
> more(e.g. user space stack), how can we get use-after-free bugs?
Use-after-free bugs happen in the vCPU thread if the vCPU resources are
freed just before the vCPU thread exits.
Paolo