From patchwork Wed Jul 31 16:06:34 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: 170150 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4217817ile; Wed, 31 Jul 2019 09:12:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkJ94WGzUOqaT404JzkowebR8LqZrIsvEUW1eQ1rgavlO8sfMx88kCQNigeoWH3R2n9B9J X-Received: by 2002:a0c:e703:: with SMTP id d3mr19953168qvn.194.1564589548545; Wed, 31 Jul 2019 09:12:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564589548; cv=none; d=google.com; s=arc-20160816; b=e511oThYcjx4sfe0u5qflKs6t/cdJYS+voKQOSg/aMoG1kUZSNE5e9MyrPeX3Iu7yE WNAmTbJBu+5U50cEpis/z4BKMUOBug5ETvrUEZ5LG9Lj8NKOaqv6sbguHUHi0KlHaZ42 psi65KUVlB6sDA7Zwb+qj+Tkj9njYVj+fM5hgNBpjoxfPNN4w8pIu+yWUP3iV8x23SCl gXutNLFsiyyg1/RpLEgtbWHqZDXdYAV9CVqI8uxQnJx+kUbWEYrC2Aj9zLbYjhifDi7u m2+dQAX9k7fmEtQJPOlbXTds1HoD85qGem7vP+dOQlD55tfUnAuPIvrN/moig3tBZ8IN MIWQ== 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:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=gqRoR6HeTII8sj4+++ItlQ9YsCPjf/Rl0PEZ/zeyKFI=; b=Csuka5R5TAdgmf4a0JgUhXSsW4Qcj5MpWd6rUhTdoWeja8jsD0UhIKXT59qUF09hkY 4FbPb/Hlhek0l153j/w7Ox1jkh4NtuE4HsfiIMfbvBhSM0sOJ7J2jY/HvQASE/4HBlk2 B3SB5uYpIrxinBIhYq6VjXyiFF+DBSUK6s0QzYYvRlG9gAmRD8zTuCChR445NZ/Rn8k3 PJZ1AcZb3GXO1WpWlysy2GTrq8yED3bKwCn2c0x5RRCQK5rhob+4zxAEsOWBwsPGSUCj Yg1Xut/Wnr9JsLuArtBspCJPCVQiwGGHQUTdvtiKm9x1BZWaDG25nnUZBbfchhkN3FQ+ el+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=s6nNj18A; 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 j13si1840675qtn.101.2019.07.31.09.12.28 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Jul 2019 09:12:28 -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=s6nNj18A; 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]:42380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrDI-0001D7-6S for patch@linaro.org; Wed, 31 Jul 2019 12:12:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40374) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsr8h-00027t-GI for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsr8e-0000kZ-CK for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:42 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:44122) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsr8d-0000ev-FB for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:07:39 -0400 Received: by mail-wr1-x443.google.com with SMTP id p17so70287613wrf.11 for ; Wed, 31 Jul 2019 09:07:28 -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=gqRoR6HeTII8sj4+++ItlQ9YsCPjf/Rl0PEZ/zeyKFI=; b=s6nNj18AsKMrJqBZ0JC3IwkFmgsVUwB1p2HwNr7yzxRDZ0q53fSFwd7i8CqdNygHBF NnHt7jaxqcvckTzl+//AHdAdo17aoSpADU3jbGVr3R/DJUBmVQGNPwAndwzj6ATmJUY+ cO7Bq9vjF5lTBQTsY083ZebT0R8o+yEEqPEq5WLnNkAEjQz57jPIwRPEJ0GHQe4pYRUi dkZ8DjPQg5O/W1gKkQlWSvBricR0P2rtNhkEUhssKEMPAFLP/N+3z1VEuy+uzBnpmTQE 7eQgrhKY1SuI3UHp0GHn2ngKlP/HoehWz5F9yT3996fA2GZvHqjbrixn4sml0dWs/4C2 GLQw== 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=gqRoR6HeTII8sj4+++ItlQ9YsCPjf/Rl0PEZ/zeyKFI=; b=XdRVT0wbVbs86PT6h9pY4P1uQaNcsuzbRtKMdaIX/KT3qE55z7ZMTwMuaI5wIajFhN gbwM5VG1ApeQS19JsI7ApNS4/MQoISKvncfU5aoUQQeaRXormE8VNV1XRtgeExbBEYrm Hm5HA5lHHtF15Vm4EGzD6lS4wRjci3ytWnkvh6pjqz9vbKakU/ODtxKG+euGQ9+Y84pY l9BjrG7POI3Rv+iHlAQjLLJjCbL7i0tdB8Ryv4fx/aO1OVZrx1pI7qXYNDeAFWQhHLDa 7gLQKaE1ImSvM+Z/HUku2rCkGMxsFDgbITuaNMRrJBZn/+wLWvHeOMu6TbjgjAhyNnlk v6og== X-Gm-Message-State: APjAAAWbJhHn3np8WBKymhLrFgDkRM2zXqVttpv1a0Wmrj8lCBxeeDPi jWeWdqJ3oQztod+FDfjRS1tWjA== X-Received: by 2002:adf:fb8e:: with SMTP id a14mr40487717wrr.263.1564589247173; Wed, 31 Jul 2019 09:07:27 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l2sm46099782wmj.4.2019.07.31.09.07.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:07:23 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 49F8F1FF99; Wed, 31 Jul 2019 17:07:20 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:06:34 +0100 Message-Id: <20190731160719.11396-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-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::443 Subject: [Qemu-devel] [PATCH v4 09/54] cpu: introduce cpu_in_exclusive_context() 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 , aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?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 --- 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/qom/cpu.h | 13 +++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) -- 2.20.1 Reviewed-by: Richard Henderson diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 6c85c3ee1e9..ab9dfd4f908 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -239,8 +239,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); @@ -254,7 +252,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); @@ -274,7 +271,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 3ca58c64e80..e87400834be 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -208,11 +208,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/qom/cpu.h b/include/qom/cpu.h index 5ee0046b629..65a0926c49a 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -373,6 +373,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; @@ -785,6 +786,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.