From patchwork Fri Apr 4 11:52:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 27806 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0BC3B20490 for ; Fri, 4 Apr 2014 11:52:52 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wn1sf10307754obc.9 for ; Fri, 04 Apr 2014 04:52:52 -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=Vinb49xYyXW2+bqWFjnTpQQ++rXSq8GGUnhh0TRcx58=; b=lB0XQupwfez7+d/FMgUoUzZ36qI96VdGijotxElGSCdJJJ3EKzZP7amYQurhrrxJyB 0bUBc/CoA1LbTl+KCcvK8nQsXtWP948E4tuKpZIOQHWXiPt5KEYe0ZWYXrmFU9oNb7QH azbQVNlGK5o7ebJzCWN+NXAQ6NgLhwnN4UvBc3ZkHK7OtyWcQldVm/FPWdr4c3WHt5iZ p1FuwdOr9t+tHyngxZxUrByQcpDWMnl6P3xhU5LPFnBl9eDzxNpcserTLV3EXuXrcYEX v4sYx7HLLkOG/LoSodBfCoFPVzIvQQVid7CqrIwpuGv0yiMJ6Hw68GmhjAxV7p+PkqYB dFtw== X-Gm-Message-State: ALoCoQnBB6MneJ1h8NvJUHdPrNz6AlGfAAlIHjCkPjAbsZQN7Dmn0JOky4alsvXDu0BPiW0Ados3 X-Received: by 10.43.88.73 with SMTP id az9mr6866712icc.5.1396612372455; Fri, 04 Apr 2014 04:52:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.28.137 with SMTP id 9ls969799qgz.14.gmail; Fri, 04 Apr 2014 04:52:52 -0700 (PDT) X-Received: by 10.221.4.66 with SMTP id ob2mr76178vcb.28.1396612372306; Fri, 04 Apr 2014 04:52:52 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id cb3si1731838vdc.203.2014.04.04.04.52.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 04 Apr 2014 04:52:52 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id im17so2968841vcb.23 for ; Fri, 04 Apr 2014 04:52:52 -0700 (PDT) X-Received: by 10.220.12.66 with SMTP id w2mr7952071vcw.15.1396612372229; Fri, 04 Apr 2014 04:52:52 -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 v8csp107365vcv; Fri, 4 Apr 2014 04:52:50 -0700 (PDT) X-Received: by 10.180.7.198 with SMTP id l6mr3919213wia.52.1396612366083; Fri, 04 Apr 2014 04:52:46 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id m49si12038797eeo.251.2014.04.04.04.52.45 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 04 Apr 2014 04:52:46 -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 1WW2fr-0003VM-D9; Fri, 04 Apr 2014 12:52:43 +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 v2 2/2] cpu-exec: Unlock tb_lock if we longjmp out of code generation Date: Fri, 4 Apr 2014 12:52:43 +0100 Message-Id: <1396612363-13439-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396612363-13439-1-git-send-email-peter.maydell@linaro.org> References: <1396612363-13439-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.220.178 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 Reviewed-by: Richard Henderson --- cpu-exec.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cpu-exec.c b/cpu-exec.c index 0914d3c..2f54054 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,10 @@ 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); + have_tb_lock = false; + } } } /* for(;;) */