From patchwork Thu Oct 17 13:15:24 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: 176604 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp917048ill; Thu, 17 Oct 2019 06:20:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwO6AtO8NP7H4UdlckU5tDodkW1BS+ZlWKor47/Ou0AjfqtfaeabYs5hqOshk4r4qe8mya6 X-Received: by 2002:a05:620a:2185:: with SMTP id g5mr3271645qka.401.1571318430043; Thu, 17 Oct 2019 06:20:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571318430; cv=none; d=google.com; s=arc-20160816; b=Zqzlfl5YH6Ek37EnIMeMJToCb9Qsz9GBp6fHoYQ1I/a+zxoGnAdLi7g6YG+8Xyanyi 0ffhXlEwH7Cab5mvwm/Gurk1uccWapHQrmNo1/yTqoGfYxljZEXyGOuR9QykyLC1UCLS DdtG9ck2QnRBMzxf/0HhSjkU5TiHP1ZJn+m+T61odljfb/mPz/kEDqgTnY9suvO4ZpPj 9kso+n2xghl4ZY/iifGJ7JEOIDjKUj4MKEvg1rTCuj9wsKxrgciJjLcGaKj2oBcPtGWh 95NODZ6mBcaAM4p2zPekeE/nakmeNb6CI5uS9RZIIUeGJ3y7aX8YkRV4Srqhh/OK88CV nPlA== 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=rbXL1fLlbklrDVwyoWdTozQcU/Hu7SOnWR5N/e8FoN+tNqu+PULtwwMmUNJ9IC7sCZ QNFA/WLje/pw75m5HBK/UXAY7u8fG6Pq09kXm7w6uORkBCSCFDeugYq1IUSfLrSWzEop 2PTZSJXjdfpdPsjckiyUbrF7njieuQ4R2xO8SixkGqJrCbkX6s2TT5sKXIOxIywiaCy0 0qP7X6SYRWJudDehnWyWGQKt8dera9TBrOmNvD1AfJVfh7QbmSFhWdg2GnUjEtqZ2AT0 6Qo3D8yxMLkWhswL42GcElU7yieheh4I1/6ePkOwYy/zMMJnc1a0N0gHCopMwJsbDtc7 I4xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jcFk3PJ1; 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 o23si1957478qto.30.2019.10.17.06.20.29 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Oct 2019 06:20:30 -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=jcFk3PJ1; 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]:47184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5hc-0003TX-Se for patch@linaro.org; Thu, 17 Oct 2019 09:20:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33855) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5df-0007zh-HC for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:16:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5dd-0005NM-Te for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:16:23 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:40831) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iL5dd-0005KN-N4 for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:16:21 -0400 Received: by mail-wm1-x341.google.com with SMTP id b24so2488461wmj.5 for ; Thu, 17 Oct 2019 06:16:21 -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=jcFk3PJ1/CmGz5/lRGB9iRGqb2UCbLBsEPlbcZ6hafLKzrw54R2liKw+Zwanewpctz caID7vLt/62jUHV0W2nZnwwjw5iqSPElxJoBCf060dyQaj57y1B8Dsv7YBeqqisE27RB pMTq6GkXnRQNtbZDNwi5RjYlm+0xCbCzhF2dLF+qBYOdoEReb8ZOvbrcozb+1nXayDq1 MD3VryDAdo5DunefZRbOkh71yhGygnibbcXDtHesPfK86joxJDx9d7YgPj8zgK0yECSi kjJNiV9cdU6Qk0ABfVp0CuRk+x09ShZ8UwV1xtn4f+I6KogxATa7EL2RH7AzS6zVUlff JFLw== 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=rGfY4SW9zm3ZAL+78VRu0L/Grt92YMUE74kPri69fs98ldWOBUAPNA1ErZSKmzGs4z d6CPoq9jQigZgHIZqQ6Ah1kR/4rsbpZ+/P6x+UcGUCQL8a4A/NyH9BFgizbgShWeBG8O z7ZNhrBaG5VEseRNdZtxzTzbCkZd9gdHI4yqoplTd+6YeH+OXSrnWz69kYRtX3jD8hL0 pCz++vRs8DpS+Ygvr4Uqzj4LiGSI1wYZJ/SjVhKYU12b4J7Hyl8vWz3javGk0QxBQP0q +WWIBPeOyFUrEUXAsO/Hi6BH0WxBsOkLGOshFwjNgpBfor3/P9+QujfgoL7hlPu4JQhB ysjA== X-Gm-Message-State: APjAAAVSCJpxTzQnvF//ocZzvEL8Q3l6+L6zr9O9eVUNyIetcae2KXul BdJ3oWcSH+nUr6J4AXVwfCxInA== X-Received: by 2002:a05:600c:2908:: with SMTP id i8mr2793009wmd.20.1571318179859; Thu, 17 Oct 2019 06:16:19 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id s13sm2015416wmc.28.2019.10.17.06.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 06:16:17 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1AEE51FF90; Thu, 17 Oct 2019 14:16:16 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v6 03/54] cpu: introduce cpu_in_exclusive_context() Date: Thu, 17 Oct 2019 14:15:24 +0100 Message-Id: <20191017131615.19660-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191017131615.19660-1-alex.bennee@linaro.org> References: <20191017131615.19660-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::341 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.