From patchwork Thu Apr 3 16:45:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 27694 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 575B520490 for ; Thu, 3 Apr 2014 16:45:12 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id wo20sf7416487obc.6 for ; Thu, 03 Apr 2014 09:45:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=hO9blwb41gZ9H67qsuZmFccmwnWRAw+CdOWuOiW56AM=; b=Wff6JfYxXUAhbuJrxpUI7Dnd852dUlq2lyoGwdRqtRmyeJocgFFc+cMFrWbNLDtEYz lp9Bg/v0q3IYWVkIJQGLDfMHY1E80Tcf3+Sc4zIsDOVnpNj1Dzh8CnXKn6BS9VngFS0K QBGJv9wVgGFqmHJDGXyFiuiPrmfvr6jSl4uxnXmD6up5T8bRg3Wupxb42u8pKfAkyxsL uHrgp2cyNtcWEpcDgZxlEynymu0afVnD85pZKBkqUZy+nWMmqOOxz+tWGL5YlI1fKVCt UdGvB8jWJiOrgc1ED4S79FiYm/GVCp5p63IyhgCOVdYdzvs+q1FqSLgfhBqfm4UVcygu IVQg== X-Gm-Message-State: ALoCoQkYpbj65tB2XR4eTwE5/dKfTxvoqDZVaobZ7gvqf0YtlT1OKJROPClXm1It0xwQBFSuhpuR X-Received: by 10.50.178.200 with SMTP id da8mr5188930igc.6.1396543511775; Thu, 03 Apr 2014 09:45:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.107.198 with SMTP id h64ls734272qgf.84.gmail; Thu, 03 Apr 2014 09:45:11 -0700 (PDT) X-Received: by 10.58.201.5 with SMTP id jw5mr416043vec.6.1396543511700; Thu, 03 Apr 2014 09:45:11 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id wy9si1331790vdc.19.2014.04.03.09.45.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Apr 2014 09:45:11 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id sa20so462061veb.22 for ; Thu, 03 Apr 2014 09:45:11 -0700 (PDT) X-Received: by 10.220.247.68 with SMTP id mb4mr3558584vcb.37.1396543511594; Thu, 03 Apr 2014 09:45:11 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.12.8 with SMTP id v8csp43619vcv; Thu, 3 Apr 2014 09:45:11 -0700 (PDT) X-Received: by 10.194.236.232 with SMTP id ux8mr12135990wjc.46.1396543510722; Thu, 03 Apr 2014 09:45:10 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id az5si2536546wjb.29.2014.04.03.09.45.10 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 03 Apr 2014 09:45:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WVklI-0003Cf-H4; Thu, 03 Apr 2014 17:45:08 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Richard Henderson , "Andrei E. Warkentin" , Riku Voipio Subject: [PATCH for-2.0? 2/2] cpu-exec: Unlock tb_lock if we longjmp out of code generation Date: Thu, 3 Apr 2014 17:45:08 +0100 Message-Id: <1396543508-12280-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396543508-12280-1-git-send-email-peter.maydell@linaro.org> References: <1396543508-12280-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , If the guest attempts to execute from unreadable memory, this will cause us to longjmp back to the main loop from inside the target frontend decoder. For linux-user mode, this means we will still hold the tb_ctx.tb_lock, and will deadlock when we try to start executing code again. Unlock the lock in the return-from-longjmp code path to avoid this. Signed-off-by: Peter Maydell Acked-by: Andrei Warkentin --- cpu-exec.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cpu-exec.c b/cpu-exec.c index 0914d3c..02168d9 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -227,6 +227,8 @@ int cpu_exec(CPUArchState *env) TranslationBlock *tb; uint8_t *tc_ptr; uintptr_t next_tb; + /* This must be volatile so it is not trashed by longjmp() */ + volatile bool have_tb_lock = false; if (cpu->halted) { if (!cpu_has_work(cpu)) { @@ -600,6 +602,7 @@ int cpu_exec(CPUArchState *env) cpu_loop_exit(cpu); } spin_lock(&tcg_ctx.tb_ctx.tb_lock); + have_tb_lock = true; tb = tb_find_fast(env); /* Note: we do it here to avoid a gcc bug on Mac OS X when doing it in tb_find_slow */ @@ -621,6 +624,7 @@ int cpu_exec(CPUArchState *env) tb_add_jump((TranslationBlock *)(next_tb & ~TB_EXIT_MASK), next_tb & TB_EXIT_MASK, tb); } + have_tb_lock = false; spin_unlock(&tcg_ctx.tb_ctx.tb_lock); /* cpu_interrupt might be called while translating the @@ -692,6 +696,9 @@ int cpu_exec(CPUArchState *env) #ifdef TARGET_I386 x86_cpu = X86_CPU(cpu); #endif + if (have_tb_lock) { + spin_unlock(&tcg_ctx.tb_ctx.tb_lock); + } } } /* for(;;) */