From patchwork Mon Oct 14 10:48:56 2019 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: 176141 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4338978ill; Mon, 14 Oct 2019 03:50:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzHDz1wl9ao1ifiazHj5aufwhApoBVOz0x6PzLu9lZK9ssn6JirA2JUJNuooJFYcrKaRZE X-Received: by 2002:a05:6402:149a:: with SMTP id e26mr27351171edv.123.1571050225364; Mon, 14 Oct 2019 03:50:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571050225; cv=none; d=google.com; s=arc-20160816; b=kEa+bW6VYAegM0iNwg/BemI9Dve3mLgp600MJ4yvFw98+0sWKF2pWTSjdk68go4ZOT 1TrPy7BjW0Y13s+bAQxhkBqfDLwYhGbjH4Ki2eZKBcNhhBaRsd0+LuUY1zbvAdRpp4Pr H6KKd2BcTAjrkDUFsRr8NQxEj7fh14IGUOjBIYtNy7TM/xnIKWdiugStrjomMuqJnjyz tVfxJ7cxlicAzCXMlEEj5EJ8ousRQ+2M0FDa5rwoKH6SmWrSujEoZEoT2L6D6DToEh8S oKKQM+YmocG4600nBjtqQ/HD15FgkCyRvqVyKeLbZH1jPo8xvNG44Tm+pmvboaXaT8yO 8CdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=xbXPv2RF3r3lJivkBr9kmxKqq17UhIjfz0xNCVqHlWU=; b=sJk1WZ1bJFXarenW1z6/TpXATq7lZAb7RNVmJXrDy8c+/CSnJR1VmIOP7z4duUcHsu E73Kv3z9zAoBG363AaQxrU0iPX0ITXwjyGLz33hrHmgAu+Tzya/Ir+g+u0Hn+aUTTjBl smHOgNBdzpzZpLnI2vcD9Xo6P11Qg5NKESUyMACUDSUH5n4FbKJJ9LqmLKCTOpJhAvZn cslFAEq8QkIN/OuxsU5nAjSwpu/n43DM075ZsYCTpMZE71MVkFWCGOK1lk8XjtiOt7kb qqFaY/PzegJFWadT6Z4Y3sTqxE5HKc47bt8/TWM98J/7lsEaAQ98mODBdhGOQdGw2ap2 LcKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qFaD6LL8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n11si10533021ejb.240.2019.10.14.03.50.24 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Oct 2019 03:50:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qFaD6LL8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJxvj-0007LT-9g for patch@linaro.org; Mon, 14 Oct 2019 06:50:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44468) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJxvJ-0007JT-7h for qemu-devel@nongnu.org; Mon, 14 Oct 2019 06:49:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJxvH-0005yu-HS for qemu-devel@nongnu.org; Mon, 14 Oct 2019 06:49:56 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:35667) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iJxvH-0005x4-BX for qemu-devel@nongnu.org; Mon, 14 Oct 2019 06:49:55 -0400 Received: by mail-wr1-x444.google.com with SMTP id v8so19150800wrt.2 for ; Mon, 14 Oct 2019 03:49:54 -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=xbXPv2RF3r3lJivkBr9kmxKqq17UhIjfz0xNCVqHlWU=; b=qFaD6LL8FzEURO4TEhMYUrqi1TkpsSCQ4Qf16bdXVPLyIPP9Hvyt9xVWZs8gVXcVof /L263HeDN6Xs/SWVJHZ0Qp5yjlsJClabCXoazBsaMDBtxs373vaeRWFDR9jUf3sTE0xu rVmy0CwfjtkSjLNDIZe3LhdyD3FCn6GNWuWMBRBlKZ7EepFfAIYPGss+uBtRTuu/b+jn HAVp43PiBoyC++Dn5qW7BRv8A5pgeUZliKarhAqwJDniz+kt9tklkG2pcsjysEcjh/ha C3mXO6yZjjW9WJwpYBWG8FvtReGicrxg+qn7buIuw/XRprOOTcXHDww78IxDkxLzCqza RE5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xbXPv2RF3r3lJivkBr9kmxKqq17UhIjfz0xNCVqHlWU=; b=LbiHpgj2TKoX2LjQEi/rrDBsOhltM9mwfeNFrTBcexTrqPrL+9RRcR3cmN7bIbAgtF 91cp8C4JFRe3dlUoKxJaQh+FDtVlobTPoW8581xNggceYtplqcIfj8o3IupIyPkxG8Dx 6BaFbF9biHJXF9pGoVU3Q8XeDe4tRKrZB7FXFn9D746/RpLwExe95nXCWeO5sZ0ZYlKH YvtRHLm79cbev0DctLWlyLMXHqidLPk0UyvVPMubQxwVCV2z9NXrEPIOowp0686k33Nk q2AD02xVEajpeI1ZMuikOIophpFOoRpq4LvD33TIpNCbabp2a29SWfFyXVr5TzyEv5M4 EdBw== X-Gm-Message-State: APjAAAXfFe3mRy90eDcQ4BEl1oFD0Ad2qKd08m4HwgnO6dg1hUbsD2x9 BJfDUZl1kflAlG50lzHWeWZI+Q== X-Received: by 2002:adf:fe8d:: with SMTP id l13mr11845837wrr.365.1571050193565; Mon, 14 Oct 2019 03:49:53 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l18sm19810331wrc.18.2019.10.14.03.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 03:49:51 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B1AD61FF90; Mon, 14 Oct 2019 11:49:49 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 03/55] cpu: introduce cpu_in_exclusive_context() Date: Mon, 14 Oct 2019 11:48:56 +0100 Message-Id: <20191014104948.4291-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191014104948.4291-1-alex.bennee@linaro.org> References: <20191014104948.4291-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , robert.foley@futurewei.com, Richard Henderson , peter.puhov@futurewei.com, aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Suggested-by: Alex Bennée Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota [AJB: moved inside start/end_exclusive fns + cleanup] Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v4 - -> cpu_in_exclusive_context - moved inside start/end exclusive - fixed up cpu_exec_step_atomic --- accel/tcg/cpu-exec.c | 5 +---- cpus-common.c | 4 ++++ include/hw/core/cpu.h | 13 +++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) -- 2.20.1 diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 48272c781b..81c33d6475 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -238,8 +238,6 @@ void cpu_exec_step_atomic(CPUState *cpu) uint32_t flags; uint32_t cflags = 1; uint32_t cf_mask = cflags & CF_HASH_MASK; - /* volatile because we modify it between setjmp and longjmp */ - volatile bool in_exclusive_region = false; if (sigsetjmp(cpu->jmp_env, 0) == 0) { tb = tb_lookup__cpu_state(cpu, &pc, &cs_base, &flags, cf_mask); @@ -253,7 +251,6 @@ void cpu_exec_step_atomic(CPUState *cpu) /* Since we got here, we know that parallel_cpus must be true. */ parallel_cpus = false; - in_exclusive_region = true; cc->cpu_exec_enter(cpu); /* execute the generated code */ trace_exec_tb(tb, pc); @@ -273,7 +270,7 @@ void cpu_exec_step_atomic(CPUState *cpu) assert_no_pages_locked(); } - if (in_exclusive_region) { + if (cpu_in_exclusive_context(cpu)) { /* We might longjump out of either the codegen or the * execution, so must make sure we only end the exclusive * region if we started it. diff --git a/cpus-common.c b/cpus-common.c index af3385a296..eaf590cb38 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -200,11 +200,15 @@ void start_exclusive(void) * section until end_exclusive resets pending_cpus to 0. */ qemu_mutex_unlock(&qemu_cpu_list_lock); + + current_cpu->in_exclusive_context = true; } /* Finish an exclusive operation. */ void end_exclusive(void) { + current_cpu->in_exclusive_context = false; + qemu_mutex_lock(&qemu_cpu_list_lock); atomic_set(&pending_cpus, 0); qemu_cond_broadcast(&exclusive_resume); diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 031f587e51..07f2ab0590 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -372,6 +372,7 @@ struct CPUState { bool unplug; bool crash_occurred; bool exit_request; + bool in_exclusive_context; uint32_t cflags_next_tb; /* updates protected by BQL */ uint32_t interrupt_request; @@ -783,6 +784,18 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data) */ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data); +/** + * cpu_in_exclusive_context() + * @cpu: The vCPU to check + * + * Returns true if @cpu is an exclusive context, for example running + * something which has previously been queued via async_safe_run_on_cpu(). + */ +static inline bool cpu_in_exclusive_context(const CPUState *cpu) +{ + return cpu->in_exclusive_context; +} + /** * qemu_get_cpu: * @index: The CPUState@cpu_index value of the CPU to obtain.