From patchwork Fri Apr 15 14:23:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 8851521 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CE90CBF29F for ; Fri, 15 Apr 2016 14:29:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1D39420374 for ; Fri, 15 Apr 2016 14:29:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 65BEF2034A for ; Fri, 15 Apr 2016 14:29:26 +0000 (UTC) Received: from localhost ([::1]:35199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar4kO-0003ON-RE for patchwork-qemu-devel@patchwork.kernel.org; Fri, 15 Apr 2016 10:29:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar4fB-0000Wx-Og for qemu-devel@nongnu.org; Fri, 15 Apr 2016 10:24:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ar4fA-0007fM-NX for qemu-devel@nongnu.org; Fri, 15 Apr 2016 10:24:01 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:35633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar4fA-0007fD-HU for qemu-devel@nongnu.org; Fri, 15 Apr 2016 10:24:00 -0400 Received: by mail-wm0-x234.google.com with SMTP id a140so33785101wma.0 for ; Fri, 15 Apr 2016 07:24:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tCaM3Cggq3O9xe02mp4rRYaelRDVmm1HLd6hXpMSZYA=; b=VGw/kY8iFIaeQN20KSLCAq3h5f6KfT7q08DouoSFbUTx/RciCDG+0Rf8K1WacyAGgn bU+hST9FfKvFDG2XTVQztkxMGZ9ogIILQ77huu0R0CEIRxWbO/6kWbkdZc/B7j38oFdg RiM7i6bRB0gZ2Z7Xx5TNjGMUEmsGLsY7l+7Vk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tCaM3Cggq3O9xe02mp4rRYaelRDVmm1HLd6hXpMSZYA=; b=Hfehp0ZKbvcPWRdmloTUvuF6o7nuU3ilEqX9waAZfdKM7E4fo633PcNhEM1v2cyV/4 ZZdfeoaEJxh+M+Y0IOqb4wp+nkd+AyisMb1ZEnwygqs60kb+Pqmsbwyhcn35gHpmiLtR upIGRZpwcPlmv/muWZADJKxZwwWM1zA8QCZQyiEdv3LYNVxP55zGu0IEoMFX4LCUNqYj 7WQwW9PFFJAVTAC3/ERfxXvVW36NBCDJ5MqaanCNZJtIlPQxQkOhCXU2SDjX4hkXTJx3 dpbup6pUkRvW0gOjjQcNJHJdE+GcLS9n+st5p40jQ5Luw+odTBlQWocu6vxzqB9IBIMS 2Pbg== X-Gm-Message-State: AOPr4FVGklVKMrFfQ2tdigsLaP0LcCQLaKQkPP8nOqjUblyZDMN5omleAZ8UkTk0SNWLpd0/ X-Received: by 10.194.92.163 with SMTP id cn3mr22290552wjb.3.1460730239953; Fri, 15 Apr 2016 07:23:59 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 7sm11864672wmn.7.2016.04.15.07.23.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Apr 2016 07:23:54 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 15F873E0587; Fri, 15 Apr 2016 15:24:05 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: mttcg@listserver.greensocs.com, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, serge.fdrv@gmail.com, cota@braap.org Date: Fri, 15 Apr 2016 15:23:48 +0100 Message-Id: <1460730231-1184-11-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1460730231-1184-1-git-send-email-alex.bennee@linaro.org> References: <1460730231-1184-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::234 Subject: [Qemu-devel] [RFC v1 09/12] translate-all: introduces tb_flush_safe. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, claudio.fontana@huawei.com, Peter Crosthwaite , jan.kiszka@siemens.com, mark.burton@greensocs.com, qemu-devel@nongnu.org, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: KONRAD Frederic tb_flush is not thread safe we definitely need to exit VCPUs to do that. This introduces tb_flush_safe which just creates an async safe work which will do a tb_flush later. This is called when we run out of space. Signed-off-by: KONRAD Frederic [AJB: merge the various tb_flush commits] Signed-off-by: Alex Bennée --- v1: - add more comments - fix build for linux-user - add log warning on linux-user --- include/exec/exec-all.h | 1 + translate-all.c | 34 +++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index f695577..858055b 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -307,6 +307,7 @@ struct TBContext { void tb_free(TranslationBlock *tb); void tb_flush(CPUState *cpu); +void tb_flush_safe(CPUState *cpu); void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr); #if defined(USE_DIRECT_JUMP) diff --git a/translate-all.c b/translate-all.c index 8e70583..874dc56 100644 --- a/translate-all.c +++ b/translate-all.c @@ -825,9 +825,30 @@ static void page_flush_tb(void) } } -/* flush all the translation blocks */ -/* XXX: tb_flush is currently not thread safe. System emulation calls it only - * with tb_lock taken or from safe_work, so no need to take tb_lock here. +#ifdef CONFIG_SOFTMMU +static void tb_flush_work(CPUState *cpu, void *opaque) +{ + tb_flush(cpu); +} +#endif + +void tb_flush_safe(CPUState *cpu) +{ +#ifdef CONFIG_SOFTMMU + async_safe_run_on_cpu(cpu, tb_flush_work, NULL); +#else + qemu_log("Safe flushing of TBs not implemented for linux-user\n"); + tb_flush(cpu); +#endif +} + +/* Flush *all* translations + * + * This invalidates all translations, lookups and caches. + * + * This is not thread save for linux-user. For softmmu targets the + * flushing is done when all vCPUs are quiescent via the + * async_safe_work mechanism */ void tb_flush(CPUState *cpu) { @@ -1183,10 +1204,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, if (unlikely(!tb)) { buffer_overflow: /* flush must be done */ - tb_flush(cpu); - /* cannot fail at this point */ - tb = tb_alloc(pc); - assert(tb != NULL); + tb_flush_safe(cpu); + tb_unlock(); + cpu_loop_exit(cpu); } gen_code_buf = tcg_ctx.code_gen_ptr;