From patchwork Thu May 11 08:04:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 680886 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp3268712wrs; Thu, 11 May 2023 01:15:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6MOxR4zMa0DYTy512wWkd07qX9UbebTfwFLYWyUJSm8MtwftdYMSzVGViJPuSxN1rg2WfQ X-Received: by 2002:a05:6214:48b:b0:5ef:486a:505e with SMTP id pt11-20020a056214048b00b005ef486a505emr32520090qvb.41.1683792938698; Thu, 11 May 2023 01:15:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683792938; cv=none; d=google.com; s=arc-20160816; b=TrJb/vBNN7FaU1xFh0Uiij7Yb0qDg5YNwH825T7MgzQrYEyTgOv7Tswb7LkUXUsEVk A4uLTf18LXuhPvld2fnsWgsYifh8GGxusHFg7M8lbnCCKD88F9Z+Wu7+dSyfJy7Z6yA+ NuWGuwGZm+/ZJO3BthrDm2WrBxH9t4tPrLVZxeaEOjL8ngupjlbjMLU95rFY2uyG5PsY hL9AcAG2hYU3QUFiwri7lX2CtIzPGNsQzDWjMyLyAs8vSxjbCcoEJbGtKciItFMIr+J1 Ox8GDeHjngz6YmAXU8dIZbARJ8AY08mEoVuhgb8RDkyOkmZVgfHxGOrtIytcqCBzpsUH c3Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=1td0lL0uZaD5nr2SdTp9WbksdhKvAu45hDttDXAoNxs=; b=YhzGqvTULoi+4UWqCGA7IDcBmTeJU+1ni9kKXqyPwVr0m9mDcIXxF2A9KaFkz0WBIN ncE+A0uBXZA7j97jAgUbZvh8w5ldIfc+AHqoiRlY35Wtt8u92wVVdJFI5TqqAEsP8sN1 rxs8dX+LFTrdh5EhJro6HIKKBeomnHTHyY3LRO1kzR03P07CDQK6A9PaKhfuMtJbrCUm tWXybIDRN5MsBxep1f6DN0w25o/8xqO0i6XFqK0LTNe2FKKeZqeQKJzt3687FOigNx8z fH0IXqDKtUdgR7q08QHVuBLaTv8mRzleVBKJrQJIP0+Uq0a95vusBLloYmt0im9gUOPv VUcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OCYaw0V7; 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=pass (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 n6-20020ac85b46000000b003ef0bd2b976si3063796qtw.196.2023.05.11.01.15.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 May 2023 01:15:38 -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=pass header.i=@linaro.org header.s=google header.b=OCYaw0V7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1px1Lg-0007Lz-KI; Thu, 11 May 2023 04:08:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1px1Le-0007KT-69 for qemu-devel@nongnu.org; Thu, 11 May 2023 04:08:26 -0400 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1px1Lb-0001xz-RZ for qemu-devel@nongnu.org; Thu, 11 May 2023 04:08:25 -0400 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-50bc456cc39so12324150a12.1 for ; Thu, 11 May 2023 01:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683792502; x=1686384502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1td0lL0uZaD5nr2SdTp9WbksdhKvAu45hDttDXAoNxs=; b=OCYaw0V7XnjiaIw05stxbkjyYISym8QxhBPJDm71DvvMmug5HukivZ7j794do6Dhk4 eSMBthWCoIxsGa7OF9AWiCJgXu+uNvvrWqqc8s0bPNImeg3QVeY+cczVWP67j/rTKXM7 dyxd10x0J9b5WnBFI189G/ksD0LGrdDBnWoHpnQKuqGL9YajXclC2l4jB5FCFEMckugS 5R0Tk8imjSEkSrmjJhGlRhZHM8nK6+EL6RkRsXzTKGwEo6N5uO3YmWno3XDwB6HAwWyO QjJoaQDWhck4EzGKZU1WwMX3yVHzSNNSlMmxAmtRQVReJXgtzyFWxjIryS6x+s9ppCa8 ggyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683792502; x=1686384502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1td0lL0uZaD5nr2SdTp9WbksdhKvAu45hDttDXAoNxs=; b=Q26w4f9HQErsHdsF+09/8rPGijddLZr2P6B2uKK+ExE24eug4p6cTZSgfDwW58vreK tbtvS4/ZYij2QWm7ehHRAZBYjHrgDiJDf6QmME5pSfzV/r3d6BhdYPc0Mo5rWeiQ5q40 7K8EAoL9fb+mPwyrkZS0yK27/bvc8IeKWUCUnXrcI2xwg/CTdafDrS5bl7PXb+iXuk5G 7BHcE+0O5cghscjGk/nFqbyjVzZBmNAN8+44PYzuD4Czy3n6sQDZztHD54wVRjwrGBYN 01vxMdbBourhFHAeOjQWjufXYKhnOyyNLTbbgpZfSvsbg0uaUvSLez5W6t/MsBguzx1t 0H/A== X-Gm-Message-State: AC+VfDxsun6vdcR/aJMtdsaOLWqEzLZMv3zEOg7wYwJU0Cko62HI+G7q Sp0YCwSKduVh9d8afYIMOYiZq5BC+JCvYYTjlQIYqQ== X-Received: by 2002:a17:907:1607:b0:96a:440b:d5c8 with SMTP id hb7-20020a170907160700b0096a440bd5c8mr3113691ejc.59.1683792502557; Thu, 11 May 2023 01:08:22 -0700 (PDT) Received: from stoup.. ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ci18-20020a170907267200b00959c6cb82basm3635225ejc.105.2023.05.11.01.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 01:08:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , Peter Maydell Subject: [PULL 49/53] accel/tcg: Add cpu_in_serial_context Date: Thu, 11 May 2023 09:04:46 +0100 Message-Id: <20230511080450.860923-50-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230511080450.860923-1-richard.henderson@linaro.org> References: <20230511080450.860923-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52d; envelope-from=richard.henderson@linaro.org; helo=mail-ed1-x52d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Like cpu_in_exclusive_context, but also true if there is no other cpu against which we could race. Use it in tb_flush as a direct replacement. Use it in cpu_loop_exit_atomic to ensure that there is no loop against cpu_exec_step_atomic. Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- accel/tcg/internal.h | 9 +++++++++ accel/tcg/cpu-exec-common.c | 3 +++ accel/tcg/tb-maint.c | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/accel/tcg/internal.h b/accel/tcg/internal.h index 7bb0fdbe14..24f225cac7 100644 --- a/accel/tcg/internal.h +++ b/accel/tcg/internal.h @@ -64,6 +64,15 @@ static inline target_ulong log_pc(CPUState *cpu, const TranslationBlock *tb) } } +/* + * Return true if CS is not running in parallel with other cpus, either + * because there are no other cpus or we are within an exclusive context. + */ +static inline bool cpu_in_serial_context(CPUState *cs) +{ + return !(cs->tcg_cflags & CF_PARALLEL) || cpu_in_exclusive_context(cs); +} + extern int64_t max_delay; extern int64_t max_advance; diff --git a/accel/tcg/cpu-exec-common.c b/accel/tcg/cpu-exec-common.c index e7962c9348..9a5fabf625 100644 --- a/accel/tcg/cpu-exec-common.c +++ b/accel/tcg/cpu-exec-common.c @@ -22,6 +22,7 @@ #include "sysemu/tcg.h" #include "exec/exec-all.h" #include "qemu/plugin.h" +#include "internal.h" bool tcg_allowed; @@ -81,6 +82,8 @@ void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc) void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc) { + /* Prevent looping if already executing in a serial context. */ + g_assert(!cpu_in_serial_context(cpu)); cpu->exception_index = EXCP_ATOMIC; cpu_loop_exit_restore(cpu, pc); } diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index 0dd173fbf0..991746f80f 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -760,7 +760,7 @@ void tb_flush(CPUState *cpu) if (tcg_enabled()) { unsigned tb_flush_count = qatomic_read(&tb_ctx.tb_flush_count); - if (cpu_in_exclusive_context(cpu)) { + if (cpu_in_serial_context(cpu)) { do_tb_flush(cpu, RUN_ON_CPU_HOST_INT(tb_flush_count)); } else { async_safe_run_on_cpu(cpu, do_tb_flush,