From patchwork Mon Mar 6 01:57:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 659222 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1593915wrb; Sun, 5 Mar 2023 17:58:35 -0800 (PST) X-Google-Smtp-Source: AK7set+S6VHdlrm5LCWfpqdbb7sqrf6dcvj1h+va0H+9WRrQ9mDavkLhCURyJ1GpAdo25zX7Qvi5 X-Received: by 2002:a05:622a:5c9:b0:3bf:cae4:296c with SMTP id d9-20020a05622a05c900b003bfcae4296cmr12876287qtb.65.1678067914916; Sun, 05 Mar 2023 17:58:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678067914; cv=none; d=google.com; s=arc-20160816; b=ObSWkVwqwEHTkyFpqQjMAidhjkscA/UHEz118VLWM33NvSeOB9+B45ttEDhtnAGh2e gzulpcrbF+pOCilYguK2ky0vICaVqTSdQfN1BL1pET3nRNe7J7c/FQW99flknfdg3/Cd 4drkYlMU7+FSCOY6W/yJGB+Ia0EGVGoXHDktcXHXnIFggrtxv2XJBcx8E9X7WupfgBkW jcKsFvDcfecUyPgCVqU3EhiUtgQhioi5PyqtwYM/YZ4sc+xoaVmG8zuDkp9rI2KR+mfo ZJebYw6eSNrwN3DiZ512GMPbiLrSAFtUpDquZLFhnThawMQlitZEuf4NATPaIUZ2FnrE q/Vw== 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=L77qkOSs51Hv1VBgnoUhwAR0MTuD2MxK8XGop9z/E6E=; b=dFX+99qW/3mrJ+vUM535Z0/7Z9ZPKXYAFwE7q2wSpZt4T9ZKz+dLK7xAVfa4KaMEfy AHqHGp5rfE78W6QIgr3BlU9SgIB2vI8gW/+FkyBIuQee/mQUtgfmWlmh9ir8t9dRsca+ KOP2e+ioI7AMjgDN3FL6FPVihkZjRFYCLnQD4fgIjwALiY7/jEr7eVuoi4iXVErT14Hd uIO1mtCUoAsYZ7mvN8nAQw1F5ShGbzDt+jxzrAaEKp9TKwDDFdrqjsZR5hggk+9uMsBP suP3yrGv5mDapRAX8784K6UZYOcFn9ZyRfCSPIoEAtiHjwBEQu02Bq9gqssoMADCZF8i 90zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="to/MfcvR"; 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 e3-20020a05622a110300b003b643511bd1si6465199qty.162.2023.03.05.17.58.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Mar 2023 17:58:34 -0800 (PST) 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="to/MfcvR"; 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 1pZ06L-000487-Jd; Sun, 05 Mar 2023 20:57:21 -0500 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 1pZ06G-00047V-Se for qemu-devel@nongnu.org; Sun, 05 Mar 2023 20:57:16 -0500 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZ06F-0003IR-CP for qemu-devel@nongnu.org; Sun, 05 Mar 2023 20:57:16 -0500 Received: by mail-pf1-x42f.google.com with SMTP id cp12so4788587pfb.5 for ; Sun, 05 Mar 2023 17:57:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678067834; 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=L77qkOSs51Hv1VBgnoUhwAR0MTuD2MxK8XGop9z/E6E=; b=to/MfcvR96FlKuEX2zW6r1r1qcKzhg5q0EyU8RIlH1fAHUkuGsrcgKjSA62AmZCOLs u1P4sfPygWsaBysj/N6eVd/l6qdMPOmvK0YvC6vZLSit5H9lELko4x4oceve4Yj3lA9W m7FO7TclTo6GDujWwlYbCZEsYKG1T/fWsXJrsKlsDWWi9LhyeLUgS6v9HQy0glEF05Jw sPXL8r7e4B5ITpLTjTmNHYYs/L2Cejvakbr+AwsGtoO55NNKzp7PVAIHAAmjCxFZSvxM kbF/cBd8tpouloji32WONGLRVAdanW46YtdFFQpLzftP2rFkfEBX26hNvj6iFe3RKwSR u8kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678067834; 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=L77qkOSs51Hv1VBgnoUhwAR0MTuD2MxK8XGop9z/E6E=; b=vXnxDl3AFR6iFjaLKCZd6FB+C96q9f2F2e0nQD7myX5zADO0PwlWRyMyeZMofIcZgY dfy0aiIo2KbynkE8y7TndD7xsgCpyLADIxSEdBeR6JGXpuntb9COBr41QVbITqi8svX/ 5vgHFUOl6+wn6iFJhg4TwAzvf0LIt5VLp1ijbqHIKuDgDP1R9zyAArro+epSvO0OnL8L Tz1a6P6Z26LfwS1/QEVtBzBknIOYPkTHMXoT538ZLDVICCJteUPo+b1D98RXP5akCZmK Q1BPqqo+ed+Ga+qHxgSHSesdlUTepr5oD12y+Xr4qi6ubBP7COokQp9JUgkE9tgoZUW9 rJsw== X-Gm-Message-State: AO0yUKUTbdLew9vfcXOd0oWqZtO8Q6Jl43bPZcOnzT7CJcc46efNFTWj dafJ7De8LxU37/1+T/+cF+bbiDvNiyHg36U8v8JJFA== X-Received: by 2002:aa7:98de:0:b0:5ec:702c:5880 with SMTP id e30-20020aa798de000000b005ec702c5880mr7556387pfm.32.1678067834076; Sun, 05 Mar 2023 17:57:14 -0800 (PST) Received: from stoup.. ([2602:ae:154a:9f01:87cc:49bb:2900:c08b]) by smtp.gmail.com with ESMTPSA id g23-20020aa78197000000b0061949fe3beasm2921056pfi.22.2023.03.05.17.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 17:57:13 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH v2 3/5] tcg: Create tcg_req_mo Date: Sun, 5 Mar 2023 17:57:08 -0800 Message-Id: <20230306015710.1868853-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306015710.1868853-1-richard.henderson@linaro.org> References: <20230306015710.1868853-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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 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 Split out the logic to emit a host memory barrier in response to a guest memory operation. Do not provide a true default for TCG_GUEST_DEFAULT_MO because the defined() check will still be useful for determining if a guest has been updated for MTTCG. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- include/tcg/tcg.h | 20 ++++++++++++++++++++ accel/tcg/tcg-all.c | 6 +----- tcg/tcg-op.c | 8 +------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index a5cf21be83..b76b597878 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -1171,6 +1171,26 @@ static inline size_t tcg_current_code_size(TCGContext *s) return tcg_ptr_byte_diff(s->code_ptr, s->code_buf); } +/** + * tcg_req_mo: + * @type: TCGBar + * + * Filter @type to the barrier that is required for the guest + * memory ordering vs the host memory ordering. A non-zero + * result indicates that some barrier is required. + * + * If TCG_GUEST_DEFAULT_MO is not defined, assume that the + * guest requires strict alignment. + * + * This is a macro so that it's constant even without optimization. + */ +#ifdef TCG_GUEST_DEFAULT_MO +# define tcg_req_mo(type) \ + ((type) & TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO) +#else +# define tcg_req_mo(type) ((type) & ~TCG_TARGET_DEFAULT_MO) +#endif + /** * tcg_qemu_tb_exec: * @env: pointer to CPUArchState for the CPU diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index 5dab1ae9dd..604efd1b18 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -74,11 +74,7 @@ DECLARE_INSTANCE_CHECKER(TCGState, TCG_STATE, static bool check_tcg_memory_orders_compatible(void) { -#if defined(TCG_GUEST_DEFAULT_MO) && defined(TCG_TARGET_DEFAULT_MO) - return (TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO) == 0; -#else - return false; -#endif + return tcg_req_mo(TCG_MO_ALL) == 0; } static bool default_mttcg_enabled(void) diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index 2721c1cab9..d6faf30c52 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -2930,13 +2930,7 @@ static void gen_ldst_i64(TCGOpcode opc, TCGv_i64 val, TCGv addr, static void tcg_gen_req_mo(TCGBar type) { -#ifdef TCG_GUEST_DEFAULT_MO - type &= TCG_GUEST_DEFAULT_MO; -#endif - type &= ~TCG_TARGET_DEFAULT_MO; - if (type) { - tcg_gen_mb(type | TCG_BAR_SC); - } + tcg_gen_mb(tcg_req_mo(type) | TCG_BAR_SC); } static inline TCGv plugin_prep_mem_callbacks(TCGv vaddr)