Received: from eggs.gnu.org ([2001:4830:134:3::10]:58391) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJ8qx-00007b-4l for qemu-devel@nongnu.org; Fri, 01 Jul 2016 20:32:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bJ8qr-0003Un-4j for qemu-devel@nongnu.org; Fri, 01 Jul 2016 20:32:10 -0400 Received: from mail-qk0-x242.google.com ([2607:f8b0:400d:c09::242]:33083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bJ8qr-0003Ui-12 for qemu-devel@nongnu.org; Fri, 01 Jul 2016 20:32:05 -0400 Received: by mail-qk0-x242.google.com with SMTP id n132so26922446qka.0 for ; Fri, 01 Jul 2016 17:32:04 -0700 (PDT) Sender: Richard Henderson References: <1467389770-9738-1-git-send-email-alex.bennee@linaro.org> <1467389770-9738-2-git-send-email-alex.bennee@linaro.org> <20160702001736.GA2295@flamenco> From: Richard Henderson Message-ID: <595ec08d-4e3b-0f1a-eee0-68c462108763@twiddle.net> Date: Fri, 1 Jul 2016 17:32:01 -0700 MIME-Version: 1.0 In-Reply-To: <20160702001736.GA2295@flamenco> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 1/2] tcg: Ensure safe tb_jmp_cache lookup out of 'tb_lock' List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Emilio G. Cota" , =?UTF-8?Q?Alex_Benn=c3=a9e?= Cc: mttcg@greensocs.com, qemu-devel@nongnu.org, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, serge.fdrv@gmail.com, bobby.prani@gmail.com, mark.burton@greensocs.com, pbonzini@redhat.com, jan.kiszka@siemens.com, peter.maydell@linaro.org, claudio.fontana@huawei.com, Sergey Fedorov , Peter Crosthwaite On 07/01/2016 05:17 PM, Emilio G. Cota wrote: > On Fri, Jul 01, 2016 at 17:16:09 +0100, Alex Bennée wrote: >> From: Sergey Fedorov > (snip) >> @@ -333,7 +338,7 @@ static inline TranslationBlock *tb_find_fast(CPUState *cpu, >> is executed. */ >> cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags); >> tb_lock(); >> - tb = cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)]; >> + tb = atomic_read(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)]); >> if (unlikely(!tb || tb->pc != pc || tb->cs_base != cs_base || >> tb->flags != flags)) { >> tb = tb_find_slow(cpu, pc, cs_base, flags); >> diff --git a/translate-all.c b/translate-all.c >> index eaa95e4..1fcfe79 100644 >> --- a/translate-all.c >> +++ b/translate-all.c >> @@ -1004,11 +1004,16 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr) >> invalidate_page_bitmap(p); >> } >> >> + /* Ensure that we won't find the TB in the shared hash table >> + * if we con't see it in CPU's local cache. > > s/con't/can't/ > >> + * Pairs with smp_rmb() in tb_find_slow(). */ >> + smp_wmb(); > > This fence is already embedded in qht_remove, since it internally > calls seqlock_write_end() on a successful removal... No. There's stuff that happens after qht_remove and before this barrier: tb_page_remove and invalidate_page_bitmap. r~