From patchwork Sat Apr 1 04:51:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 669419 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp844044wrt; Fri, 31 Mar 2023 21:52:18 -0700 (PDT) X-Google-Smtp-Source: AKy350bkeN5esTsRCA7p2dZCvr2vVZNxxXO2Obt0KtoApXb+ijxmvSEGyTkY59Wa2qMGgSb9ok8m X-Received: by 2002:a05:6214:48e:b0:56f:8b5:3e94 with SMTP id pt14-20020a056214048e00b0056f08b53e94mr21848475qvb.14.1680324738586; Fri, 31 Mar 2023 21:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680324738; cv=none; d=google.com; s=arc-20160816; b=uW8/NQXevhxfqAcfjvkXF4i4FlnzqRe6Wxgxw5Wobv4++lhxBdP2H3QzB0K1gK+3+6 KLmMYhUBRlqwTdS6Xqvj1z2MQLMkfAh0PH/83cSz64OUKTEDgQlI2tz/bpnGatp93M0B EgrD1S7ejoOP2uVpDC3bMZW/BH+/03k8+ALpzMEKSBGCixcqYPWw74AMD03KwHz35e77 8BccFtDSpelstJY7K4zoM0ggu39/XKVOgJys1TnOwdzmDhOxIx9H4SSaxi1pcffvDJ6G lVH5bStltdTYaKLTdEABRK1oxJGkJbGbNk11kLhYWP55jgAKOiMzUgZvFPQUeLKONAy5 RssA== 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=5bGxmCesttnNxUtKHDP3pWQs68ofrrfygUflIUG0Pek=; b=RUkaniL+c0g6dn0ckFqJ2/7dsLM+cIPHgpJ4p0lR9zGhqZFYB/Tzzmm0LWFp/CfkdY MHdVW9iOrxBHfOfYmeViQPe+md4JFlG9lQ/r5Nj+HE1kfta4NZJSx0thqOGqR5/4+koZ P0p2ZRN8q3X/RDFtPgGNJt9CmQLiI4Av32UatJIZ71qEVvtbJUHcp+4nBMAE0942nD9z IbLlXeOxTamNF3YtcdjrL03UkFH5Nrhx52vtgi7XHHsKgytbUm9F2tFWj0tr2yPqcTIC s0uJiwtwPU5hBjF++76Xm1PgTEH6dOUOxDzSl+Es5fxdCHnbcotvZ6QoiW4Eod2Z2swJ U7+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="t/izS8NM"; 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 f1-20020a05622a1a0100b003e4e07e4c69si2651185qtb.775.2023.03.31.21.52.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Mar 2023 21:52:18 -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="t/izS8NM"; 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 1piTCs-0003r4-TU; Sat, 01 Apr 2023 00:51:14 -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 1piTCr-0003qY-E1 for qemu-devel@nongnu.org; Sat, 01 Apr 2023 00:51:13 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1piTCp-0003PJ-L2 for qemu-devel@nongnu.org; Sat, 01 Apr 2023 00:51:13 -0400 Received: by mail-pl1-x636.google.com with SMTP id u10so23318833plz.7 for ; Fri, 31 Mar 2023 21:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680324670; 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=5bGxmCesttnNxUtKHDP3pWQs68ofrrfygUflIUG0Pek=; b=t/izS8NMP7K+fItsIFZdOqlV+fhWYjouDJCX21+WtsH8jm1BAjOvd9xLUaU908Ktq6 xtx1RShsy5Vxjz0nXL81Jc1k3qzPPotq4gNwn2/WZD7Twl5xv2ss3+4dwrBRDjjX7pkG uFTDLuaPU8n9A+2MT08cxsdC928n+eGWFnkSJXG6QgYNBXnDMxzhnW16AK+RRJ+CVIJD M3qLZXalnzfWoboYVRJBRwkgiX6z0FVQxuRhBd5P0w++2CJdTofcOZr31Q18z9EWH2yp CoJ267vkVpIdEPFIwf2/iFwP8ycHAaAAFx1y9lj9bJwPFWKUhyNsRZIQXzU/7DWDeRDq OoEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680324670; 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=5bGxmCesttnNxUtKHDP3pWQs68ofrrfygUflIUG0Pek=; b=BtRlHDLV5mV9jo1msP4Camto/JgAr4j/qdLYFgeGek2Y3+N/75JSJgbCLVXJfn7h+/ BAFpy68aEAg3JvMCFt9l2vyDWDYYqHsgPYxIMhiWnr94BTim5xf9UEmqK4xgNLlbgyZs F8C8N8JEN3nqOPSBzLkvnAynCPCNSMT64nNaE1/SmeW1J4PCLPH+YD7PI4e3VHvqBIB8 6mxL/9CRbEqVVn2qQ8LvPYgt0r0srG44mwL3K9l1CPxNKPJS1LMPGVE30a/lG8FRNzTD H/u510dTxaHWGKfxCCFPEv1qFKUMYezbg9192f1AquW3Jj3BF0/A5g7mreZ1rF1H4WOM IcAQ== X-Gm-Message-State: AAQBX9dN42NHFb4EahbdHlar3Wr95jQtZ57IE92cJgwgUGBYBcbEQG7s EzzjqOEmVUW0DmCJDv/43v9k5dGHvZlx2ZxdWsQ= X-Received: by 2002:a17:903:2290:b0:1a1:a727:a802 with SMTP id b16-20020a170903229000b001a1a727a802mr13180560plh.19.1680324670262; Fri, 31 Mar 2023 21:51:10 -0700 (PDT) Received: from stoup.. ([2602:ae:1541:f901:b714:1fce:85fa:2fc7]) by smtp.gmail.com with ESMTPSA id a17-20020a170902ee9100b001a24cded097sm2360122pld.236.2023.03.31.21.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 21:51:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, Weiwei Li Subject: [PATCH 3/3] accel/tcg: Fix jump cache set in cpu_exec_loop Date: Fri, 31 Mar 2023 21:51:06 -0700 Message-Id: <20230401045106.3885562-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230401045106.3885562-1-richard.henderson@linaro.org> References: <20230401045106.3885562-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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 Assign pc and use store_release to assign tb. Fixes: 2dd5b7a1b91 ("accel/tcg: Move jmp-cache `CF_PCREL` checks to caller") Reported-by: Weiwei Li Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- accel/tcg/cpu-exec.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index c815f2dbfd..8370c92c05 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -257,7 +257,7 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, if (cflags & CF_PCREL) { /* Use acquire to ensure current load of pc from jc. */ - tb = qatomic_load_acquire(&jc->array[hash].tb); + tb = qatomic_load_acquire(&jc->array[hash].tb); if (likely(tb && jc->array[hash].pc == pc && @@ -272,7 +272,7 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, return NULL; } jc->array[hash].pc = pc; - /* Use store_release on tb to ensure pc is written first. */ + /* Ensure pc is written first. */ qatomic_store_release(&jc->array[hash].tb, tb); } else { /* Use rcu_read to ensure current load of pc from *tb. */ @@ -971,18 +971,27 @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc) tb = tb_lookup(cpu, pc, cs_base, flags, cflags); if (tb == NULL) { + CPUJumpCache *jc; uint32_t h; mmap_lock(); tb = tb_gen_code(cpu, pc, cs_base, flags, cflags); mmap_unlock(); + /* * We add the TB in the virtual pc hash table * for the fast lookup */ h = tb_jmp_cache_hash_func(pc); - /* Use the pc value already stored in tb->pc. */ - qatomic_set(&cpu->tb_jmp_cache->array[h].tb, tb); + jc = cpu->tb_jmp_cache; + if (cflags & CF_PCREL) { + jc->array[h].pc = pc; + /* Ensure pc is written first. */ + qatomic_store_release(&jc->array[h].tb, tb); + } else { + /* Use the pc value already stored in tb->pc. */ + qatomic_set(&jc->array[h].tb, tb); + } } #ifndef CONFIG_USER_ONLY