From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZPa5f-0004Qw-LW for qemu-devel@nongnu.org; Wed, 12 Aug 2015 13:45:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZPa5c-0005ne-8R for qemu-devel@nongnu.org; Wed, 12 Aug 2015 13:45:27 -0400 Received: from greensocs.com ([193.104.36.180]:40489) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZPa5b-0005nZ-UG for qemu-devel@nongnu.org; Wed, 12 Aug 2015 13:45:24 -0400 Message-ID: <55CB862E.2090507@greensocs.com> Date: Wed, 12 Aug 2015 19:45:18 +0200 From: Frederic Konrad MIME-Version: 1.0 References: <1439220437-23957-1-git-send-email-fred.konrad@greensocs.com> <1439220437-23957-8-git-send-email-fred.konrad@greensocs.com> In-Reply-To: <1439220437-23957-8-git-send-email-fred.konrad@greensocs.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC PATCH V7 07/19] protect TBContext with tb_lock. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, mttcg@listserver.greensocs.com, alex.bennee@linaro.org Cc: pbonzini@redhat.com, mark.burton@greensocs.com, a.rigo@virtualopensystems.com, guillaume.delbergue@greensocs.com On 10/08/2015 17:27, fred.konrad@greensocs.com wrote: > From: KONRAD Frederic > > This protects TBContext with tb_lock to make tb_* thread safe. > > We can still have issue with tb_flush in case of multithread TCG: > An other CPU can be executing code during a flush. > > This can be fixed later by making all other TCG thread exiting before calling > tb_flush(). > > tb_find_slow is separated into tb_find_slow and tb_find_physical as the whole > tb_find_slow doesn't require to lock the tb. > > Signed-off-by: KONRAD Frederic > > Changes: [...] > > @@ -675,6 +710,7 @@ static inline void code_gen_alloc(size_t tb_size) > CODE_GEN_AVG_BLOCK_SIZE; > tcg_ctx.tb_ctx.tbs = > g_malloc(tcg_ctx.code_gen_max_blocks * sizeof(TranslationBlock)); > + qemu_mutex_init(&tcg_ctx.tb_ctx.tb_lock); > } > > /* Must be called before using the QEMU cpus. 'tb_size' is the size > @@ -699,16 +735,22 @@ bool tcg_enabled(void) > return tcg_ctx.code_gen_buffer != NULL; > } > > -/* Allocate a new translation block. Flush the translation buffer if > - too many translation blocks or too much generated code. */ > +/* > + * Allocate a new translation block. Flush the translation buffer if > + * too many translation blocks or too much generated code. > + * tb_alloc is not thread safe but tb_gen_code is protected by a mutex so this > + * function is called only by one thread. > + */ > static TranslationBlock *tb_alloc(target_ulong pc) > { > - TranslationBlock *tb; > + TranslationBlock *tb = NULL; > > if (tcg_ctx.tb_ctx.nb_tbs >= tcg_ctx.code_gen_max_blocks || > (tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer) >= > tcg_ctx.code_gen_buffer_max_size) { > - return NULL; > + tb = &tcg_ctx.tb_ctx.tbs[tcg_ctx.tb_ctx.nb_tbs++]; > + tb->pc = pc; > + tb->cflags = 0; Missed this wrong unreverted part which in the end doesn't do a tb_flush when required and crashes! Fixing that allows me to boot with jessie and virt. Fred